hexsha stringlengths 40 40 | size int64 5 1.05M | ext stringclasses 588
values | lang stringclasses 305
values | max_stars_repo_path stringlengths 3 363 | max_stars_repo_name stringlengths 5 118 | max_stars_repo_head_hexsha stringlengths 40 40 | max_stars_repo_licenses listlengths 1 10 | max_stars_count float64 1 191k ⌀ | max_stars_repo_stars_event_min_datetime stringdate 2015-01-01 00:00:35 2022-03-31 23:43:49 ⌀ | max_stars_repo_stars_event_max_datetime stringdate 2015-01-01 12:37:38 2022-03-31 23:59:52 ⌀ | max_issues_repo_path stringlengths 3 363 | max_issues_repo_name stringlengths 5 118 | max_issues_repo_head_hexsha stringlengths 40 40 | max_issues_repo_licenses listlengths 1 10 | max_issues_count float64 1 134k ⌀ | max_issues_repo_issues_event_min_datetime stringlengths 24 24 ⌀ | max_issues_repo_issues_event_max_datetime stringlengths 24 24 ⌀ | max_forks_repo_path stringlengths 3 363 | max_forks_repo_name stringlengths 5 135 | max_forks_repo_head_hexsha stringlengths 40 40 | max_forks_repo_licenses listlengths 1 10 | max_forks_count float64 1 105k ⌀ | max_forks_repo_forks_event_min_datetime stringdate 2015-01-01 00:01:02 2022-03-31 23:27:27 ⌀ | max_forks_repo_forks_event_max_datetime stringdate 2015-01-03 08:55:07 2022-03-31 23:59:24 ⌀ | content stringlengths 5 1.05M | avg_line_length float64 1.13 1.04M | max_line_length int64 1 1.05M | alphanum_fraction float64 0 1 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
cb71e73db654ef89c3b1103450a5cd178c129e82 | 6,935 | h | C | src/app/clusters/scenes/scenes.h | summercms/connectedhomeip | 5a9c063c83d039fe284fdb5afb1b7c5b5e1791b0 | [
"Apache-2.0"
] | 19 | 2021-02-17T12:31:28.000Z | 2022-03-24T09:15:43.000Z | src/app/clusters/scenes/scenes.h | summercms/connectedhomeip | 5a9c063c83d039fe284fdb5afb1b7c5b5e1791b0 | [
"Apache-2.0"
] | 18 | 2021-06-01T20:01:19.000Z | 2022-03-11T09:43:52.000Z | src/app/clusters/scenes/scenes.h | summercms/connectedhomeip | 5a9c063c83d039fe284fdb5afb1b7c5b5e1791b0 | [
"Apache-2.0"
] | 14 | 2020-12-14T11:05:45.000Z | 2022-03-29T08:42:30.000Z | /**
*
* Copyright (c) 2020 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
*
* Copyright (c) 2020 Silicon Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/****************************************************************************
* @file
* @brief Definitions for the Scenes plugin.
*******************************************************************************
******************************************************************************/
#pragma once
#include <app/CommandHandler.h>
#include <app/util/af-types.h>
#include <stdint.h>
EmberAfStatus emberAfScenesSetSceneCountAttribute(chip::EndpointId endpoint, uint8_t newCount);
EmberAfStatus emberAfScenesMakeValid(chip::EndpointId endpoint, uint8_t sceneId, chip::GroupId groupId);
// DEPRECATED.
#define emberAfScenesMakeInvalid emberAfScenesClusterMakeInvalidCallback
void emAfPluginScenesServerPrintInfo(void);
extern uint8_t emberAfPluginScenesServerEntriesInUse;
#if defined(EMBER_AF_PLUGIN_SCENES_USE_TOKENS) && !defined(EZSP_HOST)
// In this case, we use token storage
#define emberAfPluginScenesServerRetrieveSceneEntry(entry, i) halCommonGetIndexedToken(&entry, TOKEN_SCENES_TABLE, i)
#define emberAfPluginScenesServerSaveSceneEntry(entry, i) halCommonSetIndexedToken(TOKEN_SCENES_TABLE, i, &entry)
#define emberAfPluginScenesServerNumSceneEntriesInUse() \
(halCommonGetToken(&emberAfPluginScenesServerEntriesInUse, TOKEN_SCENES_NUM_ENTRIES), emberAfPluginScenesServerEntriesInUse)
#define emberAfPluginScenesServerSetNumSceneEntriesInUse(x) \
(emberAfPluginScenesServerEntriesInUse = (x), \
halCommonSetToken(TOKEN_SCENES_NUM_ENTRIES, &emberAfPluginScenesServerEntriesInUse))
#define emberAfPluginScenesServerIncrNumSceneEntriesInUse() \
((halCommonGetToken(&emberAfPluginScenesServerEntriesInUse, TOKEN_SCENES_NUM_ENTRIES), \
++emberAfPluginScenesServerEntriesInUse), \
halCommonSetToken(TOKEN_SCENES_NUM_ENTRIES, &emberAfPluginScenesServerEntriesInUse))
#define emberAfPluginScenesServerDecrNumSceneEntriesInUse() \
((halCommonGetToken(&emberAfPluginScenesServerEntriesInUse, TOKEN_SCENES_NUM_ENTRIES), \
--emberAfPluginScenesServerEntriesInUse), \
halCommonSetToken(TOKEN_SCENES_NUM_ENTRIES, &emberAfPluginScenesServerEntriesInUse))
#else
// Use normal RAM storage
extern EmberAfSceneTableEntry emberAfPluginScenesServerSceneTable[];
#define emberAfPluginScenesServerRetrieveSceneEntry(entry, i) (entry = emberAfPluginScenesServerSceneTable[i])
#define emberAfPluginScenesServerSaveSceneEntry(entry, i) (emberAfPluginScenesServerSceneTable[i] = entry)
#define emberAfPluginScenesServerNumSceneEntriesInUse() (emberAfPluginScenesServerEntriesInUse)
#define emberAfPluginScenesServerSetNumSceneEntriesInUse(x) (emberAfPluginScenesServerEntriesInUse = (x))
#define emberAfPluginScenesServerIncrNumSceneEntriesInUse() (++emberAfPluginScenesServerEntriesInUse)
#define emberAfPluginScenesServerDecrNumSceneEntriesInUse() (--emberAfPluginScenesServerEntriesInUse)
#endif // Use tokens
bool emberAfPluginScenesServerParseAddScene(chip::app::CommandHandler * commandObj, const EmberAfClusterCommand * cmd,
chip::GroupId groupId, uint8_t sceneId, uint16_t transitionTime, uint8_t * sceneName,
uint8_t * extensionFieldSets);
bool emberAfPluginScenesServerParseViewScene(chip::app::CommandHandler * commandObj, const EmberAfClusterCommand * cmd,
chip::GroupId groupId, uint8_t sceneId);
/** @brief Scenes Cluster Recall Saved Scene
*
* This function is called by the framework when the application should recall a
* saved scene.
*
* @param endpoint The endpoint. Ver.: always
* @param groupId The group identifier. Ver.: always
* @param sceneId The scene identifier. Ver.: always
*/
EmberAfStatus emberAfScenesClusterRecallSavedSceneCallback(chip::EndpointId endpoint, chip::GroupId groupId, uint8_t sceneId);
/** @brief Scenes Cluster Store Current Scene
*
* This function is called by the framework when the application should store
* the current scene. If an entry already exists in the scene table with the
* same scene and group ids, the application should update the entry with the
* current scene. Otherwise, a new entry should be adde to the scene table, if
* possible.
*
* @param endpoint The endpoint. Ver.: always
* @param groupId The group identifier. Ver.: always
* @param sceneId The scene identifier. Ver.: always
*/
EmberAfStatus emberAfScenesClusterStoreCurrentSceneCallback(chip::EndpointId endpoint, chip::GroupId groupId, uint8_t sceneId);
/** @brief Scenes Cluster Remove Scenes In Group
*
* This function removes the scenes from a specified group.
*
* @param endpoint Endpoint Ver.: always
* @param groupId Group ID Ver.: always
*/
void emberAfScenesClusterRemoveScenesInGroupCallback(chip::EndpointId endpoint, chip::GroupId groupId);
/** @brief Scenes Cluster Make Invalid
*
* This function is called to invalidate the valid attribute in the Scenes
* cluster.
*
* @param endpoint Ver.: always
*/
EmberAfStatus emberAfScenesClusterMakeInvalidCallback(chip::EndpointId endpoint);
| 52.938931 | 132 | 0.679019 |
8b2dcb92ef6b78e1520216337ceefe368f82b5d4 | 1,543 | h | C | ReferenceDesign/SampleQTHMI/Message/data/MessageData.h | zenghuan1/HMI_SDK_LIB | d0d03af04abe07f5ca087cabcbb1e4f4858f266a | [
"BSD-3-Clause"
] | 8 | 2019-01-04T10:08:39.000Z | 2021-12-13T16:34:08.000Z | ReferenceDesign/SampleQTHMI/Message/data/MessageData.h | zenghuan1/HMI_SDK_LIB | d0d03af04abe07f5ca087cabcbb1e4f4858f266a | [
"BSD-3-Clause"
] | 33 | 2017-07-27T09:51:59.000Z | 2018-07-13T09:45:52.000Z | ReferenceDesign/SampleQTHMI/Message/data/MessageData.h | JH-G/HMI_SDK_LIB | caa4eac66d1f3b76349ef5d6ca5cf7dd69fcd760 | [
"BSD-3-Clause"
] | 12 | 2017-07-28T02:54:53.000Z | 2022-02-20T15:48:24.000Z | #ifndef MESSAGEDATA_H
#define MESSAGEDATA_H
#include <iostream>
#include <QObject>
#include <QList>
#include <map>
#include <string>
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <QDate>
#include <QTime>
using namespace std;
struct TLastMessageInfo{
QString textContent;
QDate date;
QTime time;
bool isIn;
bool isSuccess; // send message
};
struct TText{
int sessionId;
int contactId;
QString content;
QString number;
QString picture;
QTime time;
QDate date;
bool isIn;
QString telNumTo;
QString telNumFrom;
};
struct TSessionList{
int sessionId;
int contactId;
QString lastName;
QString firstName;
QString number;
QString picture;
QString telNumFrom;
TLastMessageInfo lastInfo;
};
class MessageData : public QObject
{
Q_OBJECT
explicit MessageData();
public:
static MessageData*Inst();
void InitNameMap();
void InitTestMessageData();
void InitTestMessageListData();
QList<TText *> &GetMessageData();
QList<TSessionList *> &GetMessageListData();
void SetSessionId(int id);
int GetSessionId();
void SetViewId(int id);
int GetViewId();
signals:
public slots:
private:
static MessageData* m_pInst;
QList<TText*> m_messageData;
QList<TSessionList*> m_messageListData;
QString m_callName;
QString m_callNumber;
int m_callTime;
QString m_callStatus;
int m_iViewId;
int m_iSessionId;
QString m_telNum;
};
#endif // MESSAGEDATA_H
| 17.337079 | 48 | 0.684381 |
8b34b2b8bed2188d367fd17608a351523b3109c8 | 423,945 | c | C | src/frr/bgpd/bgp_route.c | zhouhaifeng/vpe | 9c644ffd561988e5740021ed26e0f7739844353d | [
"Apache-2.0"
] | null | null | null | src/frr/bgpd/bgp_route.c | zhouhaifeng/vpe | 9c644ffd561988e5740021ed26e0f7739844353d | [
"Apache-2.0"
] | null | null | null | src/frr/bgpd/bgp_route.c | zhouhaifeng/vpe | 9c644ffd561988e5740021ed26e0f7739844353d | [
"Apache-2.0"
] | null | null | null | /* BGP routing information
* Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
* Copyright (C) 2016 Job Snijders <job@instituut.net>
*
* This file is part of GNU Zebra.
*
* GNU Zebra 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, or (at your option) any
* later version.
*
* GNU Zebra 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; see the file COPYING; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include <math.h>
#include "printfrr.h"
#include "frrstr.h"
#include "prefix.h"
#include "linklist.h"
#include "memory.h"
#include "command.h"
#include "stream.h"
#include "filter.h"
#include "log.h"
#include "routemap.h"
#include "buffer.h"
#include "sockunion.h"
#include "plist.h"
#include "thread.h"
#include "workqueue.h"
#include "queue.h"
#include "memory.h"
#include "srv6.h"
#include "lib/json.h"
#include "lib_errors.h"
#include "zclient.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_table.h"
#include "bgpd/bgp_route.h"
#include "bgpd/bgp_attr.h"
#include "bgpd/bgp_debug.h"
#include "bgpd/bgp_errors.h"
#include "bgpd/bgp_aspath.h"
#include "bgpd/bgp_regex.h"
#include "bgpd/bgp_community.h"
#include "bgpd/bgp_community_alias.h"
#include "bgpd/bgp_ecommunity.h"
#include "bgpd/bgp_lcommunity.h"
#include "bgpd/bgp_clist.h"
#include "bgpd/bgp_packet.h"
#include "bgpd/bgp_filter.h"
#include "bgpd/bgp_fsm.h"
#include "bgpd/bgp_mplsvpn.h"
#include "bgpd/bgp_nexthop.h"
#include "bgpd/bgp_damp.h"
#include "bgpd/bgp_advertise.h"
#include "bgpd/bgp_zebra.h"
#include "bgpd/bgp_vty.h"
#include "bgpd/bgp_mpath.h"
#include "bgpd/bgp_nht.h"
#include "bgpd/bgp_updgrp.h"
#include "bgpd/bgp_label.h"
#include "bgpd/bgp_addpath.h"
#include "bgpd/bgp_mac.h"
#include "bgpd/bgp_network.h"
#include "bgpd/bgp_trace.h"
#include "bgpd/bgp_rpki.h"
#ifdef ENABLE_BGP_VNC
#include "bgpd/rfapi/rfapi_backend.h"
#include "bgpd/rfapi/vnc_import_bgp.h"
#include "bgpd/rfapi/vnc_export_bgp.h"
#endif
#include "bgpd/bgp_encap_types.h"
#include "bgpd/bgp_encap_tlv.h"
#include "bgpd/bgp_evpn.h"
#include "bgpd/bgp_evpn_mh.h"
#include "bgpd/bgp_evpn_vty.h"
#include "bgpd/bgp_flowspec.h"
#include "bgpd/bgp_flowspec_util.h"
#include "bgpd/bgp_pbr.h"
#ifndef VTYSH_EXTRACT_PL
#include "bgpd/bgp_route_clippy.c"
#endif
DEFINE_HOOK(bgp_snmp_update_stats,
(struct bgp_node *rn, struct bgp_path_info *pi, bool added),
(rn, pi, added));
DEFINE_HOOK(bgp_rpki_prefix_status,
(struct peer *peer, struct attr *attr,
const struct prefix *prefix),
(peer, attr, prefix));
/* Extern from bgp_dump.c */
extern const char *bgp_origin_str[];
extern const char *bgp_origin_long_str[];
/* PMSI strings. */
#define PMSI_TNLTYPE_STR_NO_INFO "No info"
#define PMSI_TNLTYPE_STR_DEFAULT PMSI_TNLTYPE_STR_NO_INFO
static const struct message bgp_pmsi_tnltype_str[] = {
{PMSI_TNLTYPE_NO_INFO, PMSI_TNLTYPE_STR_NO_INFO},
{PMSI_TNLTYPE_RSVP_TE_P2MP, "RSVP-TE P2MP"},
{PMSI_TNLTYPE_MLDP_P2MP, "mLDP P2MP"},
{PMSI_TNLTYPE_PIM_SSM, "PIM-SSM"},
{PMSI_TNLTYPE_PIM_SM, "PIM-SM"},
{PMSI_TNLTYPE_PIM_BIDIR, "PIM-BIDIR"},
{PMSI_TNLTYPE_INGR_REPL, "Ingress Replication"},
{PMSI_TNLTYPE_MLDP_MP2MP, "mLDP MP2MP"},
{0}
};
#define VRFID_NONE_STR "-"
#define SOFT_RECONFIG_TASK_MAX_PREFIX 25000
DEFINE_HOOK(bgp_process,
(struct bgp * bgp, afi_t afi, safi_t safi, struct bgp_dest *bn,
struct peer *peer, bool withdraw),
(bgp, afi, safi, bn, peer, withdraw));
/** Test if path is suppressed. */
static bool bgp_path_suppressed(struct bgp_path_info *pi)
{
if (pi->extra == NULL || pi->extra->aggr_suppressors == NULL)
return false;
return listcount(pi->extra->aggr_suppressors) > 0;
}
struct bgp_dest *bgp_afi_node_get(struct bgp_table *table, afi_t afi,
safi_t safi, const struct prefix *p,
struct prefix_rd *prd)
{
struct bgp_dest *dest;
struct bgp_dest *pdest = NULL;
assert(table);
if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)
|| (safi == SAFI_EVPN)) {
pdest = bgp_node_get(table, (struct prefix *)prd);
if (!bgp_dest_has_bgp_path_info_data(pdest))
bgp_dest_set_bgp_table_info(
pdest, bgp_table_init(table->bgp, afi, safi));
else
bgp_dest_unlock_node(pdest);
table = bgp_dest_get_bgp_table_info(pdest);
}
dest = bgp_node_get(table, p);
if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)
|| (safi == SAFI_EVPN))
dest->pdest = pdest;
return dest;
}
struct bgp_dest *bgp_afi_node_lookup(struct bgp_table *table, afi_t afi,
safi_t safi, const struct prefix *p,
struct prefix_rd *prd)
{
struct bgp_dest *dest;
struct bgp_dest *pdest = NULL;
if (!table)
return NULL;
if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)
|| (safi == SAFI_EVPN)) {
pdest = bgp_node_lookup(table, (struct prefix *)prd);
if (!pdest)
return NULL;
if (!bgp_dest_has_bgp_path_info_data(pdest)) {
bgp_dest_unlock_node(pdest);
return NULL;
}
table = bgp_dest_get_bgp_table_info(pdest);
}
dest = bgp_node_lookup(table, p);
return dest;
}
/* Allocate bgp_path_info_extra */
static struct bgp_path_info_extra *bgp_path_info_extra_new(void)
{
struct bgp_path_info_extra *new;
new = XCALLOC(MTYPE_BGP_ROUTE_EXTRA,
sizeof(struct bgp_path_info_extra));
new->label[0] = MPLS_INVALID_LABEL;
new->num_labels = 0;
new->bgp_fs_pbr = NULL;
new->bgp_fs_iprule = NULL;
return new;
}
void bgp_path_info_extra_free(struct bgp_path_info_extra **extra)
{
struct bgp_path_info_extra *e;
if (!extra || !*extra)
return;
e = *extra;
if (e->damp_info)
bgp_damp_info_free(e->damp_info, 0, e->damp_info->afi,
e->damp_info->safi);
e->damp_info = NULL;
if (e->parent) {
struct bgp_path_info *bpi = (struct bgp_path_info *)e->parent;
if (bpi->net) {
/* FIXME: since multiple e may have the same e->parent
* and e->parent->net is holding a refcount for each
* of them, we need to do some fudging here.
*
* WARNING: if bpi->net->lock drops to 0, bpi may be
* freed as well (because bpi->net was holding the
* last reference to bpi) => write after free!
*/
unsigned refcount;
bpi = bgp_path_info_lock(bpi);
refcount = bgp_dest_get_lock_count(bpi->net) - 1;
bgp_dest_unlock_node((struct bgp_dest *)bpi->net);
if (!refcount)
bpi->net = NULL;
bgp_path_info_unlock(bpi);
}
bgp_path_info_unlock(e->parent);
e->parent = NULL;
}
if (e->bgp_orig)
bgp_unlock(e->bgp_orig);
if (e->aggr_suppressors)
list_delete(&e->aggr_suppressors);
if (e->mh_info)
bgp_evpn_path_mh_info_free(e->mh_info);
if ((*extra)->bgp_fs_iprule)
list_delete(&((*extra)->bgp_fs_iprule));
if ((*extra)->bgp_fs_pbr)
list_delete(&((*extra)->bgp_fs_pbr));
XFREE(MTYPE_BGP_ROUTE_EXTRA, *extra);
}
/* Get bgp_path_info extra information for the given bgp_path_info, lazy
* allocated if required.
*/
struct bgp_path_info_extra *bgp_path_info_extra_get(struct bgp_path_info *pi)
{
if (!pi->extra)
pi->extra = bgp_path_info_extra_new();
return pi->extra;
}
/* Free bgp route information. */
static void bgp_path_info_free(struct bgp_path_info *path)
{
bgp_attr_unintern(&path->attr);
bgp_unlink_nexthop(path);
bgp_path_info_extra_free(&path->extra);
bgp_path_info_mpath_free(&path->mpath);
if (path->net)
bgp_addpath_free_info_data(&path->tx_addpath,
&path->net->tx_addpath);
peer_unlock(path->peer); /* bgp_path_info peer reference */
XFREE(MTYPE_BGP_ROUTE, path);
}
struct bgp_path_info *bgp_path_info_lock(struct bgp_path_info *path)
{
path->lock++;
return path;
}
struct bgp_path_info *bgp_path_info_unlock(struct bgp_path_info *path)
{
assert(path && path->lock > 0);
path->lock--;
if (path->lock == 0) {
#if 0
zlog_debug ("%s: unlocked and freeing", __func__);
zlog_backtrace (LOG_DEBUG);
#endif
bgp_path_info_free(path);
return NULL;
}
#if 0
if (path->lock == 1)
{
zlog_debug ("%s: unlocked to 1", __func__);
zlog_backtrace (LOG_DEBUG);
}
#endif
return path;
}
/* This function sets flag BGP_NODE_SELECT_DEFER based on condition */
static int bgp_dest_set_defer_flag(struct bgp_dest *dest, bool delete)
{
struct peer *peer;
struct bgp_path_info *old_pi, *nextpi;
bool set_flag = false;
struct bgp *bgp = NULL;
struct bgp_table *table = NULL;
afi_t afi = 0;
safi_t safi = 0;
/* If the flag BGP_NODE_SELECT_DEFER is set and new path is added
* then the route selection is deferred
*/
if (CHECK_FLAG(dest->flags, BGP_NODE_SELECT_DEFER) && (!delete))
return 0;
if (CHECK_FLAG(dest->flags, BGP_NODE_PROCESS_SCHEDULED)) {
if (BGP_DEBUG(update, UPDATE_OUT))
zlog_debug(
"Route %pBD is in workqueue and being processed, not deferred.",
dest);
return 0;
}
table = bgp_dest_table(dest);
if (table) {
bgp = table->bgp;
afi = table->afi;
safi = table->safi;
}
for (old_pi = bgp_dest_get_bgp_path_info(dest);
(old_pi != NULL) && (nextpi = old_pi->next, 1); old_pi = nextpi) {
if (CHECK_FLAG(old_pi->flags, BGP_PATH_SELECTED))
continue;
/* Route selection is deferred if there is a stale path which
* which indicates peer is in restart mode
*/
if (CHECK_FLAG(old_pi->flags, BGP_PATH_STALE)
&& (old_pi->sub_type == BGP_ROUTE_NORMAL)) {
set_flag = true;
} else {
/* If the peer is graceful restart capable and peer is
* restarting mode, set the flag BGP_NODE_SELECT_DEFER
*/
peer = old_pi->peer;
if (BGP_PEER_GRACEFUL_RESTART_CAPABLE(peer)
&& BGP_PEER_RESTARTING_MODE(peer)
&& (old_pi
&& old_pi->sub_type == BGP_ROUTE_NORMAL)) {
set_flag = true;
}
}
if (set_flag)
break;
}
/* Set the flag BGP_NODE_SELECT_DEFER if route selection deferral timer
* is active
*/
if (set_flag && table) {
if (bgp && (bgp->gr_info[afi][safi].t_select_deferral)) {
if (!CHECK_FLAG(dest->flags, BGP_NODE_SELECT_DEFER))
bgp->gr_info[afi][safi].gr_deferred++;
SET_FLAG(dest->flags, BGP_NODE_SELECT_DEFER);
if (BGP_DEBUG(update, UPDATE_OUT))
zlog_debug("DEFER route %pBD, dest %p", dest,
dest);
return 0;
}
}
return -1;
}
void bgp_path_info_add(struct bgp_dest *dest, struct bgp_path_info *pi)
{
struct bgp_path_info *top;
top = bgp_dest_get_bgp_path_info(dest);
pi->next = top;
pi->prev = NULL;
if (top)
top->prev = pi;
bgp_dest_set_bgp_path_info(dest, pi);
bgp_path_info_lock(pi);
bgp_dest_lock_node(dest);
peer_lock(pi->peer); /* bgp_path_info peer reference */
bgp_dest_set_defer_flag(dest, false);
hook_call(bgp_snmp_update_stats, dest, pi, true);
}
/* Do the actual removal of info from RIB, for use by bgp_process
completion callback *only* */
void bgp_path_info_reap(struct bgp_dest *dest, struct bgp_path_info *pi)
{
if (pi->next)
pi->next->prev = pi->prev;
if (pi->prev)
pi->prev->next = pi->next;
else
bgp_dest_set_bgp_path_info(dest, pi->next);
bgp_path_info_mpath_dequeue(pi);
bgp_path_info_unlock(pi);
hook_call(bgp_snmp_update_stats, dest, pi, false);
bgp_dest_unlock_node(dest);
}
void bgp_path_info_delete(struct bgp_dest *dest, struct bgp_path_info *pi)
{
bgp_path_info_set_flag(dest, pi, BGP_PATH_REMOVED);
/* set of previous already took care of pcount */
UNSET_FLAG(pi->flags, BGP_PATH_VALID);
}
/* undo the effects of a previous call to bgp_path_info_delete; typically
called when a route is deleted and then quickly re-added before the
deletion has been processed */
void bgp_path_info_restore(struct bgp_dest *dest, struct bgp_path_info *pi)
{
bgp_path_info_unset_flag(dest, pi, BGP_PATH_REMOVED);
/* unset of previous already took care of pcount */
SET_FLAG(pi->flags, BGP_PATH_VALID);
}
/* Adjust pcount as required */
static void bgp_pcount_adjust(struct bgp_dest *dest, struct bgp_path_info *pi)
{
struct bgp_table *table;
assert(dest && bgp_dest_table(dest));
assert(pi && pi->peer && pi->peer->bgp);
table = bgp_dest_table(dest);
if (pi->peer == pi->peer->bgp->peer_self)
return;
if (!BGP_PATH_COUNTABLE(pi)
&& CHECK_FLAG(pi->flags, BGP_PATH_COUNTED)) {
UNSET_FLAG(pi->flags, BGP_PATH_COUNTED);
/* slight hack, but more robust against errors. */
if (pi->peer->pcount[table->afi][table->safi])
pi->peer->pcount[table->afi][table->safi]--;
else
flog_err(EC_LIB_DEVELOPMENT,
"Asked to decrement 0 prefix count for peer");
} else if (BGP_PATH_COUNTABLE(pi)
&& !CHECK_FLAG(pi->flags, BGP_PATH_COUNTED)) {
SET_FLAG(pi->flags, BGP_PATH_COUNTED);
pi->peer->pcount[table->afi][table->safi]++;
}
}
static int bgp_label_index_differs(struct bgp_path_info *pi1,
struct bgp_path_info *pi2)
{
return (!(pi1->attr->label_index == pi2->attr->label_index));
}
/* Set/unset bgp_path_info flags, adjusting any other state as needed.
* This is here primarily to keep prefix-count in check.
*/
void bgp_path_info_set_flag(struct bgp_dest *dest, struct bgp_path_info *pi,
uint32_t flag)
{
SET_FLAG(pi->flags, flag);
/* early bath if we know it's not a flag that changes countability state
*/
if (!CHECK_FLAG(flag,
BGP_PATH_VALID | BGP_PATH_HISTORY | BGP_PATH_REMOVED))
return;
bgp_pcount_adjust(dest, pi);
}
void bgp_path_info_unset_flag(struct bgp_dest *dest, struct bgp_path_info *pi,
uint32_t flag)
{
UNSET_FLAG(pi->flags, flag);
/* early bath if we know it's not a flag that changes countability state
*/
if (!CHECK_FLAG(flag,
BGP_PATH_VALID | BGP_PATH_HISTORY | BGP_PATH_REMOVED))
return;
bgp_pcount_adjust(dest, pi);
}
/* Get MED value. If MED value is missing and "bgp bestpath
missing-as-worst" is specified, treat it as the worst value. */
static uint32_t bgp_med_value(struct attr *attr, struct bgp *bgp)
{
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
return attr->med;
else {
if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
return BGP_MED_MAX;
else
return 0;
}
}
void bgp_path_info_path_with_addpath_rx_str(struct bgp_path_info *pi, char *buf,
size_t buf_len)
{
if (pi->addpath_rx_id)
snprintf(buf, buf_len, "path %s (addpath rxid %d)",
pi->peer->host, pi->addpath_rx_id);
else
snprintf(buf, buf_len, "path %s", pi->peer->host);
}
/* Compare two bgp route entity. If 'new' is preferable over 'exist' return 1.
*/
static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
struct bgp_path_info *exist, int *paths_eq,
struct bgp_maxpaths_cfg *mpath_cfg, int debug,
char *pfx_buf, afi_t afi, safi_t safi,
enum bgp_path_selection_reason *reason)
{
const struct prefix *new_p;
struct attr *newattr, *existattr;
bgp_peer_sort_t new_sort;
bgp_peer_sort_t exist_sort;
uint32_t new_pref;
uint32_t exist_pref;
uint32_t new_med;
uint32_t exist_med;
uint32_t new_weight;
uint32_t exist_weight;
uint32_t newm, existm;
struct in_addr new_id;
struct in_addr exist_id;
int new_cluster;
int exist_cluster;
int internal_as_route;
int confed_as_route;
int ret = 0;
int igp_metric_ret = 0;
int peer_sort_ret = -1;
char new_buf[PATH_ADDPATH_STR_BUFFER];
char exist_buf[PATH_ADDPATH_STR_BUFFER];
uint32_t new_mm_seq;
uint32_t exist_mm_seq;
int nh_cmp;
esi_t *exist_esi;
esi_t *new_esi;
bool same_esi;
bool old_proxy;
bool new_proxy;
bool new_origin, exist_origin;
*paths_eq = 0;
/* 0. Null check. */
if (new == NULL) {
*reason = bgp_path_selection_none;
if (debug)
zlog_debug("%s: new is NULL", pfx_buf);
return 0;
}
if (debug)
bgp_path_info_path_with_addpath_rx_str(new, new_buf,
sizeof(new_buf));
if (exist == NULL) {
*reason = bgp_path_selection_first;
if (debug)
zlog_debug("%s: %s is the initial bestpath", pfx_buf,
new_buf);
return 1;
}
if (debug) {
bgp_path_info_path_with_addpath_rx_str(exist, exist_buf,
sizeof(exist_buf));
zlog_debug("%s: Comparing %s flags 0x%x with %s flags 0x%x",
pfx_buf, new_buf, new->flags, exist_buf,
exist->flags);
}
newattr = new->attr;
existattr = exist->attr;
new_p = bgp_dest_get_prefix(new->net);
/* For EVPN routes, we cannot just go by local vs remote, we have to
* look at the MAC mobility sequence number, if present.
*/
if ((safi == SAFI_EVPN)
&& (new_p->u.prefix_evpn.route_type == BGP_EVPN_MAC_IP_ROUTE)) {
/* This is an error condition described in RFC 7432 Section
* 15.2. The RFC
* states that in this scenario "the PE MUST alert the operator"
* but it
* does not state what other action to take. In order to provide
* some
* consistency in this scenario we are going to prefer the path
* with the
* sticky flag.
*/
if (newattr->sticky != existattr->sticky) {
if (!debug) {
prefix2str(new_p, pfx_buf,
sizeof(*pfx_buf)
* PREFIX2STR_BUFFER);
bgp_path_info_path_with_addpath_rx_str(
new, new_buf, sizeof(new_buf));
bgp_path_info_path_with_addpath_rx_str(
exist, exist_buf, sizeof(exist_buf));
}
if (newattr->sticky && !existattr->sticky) {
*reason = bgp_path_selection_evpn_sticky_mac;
if (debug)
zlog_debug(
"%s: %s wins over %s due to sticky MAC flag",
pfx_buf, new_buf, exist_buf);
return 1;
}
if (!newattr->sticky && existattr->sticky) {
*reason = bgp_path_selection_evpn_sticky_mac;
if (debug)
zlog_debug(
"%s: %s loses to %s due to sticky MAC flag",
pfx_buf, new_buf, exist_buf);
return 0;
}
}
new_esi = bgp_evpn_attr_get_esi(newattr);
exist_esi = bgp_evpn_attr_get_esi(existattr);
if (bgp_evpn_is_esi_valid(new_esi) &&
!memcmp(new_esi, exist_esi, sizeof(esi_t))) {
same_esi = true;
} else {
same_esi = false;
}
/* If both paths have the same non-zero ES and
* one path is local it wins.
* PS: Note the local path wins even if the remote
* has the higher MM seq. The local path's
* MM seq will be fixed up to match the highest
* rem seq, subsequently.
*/
if (same_esi) {
char esi_buf[ESI_STR_LEN];
if (bgp_evpn_is_path_local(bgp, new)) {
*reason = bgp_path_selection_evpn_local_path;
if (debug)
zlog_debug(
"%s: %s wins over %s as ES %s is same and local",
pfx_buf, new_buf, exist_buf,
esi_to_str(new_esi, esi_buf,
sizeof(esi_buf)));
return 1;
}
if (bgp_evpn_is_path_local(bgp, exist)) {
*reason = bgp_path_selection_evpn_local_path;
if (debug)
zlog_debug(
"%s: %s loses to %s as ES %s is same and local",
pfx_buf, new_buf, exist_buf,
esi_to_str(new_esi, esi_buf,
sizeof(esi_buf)));
return 0;
}
}
new_mm_seq = mac_mobility_seqnum(newattr);
exist_mm_seq = mac_mobility_seqnum(existattr);
if (new_mm_seq > exist_mm_seq) {
*reason = bgp_path_selection_evpn_seq;
if (debug)
zlog_debug(
"%s: %s wins over %s due to MM seq %u > %u",
pfx_buf, new_buf, exist_buf, new_mm_seq,
exist_mm_seq);
return 1;
}
if (new_mm_seq < exist_mm_seq) {
*reason = bgp_path_selection_evpn_seq;
if (debug)
zlog_debug(
"%s: %s loses to %s due to MM seq %u < %u",
pfx_buf, new_buf, exist_buf, new_mm_seq,
exist_mm_seq);
return 0;
}
/* if the sequence numbers and ESI are the same and one path
* is non-proxy it wins (over proxy)
*/
new_proxy = bgp_evpn_attr_is_proxy(newattr);
old_proxy = bgp_evpn_attr_is_proxy(existattr);
if (same_esi && bgp_evpn_attr_is_local_es(newattr) &&
old_proxy != new_proxy) {
if (!new_proxy) {
*reason = bgp_path_selection_evpn_non_proxy;
if (debug)
zlog_debug(
"%s: %s wins over %s, same seq/es and non-proxy",
pfx_buf, new_buf, exist_buf);
return 1;
}
*reason = bgp_path_selection_evpn_non_proxy;
if (debug)
zlog_debug(
"%s: %s loses to %s, same seq/es and non-proxy",
pfx_buf, new_buf, exist_buf);
return 0;
}
/*
* if sequence numbers are the same path with the lowest IP
* wins
*/
nh_cmp = bgp_path_info_nexthop_cmp(new, exist);
if (nh_cmp < 0) {
*reason = bgp_path_selection_evpn_lower_ip;
if (debug)
zlog_debug(
"%s: %s wins over %s due to same MM seq %u and lower IP %pI4",
pfx_buf, new_buf, exist_buf, new_mm_seq,
&new->attr->nexthop);
return 1;
}
if (nh_cmp > 0) {
*reason = bgp_path_selection_evpn_lower_ip;
if (debug)
zlog_debug(
"%s: %s loses to %s due to same MM seq %u and higher IP %pI4",
pfx_buf, new_buf, exist_buf, new_mm_seq,
&new->attr->nexthop);
return 0;
}
}
/* 1. Weight check. */
new_weight = newattr->weight;
exist_weight = existattr->weight;
if (new_weight > exist_weight) {
*reason = bgp_path_selection_weight;
if (debug)
zlog_debug("%s: %s wins over %s due to weight %d > %d",
pfx_buf, new_buf, exist_buf, new_weight,
exist_weight);
return 1;
}
if (new_weight < exist_weight) {
*reason = bgp_path_selection_weight;
if (debug)
zlog_debug("%s: %s loses to %s due to weight %d < %d",
pfx_buf, new_buf, exist_buf, new_weight,
exist_weight);
return 0;
}
/* 2. Local preference check. */
new_pref = exist_pref = bgp->default_local_pref;
if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
new_pref = newattr->local_pref;
if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
exist_pref = existattr->local_pref;
if (new_pref > exist_pref) {
*reason = bgp_path_selection_local_pref;
if (debug)
zlog_debug(
"%s: %s wins over %s due to localpref %d > %d",
pfx_buf, new_buf, exist_buf, new_pref,
exist_pref);
return 1;
}
if (new_pref < exist_pref) {
*reason = bgp_path_selection_local_pref;
if (debug)
zlog_debug(
"%s: %s loses to %s due to localpref %d < %d",
pfx_buf, new_buf, exist_buf, new_pref,
exist_pref);
return 0;
}
/* 3. Local route check. We prefer:
* - BGP_ROUTE_STATIC
* - BGP_ROUTE_AGGREGATE
* - BGP_ROUTE_REDISTRIBUTE
*/
new_origin = !(new->sub_type == BGP_ROUTE_NORMAL ||
new->sub_type == BGP_ROUTE_IMPORTED);
exist_origin = !(exist->sub_type == BGP_ROUTE_NORMAL ||
exist->sub_type == BGP_ROUTE_IMPORTED);
if (new_origin && !exist_origin) {
*reason = bgp_path_selection_local_route;
if (debug)
zlog_debug(
"%s: %s wins over %s due to preferred BGP_ROUTE type",
pfx_buf, new_buf, exist_buf);
return 1;
}
if (!new_origin && exist_origin) {
*reason = bgp_path_selection_local_route;
if (debug)
zlog_debug(
"%s: %s loses to %s due to preferred BGP_ROUTE type",
pfx_buf, new_buf, exist_buf);
return 0;
}
/* 4. AS path length check. */
if (!CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE)) {
int exist_hops = aspath_count_hops(existattr->aspath);
int exist_confeds = aspath_count_confeds(existattr->aspath);
if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED)) {
int aspath_hops;
aspath_hops = aspath_count_hops(newattr->aspath);
aspath_hops += aspath_count_confeds(newattr->aspath);
if (aspath_hops < (exist_hops + exist_confeds)) {
*reason = bgp_path_selection_confed_as_path;
if (debug)
zlog_debug(
"%s: %s wins over %s due to aspath (with confeds) hopcount %d < %d",
pfx_buf, new_buf, exist_buf,
aspath_hops,
(exist_hops + exist_confeds));
return 1;
}
if (aspath_hops > (exist_hops + exist_confeds)) {
*reason = bgp_path_selection_confed_as_path;
if (debug)
zlog_debug(
"%s: %s loses to %s due to aspath (with confeds) hopcount %d > %d",
pfx_buf, new_buf, exist_buf,
aspath_hops,
(exist_hops + exist_confeds));
return 0;
}
} else {
int newhops = aspath_count_hops(newattr->aspath);
if (newhops < exist_hops) {
*reason = bgp_path_selection_as_path;
if (debug)
zlog_debug(
"%s: %s wins over %s due to aspath hopcount %d < %d",
pfx_buf, new_buf, exist_buf,
newhops, exist_hops);
return 1;
}
if (newhops > exist_hops) {
*reason = bgp_path_selection_as_path;
if (debug)
zlog_debug(
"%s: %s loses to %s due to aspath hopcount %d > %d",
pfx_buf, new_buf, exist_buf,
newhops, exist_hops);
return 0;
}
}
}
/* 5. Origin check. */
if (newattr->origin < existattr->origin) {
*reason = bgp_path_selection_origin;
if (debug)
zlog_debug("%s: %s wins over %s due to ORIGIN %s < %s",
pfx_buf, new_buf, exist_buf,
bgp_origin_long_str[newattr->origin],
bgp_origin_long_str[existattr->origin]);
return 1;
}
if (newattr->origin > existattr->origin) {
*reason = bgp_path_selection_origin;
if (debug)
zlog_debug("%s: %s loses to %s due to ORIGIN %s > %s",
pfx_buf, new_buf, exist_buf,
bgp_origin_long_str[newattr->origin],
bgp_origin_long_str[existattr->origin]);
return 0;
}
/* 6. MED check. */
internal_as_route = (aspath_count_hops(newattr->aspath) == 0
&& aspath_count_hops(existattr->aspath) == 0);
confed_as_route = (aspath_count_confeds(newattr->aspath) > 0
&& aspath_count_confeds(existattr->aspath) > 0
&& aspath_count_hops(newattr->aspath) == 0
&& aspath_count_hops(existattr->aspath) == 0);
if (CHECK_FLAG(bgp->flags, BGP_FLAG_ALWAYS_COMPARE_MED)
|| (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED) && confed_as_route)
|| aspath_cmp_left(newattr->aspath, existattr->aspath)
|| aspath_cmp_left_confed(newattr->aspath, existattr->aspath)
|| internal_as_route) {
new_med = bgp_med_value(new->attr, bgp);
exist_med = bgp_med_value(exist->attr, bgp);
if (new_med < exist_med) {
*reason = bgp_path_selection_med;
if (debug)
zlog_debug(
"%s: %s wins over %s due to MED %d < %d",
pfx_buf, new_buf, exist_buf, new_med,
exist_med);
return 1;
}
if (new_med > exist_med) {
*reason = bgp_path_selection_med;
if (debug)
zlog_debug(
"%s: %s loses to %s due to MED %d > %d",
pfx_buf, new_buf, exist_buf, new_med,
exist_med);
return 0;
}
}
/* 7. Peer type check. */
new_sort = new->peer->sort;
exist_sort = exist->peer->sort;
if (new_sort == BGP_PEER_EBGP
&& (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED)) {
*reason = bgp_path_selection_peer;
if (debug)
zlog_debug(
"%s: %s wins over %s due to eBGP peer > iBGP peer",
pfx_buf, new_buf, exist_buf);
if (!CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
return 1;
peer_sort_ret = 1;
}
if (exist_sort == BGP_PEER_EBGP
&& (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED)) {
*reason = bgp_path_selection_peer;
if (debug)
zlog_debug(
"%s: %s loses to %s due to iBGP peer < eBGP peer",
pfx_buf, new_buf, exist_buf);
if (!CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
return 0;
peer_sort_ret = 0;
}
/* 8. IGP metric check. */
newm = existm = 0;
if (new->extra)
newm = new->extra->igpmetric;
if (exist->extra)
existm = exist->extra->igpmetric;
if (newm < existm) {
if (debug && peer_sort_ret < 0)
zlog_debug(
"%s: %s wins over %s due to IGP metric %u < %u",
pfx_buf, new_buf, exist_buf, newm, existm);
igp_metric_ret = 1;
}
if (newm > existm) {
if (debug && peer_sort_ret < 0)
zlog_debug(
"%s: %s loses to %s due to IGP metric %u > %u",
pfx_buf, new_buf, exist_buf, newm, existm);
igp_metric_ret = 0;
}
/* 9. Same IGP metric. Compare the cluster list length as
representative of IGP hops metric. Rewrite the metric value
pair (newm, existm) with the cluster list length. Prefer the
path with smaller cluster list length. */
if (newm == existm) {
if (peer_sort_lookup(new->peer) == BGP_PEER_IBGP
&& peer_sort_lookup(exist->peer) == BGP_PEER_IBGP
&& (mpath_cfg == NULL
|| CHECK_FLAG(
mpath_cfg->ibgp_flags,
BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN))) {
newm = BGP_CLUSTER_LIST_LENGTH(new->attr);
existm = BGP_CLUSTER_LIST_LENGTH(exist->attr);
if (newm < existm) {
if (debug && peer_sort_ret < 0)
zlog_debug(
"%s: %s wins over %s due to CLUSTER_LIST length %u < %u",
pfx_buf, new_buf, exist_buf,
newm, existm);
igp_metric_ret = 1;
}
if (newm > existm) {
if (debug && peer_sort_ret < 0)
zlog_debug(
"%s: %s loses to %s due to CLUSTER_LIST length %u > %u",
pfx_buf, new_buf, exist_buf,
newm, existm);
igp_metric_ret = 0;
}
}
}
/* 10. confed-external vs. confed-internal */
if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)) {
if (new_sort == BGP_PEER_CONFED
&& exist_sort == BGP_PEER_IBGP) {
*reason = bgp_path_selection_confed;
if (debug)
zlog_debug(
"%s: %s wins over %s due to confed-external peer > confed-internal peer",
pfx_buf, new_buf, exist_buf);
if (!CHECK_FLAG(bgp->flags,
BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
return 1;
peer_sort_ret = 1;
}
if (exist_sort == BGP_PEER_CONFED
&& new_sort == BGP_PEER_IBGP) {
*reason = bgp_path_selection_confed;
if (debug)
zlog_debug(
"%s: %s loses to %s due to confed-internal peer < confed-external peer",
pfx_buf, new_buf, exist_buf);
if (!CHECK_FLAG(bgp->flags,
BGP_FLAG_PEERTYPE_MULTIPATH_RELAX))
return 0;
peer_sort_ret = 0;
}
}
/* 11. Maximum path check. */
if (newm == existm) {
/* If one path has a label but the other does not, do not treat
* them as equals for multipath
*/
if ((new->extra &&bgp_is_valid_label(&new->extra->label[0]))
!= (exist->extra
&& bgp_is_valid_label(&exist->extra->label[0]))) {
if (debug)
zlog_debug(
"%s: %s and %s cannot be multipath, one has a label while the other does not",
pfx_buf, new_buf, exist_buf);
} else if (CHECK_FLAG(bgp->flags,
BGP_FLAG_ASPATH_MULTIPATH_RELAX)) {
/*
* For the two paths, all comparison steps till IGP
* metric
* have succeeded - including AS_PATH hop count. Since
* 'bgp
* bestpath as-path multipath-relax' knob is on, we
* don't need
* an exact match of AS_PATH. Thus, mark the paths are
* equal.
* That will trigger both these paths to get into the
* multipath
* array.
*/
*paths_eq = 1;
if (debug)
zlog_debug(
"%s: %s and %s are equal via multipath-relax",
pfx_buf, new_buf, exist_buf);
} else if (new->peer->sort == BGP_PEER_IBGP) {
if (aspath_cmp(new->attr->aspath,
exist->attr->aspath)) {
*paths_eq = 1;
if (debug)
zlog_debug(
"%s: %s and %s are equal via matching aspaths",
pfx_buf, new_buf, exist_buf);
}
} else if (new->peer->as == exist->peer->as) {
*paths_eq = 1;
if (debug)
zlog_debug(
"%s: %s and %s are equal via same remote-as",
pfx_buf, new_buf, exist_buf);
}
} else {
/*
* TODO: If unequal cost ibgp multipath is enabled we can
* mark the paths as equal here instead of returning
*/
/* Prior to the addition of BGP_FLAG_PEERTYPE_MULTIPATH_RELAX,
* if either step 7 or 10 (peer type checks) yielded a winner,
* that result was returned immediately. Returning from step 10
* ignored the return value computed in steps 8 and 9 (IGP
* metric checks). In order to preserve that behavior, if
* peer_sort_ret is set, return that rather than igp_metric_ret.
*/
ret = peer_sort_ret;
if (peer_sort_ret < 0) {
ret = igp_metric_ret;
if (debug) {
if (ret == 1)
zlog_debug(
"%s: %s wins over %s after IGP metric comparison",
pfx_buf, new_buf, exist_buf);
else
zlog_debug(
"%s: %s loses to %s after IGP metric comparison",
pfx_buf, new_buf, exist_buf);
}
*reason = bgp_path_selection_igp_metric;
}
return ret;
}
/*
* At this point, the decision whether to set *paths_eq = 1 has been
* completed. If we deferred returning because of bestpath peer-type
* relax configuration, return now.
*/
if (peer_sort_ret >= 0)
return peer_sort_ret;
/* 12. If both paths are external, prefer the path that was received
first (the oldest one). This step minimizes route-flap, since a
newer path won't displace an older one, even if it was the
preferred route based on the additional decision criteria below. */
if (!CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID)
&& new_sort == BGP_PEER_EBGP && exist_sort == BGP_PEER_EBGP) {
if (CHECK_FLAG(new->flags, BGP_PATH_SELECTED)) {
*reason = bgp_path_selection_older;
if (debug)
zlog_debug(
"%s: %s wins over %s due to oldest external",
pfx_buf, new_buf, exist_buf);
return 1;
}
if (CHECK_FLAG(exist->flags, BGP_PATH_SELECTED)) {
*reason = bgp_path_selection_older;
if (debug)
zlog_debug(
"%s: %s loses to %s due to oldest external",
pfx_buf, new_buf, exist_buf);
return 0;
}
}
/* 13. Router-ID comparision. */
/* If one of the paths is "stale", the corresponding peer router-id will
* be 0 and would always win over the other path. If originator id is
* used for the comparision, it will decide which path is better.
*/
if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
new_id.s_addr = newattr->originator_id.s_addr;
else
new_id.s_addr = new->peer->remote_id.s_addr;
if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
exist_id.s_addr = existattr->originator_id.s_addr;
else
exist_id.s_addr = exist->peer->remote_id.s_addr;
if (ntohl(new_id.s_addr) < ntohl(exist_id.s_addr)) {
*reason = bgp_path_selection_router_id;
if (debug)
zlog_debug(
"%s: %s wins over %s due to Router-ID comparison",
pfx_buf, new_buf, exist_buf);
return 1;
}
if (ntohl(new_id.s_addr) > ntohl(exist_id.s_addr)) {
*reason = bgp_path_selection_router_id;
if (debug)
zlog_debug(
"%s: %s loses to %s due to Router-ID comparison",
pfx_buf, new_buf, exist_buf);
return 0;
}
/* 14. Cluster length comparision. */
new_cluster = BGP_CLUSTER_LIST_LENGTH(new->attr);
exist_cluster = BGP_CLUSTER_LIST_LENGTH(exist->attr);
if (new_cluster < exist_cluster) {
*reason = bgp_path_selection_cluster_length;
if (debug)
zlog_debug(
"%s: %s wins over %s due to CLUSTER_LIST length %d < %d",
pfx_buf, new_buf, exist_buf, new_cluster,
exist_cluster);
return 1;
}
if (new_cluster > exist_cluster) {
*reason = bgp_path_selection_cluster_length;
if (debug)
zlog_debug(
"%s: %s loses to %s due to CLUSTER_LIST length %d > %d",
pfx_buf, new_buf, exist_buf, new_cluster,
exist_cluster);
return 0;
}
/* 15. Neighbor address comparision. */
/* Do this only if neither path is "stale" as stale paths do not have
* valid peer information (as the connection may or may not be up).
*/
if (CHECK_FLAG(exist->flags, BGP_PATH_STALE)) {
*reason = bgp_path_selection_stale;
if (debug)
zlog_debug(
"%s: %s wins over %s due to latter path being STALE",
pfx_buf, new_buf, exist_buf);
return 1;
}
if (CHECK_FLAG(new->flags, BGP_PATH_STALE)) {
*reason = bgp_path_selection_stale;
if (debug)
zlog_debug(
"%s: %s loses to %s due to former path being STALE",
pfx_buf, new_buf, exist_buf);
return 0;
}
/* locally configured routes to advertise do not have su_remote */
if (new->peer->su_remote == NULL) {
*reason = bgp_path_selection_local_configured;
return 0;
}
if (exist->peer->su_remote == NULL) {
*reason = bgp_path_selection_local_configured;
return 1;
}
ret = sockunion_cmp(new->peer->su_remote, exist->peer->su_remote);
if (ret == 1) {
*reason = bgp_path_selection_neighbor_ip;
if (debug)
zlog_debug(
"%s: %s loses to %s due to Neighor IP comparison",
pfx_buf, new_buf, exist_buf);
return 0;
}
if (ret == -1) {
*reason = bgp_path_selection_neighbor_ip;
if (debug)
zlog_debug(
"%s: %s wins over %s due to Neighor IP comparison",
pfx_buf, new_buf, exist_buf);
return 1;
}
*reason = bgp_path_selection_default;
if (debug)
zlog_debug("%s: %s wins over %s due to nothing left to compare",
pfx_buf, new_buf, exist_buf);
return 1;
}
int bgp_evpn_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
struct bgp_path_info *exist, int *paths_eq)
{
enum bgp_path_selection_reason reason;
char pfx_buf[PREFIX2STR_BUFFER];
return bgp_path_info_cmp(bgp, new, exist, paths_eq, NULL, 0, pfx_buf,
AFI_L2VPN, SAFI_EVPN, &reason);
}
/* Compare two bgp route entity. Return -1 if new is preferred, 1 if exist
* is preferred, or 0 if they are the same (usually will only occur if
* multipath is enabled
* This version is compatible with */
int bgp_path_info_cmp_compatible(struct bgp *bgp, struct bgp_path_info *new,
struct bgp_path_info *exist, char *pfx_buf,
afi_t afi, safi_t safi,
enum bgp_path_selection_reason *reason)
{
int paths_eq;
int ret;
ret = bgp_path_info_cmp(bgp, new, exist, &paths_eq, NULL, 0, pfx_buf,
afi, safi, reason);
if (paths_eq)
ret = 0;
else {
if (ret == 1)
ret = -1;
else
ret = 1;
}
return ret;
}
static enum filter_type bgp_input_filter(struct peer *peer,
const struct prefix *p,
struct attr *attr, afi_t afi,
safi_t safi)
{
struct bgp_filter *filter;
enum filter_type ret = FILTER_PERMIT;
filter = &peer->filter[afi][safi];
#define FILTER_EXIST_WARN(F, f, filter) \
if (BGP_DEBUG(update, UPDATE_IN) && !(F##_IN(filter))) \
zlog_debug("%s: Could not find configured input %s-list %s!", \
peer->host, #f, F##_IN_NAME(filter));
if (DISTRIBUTE_IN_NAME(filter)) {
FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
if (access_list_apply(DISTRIBUTE_IN(filter), p)
== FILTER_DENY) {
ret = FILTER_DENY;
goto done;
}
}
if (PREFIX_LIST_IN_NAME(filter)) {
FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
if (prefix_list_apply(PREFIX_LIST_IN(filter), p)
== PREFIX_DENY) {
ret = FILTER_DENY;
goto done;
}
}
if (FILTER_LIST_IN_NAME(filter)) {
FILTER_EXIST_WARN(FILTER_LIST, as, filter);
if (as_list_apply(FILTER_LIST_IN(filter), attr->aspath)
== AS_FILTER_DENY) {
ret = FILTER_DENY;
goto done;
}
}
done:
if (frrtrace_enabled(frr_bgp, input_filter)) {
char pfxprint[PREFIX2STR_BUFFER];
prefix2str(p, pfxprint, sizeof(pfxprint));
frrtrace(5, frr_bgp, input_filter, peer, pfxprint, afi, safi,
ret == FILTER_PERMIT ? "permit" : "deny");
}
return ret;
#undef FILTER_EXIST_WARN
}
static enum filter_type bgp_output_filter(struct peer *peer,
const struct prefix *p,
struct attr *attr, afi_t afi,
safi_t safi)
{
struct bgp_filter *filter;
enum filter_type ret = FILTER_PERMIT;
filter = &peer->filter[afi][safi];
#define FILTER_EXIST_WARN(F, f, filter) \
if (BGP_DEBUG(update, UPDATE_OUT) && !(F##_OUT(filter))) \
zlog_debug("%s: Could not find configured output %s-list %s!", \
peer->host, #f, F##_OUT_NAME(filter));
if (DISTRIBUTE_OUT_NAME(filter)) {
FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
if (access_list_apply(DISTRIBUTE_OUT(filter), p)
== FILTER_DENY) {
ret = FILTER_DENY;
goto done;
}
}
if (PREFIX_LIST_OUT_NAME(filter)) {
FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
if (prefix_list_apply(PREFIX_LIST_OUT(filter), p)
== PREFIX_DENY) {
ret = FILTER_DENY;
goto done;
}
}
if (FILTER_LIST_OUT_NAME(filter)) {
FILTER_EXIST_WARN(FILTER_LIST, as, filter);
if (as_list_apply(FILTER_LIST_OUT(filter), attr->aspath)
== AS_FILTER_DENY) {
ret = FILTER_DENY;
goto done;
}
}
if (frrtrace_enabled(frr_bgp, output_filter)) {
char pfxprint[PREFIX2STR_BUFFER];
prefix2str(p, pfxprint, sizeof(pfxprint));
frrtrace(5, frr_bgp, output_filter, peer, pfxprint, afi, safi,
ret == FILTER_PERMIT ? "permit" : "deny");
}
done:
return ret;
#undef FILTER_EXIST_WARN
}
/* If community attribute includes no_export then return 1. */
static bool bgp_community_filter(struct peer *peer, struct attr *attr)
{
if (attr->community) {
/* NO_ADVERTISE check. */
if (community_include(attr->community, COMMUNITY_NO_ADVERTISE))
return true;
/* NO_EXPORT check. */
if (peer->sort == BGP_PEER_EBGP
&& community_include(attr->community, COMMUNITY_NO_EXPORT))
return true;
/* NO_EXPORT_SUBCONFED check. */
if (peer->sort == BGP_PEER_EBGP
|| peer->sort == BGP_PEER_CONFED)
if (community_include(attr->community,
COMMUNITY_NO_EXPORT_SUBCONFED))
return true;
}
return false;
}
/* Route reflection loop check. */
static bool bgp_cluster_filter(struct peer *peer, struct attr *attr)
{
struct in_addr cluster_id;
struct cluster_list *cluster = bgp_attr_get_cluster(attr);
if (cluster) {
if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
cluster_id = peer->bgp->cluster_id;
else
cluster_id = peer->bgp->router_id;
if (cluster_loop_check(cluster, cluster_id))
return true;
}
return false;
}
static int bgp_input_modifier(struct peer *peer, const struct prefix *p,
struct attr *attr, afi_t afi, safi_t safi,
const char *rmap_name, mpls_label_t *label,
uint32_t num_labels, struct bgp_dest *dest)
{
struct bgp_filter *filter;
struct bgp_path_info rmap_path = { 0 };
struct bgp_path_info_extra extra = { 0 };
route_map_result_t ret;
struct route_map *rmap = NULL;
filter = &peer->filter[afi][safi];
/* Apply default weight value. */
if (peer->weight[afi][safi])
attr->weight = peer->weight[afi][safi];
if (rmap_name) {
rmap = route_map_lookup_by_name(rmap_name);
if (rmap == NULL)
return RMAP_DENY;
} else {
if (ROUTE_MAP_IN_NAME(filter)) {
rmap = ROUTE_MAP_IN(filter);
if (rmap == NULL)
return RMAP_DENY;
}
}
/* Route map apply. */
if (rmap) {
memset(&rmap_path, 0, sizeof(struct bgp_path_info));
/* Duplicate current value to new strucutre for modification. */
rmap_path.peer = peer;
rmap_path.attr = attr;
rmap_path.extra = &extra;
rmap_path.net = dest;
extra.num_labels = num_labels;
if (label && num_labels && num_labels <= BGP_MAX_LABELS)
memcpy(extra.label, label,
num_labels * sizeof(mpls_label_t));
SET_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IN);
/* Apply BGP route map to the attribute. */
ret = route_map_apply(rmap, p, &rmap_path);
peer->rmap_type = 0;
if (ret == RMAP_DENYMATCH)
return RMAP_DENY;
}
return RMAP_PERMIT;
}
static int bgp_output_modifier(struct peer *peer, const struct prefix *p,
struct attr *attr, afi_t afi, safi_t safi,
const char *rmap_name)
{
struct bgp_path_info rmap_path;
route_map_result_t ret;
struct route_map *rmap = NULL;
uint8_t rmap_type;
/*
* So if we get to this point and have no rmap_name
* we want to just show the output as it currently
* exists.
*/
if (!rmap_name)
return RMAP_PERMIT;
/* Apply default weight value. */
if (peer->weight[afi][safi])
attr->weight = peer->weight[afi][safi];
rmap = route_map_lookup_by_name(rmap_name);
/*
* If we have a route map name and we do not find
* the routemap that means we have an implicit
* deny.
*/
if (rmap == NULL)
return RMAP_DENY;
memset(&rmap_path, 0, sizeof(struct bgp_path_info));
/* Route map apply. */
/* Duplicate current value to new strucutre for modification. */
rmap_path.peer = peer;
rmap_path.attr = attr;
rmap_type = peer->rmap_type;
SET_FLAG(peer->rmap_type, PEER_RMAP_TYPE_OUT);
/* Apply BGP route map to the attribute. */
ret = route_map_apply(rmap, p, &rmap_path);
peer->rmap_type = rmap_type;
if (ret == RMAP_DENYMATCH)
/*
* caller has multiple error paths with bgp_attr_flush()
*/
return RMAP_DENY;
return RMAP_PERMIT;
}
/* If this is an EBGP peer with remove-private-AS */
static void bgp_peer_remove_private_as(struct bgp *bgp, afi_t afi, safi_t safi,
struct peer *peer, struct attr *attr)
{
if (peer->sort == BGP_PEER_EBGP
&& (peer_af_flag_check(peer, afi, safi,
PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)
|| peer_af_flag_check(peer, afi, safi,
PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE)
|| peer_af_flag_check(peer, afi, safi,
PEER_FLAG_REMOVE_PRIVATE_AS_ALL)
|| peer_af_flag_check(peer, afi, safi,
PEER_FLAG_REMOVE_PRIVATE_AS))) {
// Take action on the entire aspath
if (peer_af_flag_check(peer, afi, safi,
PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE)
|| peer_af_flag_check(peer, afi, safi,
PEER_FLAG_REMOVE_PRIVATE_AS_ALL)) {
if (peer_af_flag_check(
peer, afi, safi,
PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))
attr->aspath = aspath_replace_private_asns(
attr->aspath, bgp->as, peer->as);
// The entire aspath consists of private ASNs so create
// an empty aspath
else if (aspath_private_as_check(attr->aspath))
attr->aspath = aspath_empty_get();
// There are some public and some private ASNs, remove
// the private ASNs
else
attr->aspath = aspath_remove_private_asns(
attr->aspath, peer->as);
}
// 'all' was not specified so the entire aspath must be private
// ASNs
// for us to do anything
else if (aspath_private_as_check(attr->aspath)) {
if (peer_af_flag_check(
peer, afi, safi,
PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE))
attr->aspath = aspath_replace_private_asns(
attr->aspath, bgp->as, peer->as);
else
attr->aspath = aspath_empty_get();
}
}
}
/* If this is an EBGP peer with as-override */
static void bgp_peer_as_override(struct bgp *bgp, afi_t afi, safi_t safi,
struct peer *peer, struct attr *attr)
{
if (peer->sort == BGP_PEER_EBGP
&& peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_OVERRIDE)) {
if (aspath_single_asn_check(attr->aspath, peer->as))
attr->aspath = aspath_replace_specific_asn(
attr->aspath, peer->as, bgp->as);
}
}
void bgp_attr_add_gshut_community(struct attr *attr)
{
struct community *old;
struct community *new;
struct community *merge;
struct community *gshut;
old = attr->community;
gshut = community_str2com("graceful-shutdown");
assert(gshut);
if (old) {
merge = community_merge(community_dup(old), gshut);
if (old->refcnt == 0)
community_free(&old);
new = community_uniq_sort(merge);
community_free(&merge);
} else {
new = community_dup(gshut);
}
community_free(&gshut);
attr->community = new;
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES);
/* When we add the graceful-shutdown community we must also
* lower the local-preference */
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF);
attr->local_pref = BGP_GSHUT_LOCAL_PREF;
}
/* Notify BGP Conditional advertisement scanner process. */
void bgp_notify_conditional_adv_scanner(struct update_subgroup *subgrp)
{
struct peer *temp_peer;
struct peer *peer = SUBGRP_PEER(subgrp);
struct listnode *temp_node, *temp_nnode = NULL;
afi_t afi = SUBGRP_AFI(subgrp);
safi_t safi = SUBGRP_SAFI(subgrp);
struct bgp *bgp = SUBGRP_INST(subgrp);
struct bgp_filter *filter = &peer->filter[afi][safi];
if (!ADVERTISE_MAP_NAME(filter))
return;
for (ALL_LIST_ELEMENTS(bgp->peer, temp_node, temp_nnode, temp_peer)) {
if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
continue;
if (peer != temp_peer)
continue;
temp_peer->advmap_table_change = true;
break;
}
}
void subgroup_announce_reset_nhop(uint8_t family, struct attr *attr)
{
if (family == AF_INET) {
attr->nexthop.s_addr = INADDR_ANY;
attr->mp_nexthop_global_in.s_addr = INADDR_ANY;
}
if (family == AF_INET6)
memset(&attr->mp_nexthop_global, 0, IPV6_MAX_BYTELEN);
if (family == AF_EVPN)
memset(&attr->mp_nexthop_global_in, 0, BGP_ATTR_NHLEN_IPV4);
}
bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi,
struct update_subgroup *subgrp,
const struct prefix *p, struct attr *attr,
bool skip_rmap_check)
{
struct bgp_filter *filter;
struct peer *from;
struct peer *peer;
struct peer *onlypeer;
struct bgp *bgp;
struct attr *piattr;
route_map_result_t ret;
int transparent;
int reflect;
afi_t afi;
safi_t safi;
int samepeer_safe = 0; /* for synthetic mplsvpns routes */
bool nh_reset = false;
uint64_t cum_bw;
if (DISABLE_BGP_ANNOUNCE)
return false;
afi = SUBGRP_AFI(subgrp);
safi = SUBGRP_SAFI(subgrp);
peer = SUBGRP_PEER(subgrp);
onlypeer = NULL;
if (CHECK_FLAG(peer->flags, PEER_FLAG_LONESOUL))
onlypeer = SUBGRP_PFIRST(subgrp)->peer;
from = pi->peer;
filter = &peer->filter[afi][safi];
bgp = SUBGRP_INST(subgrp);
piattr = bgp_path_info_mpath_count(pi) ? bgp_path_info_mpath_attr(pi)
: pi->attr;
#ifdef ENABLE_BGP_VNC
if (((afi == AFI_IP) || (afi == AFI_IP6)) && (safi == SAFI_MPLS_VPN)
&& ((pi->type == ZEBRA_ROUTE_BGP_DIRECT)
|| (pi->type == ZEBRA_ROUTE_BGP_DIRECT_EXT))) {
/*
* direct and direct_ext type routes originate internally even
* though they can have peer pointers that reference other
* systems
*/
zlog_debug("%s: pfx %pFX bgp_direct->vpn route peer safe",
__func__, p);
samepeer_safe = 1;
}
#endif
if (((afi == AFI_IP) || (afi == AFI_IP6))
&& ((safi == SAFI_MPLS_VPN) || (safi == SAFI_UNICAST))
&& (pi->type == ZEBRA_ROUTE_BGP)
&& (pi->sub_type == BGP_ROUTE_IMPORTED)) {
/* Applies to routes leaked vpn->vrf and vrf->vpn */
samepeer_safe = 1;
}
/* With addpath we may be asked to TX all kinds of paths so make sure
* pi is valid */
if (!CHECK_FLAG(pi->flags, BGP_PATH_VALID)
|| CHECK_FLAG(pi->flags, BGP_PATH_HISTORY)
|| CHECK_FLAG(pi->flags, BGP_PATH_REMOVED)) {
return false;
}
/* If this is not the bestpath then check to see if there is an enabled
* addpath
* feature that requires us to advertise it */
if (!CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)) {
if (!bgp_addpath_tx_path(peer->addpath_type[afi][safi], pi)) {
return false;
}
}
/* Aggregate-address suppress check. */
if (bgp_path_suppressed(pi) && !UNSUPPRESS_MAP_NAME(filter))
return false;
/*
* If we are doing VRF 2 VRF leaking via the import
* statement, we want to prevent the route going
* off box as that the RT and RD created are localy
* significant and globaly useless.
*/
if (safi == SAFI_MPLS_VPN && pi->extra && pi->extra->num_labels
&& pi->extra->label[0] == BGP_PREVENT_VRF_2_VRF_LEAK)
return false;
/* If it's labeled safi, make sure the route has a valid label. */
if (safi == SAFI_LABELED_UNICAST) {
mpls_label_t label = bgp_adv_label(dest, pi, peer, afi, safi);
if (!bgp_is_valid_label(&label)) {
if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
zlog_debug("u%" PRIu64 ":s%" PRIu64
" %pFX is filtered - no label (%p)",
subgrp->update_group->id, subgrp->id,
p, &label);
return false;
}
}
/* Do not send back route to sender. */
if (onlypeer && from == onlypeer) {
return false;
}
/* Do not send the default route in the BGP table if the neighbor is
* configured for default-originate */
if (CHECK_FLAG(peer->af_flags[afi][safi],
PEER_FLAG_DEFAULT_ORIGINATE)) {
if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
return false;
else if (p->family == AF_INET6 && p->prefixlen == 0)
return false;
}
/* Transparency check. */
if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
&& CHECK_FLAG(from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
transparent = 1;
else
transparent = 0;
/* If community is not disabled check the no-export and local. */
if (!transparent && bgp_community_filter(peer, piattr)) {
if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
zlog_debug("%s: community filter check fail for %pFX",
__func__, p);
return false;
}
/* If the attribute has originator-id and it is same as remote
peer's id. */
if (onlypeer && piattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)
&& (IPV4_ADDR_SAME(&onlypeer->remote_id, &piattr->originator_id))) {
if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
zlog_debug(
"%s [Update:SEND] %pFX originator-id is same as remote router-id",
onlypeer->host, p);
return false;
}
/* ORF prefix-list filter check */
if (CHECK_FLAG(peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
&& (CHECK_FLAG(peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
|| CHECK_FLAG(peer->af_cap[afi][safi],
PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
if (peer->orf_plist[afi][safi]) {
if (prefix_list_apply(peer->orf_plist[afi][safi], p)
== PREFIX_DENY) {
if (bgp_debug_update(NULL, p,
subgrp->update_group, 0))
zlog_debug(
"%s [Update:SEND] %pFX is filtered via ORF",
peer->host, p);
return false;
}
}
/* Output filter check. */
if (bgp_output_filter(peer, p, piattr, afi, safi) == FILTER_DENY) {
if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
zlog_debug("%s [Update:SEND] %pFX is filtered",
peer->host, p);
return false;
}
/* AS path loop check. */
if (onlypeer && onlypeer->as_path_loop_detection
&& aspath_loop_check(piattr->aspath, onlypeer->as)) {
if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
zlog_debug(
"%s [Update:SEND] suppress announcement to peer AS %u that is part of AS path.",
onlypeer->host, onlypeer->as);
return false;
}
/* If we're a CONFED we need to loop check the CONFED ID too */
if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)) {
if (aspath_loop_check(piattr->aspath, bgp->confed_id)) {
if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
zlog_debug(
"%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
peer->host, bgp->confed_id);
return false;
}
}
/* Route-Reflect check. */
if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
reflect = 1;
else
reflect = 0;
/* IBGP reflection check. */
if (reflect && !samepeer_safe) {
/* A route from a Client peer. */
if (CHECK_FLAG(from->af_flags[afi][safi],
PEER_FLAG_REFLECTOR_CLIENT)) {
/* Reflect to all the Non-Client peers and also to the
Client peers other than the originator. Originator
check
is already done. So there is noting to do. */
/* no bgp client-to-client reflection check. */
if (CHECK_FLAG(bgp->flags,
BGP_FLAG_NO_CLIENT_TO_CLIENT))
if (CHECK_FLAG(peer->af_flags[afi][safi],
PEER_FLAG_REFLECTOR_CLIENT))
return false;
} else {
/* A route from a Non-client peer. Reflect to all other
clients. */
if (!CHECK_FLAG(peer->af_flags[afi][safi],
PEER_FLAG_REFLECTOR_CLIENT))
return false;
}
}
/* For modify attribute, copy it to temporary structure. */
*attr = *piattr;
/* If local-preference is not set. */
if ((peer->sort == BGP_PEER_IBGP || peer->sort == BGP_PEER_CONFED)
&& (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)))) {
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF);
attr->local_pref = bgp->default_local_pref;
}
/* If originator-id is not set and the route is to be reflected,
set the originator id */
if (reflect
&& (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)))) {
IPV4_ADDR_COPY(&(attr->originator_id), &(from->remote_id));
SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
}
/* Remove MED if its an EBGP peer - will get overwritten by route-maps
*/
if (peer->sort == BGP_PEER_EBGP
&& attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC)) {
if (from != bgp->peer_self && !transparent
&& !CHECK_FLAG(peer->af_flags[afi][safi],
PEER_FLAG_MED_UNCHANGED))
attr->flag &=
~(ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC));
}
/* Since the nexthop attribute can vary per peer, it is not explicitly
* set
* in announce check, only certain flags and length (or number of
* nexthops
* -- for IPv6/MP_REACH) are set here in order to guide the update
* formation
* code in setting the nexthop(s) on a per peer basis in
* reformat_peer().
* Typically, the source nexthop in the attribute is preserved but in
* the
* scenarios where we know it will always be overwritten, we reset the
* nexthop to "0" in an attempt to achieve better Update packing. An
* example of this is when a prefix from each of 2 IBGP peers needs to
* be
* announced to an EBGP peer (and they have the same attributes barring
* their nexthop).
*/
if (reflect)
SET_FLAG(attr->rmap_change_flags, BATTR_REFLECTED);
#define NEXTHOP_IS_V6 \
((safi != SAFI_ENCAP && safi != SAFI_MPLS_VPN \
&& (p->family == AF_INET6 || peer_cap_enhe(peer, afi, safi))) \
|| ((safi == SAFI_ENCAP || safi == SAFI_MPLS_VPN) \
&& attr->mp_nexthop_len >= IPV6_MAX_BYTELEN))
/* IPv6/MP starts with 1 nexthop. The link-local address is passed only
* if
* the peer (group) is configured to receive link-local nexthop
* unchanged
* and it is available in the prefix OR we're not reflecting the route,
* link-local nexthop address is valid and
* the peer (group) to whom we're going to announce is on a shared
* network
* and this is either a self-originated route or the peer is EBGP.
* By checking if nexthop LL address is valid we are sure that
* we do not announce LL address as `::`.
*/
if (NEXTHOP_IS_V6) {
attr->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
if ((CHECK_FLAG(peer->af_flags[afi][safi],
PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)
&& IN6_IS_ADDR_LINKLOCAL(&attr->mp_nexthop_local))
|| (!reflect
&& IN6_IS_ADDR_LINKLOCAL(&peer->nexthop.v6_local)
&& peer->shared_network
&& (from == bgp->peer_self
|| peer->sort == BGP_PEER_EBGP))) {
attr->mp_nexthop_len =
BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
}
/* Clear off link-local nexthop in source, whenever it is not
* needed to
* ensure more prefixes share the same attribute for
* announcement.
*/
if (!(CHECK_FLAG(peer->af_flags[afi][safi],
PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED)))
memset(&attr->mp_nexthop_local, 0, IPV6_MAX_BYTELEN);
}
bgp_peer_remove_private_as(bgp, afi, safi, peer, attr);
bgp_peer_as_override(bgp, afi, safi, peer, attr);
/* Route map & unsuppress-map apply. */
if (!skip_rmap_check
&& (ROUTE_MAP_OUT_NAME(filter) || bgp_path_suppressed(pi))) {
struct bgp_path_info rmap_path = {0};
struct bgp_path_info_extra dummy_rmap_path_extra = {0};
struct attr dummy_attr = {0};
/* Fill temp path_info */
prep_for_rmap_apply(&rmap_path, &dummy_rmap_path_extra, dest,
pi, peer, attr);
/* don't confuse inbound and outbound setting */
RESET_FLAG(attr->rmap_change_flags);
/*
* The route reflector is not allowed to modify the attributes
* of the reflected IBGP routes unless explicitly allowed.
*/
if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
&& !CHECK_FLAG(bgp->flags,
BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY)) {
dummy_attr = *attr;
rmap_path.attr = &dummy_attr;
}
SET_FLAG(peer->rmap_type, PEER_RMAP_TYPE_OUT);
if (bgp_path_suppressed(pi))
ret = route_map_apply(UNSUPPRESS_MAP(filter), p,
&rmap_path);
else
ret = route_map_apply(ROUTE_MAP_OUT(filter), p,
&rmap_path);
peer->rmap_type = 0;
if (ret == RMAP_DENYMATCH) {
if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
zlog_debug(
"%s [Update:SEND] %pFX is filtered by route-map",
peer->host, p);
bgp_attr_flush(attr);
return false;
}
}
/* RFC 8212 to prevent route leaks.
* This specification intends to improve this situation by requiring the
* explicit configuration of both BGP Import and Export Policies for any
* External BGP (EBGP) session such as customers, peers, or
* confederation boundaries for all enabled address families. Through
* codification of the aforementioned requirement, operators will
* benefit from consistent behavior across different BGP
* implementations.
*/
if (CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY))
if (!bgp_outbound_policy_exists(peer, filter))
return false;
/* draft-ietf-idr-deprecate-as-set-confed-set
* Filter routes having AS_SET or AS_CONFED_SET in the path.
* Eventually, This document (if approved) updates RFC 4271
* and RFC 5065 by eliminating AS_SET and AS_CONFED_SET types,
* and obsoletes RFC 6472.
*/
if (peer->bgp->reject_as_sets)
if (aspath_check_as_sets(attr->aspath))
return false;
/* Codification of AS 0 Processing */
if (aspath_check_as_zero(attr->aspath))
return false;
if (bgp_in_graceful_shutdown(bgp)) {
if (peer->sort == BGP_PEER_IBGP
|| peer->sort == BGP_PEER_CONFED) {
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF);
attr->local_pref = BGP_GSHUT_LOCAL_PREF;
} else {
bgp_attr_add_gshut_community(attr);
}
}
/* After route-map has been applied, we check to see if the nexthop to
* be carried in the attribute (that is used for the announcement) can
* be cleared off or not. We do this in all cases where we would be
* setting the nexthop to "ourselves". For IPv6, we only need to
* consider
* the global nexthop here; the link-local nexthop would have been
* cleared
* already, and if not, it is required by the update formation code.
* Also see earlier comments in this function.
*/
/*
* If route-map has performed some operation on the nexthop or the peer
* configuration says to pass it unchanged, we cannot reset the nexthop
* here, so only attempt to do it if these aren't true. Note that the
* route-map handler itself might have cleared the nexthop, if for
* example,
* it is configured as 'peer-address'.
*/
if (!bgp_rmap_nhop_changed(attr->rmap_change_flags,
piattr->rmap_change_flags)
&& !transparent
&& !CHECK_FLAG(peer->af_flags[afi][safi],
PEER_FLAG_NEXTHOP_UNCHANGED)) {
/* We can reset the nexthop, if setting (or forcing) it to
* 'self' */
if (CHECK_FLAG(peer->af_flags[afi][safi],
PEER_FLAG_NEXTHOP_SELF)
|| CHECK_FLAG(peer->af_flags[afi][safi],
PEER_FLAG_FORCE_NEXTHOP_SELF)) {
if (!reflect
|| CHECK_FLAG(peer->af_flags[afi][safi],
PEER_FLAG_FORCE_NEXTHOP_SELF)) {
subgroup_announce_reset_nhop(
(peer_cap_enhe(peer, afi, safi)
? AF_INET6
: p->family),
attr);
nh_reset = true;
}
} else if (peer->sort == BGP_PEER_EBGP) {
/* Can also reset the nexthop if announcing to EBGP, but
* only if
* no peer in the subgroup is on a shared subnet.
* Note: 3rd party nexthop currently implemented for
* IPv4 only.
*/
if ((p->family == AF_INET) &&
(!bgp_subgrp_multiaccess_check_v4(
piattr->nexthop,
subgrp, from))) {
subgroup_announce_reset_nhop(
(peer_cap_enhe(peer, afi, safi)
? AF_INET6
: p->family),
attr);
nh_reset = true;
}
if ((p->family == AF_INET6) &&
(!bgp_subgrp_multiaccess_check_v6(
piattr->mp_nexthop_global,
subgrp, from))) {
subgroup_announce_reset_nhop(
(peer_cap_enhe(peer, afi, safi)
? AF_INET6
: p->family),
attr);
nh_reset = true;
}
} else if (CHECK_FLAG(pi->flags, BGP_PATH_ANNC_NH_SELF)) {
/*
* This flag is used for leaked vpn-vrf routes
*/
int family = p->family;
if (peer_cap_enhe(peer, afi, safi))
family = AF_INET6;
if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
zlog_debug(
"%s: BGP_PATH_ANNC_NH_SELF, family=%s",
__func__, family2str(family));
subgroup_announce_reset_nhop(family, attr);
nh_reset = true;
}
}
/* If IPv6/MP and nexthop does not have any override and happens
* to
* be a link-local address, reset it so that we don't pass along
* the
* source's link-local IPv6 address to recipients who may not be
* on
* the same interface.
*/
if (p->family == AF_INET6 || peer_cap_enhe(peer, afi, safi)) {
if (IN6_IS_ADDR_LINKLOCAL(&attr->mp_nexthop_global)) {
subgroup_announce_reset_nhop(AF_INET6, attr);
nh_reset = true;
}
}
/*
* When the next hop is set to ourselves, if all multipaths have
* link-bandwidth announce the cumulative bandwidth as that makes
* the most sense. However, don't modify if the link-bandwidth has
* been explicitly set by user policy.
*/
if (nh_reset &&
bgp_path_info_mpath_chkwtd(bgp, pi) &&
(cum_bw = bgp_path_info_mpath_cumbw(pi)) != 0 &&
!CHECK_FLAG(attr->rmap_change_flags, BATTR_RMAP_LINK_BW_SET))
attr->ecommunity = ecommunity_replace_linkbw(
bgp->as, attr->ecommunity, cum_bw,
CHECK_FLAG(peer->flags,
PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE));
return true;
}
static int bgp_route_select_timer_expire(struct thread *thread)
{
struct afi_safi_info *info;
afi_t afi;
safi_t safi;
struct bgp *bgp;
info = THREAD_ARG(thread);
afi = info->afi;
safi = info->safi;
bgp = info->bgp;
if (BGP_DEBUG(update, UPDATE_OUT))
zlog_debug("afi %d, safi %d : route select timer expired", afi,
safi);
bgp->gr_info[afi][safi].t_route_select = NULL;
XFREE(MTYPE_TMP, info);
/* Best path selection */
return bgp_best_path_select_defer(bgp, afi, safi);
}
void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest,
struct bgp_maxpaths_cfg *mpath_cfg,
struct bgp_path_info_pair *result, afi_t afi,
safi_t safi)
{
struct bgp_path_info *new_select;
struct bgp_path_info *old_select;
struct bgp_path_info *pi;
struct bgp_path_info *pi1;
struct bgp_path_info *pi2;
struct bgp_path_info *nextpi = NULL;
int paths_eq, do_mpath, debug;
struct list mp_list;
char pfx_buf[PREFIX2STR_BUFFER];
char path_buf[PATH_ADDPATH_STR_BUFFER];
bgp_mp_list_init(&mp_list);
do_mpath =
(mpath_cfg->maxpaths_ebgp > 1 || mpath_cfg->maxpaths_ibgp > 1);
debug = bgp_debug_bestpath(dest);
if (debug)
prefix2str(bgp_dest_get_prefix(dest), pfx_buf, sizeof(pfx_buf));
dest->reason = bgp_path_selection_none;
/* bgp deterministic-med */
new_select = NULL;
if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)) {
/* Clear BGP_PATH_DMED_SELECTED for all paths */
for (pi1 = bgp_dest_get_bgp_path_info(dest); pi1;
pi1 = pi1->next)
bgp_path_info_unset_flag(dest, pi1,
BGP_PATH_DMED_SELECTED);
for (pi1 = bgp_dest_get_bgp_path_info(dest); pi1;
pi1 = pi1->next) {
if (CHECK_FLAG(pi1->flags, BGP_PATH_DMED_CHECK))
continue;
if (BGP_PATH_HOLDDOWN(pi1))
continue;
if (pi1->peer != bgp->peer_self)
if (!peer_established(pi1->peer))
continue;
new_select = pi1;
if (pi1->next) {
for (pi2 = pi1->next; pi2; pi2 = pi2->next) {
if (CHECK_FLAG(pi2->flags,
BGP_PATH_DMED_CHECK))
continue;
if (BGP_PATH_HOLDDOWN(pi2))
continue;
if (pi2->peer != bgp->peer_self
&& !CHECK_FLAG(
pi2->peer->sflags,
PEER_STATUS_NSF_WAIT))
if (pi2->peer->status
!= Established)
continue;
if (!aspath_cmp_left(pi1->attr->aspath,
pi2->attr->aspath)
&& !aspath_cmp_left_confed(
pi1->attr->aspath,
pi2->attr->aspath))
continue;
if (bgp_path_info_cmp(
bgp, pi2, new_select,
&paths_eq, mpath_cfg, debug,
pfx_buf, afi, safi,
&dest->reason)) {
bgp_path_info_unset_flag(
dest, new_select,
BGP_PATH_DMED_SELECTED);
new_select = pi2;
}
bgp_path_info_set_flag(
dest, pi2, BGP_PATH_DMED_CHECK);
}
}
bgp_path_info_set_flag(dest, new_select,
BGP_PATH_DMED_CHECK);
bgp_path_info_set_flag(dest, new_select,
BGP_PATH_DMED_SELECTED);
if (debug) {
bgp_path_info_path_with_addpath_rx_str(
new_select, path_buf, sizeof(path_buf));
zlog_debug(
"%pBD: %s is the bestpath from AS %u",
dest, path_buf,
aspath_get_first_as(
new_select->attr->aspath));
}
}
}
/* Check old selected route and new selected route. */
old_select = NULL;
new_select = NULL;
for (pi = bgp_dest_get_bgp_path_info(dest);
(pi != NULL) && (nextpi = pi->next, 1); pi = nextpi) {
enum bgp_path_selection_reason reason;
if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED))
old_select = pi;
if (BGP_PATH_HOLDDOWN(pi)) {
/* reap REMOVED routes, if needs be
* selected route must stay for a while longer though
*/
if (CHECK_FLAG(pi->flags, BGP_PATH_REMOVED)
&& (pi != old_select))
bgp_path_info_reap(dest, pi);
if (debug)
zlog_debug("%s: pi %p in holddown", __func__,
pi);
continue;
}
if (pi->peer && pi->peer != bgp->peer_self
&& !CHECK_FLAG(pi->peer->sflags, PEER_STATUS_NSF_WAIT))
if (!peer_established(pi->peer)) {
if (debug)
zlog_debug(
"%s: pi %p non self peer %s not estab state",
__func__, pi, pi->peer->host);
continue;
}
if (CHECK_FLAG(bgp->flags, BGP_FLAG_DETERMINISTIC_MED)
&& (!CHECK_FLAG(pi->flags, BGP_PATH_DMED_SELECTED))) {
bgp_path_info_unset_flag(dest, pi, BGP_PATH_DMED_CHECK);
if (debug)
zlog_debug("%s: pi %p dmed", __func__, pi);
continue;
}
bgp_path_info_unset_flag(dest, pi, BGP_PATH_DMED_CHECK);
reason = dest->reason;
if (bgp_path_info_cmp(bgp, pi, new_select, &paths_eq, mpath_cfg,
debug, pfx_buf, afi, safi,
&dest->reason)) {
if (new_select == NULL &&
reason != bgp_path_selection_none)
dest->reason = reason;
new_select = pi;
}
}
/* Now that we know which path is the bestpath see if any of the other
* paths
* qualify as multipaths
*/
if (debug) {
if (new_select)
bgp_path_info_path_with_addpath_rx_str(
new_select, path_buf, sizeof(path_buf));
else
snprintf(path_buf, sizeof(path_buf), "NONE");
zlog_debug(
"%pBD: After path selection, newbest is %s oldbest was %s",
dest, path_buf,
old_select ? old_select->peer->host : "NONE");
}
if (do_mpath && new_select) {
for (pi = bgp_dest_get_bgp_path_info(dest);
(pi != NULL) && (nextpi = pi->next, 1); pi = nextpi) {
if (debug)
bgp_path_info_path_with_addpath_rx_str(
pi, path_buf, sizeof(path_buf));
if (pi == new_select) {
if (debug)
zlog_debug(
"%pBD: %s is the bestpath, add to the multipath list",
dest, path_buf);
bgp_mp_list_add(&mp_list, pi);
continue;
}
if (BGP_PATH_HOLDDOWN(pi))
continue;
if (pi->peer && pi->peer != bgp->peer_self
&& !CHECK_FLAG(pi->peer->sflags,
PEER_STATUS_NSF_WAIT))
if (!peer_established(pi->peer))
continue;
if (!bgp_path_info_nexthop_cmp(pi, new_select)) {
if (debug)
zlog_debug(
"%pBD: %s has the same nexthop as the bestpath, skip it",
dest, path_buf);
continue;
}
bgp_path_info_cmp(bgp, pi, new_select, &paths_eq,
mpath_cfg, debug, pfx_buf, afi, safi,
&dest->reason);
if (paths_eq) {
if (debug)
zlog_debug(
"%pBD: %s is equivalent to the bestpath, add to the multipath list",
dest, path_buf);
bgp_mp_list_add(&mp_list, pi);
}
}
}
bgp_path_info_mpath_update(dest, new_select, old_select, &mp_list,
mpath_cfg);
bgp_path_info_mpath_aggregate_update(new_select, old_select);
bgp_mp_list_clear(&mp_list);
bgp_addpath_update_ids(bgp, dest, afi, safi);
result->old = old_select;
result->new = new_select;
return;
}
/*
* A new route/change in bestpath of an existing route. Evaluate the path
* for advertisement to the subgroup.
*/
void subgroup_process_announce_selected(struct update_subgroup *subgrp,
struct bgp_path_info *selected,
struct bgp_dest *dest,
uint32_t addpath_tx_id)
{
const struct prefix *p;
struct peer *onlypeer;
struct attr attr;
afi_t afi;
safi_t safi;
struct bgp *bgp;
bool advertise;
p = bgp_dest_get_prefix(dest);
afi = SUBGRP_AFI(subgrp);
safi = SUBGRP_SAFI(subgrp);
bgp = SUBGRP_INST(subgrp);
onlypeer = ((SUBGRP_PCOUNT(subgrp) == 1) ? (SUBGRP_PFIRST(subgrp))->peer
: NULL);
if (BGP_DEBUG(update, UPDATE_OUT))
zlog_debug("%s: p=%pFX, selected=%p", __func__, p, selected);
/* First update is deferred until ORF or ROUTE-REFRESH is received */
if (onlypeer && CHECK_FLAG(onlypeer->af_sflags[afi][safi],
PEER_STATUS_ORF_WAIT_REFRESH))
return;
memset(&attr, 0, sizeof(struct attr));
/* It's initialized in bgp_announce_check() */
/* Announcement to the subgroup. If the route is filtered withdraw it.
* If BGP_NODE_FIB_INSTALL_PENDING is set and data plane install status
* is pending (BGP_NODE_FIB_INSTALL_PENDING), do not advertise the
* route
*/
advertise = bgp_check_advertise(bgp, dest);
if (selected) {
if (subgroup_announce_check(dest, selected, subgrp, p, &attr,
false)) {
/* Route is selected, if the route is already installed
* in FIB, then it is advertised
*/
if (advertise)
bgp_adj_out_set_subgroup(dest, subgrp, &attr,
selected);
} else
bgp_adj_out_unset_subgroup(dest, subgrp, 1,
addpath_tx_id);
}
/* If selected is NULL we must withdraw the path using addpath_tx_id */
else {
bgp_adj_out_unset_subgroup(dest, subgrp, 1, addpath_tx_id);
}
}
/*
* Clear IGP changed flag and attribute changed flag for a route (all paths).
* This is called at the end of route processing.
*/
void bgp_zebra_clear_route_change_flags(struct bgp_dest *dest)
{
struct bgp_path_info *pi;
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) {
if (BGP_PATH_HOLDDOWN(pi))
continue;
UNSET_FLAG(pi->flags, BGP_PATH_IGP_CHANGED);
UNSET_FLAG(pi->flags, BGP_PATH_ATTR_CHANGED);
}
}
/*
* Has the route changed from the RIB's perspective? This is invoked only
* if the route selection returns the same best route as earlier - to
* determine if we need to update zebra or not.
*/
bool bgp_zebra_has_route_changed(struct bgp_path_info *selected)
{
struct bgp_path_info *mpinfo;
/* If this is multipath, check all selected paths for any nexthop
* change or attribute change. Some attribute changes (e.g., community)
* aren't of relevance to the RIB, but we'll update zebra to ensure
* we handle the case of BGP nexthop change. This is the behavior
* when the best path has an attribute change anyway.
*/
if (CHECK_FLAG(selected->flags, BGP_PATH_IGP_CHANGED)
|| CHECK_FLAG(selected->flags, BGP_PATH_MULTIPATH_CHG)
|| CHECK_FLAG(selected->flags, BGP_PATH_LINK_BW_CHG))
return true;
/*
* If this is multipath, check all selected paths for any nexthop change
*/
for (mpinfo = bgp_path_info_mpath_first(selected); mpinfo;
mpinfo = bgp_path_info_mpath_next(mpinfo)) {
if (CHECK_FLAG(mpinfo->flags, BGP_PATH_IGP_CHANGED)
|| CHECK_FLAG(mpinfo->flags, BGP_PATH_ATTR_CHANGED))
return true;
}
/* Nothing has changed from the RIB's perspective. */
return false;
}
struct bgp_process_queue {
struct bgp *bgp;
STAILQ_HEAD(, bgp_dest) pqueue;
#define BGP_PROCESS_QUEUE_EOIU_MARKER (1 << 0)
unsigned int flags;
unsigned int queued;
};
static void bgp_process_evpn_route_injection(struct bgp *bgp, afi_t afi,
safi_t safi, struct bgp_dest *dest,
struct bgp_path_info *new_select,
struct bgp_path_info *old_select)
{
const struct prefix *p = bgp_dest_get_prefix(dest);
if ((afi != AFI_IP && afi != AFI_IP6) || (safi != SAFI_UNICAST))
return;
if (advertise_type5_routes(bgp, afi) && new_select
&& is_route_injectable_into_evpn(new_select)) {
/* apply the route-map */
if (bgp->adv_cmd_rmap[afi][safi].map) {
route_map_result_t ret;
struct bgp_path_info rmap_path;
struct bgp_path_info_extra rmap_path_extra;
struct attr dummy_attr;
dummy_attr = *new_select->attr;
/* Fill temp path_info */
prep_for_rmap_apply(&rmap_path, &rmap_path_extra, dest,
new_select, new_select->peer,
&dummy_attr);
RESET_FLAG(dummy_attr.rmap_change_flags);
ret = route_map_apply(bgp->adv_cmd_rmap[afi][safi].map,
p, &rmap_path);
if (ret == RMAP_DENYMATCH) {
bgp_attr_flush(&dummy_attr);
bgp_evpn_withdraw_type5_route(bgp, p, afi,
safi);
} else
bgp_evpn_advertise_type5_route(
bgp, p, &dummy_attr, afi, safi);
} else {
bgp_evpn_advertise_type5_route(bgp, p, new_select->attr,
afi, safi);
}
} else if (advertise_type5_routes(bgp, afi) && old_select
&& is_route_injectable_into_evpn(old_select))
bgp_evpn_withdraw_type5_route(bgp, p, afi, safi);
}
/*
* old_select = The old best path
* new_select = the new best path
*
* if (!old_select && new_select)
* We are sending new information on.
*
* if (old_select && new_select) {
* if (new_select != old_select)
* We have a new best path send a change
* else
* We've received a update with new attributes that needs
* to be passed on.
* }
*
* if (old_select && !new_select)
* We have no eligible route that we can announce or the rn
* is being removed.
*/
static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest,
afi_t afi, safi_t safi)
{
struct bgp_path_info *new_select;
struct bgp_path_info *old_select;
struct bgp_path_info_pair old_and_new;
int debug = 0;
if (CHECK_FLAG(bgp->flags, BGP_FLAG_DELETE_IN_PROGRESS)) {
if (dest)
debug = bgp_debug_bestpath(dest);
if (debug)
zlog_debug(
"%s: bgp delete in progress, ignoring event, p=%pBD",
__func__, dest);
return;
}
/* Is it end of initial update? (after startup) */
if (!dest) {
quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
sizeof(bgp->update_delay_zebra_resume_time));
bgp->main_zebra_update_hold = 0;
FOREACH_AFI_SAFI (afi, safi) {
if (bgp_fibupd_safi(safi))
bgp_zebra_announce_table(bgp, afi, safi);
}
bgp->main_peers_update_hold = 0;
bgp_start_routeadv(bgp);
return;
}
const struct prefix *p = bgp_dest_get_prefix(dest);
debug = bgp_debug_bestpath(dest);
if (debug)
zlog_debug("%s: p=%pBD afi=%s, safi=%s start", __func__, dest,
afi2str(afi), safi2str(safi));
/* The best path calculation for the route is deferred if
* BGP_NODE_SELECT_DEFER is set
*/
if (CHECK_FLAG(dest->flags, BGP_NODE_SELECT_DEFER)) {
if (BGP_DEBUG(update, UPDATE_OUT))
zlog_debug("SELECT_DEFER flag set for route %p", dest);
return;
}
/* Best path selection. */
bgp_best_selection(bgp, dest, &bgp->maxpaths[afi][safi], &old_and_new,
afi, safi);
old_select = old_and_new.old;
new_select = old_and_new.new;
/* Do we need to allocate or free labels?
* Right now, since we only deal with per-prefix labels, it is not
* necessary to do this upon changes to best path. Exceptions:
* - label index has changed -> recalculate resulting label
* - path_info sub_type changed -> switch to/from implicit-null
* - no valid label (due to removed static label binding) -> get new one
*/
if (bgp->allocate_mpls_labels[afi][safi]) {
if (new_select) {
if (!old_select
|| bgp_label_index_differs(new_select, old_select)
|| new_select->sub_type != old_select->sub_type
|| !bgp_is_valid_label(&dest->local_label)) {
/* Enforced penultimate hop popping:
* implicit-null for local routes, aggregate
* and redistributed routes
*/
if (new_select->sub_type == BGP_ROUTE_STATIC
|| new_select->sub_type
== BGP_ROUTE_AGGREGATE
|| new_select->sub_type
== BGP_ROUTE_REDISTRIBUTE) {
if (CHECK_FLAG(
dest->flags,
BGP_NODE_REGISTERED_FOR_LABEL)
|| CHECK_FLAG(
dest->flags,
BGP_NODE_LABEL_REQUESTED))
bgp_unregister_for_label(dest);
label_ntop(MPLS_LABEL_IMPLICIT_NULL, 1,
&dest->local_label);
bgp_set_valid_label(&dest->local_label);
} else
bgp_register_for_label(dest,
new_select);
}
} else if (CHECK_FLAG(dest->flags,
BGP_NODE_REGISTERED_FOR_LABEL)
|| CHECK_FLAG(dest->flags,
BGP_NODE_LABEL_REQUESTED)) {
bgp_unregister_for_label(dest);
}
} else if (CHECK_FLAG(dest->flags, BGP_NODE_REGISTERED_FOR_LABEL)
|| CHECK_FLAG(dest->flags, BGP_NODE_LABEL_REQUESTED)) {
bgp_unregister_for_label(dest);
}
if (debug)
zlog_debug(
"%s: p=%pBD afi=%s, safi=%s, old_select=%p, new_select=%p",
__func__, dest, afi2str(afi), safi2str(safi),
old_select, new_select);
/* If best route remains the same and this is not due to user-initiated
* clear, see exactly what needs to be done.
*/
if (old_select && old_select == new_select
&& !CHECK_FLAG(dest->flags, BGP_NODE_USER_CLEAR)
&& !CHECK_FLAG(old_select->flags, BGP_PATH_ATTR_CHANGED)
&& !bgp_addpath_is_addpath_used(&bgp->tx_addpath, afi, safi)) {
if (bgp_zebra_has_route_changed(old_select)) {
#ifdef ENABLE_BGP_VNC
vnc_import_bgp_add_route(bgp, p, old_select);
vnc_import_bgp_exterior_add_route(bgp, p, old_select);
#endif
if (bgp_fibupd_safi(safi)
&& !bgp_option_check(BGP_OPT_NO_FIB)) {
if (new_select->type == ZEBRA_ROUTE_BGP
&& (new_select->sub_type == BGP_ROUTE_NORMAL
|| new_select->sub_type
== BGP_ROUTE_IMPORTED))
bgp_zebra_announce(dest, p, old_select,
bgp, afi, safi);
}
}
/* If there is a change of interest to peers, reannounce the
* route. */
if (CHECK_FLAG(old_select->flags, BGP_PATH_ATTR_CHANGED)
|| CHECK_FLAG(old_select->flags, BGP_PATH_LINK_BW_CHG)
|| CHECK_FLAG(dest->flags, BGP_NODE_LABEL_CHANGED)) {
group_announce_route(bgp, afi, safi, dest, new_select);
/* unicast routes must also be annouced to
* labeled-unicast update-groups */
if (safi == SAFI_UNICAST)
group_announce_route(bgp, afi,
SAFI_LABELED_UNICAST, dest,
new_select);
UNSET_FLAG(old_select->flags, BGP_PATH_ATTR_CHANGED);
UNSET_FLAG(dest->flags, BGP_NODE_LABEL_CHANGED);
}
/* advertise/withdraw type-5 routes */
if (CHECK_FLAG(old_select->flags, BGP_PATH_LINK_BW_CHG)
|| CHECK_FLAG(old_select->flags, BGP_PATH_MULTIPATH_CHG))
bgp_process_evpn_route_injection(
bgp, afi, safi, dest, old_select, old_select);
UNSET_FLAG(old_select->flags, BGP_PATH_MULTIPATH_CHG);
UNSET_FLAG(old_select->flags, BGP_PATH_LINK_BW_CHG);
bgp_zebra_clear_route_change_flags(dest);
UNSET_FLAG(dest->flags, BGP_NODE_PROCESS_SCHEDULED);
return;
}
/* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set
*/
UNSET_FLAG(dest->flags, BGP_NODE_USER_CLEAR);
/* bestpath has changed; bump version */
if (old_select || new_select) {
bgp_bump_version(dest);
if (!bgp->t_rmap_def_originate_eval) {
bgp_lock(bgp);
thread_add_timer(
bm->master,
update_group_refresh_default_originate_route_map,
bgp, RMAP_DEFAULT_ORIGINATE_EVAL_TIMER,
&bgp->t_rmap_def_originate_eval);
}
}
if (old_select)
bgp_path_info_unset_flag(dest, old_select, BGP_PATH_SELECTED);
if (new_select) {
if (debug)
zlog_debug("%s: setting SELECTED flag", __func__);
bgp_path_info_set_flag(dest, new_select, BGP_PATH_SELECTED);
bgp_path_info_unset_flag(dest, new_select,
BGP_PATH_ATTR_CHANGED);
UNSET_FLAG(new_select->flags, BGP_PATH_MULTIPATH_CHG);
UNSET_FLAG(new_select->flags, BGP_PATH_LINK_BW_CHG);
}
#ifdef ENABLE_BGP_VNC
if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) {
if (old_select != new_select) {
if (old_select) {
vnc_import_bgp_exterior_del_route(bgp, p,
old_select);
vnc_import_bgp_del_route(bgp, p, old_select);
}
if (new_select) {
vnc_import_bgp_exterior_add_route(bgp, p,
new_select);
vnc_import_bgp_add_route(bgp, p, new_select);
}
}
}
#endif
group_announce_route(bgp, afi, safi, dest, new_select);
/* unicast routes must also be annouced to labeled-unicast update-groups
*/
if (safi == SAFI_UNICAST)
group_announce_route(bgp, afi, SAFI_LABELED_UNICAST, dest,
new_select);
/* FIB update. */
if (bgp_fibupd_safi(safi) && (bgp->inst_type != BGP_INSTANCE_TYPE_VIEW)
&& !bgp_option_check(BGP_OPT_NO_FIB)) {
if (new_select && new_select->type == ZEBRA_ROUTE_BGP
&& (new_select->sub_type == BGP_ROUTE_NORMAL
|| new_select->sub_type == BGP_ROUTE_AGGREGATE
|| new_select->sub_type == BGP_ROUTE_IMPORTED)) {
/* if this is an evpn imported type-5 prefix,
* we need to withdraw the route first to clear
* the nh neigh and the RMAC entry.
*/
if (old_select &&
is_route_parent_evpn(old_select))
bgp_zebra_withdraw(p, old_select, bgp, safi);
bgp_zebra_announce(dest, p, new_select, bgp, afi, safi);
} else {
/* Withdraw the route from the kernel. */
if (old_select && old_select->type == ZEBRA_ROUTE_BGP
&& (old_select->sub_type == BGP_ROUTE_NORMAL
|| old_select->sub_type == BGP_ROUTE_AGGREGATE
|| old_select->sub_type == BGP_ROUTE_IMPORTED))
bgp_zebra_withdraw(p, old_select, bgp, safi);
}
}
bgp_process_evpn_route_injection(bgp, afi, safi, dest, new_select,
old_select);
/* Clear any route change flags. */
bgp_zebra_clear_route_change_flags(dest);
/* Reap old select bgp_path_info, if it has been removed */
if (old_select && CHECK_FLAG(old_select->flags, BGP_PATH_REMOVED))
bgp_path_info_reap(dest, old_select);
UNSET_FLAG(dest->flags, BGP_NODE_PROCESS_SCHEDULED);
return;
}
/* Process the routes with the flag BGP_NODE_SELECT_DEFER set */
int bgp_best_path_select_defer(struct bgp *bgp, afi_t afi, safi_t safi)
{
struct bgp_dest *dest;
int cnt = 0;
struct afi_safi_info *thread_info;
if (bgp->gr_info[afi][safi].t_route_select) {
struct thread *t = bgp->gr_info[afi][safi].t_route_select;
thread_info = THREAD_ARG(t);
XFREE(MTYPE_TMP, thread_info);
BGP_TIMER_OFF(bgp->gr_info[afi][safi].t_route_select);
}
if (BGP_DEBUG(update, UPDATE_OUT)) {
zlog_debug("%s: processing route for %s : cnt %d", __func__,
get_afi_safi_str(afi, safi, false),
bgp->gr_info[afi][safi].gr_deferred);
}
/* Process the route list */
for (dest = bgp_table_top(bgp->rib[afi][safi]);
dest && bgp->gr_info[afi][safi].gr_deferred != 0;
dest = bgp_route_next(dest)) {
if (!CHECK_FLAG(dest->flags, BGP_NODE_SELECT_DEFER))
continue;
UNSET_FLAG(dest->flags, BGP_NODE_SELECT_DEFER);
bgp->gr_info[afi][safi].gr_deferred--;
bgp_process_main_one(bgp, dest, afi, safi);
cnt++;
if (cnt >= BGP_MAX_BEST_ROUTE_SELECT) {
bgp_dest_unlock_node(dest);
break;
}
}
/* Send EOR message when all routes are processed */
if (!bgp->gr_info[afi][safi].gr_deferred) {
bgp_send_delayed_eor(bgp);
/* Send route processing complete message to RIB */
bgp_zebra_update(afi, safi, bgp->vrf_id,
ZEBRA_CLIENT_ROUTE_UPDATE_COMPLETE);
return 0;
}
thread_info = XMALLOC(MTYPE_TMP, sizeof(struct afi_safi_info));
thread_info->afi = afi;
thread_info->safi = safi;
thread_info->bgp = bgp;
/* If there are more routes to be processed, start the
* selection timer
*/
thread_add_timer(bm->master, bgp_route_select_timer_expire, thread_info,
BGP_ROUTE_SELECT_DELAY,
&bgp->gr_info[afi][safi].t_route_select);
return 0;
}
static wq_item_status bgp_process_wq(struct work_queue *wq, void *data)
{
struct bgp_process_queue *pqnode = data;
struct bgp *bgp = pqnode->bgp;
struct bgp_table *table;
struct bgp_dest *dest;
/* eoiu marker */
if (CHECK_FLAG(pqnode->flags, BGP_PROCESS_QUEUE_EOIU_MARKER)) {
bgp_process_main_one(bgp, NULL, 0, 0);
/* should always have dedicated wq call */
assert(STAILQ_FIRST(&pqnode->pqueue) == NULL);
return WQ_SUCCESS;
}
while (!STAILQ_EMPTY(&pqnode->pqueue)) {
dest = STAILQ_FIRST(&pqnode->pqueue);
STAILQ_REMOVE_HEAD(&pqnode->pqueue, pq);
STAILQ_NEXT(dest, pq) = NULL; /* complete unlink */
table = bgp_dest_table(dest);
/* note, new DESTs may be added as part of processing */
bgp_process_main_one(bgp, dest, table->afi, table->safi);
bgp_dest_unlock_node(dest);
bgp_table_unlock(table);
}
return WQ_SUCCESS;
}
static void bgp_processq_del(struct work_queue *wq, void *data)
{
struct bgp_process_queue *pqnode = data;
bgp_unlock(pqnode->bgp);
XFREE(MTYPE_BGP_PROCESS_QUEUE, pqnode);
}
void bgp_process_queue_init(struct bgp *bgp)
{
if (!bgp->process_queue) {
char name[BUFSIZ];
snprintf(name, BUFSIZ, "process_queue %s", bgp->name_pretty);
bgp->process_queue = work_queue_new(bm->master, name);
}
bgp->process_queue->spec.workfunc = &bgp_process_wq;
bgp->process_queue->spec.del_item_data = &bgp_processq_del;
bgp->process_queue->spec.max_retries = 0;
bgp->process_queue->spec.hold = 50;
/* Use a higher yield value of 50ms for main queue processing */
bgp->process_queue->spec.yield = 50 * 1000L;
}
static struct bgp_process_queue *bgp_processq_alloc(struct bgp *bgp)
{
struct bgp_process_queue *pqnode;
pqnode = XCALLOC(MTYPE_BGP_PROCESS_QUEUE,
sizeof(struct bgp_process_queue));
/* unlocked in bgp_processq_del */
pqnode->bgp = bgp_lock(bgp);
STAILQ_INIT(&pqnode->pqueue);
return pqnode;
}
void bgp_process(struct bgp *bgp, struct bgp_dest *dest, afi_t afi, safi_t safi)
{
#define ARBITRARY_PROCESS_QLEN 10000
struct work_queue *wq = bgp->process_queue;
struct bgp_process_queue *pqnode;
int pqnode_reuse = 0;
/* already scheduled for processing? */
if (CHECK_FLAG(dest->flags, BGP_NODE_PROCESS_SCHEDULED))
return;
/* If the flag BGP_NODE_SELECT_DEFER is set, do not add route to
* the workqueue
*/
if (CHECK_FLAG(dest->flags, BGP_NODE_SELECT_DEFER)) {
if (BGP_DEBUG(update, UPDATE_OUT))
zlog_debug("BGP_NODE_SELECT_DEFER set for route %p",
dest);
return;
}
if (CHECK_FLAG(dest->flags, BGP_NODE_SOFT_RECONFIG)) {
if (BGP_DEBUG(update, UPDATE_OUT))
zlog_debug(
"Soft reconfigure table in progress for route %p",
dest);
return;
}
if (wq == NULL)
return;
/* Add route nodes to an existing work queue item until reaching the
limit only if is from the same BGP view and it's not an EOIU marker
*/
if (work_queue_item_count(wq)) {
struct work_queue_item *item = work_queue_last_item(wq);
pqnode = item->data;
if (CHECK_FLAG(pqnode->flags, BGP_PROCESS_QUEUE_EOIU_MARKER)
|| pqnode->bgp != bgp
|| pqnode->queued >= ARBITRARY_PROCESS_QLEN)
pqnode = bgp_processq_alloc(bgp);
else
pqnode_reuse = 1;
} else
pqnode = bgp_processq_alloc(bgp);
/* all unlocked in bgp_process_wq */
bgp_table_lock(bgp_dest_table(dest));
SET_FLAG(dest->flags, BGP_NODE_PROCESS_SCHEDULED);
bgp_dest_lock_node(dest);
/* can't be enqueued twice */
assert(STAILQ_NEXT(dest, pq) == NULL);
STAILQ_INSERT_TAIL(&pqnode->pqueue, dest, pq);
pqnode->queued++;
if (!pqnode_reuse)
work_queue_add(wq, pqnode);
return;
}
void bgp_add_eoiu_mark(struct bgp *bgp)
{
struct bgp_process_queue *pqnode;
if (bgp->process_queue == NULL)
return;
pqnode = bgp_processq_alloc(bgp);
SET_FLAG(pqnode->flags, BGP_PROCESS_QUEUE_EOIU_MARKER);
work_queue_add(bgp->process_queue, pqnode);
}
static int bgp_maximum_prefix_restart_timer(struct thread *thread)
{
struct peer *peer;
peer = THREAD_ARG(thread);
peer->t_pmax_restart = NULL;
if (bgp_debug_neighbor_events(peer))
zlog_debug(
"%s Maximum-prefix restart timer expired, restore peering",
peer->host);
if ((peer_clear(peer, NULL) < 0) && bgp_debug_neighbor_events(peer))
zlog_debug("%s: %s peer_clear failed", __func__, peer->host);
return 0;
}
static uint32_t bgp_filtered_routes_count(struct peer *peer, afi_t afi,
safi_t safi)
{
uint32_t count = 0;
bool filtered = false;
struct bgp_dest *dest;
struct bgp_adj_in *ain;
struct attr attr = {};
struct bgp_table *table = peer->bgp->rib[afi][safi];
for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) {
for (ain = dest->adj_in; ain; ain = ain->next) {
const struct prefix *rn_p = bgp_dest_get_prefix(dest);
attr = *ain->attr;
if (bgp_input_filter(peer, rn_p, &attr, afi, safi)
== FILTER_DENY)
filtered = true;
if (bgp_input_modifier(
peer, rn_p, &attr, afi, safi,
ROUTE_MAP_IN_NAME(&peer->filter[afi][safi]),
NULL, 0, NULL)
== RMAP_DENY)
filtered = true;
if (filtered)
count++;
bgp_attr_undup(&attr, ain->attr);
}
}
return count;
}
bool bgp_maximum_prefix_overflow(struct peer *peer, afi_t afi, safi_t safi,
int always)
{
iana_afi_t pkt_afi;
iana_safi_t pkt_safi;
uint32_t pcount = (CHECK_FLAG(peer->af_flags[afi][safi],
PEER_FLAG_MAX_PREFIX_FORCE))
? bgp_filtered_routes_count(peer, afi, safi)
+ peer->pcount[afi][safi]
: peer->pcount[afi][safi];
if (!CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
return false;
if (pcount > peer->pmax[afi][safi]) {
if (CHECK_FLAG(peer->af_sflags[afi][safi],
PEER_STATUS_PREFIX_LIMIT)
&& !always)
return false;
zlog_info(
"%%MAXPFXEXCEED: No. of %s prefix received from %s %u exceed, limit %u",
get_afi_safi_str(afi, safi, false), peer->host, pcount,
peer->pmax[afi][safi]);
SET_FLAG(peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
if (CHECK_FLAG(peer->af_flags[afi][safi],
PEER_FLAG_MAX_PREFIX_WARNING))
return false;
/* Convert AFI, SAFI to values for packet. */
pkt_afi = afi_int2iana(afi);
pkt_safi = safi_int2iana(safi);
{
uint8_t ndata[7];
ndata[0] = (pkt_afi >> 8);
ndata[1] = pkt_afi;
ndata[2] = pkt_safi;
ndata[3] = (peer->pmax[afi][safi] >> 24);
ndata[4] = (peer->pmax[afi][safi] >> 16);
ndata[5] = (peer->pmax[afi][safi] >> 8);
ndata[6] = (peer->pmax[afi][safi]);
SET_FLAG(peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
bgp_notify_send_with_data(peer, BGP_NOTIFY_CEASE,
BGP_NOTIFY_CEASE_MAX_PREFIX,
ndata, 7);
}
/* Dynamic peers will just close their connection. */
if (peer_dynamic_neighbor(peer))
return true;
/* restart timer start */
if (peer->pmax_restart[afi][safi]) {
peer->v_pmax_restart =
peer->pmax_restart[afi][safi] * 60;
if (bgp_debug_neighbor_events(peer))
zlog_debug(
"%s Maximum-prefix restart timer started for %d secs",
peer->host, peer->v_pmax_restart);
BGP_TIMER_ON(peer->t_pmax_restart,
bgp_maximum_prefix_restart_timer,
peer->v_pmax_restart);
}
return true;
} else
UNSET_FLAG(peer->af_sflags[afi][safi],
PEER_STATUS_PREFIX_LIMIT);
if (pcount
> (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100)) {
if (CHECK_FLAG(peer->af_sflags[afi][safi],
PEER_STATUS_PREFIX_THRESHOLD)
&& !always)
return false;
zlog_info(
"%%MAXPFX: No. of %s prefix received from %s reaches %u, max %u",
get_afi_safi_str(afi, safi, false), peer->host, pcount,
peer->pmax[afi][safi]);
SET_FLAG(peer->af_sflags[afi][safi],
PEER_STATUS_PREFIX_THRESHOLD);
} else
UNSET_FLAG(peer->af_sflags[afi][safi],
PEER_STATUS_PREFIX_THRESHOLD);
return false;
}
/* Unconditionally remove the route from the RIB, without taking
* damping into consideration (eg, because the session went down)
*/
void bgp_rib_remove(struct bgp_dest *dest, struct bgp_path_info *pi,
struct peer *peer, afi_t afi, safi_t safi)
{
struct bgp *bgp = NULL;
bool delete_route = false;
bgp_aggregate_decrement(peer->bgp, bgp_dest_get_prefix(dest), pi, afi,
safi);
if (!CHECK_FLAG(pi->flags, BGP_PATH_HISTORY)) {
bgp_path_info_delete(dest, pi); /* keep historical info */
/* If the selected path is removed, reset BGP_NODE_SELECT_DEFER
* flag
*/
if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED))
delete_route = true;
else if (bgp_dest_set_defer_flag(dest, true) < 0)
delete_route = true;
if (delete_route) {
if (CHECK_FLAG(dest->flags, BGP_NODE_SELECT_DEFER)) {
UNSET_FLAG(dest->flags, BGP_NODE_SELECT_DEFER);
bgp = pi->peer->bgp;
bgp->gr_info[afi][safi].gr_deferred--;
}
}
}
hook_call(bgp_process, peer->bgp, afi, safi, dest, peer, true);
bgp_process(peer->bgp, dest, afi, safi);
}
static void bgp_rib_withdraw(struct bgp_dest *dest, struct bgp_path_info *pi,
struct peer *peer, afi_t afi, safi_t safi,
struct prefix_rd *prd)
{
const struct prefix *p = bgp_dest_get_prefix(dest);
/* apply dampening, if result is suppressed, we'll be retaining
* the bgp_path_info in the RIB for historical reference.
*/
if (CHECK_FLAG(peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
&& peer->sort == BGP_PEER_EBGP)
if ((bgp_damp_withdraw(pi, dest, afi, safi, 0))
== BGP_DAMP_SUPPRESSED) {
bgp_aggregate_decrement(peer->bgp, p, pi, afi,
safi);
return;
}
#ifdef ENABLE_BGP_VNC
if (safi == SAFI_MPLS_VPN) {
struct bgp_dest *pdest = NULL;
struct bgp_table *table = NULL;
pdest = bgp_node_get(peer->bgp->rib[afi][safi],
(struct prefix *)prd);
if (bgp_dest_has_bgp_path_info_data(pdest)) {
table = bgp_dest_get_bgp_table_info(pdest);
vnc_import_bgp_del_vnc_host_route_mode_resolve_nve(
peer->bgp, prd, table, p, pi);
}
bgp_dest_unlock_node(pdest);
}
if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) {
if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)) {
vnc_import_bgp_del_route(peer->bgp, p, pi);
vnc_import_bgp_exterior_del_route(peer->bgp, p, pi);
}
}
#endif
/* If this is an EVPN route, process for un-import. */
if (safi == SAFI_EVPN)
bgp_evpn_unimport_route(peer->bgp, afi, safi, p, pi);
bgp_rib_remove(dest, pi, peer, afi, safi);
}
struct bgp_path_info *info_make(int type, int sub_type, unsigned short instance,
struct peer *peer, struct attr *attr,
struct bgp_dest *dest)
{
struct bgp_path_info *new;
/* Make new BGP info. */
new = XCALLOC(MTYPE_BGP_ROUTE, sizeof(struct bgp_path_info));
new->type = type;
new->instance = instance;
new->sub_type = sub_type;
new->peer = peer;
new->attr = attr;
new->uptime = bgp_clock();
new->net = dest;
return new;
}
static bool overlay_index_equal(afi_t afi, struct bgp_path_info *path,
union gw_addr *gw_ip)
{
const struct bgp_route_evpn *eo = bgp_attr_get_evpn_overlay(path->attr);
union gw_addr path_gw_ip, *path_gw_ip_remote;
union {
esi_t esi;
union gw_addr ip;
} temp;
if (afi != AFI_L2VPN)
return true;
path_gw_ip = eo->gw_ip;
if (gw_ip == NULL) {
memset(&temp, 0, sizeof(temp));
path_gw_ip_remote = &temp.ip;
} else
path_gw_ip_remote = gw_ip;
return !!memcmp(&path_gw_ip, path_gw_ip_remote, sizeof(union gw_addr));
}
/* Check if received nexthop is valid or not. */
bool bgp_update_martian_nexthop(struct bgp *bgp, afi_t afi, safi_t safi,
uint8_t type, uint8_t stype, struct attr *attr,
struct bgp_dest *dest)
{
bool ret = false;
bool is_bgp_static_route =
(type == ZEBRA_ROUTE_BGP && stype == BGP_ROUTE_STATIC) ? true
: false;
/*
* Only validated for unicast and multicast currently.
* Also valid for EVPN where the nexthop is an IP address.
* If we are a bgp static route being checked then there is
* no need to check to see if the nexthop is martian as
* that it should be ok.
*/
if (is_bgp_static_route ||
(safi != SAFI_UNICAST && safi != SAFI_MULTICAST && safi != SAFI_EVPN))
return false;
/* If NEXT_HOP is present, validate it. */
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP)) {
if (attr->nexthop.s_addr == INADDR_ANY
|| IPV4_CLASS_DE(ntohl(attr->nexthop.s_addr))
|| bgp_nexthop_self(bgp, afi, type, stype, attr, dest))
return true;
}
/* If MP_NEXTHOP is present, validate it. */
/* Note: For IPv6 nexthops, we only validate the global (1st) nexthop;
* there is code in bgp_attr.c to ignore the link-local (2nd) nexthop if
* it is not an IPv6 link-local address.
*
* If we receive an UPDATE with nexthop length set to 32 bytes
* we shouldn't discard an UPDATE if it's set to (::).
* The link-local (2st) is validated along the code path later.
*/
if (attr->mp_nexthop_len) {
switch (attr->mp_nexthop_len) {
case BGP_ATTR_NHLEN_IPV4:
case BGP_ATTR_NHLEN_VPNV4:
ret = (attr->mp_nexthop_global_in.s_addr == INADDR_ANY
|| IPV4_CLASS_DE(
ntohl(attr->mp_nexthop_global_in.s_addr))
|| bgp_nexthop_self(bgp, afi, type, stype, attr,
dest));
break;
case BGP_ATTR_NHLEN_IPV6_GLOBAL:
case BGP_ATTR_NHLEN_VPNV6_GLOBAL:
ret = (IN6_IS_ADDR_UNSPECIFIED(
&attr->mp_nexthop_global)
|| IN6_IS_ADDR_LOOPBACK(&attr->mp_nexthop_global)
|| IN6_IS_ADDR_MULTICAST(
&attr->mp_nexthop_global)
|| bgp_nexthop_self(bgp, afi, type, stype, attr,
dest));
break;
case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL:
ret = (IN6_IS_ADDR_LOOPBACK(&attr->mp_nexthop_global)
|| IN6_IS_ADDR_MULTICAST(
&attr->mp_nexthop_global)
|| bgp_nexthop_self(bgp, afi, type, stype, attr,
dest));
break;
default:
ret = true;
break;
}
}
return ret;
}
static void bgp_attr_add_no_export_community(struct attr *attr)
{
struct community *old;
struct community *new;
struct community *merge;
struct community *no_export;
old = attr->community;
no_export = community_str2com("no-export");
assert(no_export);
if (old) {
merge = community_merge(community_dup(old), no_export);
if (!old->refcnt)
community_free(&old);
new = community_uniq_sort(merge);
community_free(&merge);
} else {
new = community_dup(no_export);
}
community_free(&no_export);
attr->community = new;
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES);
}
int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
struct attr *attr, afi_t afi, safi_t safi, int type,
int sub_type, struct prefix_rd *prd, mpls_label_t *label,
uint32_t num_labels, int soft_reconfig,
struct bgp_route_evpn *evpn)
{
int ret;
int aspath_loop_count = 0;
struct bgp_dest *dest;
struct bgp *bgp;
struct attr new_attr;
struct attr *attr_new;
struct bgp_path_info *pi;
struct bgp_path_info *new;
struct bgp_path_info_extra *extra;
const char *reason;
char pfx_buf[BGP_PRD_PATH_STRLEN];
int connected = 0;
int do_loop_check = 1;
int has_valid_label = 0;
afi_t nh_afi;
uint8_t pi_type = 0;
uint8_t pi_sub_type = 0;
bool force_evpn_import = false;
if (frrtrace_enabled(frr_bgp, process_update)) {
char pfxprint[PREFIX2STR_BUFFER];
prefix2str(p, pfxprint, sizeof(pfxprint));
frrtrace(6, frr_bgp, process_update, peer, pfxprint, addpath_id,
afi, safi, attr);
}
#ifdef ENABLE_BGP_VNC
int vnc_implicit_withdraw = 0;
#endif
int same_attr = 0;
memset(&new_attr, 0, sizeof(struct attr));
new_attr.label_index = BGP_INVALID_LABEL_INDEX;
new_attr.label = MPLS_INVALID_LABEL;
bgp = peer->bgp;
dest = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi, p, prd);
/* TODO: Check to see if we can get rid of "is_valid_label" */
if (afi == AFI_L2VPN && safi == SAFI_EVPN)
has_valid_label = (num_labels > 0) ? 1 : 0;
else
has_valid_label = bgp_is_valid_label(label);
if (has_valid_label)
assert(label != NULL);
/* Update overlay index of the attribute */
if (afi == AFI_L2VPN && evpn)
memcpy(&attr->evpn_overlay, evpn,
sizeof(struct bgp_route_evpn));
/* When peer's soft reconfiguration enabled. Record input packet in
Adj-RIBs-In. */
if (!soft_reconfig
&& CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
&& peer != bgp->peer_self)
bgp_adj_in_set(dest, peer, attr, addpath_id);
/* Check previously received route. */
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next)
if (pi->peer == peer && pi->type == type
&& pi->sub_type == sub_type
&& pi->addpath_rx_id == addpath_id)
break;
/* AS path local-as loop check. */
if (peer->change_local_as) {
if (peer->allowas_in[afi][safi])
aspath_loop_count = peer->allowas_in[afi][safi];
else if (!CHECK_FLAG(peer->flags,
PEER_FLAG_LOCAL_AS_NO_PREPEND))
aspath_loop_count = 1;
if (aspath_loop_check(attr->aspath, peer->change_local_as)
> aspath_loop_count) {
peer->stat_pfx_aspath_loop++;
reason = "as-path contains our own AS;";
goto filtered;
}
}
/* If the peer is configured for "allowas-in origin" and the last ASN in
* the
* as-path is our ASN then we do not need to call aspath_loop_check
*/
if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN_ORIGIN))
if (aspath_get_last_as(attr->aspath) == bgp->as)
do_loop_check = 0;
/* AS path loop check. */
if (do_loop_check) {
if (aspath_loop_check(attr->aspath, bgp->as)
> peer->allowas_in[afi][safi]
|| (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
&& aspath_loop_check(attr->aspath, bgp->confed_id)
> peer->allowas_in[afi][safi])) {
peer->stat_pfx_aspath_loop++;
reason = "as-path contains our own AS;";
goto filtered;
}
}
/* Route reflector originator ID check. */
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)
&& IPV4_ADDR_SAME(&bgp->router_id, &attr->originator_id)) {
peer->stat_pfx_originator_loop++;
reason = "originator is us;";
goto filtered;
}
/* Route reflector cluster ID check. */
if (bgp_cluster_filter(peer, attr)) {
peer->stat_pfx_cluster_loop++;
reason = "reflected from the same cluster;";
goto filtered;
}
/* Apply incoming filter. */
if (bgp_input_filter(peer, p, attr, afi, safi) == FILTER_DENY) {
peer->stat_pfx_filter++;
reason = "filter;";
goto filtered;
}
/* RFC 8212 to prevent route leaks.
* This specification intends to improve this situation by requiring the
* explicit configuration of both BGP Import and Export Policies for any
* External BGP (EBGP) session such as customers, peers, or
* confederation boundaries for all enabled address families. Through
* codification of the aforementioned requirement, operators will
* benefit from consistent behavior across different BGP
* implementations.
*/
if (CHECK_FLAG(bgp->flags, BGP_FLAG_EBGP_REQUIRES_POLICY))
if (!bgp_inbound_policy_exists(peer,
&peer->filter[afi][safi])) {
reason = "inbound policy missing";
goto filtered;
}
/* draft-ietf-idr-deprecate-as-set-confed-set
* Filter routes having AS_SET or AS_CONFED_SET in the path.
* Eventually, This document (if approved) updates RFC 4271
* and RFC 5065 by eliminating AS_SET and AS_CONFED_SET types,
* and obsoletes RFC 6472.
*/
if (peer->bgp->reject_as_sets)
if (aspath_check_as_sets(attr->aspath)) {
reason =
"as-path contains AS_SET or AS_CONFED_SET type;";
goto filtered;
}
new_attr = *attr;
/* Apply incoming route-map.
* NB: new_attr may now contain newly allocated values from route-map
* "set"
* commands, so we need bgp_attr_flush in the error paths, until we
* intern
* the attr (which takes over the memory references) */
if (bgp_input_modifier(peer, p, &new_attr, afi, safi, NULL, label,
num_labels, dest)
== RMAP_DENY) {
peer->stat_pfx_filter++;
reason = "route-map;";
bgp_attr_flush(&new_attr);
goto filtered;
}
if (pi && pi->attr->rmap_table_id != new_attr.rmap_table_id) {
if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED))
/* remove from RIB previous entry */
bgp_zebra_withdraw(p, pi, bgp, safi);
}
if (peer->sort == BGP_PEER_EBGP) {
/* rfc7999:
* A BGP speaker receiving an announcement tagged with the
* BLACKHOLE community SHOULD add the NO_ADVERTISE or
* NO_EXPORT community as defined in RFC1997, or a
* similar community, to prevent propagation of the
* prefix outside the local AS. The community to prevent
* propagation SHOULD be chosen according to the operator's
* routing policy.
*/
if (new_attr.community
&& community_include(new_attr.community,
COMMUNITY_BLACKHOLE))
bgp_attr_add_no_export_community(&new_attr);
/* If we receive the graceful-shutdown community from an eBGP
* peer we must lower local-preference */
if (new_attr.community
&& community_include(new_attr.community, COMMUNITY_GSHUT)) {
new_attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF);
new_attr.local_pref = BGP_GSHUT_LOCAL_PREF;
/* If graceful-shutdown is configured then add the GSHUT
* community to all paths received from eBGP peers */
} else if (bgp_in_graceful_shutdown(peer->bgp))
bgp_attr_add_gshut_community(&new_attr);
}
if (pi) {
pi_type = pi->type;
pi_sub_type = pi->sub_type;
}
/* next hop check. */
if (!CHECK_FLAG(peer->flags, PEER_FLAG_IS_RFAPI_HD)
&& bgp_update_martian_nexthop(bgp, afi, safi, pi_type, pi_sub_type,
&new_attr, dest)) {
peer->stat_pfx_nh_invalid++;
reason = "martian or self next-hop;";
bgp_attr_flush(&new_attr);
goto filtered;
}
if (bgp_mac_entry_exists(p) || bgp_mac_exist(&attr->rmac)) {
peer->stat_pfx_nh_invalid++;
reason = "self mac;";
goto filtered;
}
/* The flag BGP_NODE_FIB_INSTALL_PENDING is for the following
* condition :
* Suppress fib is enabled
* BGP_OPT_NO_FIB is not enabled
* Route type is BGP_ROUTE_NORMAL (peer learnt routes)
* Route is being installed first time (BGP_NODE_FIB_INSTALLED not set)
*/
if (bgp_fibupd_safi(safi) && BGP_SUPPRESS_FIB_ENABLED(bgp)
&& (sub_type == BGP_ROUTE_NORMAL)
&& (!bgp_option_check(BGP_OPT_NO_FIB))
&& (!CHECK_FLAG(dest->flags, BGP_NODE_FIB_INSTALLED)))
SET_FLAG(dest->flags, BGP_NODE_FIB_INSTALL_PENDING);
attr_new = bgp_attr_intern(&new_attr);
/* If maximum prefix count is configured and current prefix
* count exeed it.
*/
if (bgp_maximum_prefix_overflow(peer, afi, safi, 0))
return -1;
/* If the update is implicit withdraw. */
if (pi) {
pi->uptime = bgp_clock();
same_attr = attrhash_cmp(pi->attr, attr_new);
hook_call(bgp_process, bgp, afi, safi, dest, peer, true);
/* Same attribute comes in. */
if (!CHECK_FLAG(pi->flags, BGP_PATH_REMOVED)
&& same_attr
&& (!has_valid_label
|| memcmp(&(bgp_path_info_extra_get(pi))->label, label,
num_labels * sizeof(mpls_label_t))
== 0)) {
if (CHECK_FLAG(bgp->af_flags[afi][safi],
BGP_CONFIG_DAMPENING)
&& peer->sort == BGP_PEER_EBGP
&& CHECK_FLAG(pi->flags, BGP_PATH_HISTORY)) {
if (bgp_debug_update(peer, p, NULL, 1)) {
bgp_debug_rdpfxpath2str(
afi, safi, prd, p, label,
num_labels, addpath_id ? 1 : 0,
addpath_id, evpn, pfx_buf,
sizeof(pfx_buf));
zlog_debug("%s rcvd %s", peer->host,
pfx_buf);
}
if (bgp_damp_update(pi, dest, afi, safi)
!= BGP_DAMP_SUPPRESSED) {
bgp_aggregate_increment(bgp, p, pi, afi,
safi);
bgp_process(bgp, dest, afi, safi);
}
} else /* Duplicate - odd */
{
if (bgp_debug_update(peer, p, NULL, 1)) {
if (!peer->rcvd_attr_printed) {
zlog_debug(
"%s rcvd UPDATE w/ attr: %s",
peer->host,
peer->rcvd_attr_str);
peer->rcvd_attr_printed = 1;
}
bgp_debug_rdpfxpath2str(
afi, safi, prd, p, label,
num_labels, addpath_id ? 1 : 0,
addpath_id, evpn, pfx_buf,
sizeof(pfx_buf));
zlog_debug(
"%s rcvd %s...duplicate ignored",
peer->host, pfx_buf);
}
/* graceful restart STALE flag unset. */
if (CHECK_FLAG(pi->flags, BGP_PATH_STALE)) {
bgp_path_info_unset_flag(
dest, pi, BGP_PATH_STALE);
bgp_dest_set_defer_flag(dest, false);
bgp_process(bgp, dest, afi, safi);
}
}
bgp_dest_unlock_node(dest);
bgp_attr_unintern(&attr_new);
return 0;
}
/* Withdraw/Announce before we fully processed the withdraw */
if (CHECK_FLAG(pi->flags, BGP_PATH_REMOVED)) {
if (bgp_debug_update(peer, p, NULL, 1)) {
bgp_debug_rdpfxpath2str(
afi, safi, prd, p, label, num_labels,
addpath_id ? 1 : 0, addpath_id, evpn,
pfx_buf, sizeof(pfx_buf));
zlog_debug(
"%s rcvd %s, flapped quicker than processing",
peer->host, pfx_buf);
}
bgp_path_info_restore(dest, pi);
/*
* If the BGP_PATH_REMOVED flag is set, then EVPN
* routes would have been unimported already when a
* prior BGP withdraw processing happened. Such routes
* need to be imported again, so flag accordingly.
*/
force_evpn_import = true;
}
/* Received Logging. */
if (bgp_debug_update(peer, p, NULL, 1)) {
bgp_debug_rdpfxpath2str(afi, safi, prd, p, label,
num_labels, addpath_id ? 1 : 0,
addpath_id, evpn, pfx_buf,
sizeof(pfx_buf));
zlog_debug("%s rcvd %s", peer->host, pfx_buf);
}
/* graceful restart STALE flag unset. */
if (CHECK_FLAG(pi->flags, BGP_PATH_STALE)) {
bgp_path_info_unset_flag(dest, pi, BGP_PATH_STALE);
bgp_dest_set_defer_flag(dest, false);
}
/* The attribute is changed. */
bgp_path_info_set_flag(dest, pi, BGP_PATH_ATTR_CHANGED);
/* implicit withdraw, decrement aggregate and pcount here.
* only if update is accepted, they'll increment below.
*/
bgp_aggregate_decrement(bgp, p, pi, afi, safi);
/* Update bgp route dampening information. */
if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
&& peer->sort == BGP_PEER_EBGP) {
/* This is implicit withdraw so we should update
dampening
information. */
if (!CHECK_FLAG(pi->flags, BGP_PATH_HISTORY))
bgp_damp_withdraw(pi, dest, afi, safi, 1);
}
#ifdef ENABLE_BGP_VNC
if (safi == SAFI_MPLS_VPN) {
struct bgp_dest *pdest = NULL;
struct bgp_table *table = NULL;
pdest = bgp_node_get(bgp->rib[afi][safi],
(struct prefix *)prd);
if (bgp_dest_has_bgp_path_info_data(pdest)) {
table = bgp_dest_get_bgp_table_info(pdest);
vnc_import_bgp_del_vnc_host_route_mode_resolve_nve(
bgp, prd, table, p, pi);
}
bgp_dest_unlock_node(pdest);
}
if ((afi == AFI_IP || afi == AFI_IP6)
&& (safi == SAFI_UNICAST)) {
if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)) {
/*
* Implicit withdraw case.
*/
++vnc_implicit_withdraw;
vnc_import_bgp_del_route(bgp, p, pi);
vnc_import_bgp_exterior_del_route(bgp, p, pi);
}
}
#endif
/* Special handling for EVPN update of an existing route. If the
* extended community attribute has changed, we need to
* un-import
* the route using its existing extended community. It will be
* subsequently processed for import with the new extended
* community.
*/
if (((safi == SAFI_EVPN) || (safi == SAFI_MPLS_VPN))
&& !same_attr) {
if ((pi->attr->flag
& ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
&& (attr_new->flag
& ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))) {
int cmp;
cmp = ecommunity_cmp(pi->attr->ecommunity,
attr_new->ecommunity);
if (!cmp) {
if (bgp_debug_update(peer, p, NULL, 1))
zlog_debug(
"Change in EXT-COMM, existing %s new %s",
ecommunity_str(
pi->attr->ecommunity),
ecommunity_str(
attr_new->ecommunity));
if (safi == SAFI_EVPN)
bgp_evpn_unimport_route(
bgp, afi, safi, p, pi);
else /* SAFI_MPLS_VPN */
vpn_leak_to_vrf_withdraw(bgp,
pi);
}
}
}
/* Update to new attribute. */
bgp_attr_unintern(&pi->attr);
pi->attr = attr_new;
/* Update MPLS label */
if (has_valid_label) {
extra = bgp_path_info_extra_get(pi);
if (extra->label != label) {
memcpy(&extra->label, label,
num_labels * sizeof(mpls_label_t));
extra->num_labels = num_labels;
}
if (!(afi == AFI_L2VPN && safi == SAFI_EVPN))
bgp_set_valid_label(&extra->label[0]);
}
/* Update SRv6 SID */
if (attr->srv6_l3vpn) {
extra = bgp_path_info_extra_get(pi);
if (sid_diff(&extra->sid[0].sid,
&attr->srv6_l3vpn->sid)) {
sid_copy(&extra->sid[0].sid,
&attr->srv6_l3vpn->sid);
extra->num_sids = 1;
extra->sid[0].loc_block_len = 0;
extra->sid[0].loc_node_len = 0;
extra->sid[0].func_len = 0;
extra->sid[0].arg_len = 0;
if (attr->srv6_l3vpn->loc_block_len != 0) {
extra->sid[0].loc_block_len =
attr->srv6_l3vpn->loc_block_len;
extra->sid[0].loc_node_len =
attr->srv6_l3vpn->loc_node_len;
extra->sid[0].func_len =
attr->srv6_l3vpn->func_len;
extra->sid[0].arg_len =
attr->srv6_l3vpn->arg_len;
}
/*
* draft-ietf-bess-srv6-services-07
* The part of SRv6 SID may be encoded as MPLS
* Label for the efficient packing.
*/
if (attr->srv6_l3vpn->transposition_len != 0)
transpose_sid(
&extra->sid[0].sid,
decode_label(label),
attr->srv6_l3vpn
->transposition_offset,
attr->srv6_l3vpn
->transposition_len);
}
} else if (attr->srv6_vpn) {
extra = bgp_path_info_extra_get(pi);
if (sid_diff(&extra->sid[0].sid,
&attr->srv6_vpn->sid)) {
sid_copy(&extra->sid[0].sid,
&attr->srv6_vpn->sid);
extra->num_sids = 1;
}
}
#ifdef ENABLE_BGP_VNC
if ((afi == AFI_IP || afi == AFI_IP6)
&& (safi == SAFI_UNICAST)) {
if (vnc_implicit_withdraw) {
/*
* Add back the route with its new attributes
* (e.g., nexthop).
* The route is still selected, until the route
* selection
* queued by bgp_process actually runs. We have
* to make this
* update to the VNC side immediately to avoid
* racing against
* configuration changes (e.g., route-map
* changes) which
* trigger re-importation of the entire RIB.
*/
vnc_import_bgp_add_route(bgp, p, pi);
vnc_import_bgp_exterior_add_route(bgp, p, pi);
}
}
#endif
/* Update bgp route dampening information. */
if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
&& peer->sort == BGP_PEER_EBGP) {
/* Now we do normal update dampening. */
ret = bgp_damp_update(pi, dest, afi, safi);
if (ret == BGP_DAMP_SUPPRESSED) {
bgp_dest_unlock_node(dest);
return 0;
}
}
/* Nexthop reachability check - for unicast and
* labeled-unicast.. */
if (((afi == AFI_IP || afi == AFI_IP6)
&& (safi == SAFI_UNICAST || safi == SAFI_LABELED_UNICAST))
|| (safi == SAFI_EVPN &&
bgp_evpn_is_prefix_nht_supported(p))) {
if (safi != SAFI_EVPN && peer->sort == BGP_PEER_EBGP
&& peer->ttl == BGP_DEFAULT_TTL
&& !CHECK_FLAG(peer->flags,
PEER_FLAG_DISABLE_CONNECTED_CHECK)
&& !CHECK_FLAG(bgp->flags,
BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
connected = 1;
else
connected = 0;
struct bgp *bgp_nexthop = bgp;
if (pi->extra && pi->extra->bgp_orig)
bgp_nexthop = pi->extra->bgp_orig;
nh_afi = BGP_ATTR_NH_AFI(afi, pi->attr);
if (bgp_find_or_add_nexthop(bgp, bgp_nexthop, nh_afi,
safi, pi, NULL, connected,
p)
|| CHECK_FLAG(peer->flags, PEER_FLAG_IS_RFAPI_HD))
bgp_path_info_set_flag(dest, pi,
BGP_PATH_VALID);
else {
if (BGP_DEBUG(nht, NHT)) {
zlog_debug("%s(%pI4): NH unresolved",
__func__,
(in_addr_t *)&attr_new->nexthop);
}
bgp_path_info_unset_flag(dest, pi,
BGP_PATH_VALID);
}
} else
bgp_path_info_set_flag(dest, pi, BGP_PATH_VALID);
#ifdef ENABLE_BGP_VNC
if (safi == SAFI_MPLS_VPN) {
struct bgp_dest *pdest = NULL;
struct bgp_table *table = NULL;
pdest = bgp_node_get(bgp->rib[afi][safi],
(struct prefix *)prd);
if (bgp_dest_has_bgp_path_info_data(pdest)) {
table = bgp_dest_get_bgp_table_info(pdest);
vnc_import_bgp_add_vnc_host_route_mode_resolve_nve(
bgp, prd, table, p, pi);
}
bgp_dest_unlock_node(pdest);
}
#endif
/* If this is an EVPN route and some attribute has changed,
* or we are explicitly told to perform a route import, process
* route for import. If the extended community has changed, we
* would
* have done the un-import earlier and the import would result
* in the
* route getting injected into appropriate L2 VNIs. If it is
* just
* some other attribute change, the import will result in
* updating
* the attributes for the route in the VNI(s).
*/
if (safi == SAFI_EVPN &&
(!same_attr || force_evpn_import) &&
CHECK_FLAG(pi->flags, BGP_PATH_VALID))
bgp_evpn_import_route(bgp, afi, safi, p, pi);
/* Process change. */
bgp_aggregate_increment(bgp, p, pi, afi, safi);
bgp_process(bgp, dest, afi, safi);
bgp_dest_unlock_node(dest);
if (SAFI_UNICAST == safi
&& (bgp->inst_type == BGP_INSTANCE_TYPE_VRF
|| bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) {
vpn_leak_from_vrf_update(bgp_get_default(), bgp, pi);
}
if ((SAFI_MPLS_VPN == safi)
&& (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) {
vpn_leak_to_vrf_update(bgp, pi);
}
#ifdef ENABLE_BGP_VNC
if (SAFI_MPLS_VPN == safi) {
mpls_label_t label_decoded = decode_label(label);
rfapiProcessUpdate(peer, NULL, p, prd, attr, afi, safi,
type, sub_type, &label_decoded);
}
if (SAFI_ENCAP == safi) {
rfapiProcessUpdate(peer, NULL, p, prd, attr, afi, safi,
type, sub_type, NULL);
}
#endif
return 0;
} // End of implicit withdraw
/* Received Logging. */
if (bgp_debug_update(peer, p, NULL, 1)) {
if (!peer->rcvd_attr_printed) {
zlog_debug("%s rcvd UPDATE w/ attr: %s", peer->host,
peer->rcvd_attr_str);
peer->rcvd_attr_printed = 1;
}
bgp_debug_rdpfxpath2str(afi, safi, prd, p, label, num_labels,
addpath_id ? 1 : 0, addpath_id, evpn,
pfx_buf, sizeof(pfx_buf));
zlog_debug("%s rcvd %s", peer->host, pfx_buf);
}
/* Make new BGP info. */
new = info_make(type, sub_type, 0, peer, attr_new, dest);
/* Update MPLS label */
if (has_valid_label) {
extra = bgp_path_info_extra_get(new);
if (extra->label != label) {
memcpy(&extra->label, label,
num_labels * sizeof(mpls_label_t));
extra->num_labels = num_labels;
}
if (!(afi == AFI_L2VPN && safi == SAFI_EVPN))
bgp_set_valid_label(&extra->label[0]);
}
/* Update SRv6 SID */
if (safi == SAFI_MPLS_VPN) {
extra = bgp_path_info_extra_get(new);
if (attr->srv6_l3vpn) {
sid_copy(&extra->sid[0].sid, &attr->srv6_l3vpn->sid);
extra->num_sids = 1;
extra->sid[0].loc_block_len =
attr->srv6_l3vpn->loc_block_len;
extra->sid[0].loc_node_len =
attr->srv6_l3vpn->loc_node_len;
extra->sid[0].func_len = attr->srv6_l3vpn->func_len;
extra->sid[0].arg_len = attr->srv6_l3vpn->arg_len;
/*
* draft-ietf-bess-srv6-services-07
* The part of SRv6 SID may be encoded as MPLS Label for
* the efficient packing.
*/
if (attr->srv6_l3vpn->transposition_len != 0)
transpose_sid(
&extra->sid[0].sid, decode_label(label),
attr->srv6_l3vpn->transposition_offset,
attr->srv6_l3vpn->transposition_len);
} else if (attr->srv6_vpn) {
sid_copy(&extra->sid[0].sid, &attr->srv6_vpn->sid);
extra->num_sids = 1;
}
}
/* Nexthop reachability check. */
if (((afi == AFI_IP || afi == AFI_IP6)
&& (safi == SAFI_UNICAST || safi == SAFI_LABELED_UNICAST))
|| (safi == SAFI_EVPN && bgp_evpn_is_prefix_nht_supported(p))) {
if (safi != SAFI_EVPN && peer->sort == BGP_PEER_EBGP
&& peer->ttl == BGP_DEFAULT_TTL
&& !CHECK_FLAG(peer->flags,
PEER_FLAG_DISABLE_CONNECTED_CHECK)
&& !CHECK_FLAG(bgp->flags,
BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
connected = 1;
else
connected = 0;
nh_afi = BGP_ATTR_NH_AFI(afi, new->attr);
if (bgp_find_or_add_nexthop(bgp, bgp, nh_afi, safi, new, NULL,
connected, p)
|| CHECK_FLAG(peer->flags, PEER_FLAG_IS_RFAPI_HD))
bgp_path_info_set_flag(dest, new, BGP_PATH_VALID);
else {
if (BGP_DEBUG(nht, NHT)) {
char buf1[INET6_ADDRSTRLEN];
inet_ntop(AF_INET,
(const void *)&attr_new->nexthop,
buf1, INET6_ADDRSTRLEN);
zlog_debug("%s(%s): NH unresolved", __func__,
buf1);
}
bgp_path_info_unset_flag(dest, new, BGP_PATH_VALID);
}
} else
bgp_path_info_set_flag(dest, new, BGP_PATH_VALID);
/* Addpath ID */
new->addpath_rx_id = addpath_id;
/* Increment prefix */
bgp_aggregate_increment(bgp, p, new, afi, safi);
/* Register new BGP information. */
bgp_path_info_add(dest, new);
/* route_node_get lock */
bgp_dest_unlock_node(dest);
#ifdef ENABLE_BGP_VNC
if (safi == SAFI_MPLS_VPN) {
struct bgp_dest *pdest = NULL;
struct bgp_table *table = NULL;
pdest = bgp_node_get(bgp->rib[afi][safi], (struct prefix *)prd);
if (bgp_dest_has_bgp_path_info_data(pdest)) {
table = bgp_dest_get_bgp_table_info(pdest);
vnc_import_bgp_add_vnc_host_route_mode_resolve_nve(
bgp, prd, table, p, new);
}
bgp_dest_unlock_node(pdest);
}
#endif
/* If this is an EVPN route, process for import. */
if (safi == SAFI_EVPN && CHECK_FLAG(new->flags, BGP_PATH_VALID))
bgp_evpn_import_route(bgp, afi, safi, p, new);
hook_call(bgp_process, bgp, afi, safi, dest, peer, false);
/* Process change. */
bgp_process(bgp, dest, afi, safi);
if (SAFI_UNICAST == safi
&& (bgp->inst_type == BGP_INSTANCE_TYPE_VRF
|| bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) {
vpn_leak_from_vrf_update(bgp_get_default(), bgp, new);
}
if ((SAFI_MPLS_VPN == safi)
&& (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) {
vpn_leak_to_vrf_update(bgp, new);
}
#ifdef ENABLE_BGP_VNC
if (SAFI_MPLS_VPN == safi) {
mpls_label_t label_decoded = decode_label(label);
rfapiProcessUpdate(peer, NULL, p, prd, attr, afi, safi, type,
sub_type, &label_decoded);
}
if (SAFI_ENCAP == safi) {
rfapiProcessUpdate(peer, NULL, p, prd, attr, afi, safi, type,
sub_type, NULL);
}
#endif
return 0;
/* This BGP update is filtered. Log the reason then update BGP
entry. */
filtered:
hook_call(bgp_process, bgp, afi, safi, dest, peer, true);
if (bgp_debug_update(peer, p, NULL, 1)) {
if (!peer->rcvd_attr_printed) {
zlog_debug("%s rcvd UPDATE w/ attr: %s", peer->host,
peer->rcvd_attr_str);
peer->rcvd_attr_printed = 1;
}
bgp_debug_rdpfxpath2str(afi, safi, prd, p, label, num_labels,
addpath_id ? 1 : 0, addpath_id, evpn,
pfx_buf, sizeof(pfx_buf));
zlog_debug("%s rcvd UPDATE about %s -- DENIED due to: %s",
peer->host, pfx_buf, reason);
}
if (pi) {
/* If this is an EVPN route, un-import it as it is now filtered.
*/
if (safi == SAFI_EVPN)
bgp_evpn_unimport_route(bgp, afi, safi, p, pi);
if (SAFI_UNICAST == safi
&& (bgp->inst_type == BGP_INSTANCE_TYPE_VRF
|| bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) {
vpn_leak_from_vrf_withdraw(bgp_get_default(), bgp, pi);
}
if ((SAFI_MPLS_VPN == safi)
&& (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) {
vpn_leak_to_vrf_withdraw(bgp, pi);
}
bgp_rib_remove(dest, pi, peer, afi, safi);
}
bgp_dest_unlock_node(dest);
#ifdef ENABLE_BGP_VNC
/*
* Filtered update is treated as an implicit withdrawal (see
* bgp_rib_remove()
* a few lines above)
*/
if ((SAFI_MPLS_VPN == safi) || (SAFI_ENCAP == safi)) {
rfapiProcessWithdraw(peer, NULL, p, prd, NULL, afi, safi, type,
0);
}
#endif
return 0;
}
int bgp_withdraw(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
struct attr *attr, afi_t afi, safi_t safi, int type,
int sub_type, struct prefix_rd *prd, mpls_label_t *label,
uint32_t num_labels, struct bgp_route_evpn *evpn)
{
struct bgp *bgp;
char pfx_buf[BGP_PRD_PATH_STRLEN];
struct bgp_dest *dest;
struct bgp_path_info *pi;
#ifdef ENABLE_BGP_VNC
if ((SAFI_MPLS_VPN == safi) || (SAFI_ENCAP == safi)) {
rfapiProcessWithdraw(peer, NULL, p, prd, NULL, afi, safi, type,
0);
}
#endif
bgp = peer->bgp;
/* Lookup node. */
dest = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi, p, prd);
/* If peer is soft reconfiguration enabled. Record input packet for
* further calculation.
*
* Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
* routes that are filtered. This tanks out Quagga RS pretty badly due
* to
* the iteration over all RS clients.
* Since we need to remove the entry from adj_in anyway, do that first
* and
* if there was no entry, we don't need to do anything more.
*/
if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
&& peer != bgp->peer_self)
if (!bgp_adj_in_unset(dest, peer, addpath_id)) {
peer->stat_pfx_dup_withdraw++;
if (bgp_debug_update(peer, p, NULL, 1)) {
bgp_debug_rdpfxpath2str(
afi, safi, prd, p, label, num_labels,
addpath_id ? 1 : 0, addpath_id, NULL,
pfx_buf, sizeof(pfx_buf));
zlog_debug(
"%s withdrawing route %s not in adj-in",
peer->host, pfx_buf);
}
bgp_dest_unlock_node(dest);
return 0;
}
/* Lookup withdrawn route. */
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next)
if (pi->peer == peer && pi->type == type
&& pi->sub_type == sub_type
&& pi->addpath_rx_id == addpath_id)
break;
/* Logging. */
if (bgp_debug_update(peer, p, NULL, 1)) {
bgp_debug_rdpfxpath2str(afi, safi, prd, p, label, num_labels,
addpath_id ? 1 : 0, addpath_id, NULL,
pfx_buf, sizeof(pfx_buf));
zlog_debug("%s rcvd UPDATE about %s -- withdrawn", peer->host,
pfx_buf);
}
/* Withdraw specified route from routing table. */
if (pi && !CHECK_FLAG(pi->flags, BGP_PATH_HISTORY)) {
bgp_rib_withdraw(dest, pi, peer, afi, safi, prd);
if (SAFI_UNICAST == safi
&& (bgp->inst_type == BGP_INSTANCE_TYPE_VRF
|| bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) {
vpn_leak_from_vrf_withdraw(bgp_get_default(), bgp, pi);
}
if ((SAFI_MPLS_VPN == safi)
&& (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) {
vpn_leak_to_vrf_withdraw(bgp, pi);
}
} else if (bgp_debug_update(peer, p, NULL, 1)) {
bgp_debug_rdpfxpath2str(afi, safi, prd, p, label, num_labels,
addpath_id ? 1 : 0, addpath_id, NULL,
pfx_buf, sizeof(pfx_buf));
zlog_debug("%s Can't find the route %s", peer->host, pfx_buf);
}
/* Unlock bgp_node_get() lock. */
bgp_dest_unlock_node(dest);
return 0;
}
void bgp_default_originate(struct peer *peer, afi_t afi, safi_t safi,
int withdraw)
{
struct update_subgroup *subgrp;
subgrp = peer_subgroup(peer, afi, safi);
subgroup_default_originate(subgrp, withdraw);
}
/*
* bgp_stop_announce_route_timer
*/
void bgp_stop_announce_route_timer(struct peer_af *paf)
{
if (!paf->t_announce_route)
return;
thread_cancel(&paf->t_announce_route);
}
/*
* bgp_announce_route_timer_expired
*
* Callback that is invoked when the route announcement timer for a
* peer_af expires.
*/
static int bgp_announce_route_timer_expired(struct thread *t)
{
struct peer_af *paf;
struct peer *peer;
paf = THREAD_ARG(t);
peer = paf->peer;
if (!peer_established(peer))
return 0;
if (!peer->afc_nego[paf->afi][paf->safi])
return 0;
peer_af_announce_route(paf, 1);
/* Notify BGP conditional advertisement scanner percess */
peer->advmap_config_change[paf->afi][paf->safi] = true;
return 0;
}
/*
* bgp_announce_route
*
* *Triggers* announcement of routes of a given AFI/SAFI to a peer.
*/
void bgp_announce_route(struct peer *peer, afi_t afi, safi_t safi)
{
struct peer_af *paf;
struct update_subgroup *subgrp;
paf = peer_af_find(peer, afi, safi);
if (!paf)
return;
subgrp = PAF_SUBGRP(paf);
/*
* Ignore if subgroup doesn't exist (implies AF is not negotiated)
* or a refresh has already been triggered.
*/
if (!subgrp || paf->t_announce_route)
return;
/*
* Start a timer to stagger/delay the announce. This serves
* two purposes - announcement can potentially be combined for
* multiple peers and the announcement doesn't happen in the
* vty context.
*/
thread_add_timer_msec(bm->master, bgp_announce_route_timer_expired, paf,
(subgrp->peer_count == 1)
? BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS
: BGP_ANNOUNCE_ROUTE_DELAY_MS,
&paf->t_announce_route);
}
/*
* Announce routes from all AF tables to a peer.
*
* This should ONLY be called when there is a need to refresh the
* routes to the peer based on a policy change for this peer alone
* or a route refresh request received from the peer.
* The operation will result in splitting the peer from its existing
* subgroups and putting it in new subgroups.
*/
void bgp_announce_route_all(struct peer *peer)
{
afi_t afi;
safi_t safi;
FOREACH_AFI_SAFI (afi, safi)
bgp_announce_route(peer, afi, safi);
}
/* Flag or unflag bgp_dest to determine whether it should be treated by
* bgp_soft_reconfig_table_task.
* Flag if flag is true. Unflag if flag is false.
*/
static void bgp_soft_reconfig_table_flag(struct bgp_table *table, bool flag)
{
struct bgp_dest *dest;
struct bgp_adj_in *ain;
if (!table)
return;
for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) {
for (ain = dest->adj_in; ain; ain = ain->next) {
if (ain->peer != NULL)
break;
}
if (flag && ain != NULL && ain->peer != NULL)
SET_FLAG(dest->flags, BGP_NODE_SOFT_RECONFIG);
else
UNSET_FLAG(dest->flags, BGP_NODE_SOFT_RECONFIG);
}
}
static int bgp_soft_reconfig_table_update(struct peer *peer,
struct bgp_dest *dest,
struct bgp_adj_in *ain, afi_t afi,
safi_t safi, struct prefix_rd *prd)
{
struct bgp_path_info *pi;
uint32_t num_labels = 0;
mpls_label_t *label_pnt = NULL;
struct bgp_route_evpn evpn;
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next)
if (pi->peer == peer)
break;
if (pi && pi->extra)
num_labels = pi->extra->num_labels;
if (num_labels)
label_pnt = &pi->extra->label[0];
if (pi)
memcpy(&evpn, bgp_attr_get_evpn_overlay(pi->attr),
sizeof(evpn));
else
memset(&evpn, 0, sizeof(evpn));
return bgp_update(peer, bgp_dest_get_prefix(dest), ain->addpath_rx_id,
ain->attr, afi, safi, ZEBRA_ROUTE_BGP,
BGP_ROUTE_NORMAL, prd, label_pnt, num_labels, 1,
&evpn);
}
static void bgp_soft_reconfig_table(struct peer *peer, afi_t afi, safi_t safi,
struct bgp_table *table,
struct prefix_rd *prd)
{
int ret;
struct bgp_dest *dest;
struct bgp_adj_in *ain;
if (!table)
table = peer->bgp->rib[afi][safi];
for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest))
for (ain = dest->adj_in; ain; ain = ain->next) {
if (ain->peer != peer)
continue;
ret = bgp_soft_reconfig_table_update(peer, dest, ain,
afi, safi, prd);
if (ret < 0) {
bgp_dest_unlock_node(dest);
return;
}
}
}
/* Do soft reconfig table per bgp table.
* Walk on SOFT_RECONFIG_TASK_MAX_PREFIX bgp_dest,
* when BGP_NODE_SOFT_RECONFIG is set,
* reconfig bgp_dest for list of table->soft_reconfig_peers peers.
* Schedule a new thread to continue the job.
* Without splitting the full job into several part,
* vtysh waits for the job to finish before responding to a BGP command
*/
static int bgp_soft_reconfig_table_task(struct thread *thread)
{
uint32_t iter, max_iter;
int ret;
struct bgp_dest *dest;
struct bgp_adj_in *ain;
struct peer *peer;
struct bgp_table *table;
struct prefix_rd *prd;
struct listnode *node, *nnode;
table = THREAD_ARG(thread);
prd = NULL;
max_iter = SOFT_RECONFIG_TASK_MAX_PREFIX;
if (table->soft_reconfig_init) {
/* first call of the function with a new srta structure.
* Don't do any treatment this time on nodes
* in order vtysh to respond quickly
*/
max_iter = 0;
}
for (iter = 0, dest = bgp_table_top(table); (dest && iter < max_iter);
dest = bgp_route_next(dest)) {
if (!CHECK_FLAG(dest->flags, BGP_NODE_SOFT_RECONFIG))
continue;
UNSET_FLAG(dest->flags, BGP_NODE_SOFT_RECONFIG);
for (ain = dest->adj_in; ain; ain = ain->next) {
for (ALL_LIST_ELEMENTS(table->soft_reconfig_peers, node,
nnode, peer)) {
if (ain->peer != peer)
continue;
ret = bgp_soft_reconfig_table_update(
peer, dest, ain, table->afi,
table->safi, prd);
iter++;
if (ret < 0) {
bgp_dest_unlock_node(dest);
listnode_delete(
table->soft_reconfig_peers,
peer);
bgp_announce_route(peer, table->afi,
table->safi);
if (list_isempty(
table->soft_reconfig_peers)) {
list_delete(
&table->soft_reconfig_peers);
bgp_soft_reconfig_table_flag(
table, false);
return 0;
}
}
}
}
}
/* we're either starting the initial iteration,
* or we're going to continue an ongoing iteration
*/
if (dest || table->soft_reconfig_init) {
table->soft_reconfig_init = false;
thread_add_event(bm->master, bgp_soft_reconfig_table_task,
table, 0, &table->soft_reconfig_thread);
return 0;
}
/* we're done, clean up the background iteration context info and
schedule route annoucement
*/
for (ALL_LIST_ELEMENTS(table->soft_reconfig_peers, node, nnode, peer)) {
listnode_delete(table->soft_reconfig_peers, peer);
bgp_announce_route(peer, table->afi, table->safi);
}
list_delete(&table->soft_reconfig_peers);
return 0;
}
/* Cancel soft_reconfig_table task matching bgp instance, bgp_table
* and peer.
* - bgp cannot be NULL
* - if table and peer are NULL, cancel all threads within the bgp instance
* - if table is NULL and peer is not,
* remove peer in all threads within the bgp instance
* - if peer is NULL, cancel all threads matching table within the bgp instance
*/
void bgp_soft_reconfig_table_task_cancel(const struct bgp *bgp,
const struct bgp_table *table,
const struct peer *peer)
{
struct peer *npeer;
struct listnode *node, *nnode;
int afi, safi;
struct bgp_table *ntable;
if (!bgp)
return;
FOREACH_AFI_SAFI (afi, safi) {
ntable = bgp->rib[afi][safi];
if (!ntable)
continue;
if (table && table != ntable)
continue;
for (ALL_LIST_ELEMENTS(ntable->soft_reconfig_peers, node, nnode,
npeer)) {
if (peer && peer != npeer)
continue;
listnode_delete(ntable->soft_reconfig_peers, npeer);
}
if (!ntable->soft_reconfig_peers
|| !list_isempty(ntable->soft_reconfig_peers))
continue;
list_delete(&ntable->soft_reconfig_peers);
bgp_soft_reconfig_table_flag(ntable, false);
BGP_TIMER_OFF(ntable->soft_reconfig_thread);
}
}
void bgp_soft_reconfig_in(struct peer *peer, afi_t afi, safi_t safi)
{
struct bgp_dest *dest;
struct bgp_table *table;
struct listnode *node, *nnode;
struct peer *npeer;
struct peer_af *paf;
if (!peer_established(peer))
return;
if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP)
&& (safi != SAFI_EVPN)) {
table = peer->bgp->rib[afi][safi];
if (!table)
return;
table->soft_reconfig_init = true;
if (!table->soft_reconfig_peers)
table->soft_reconfig_peers = list_new();
npeer = NULL;
/* add peer to the table soft_reconfig_peers if not already
* there
*/
for (ALL_LIST_ELEMENTS(table->soft_reconfig_peers, node, nnode,
npeer)) {
if (peer == npeer)
break;
}
if (peer != npeer)
listnode_add(table->soft_reconfig_peers, peer);
/* (re)flag all bgp_dest in table. Existing soft_reconfig_in job
* on table would start back at the beginning.
*/
bgp_soft_reconfig_table_flag(table, true);
if (!table->soft_reconfig_thread)
thread_add_event(bm->master,
bgp_soft_reconfig_table_task, table, 0,
&table->soft_reconfig_thread);
/* Cancel bgp_announce_route_timer_expired threads.
* bgp_announce_route_timer_expired threads have been scheduled
* to announce routes as soon as the soft_reconfigure process
* finishes.
* In this case, soft_reconfigure is also scheduled by using
* a thread but is planned after the
* bgp_announce_route_timer_expired threads. It means that,
* without cancelling the threads, the route announcement task
* would run before the soft reconfiguration one. That would
* useless and would block vtysh during several seconds. Route
* announcements are rescheduled as soon as the soft_reconfigure
* process finishes.
*/
paf = peer_af_find(peer, afi, safi);
if (paf)
bgp_stop_announce_route_timer(paf);
} else
for (dest = bgp_table_top(peer->bgp->rib[afi][safi]); dest;
dest = bgp_route_next(dest)) {
table = bgp_dest_get_bgp_table_info(dest);
if (table == NULL)
continue;
const struct prefix *p = bgp_dest_get_prefix(dest);
struct prefix_rd prd;
prd.family = AF_UNSPEC;
prd.prefixlen = 64;
memcpy(&prd.val, p->u.val, 8);
bgp_soft_reconfig_table(peer, afi, safi, table, &prd);
}
}
struct bgp_clear_node_queue {
struct bgp_dest *dest;
};
static wq_item_status bgp_clear_route_node(struct work_queue *wq, void *data)
{
struct bgp_clear_node_queue *cnq = data;
struct bgp_dest *dest = cnq->dest;
struct peer *peer = wq->spec.data;
struct bgp_path_info *pi;
struct bgp *bgp;
afi_t afi = bgp_dest_table(dest)->afi;
safi_t safi = bgp_dest_table(dest)->safi;
assert(dest && peer);
bgp = peer->bgp;
/* It is possible that we have multiple paths for a prefix from a peer
* if that peer is using AddPath.
*/
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) {
if (pi->peer != peer)
continue;
/* graceful restart STALE flag set. */
if (((CHECK_FLAG(peer->sflags, PEER_STATUS_NSF_WAIT)
&& peer->nsf[afi][safi])
|| CHECK_FLAG(peer->af_sflags[afi][safi],
PEER_STATUS_ENHANCED_REFRESH))
&& !CHECK_FLAG(pi->flags, BGP_PATH_STALE)
&& !CHECK_FLAG(pi->flags, BGP_PATH_UNUSEABLE))
bgp_path_info_set_flag(dest, pi, BGP_PATH_STALE);
else {
/* If this is an EVPN route, process for
* un-import. */
if (safi == SAFI_EVPN)
bgp_evpn_unimport_route(
bgp, afi, safi,
bgp_dest_get_prefix(dest), pi);
/* Handle withdraw for VRF route-leaking and L3VPN */
if (SAFI_UNICAST == safi
&& (bgp->inst_type == BGP_INSTANCE_TYPE_VRF ||
bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) {
vpn_leak_from_vrf_withdraw(bgp_get_default(),
bgp, pi);
}
if (SAFI_MPLS_VPN == safi &&
bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
vpn_leak_to_vrf_withdraw(bgp, pi);
}
bgp_rib_remove(dest, pi, peer, afi, safi);
}
}
return WQ_SUCCESS;
}
static void bgp_clear_node_queue_del(struct work_queue *wq, void *data)
{
struct bgp_clear_node_queue *cnq = data;
struct bgp_dest *dest = cnq->dest;
struct bgp_table *table = bgp_dest_table(dest);
bgp_dest_unlock_node(dest);
bgp_table_unlock(table);
XFREE(MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
}
static void bgp_clear_node_complete(struct work_queue *wq)
{
struct peer *peer = wq->spec.data;
/* Tickle FSM to start moving again */
BGP_EVENT_ADD(peer, Clearing_Completed);
peer_unlock(peer); /* bgp_clear_route */
}
static void bgp_clear_node_queue_init(struct peer *peer)
{
char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
snprintf(wname, sizeof(wname), "clear %s", peer->host);
#undef CLEAR_QUEUE_NAME_LEN
peer->clear_node_queue = work_queue_new(bm->master, wname);
peer->clear_node_queue->spec.hold = 10;
peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
peer->clear_node_queue->spec.max_retries = 0;
/* we only 'lock' this peer reference when the queue is actually active
*/
peer->clear_node_queue->spec.data = peer;
}
static void bgp_clear_route_table(struct peer *peer, afi_t afi, safi_t safi,
struct bgp_table *table)
{
struct bgp_dest *dest;
int force = peer->bgp->process_queue ? 0 : 1;
if (!table)
table = peer->bgp->rib[afi][safi];
/* If still no table => afi/safi isn't configured at all or smth. */
if (!table)
return;
for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) {
struct bgp_path_info *pi, *next;
struct bgp_adj_in *ain;
struct bgp_adj_in *ain_next;
/* XXX:TODO: This is suboptimal, every non-empty route_node is
* queued for every clearing peer, regardless of whether it is
* relevant to the peer at hand.
*
* Overview: There are 3 different indices which need to be
* scrubbed, potentially, when a peer is removed:
*
* 1 peer's routes visible via the RIB (ie accepted routes)
* 2 peer's routes visible by the (optional) peer's adj-in index
* 3 other routes visible by the peer's adj-out index
*
* 3 there is no hurry in scrubbing, once the struct peer is
* removed from bgp->peer, we could just GC such deleted peer's
* adj-outs at our leisure.
*
* 1 and 2 must be 'scrubbed' in some way, at least made
* invisible via RIB index before peer session is allowed to be
* brought back up. So one needs to know when such a 'search' is
* complete.
*
* Ideally:
*
* - there'd be a single global queue or a single RIB walker
* - rather than tracking which route_nodes still need to be
* examined on a peer basis, we'd track which peers still
* aren't cleared
*
* Given that our per-peer prefix-counts now should be reliable,
* this may actually be achievable. It doesn't seem to be a huge
* problem at this time,
*
* It is possible that we have multiple paths for a prefix from
* a peer
* if that peer is using AddPath.
*/
ain = dest->adj_in;
while (ain) {
ain_next = ain->next;
if (ain->peer == peer)
bgp_adj_in_remove(dest, ain);
ain = ain_next;
}
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = next) {
next = pi->next;
if (pi->peer != peer)
continue;
if (force)
bgp_path_info_reap(dest, pi);
else {
struct bgp_clear_node_queue *cnq;
/* both unlocked in bgp_clear_node_queue_del */
bgp_table_lock(bgp_dest_table(dest));
bgp_dest_lock_node(dest);
cnq = XCALLOC(
MTYPE_BGP_CLEAR_NODE_QUEUE,
sizeof(struct bgp_clear_node_queue));
cnq->dest = dest;
work_queue_add(peer->clear_node_queue, cnq);
break;
}
}
}
return;
}
void bgp_clear_route(struct peer *peer, afi_t afi, safi_t safi)
{
struct bgp_dest *dest;
struct bgp_table *table;
if (peer->clear_node_queue == NULL)
bgp_clear_node_queue_init(peer);
/* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
* Idle until it receives a Clearing_Completed event. This protects
* against peers which flap faster than we can we clear, which could
* lead to:
*
* a) race with routes from the new session being installed before
* clear_route_node visits the node (to delete the route of that
* peer)
* b) resource exhaustion, clear_route_node likely leads to an entry
* on the process_main queue. Fast-flapping could cause that queue
* to grow and grow.
*/
/* lock peer in assumption that clear-node-queue will get nodes; if so,
* the unlock will happen upon work-queue completion; other wise, the
* unlock happens at the end of this function.
*/
if (!peer->clear_node_queue->thread)
peer_lock(peer);
if (safi != SAFI_MPLS_VPN && safi != SAFI_ENCAP && safi != SAFI_EVPN)
bgp_clear_route_table(peer, afi, safi, NULL);
else
for (dest = bgp_table_top(peer->bgp->rib[afi][safi]); dest;
dest = bgp_route_next(dest)) {
table = bgp_dest_get_bgp_table_info(dest);
if (!table)
continue;
bgp_clear_route_table(peer, afi, safi, table);
}
/* unlock if no nodes got added to the clear-node-queue. */
if (!peer->clear_node_queue->thread)
peer_unlock(peer);
}
void bgp_clear_route_all(struct peer *peer)
{
afi_t afi;
safi_t safi;
FOREACH_AFI_SAFI (afi, safi)
bgp_clear_route(peer, afi, safi);
#ifdef ENABLE_BGP_VNC
rfapiProcessPeerDown(peer);
#endif
}
void bgp_clear_adj_in(struct peer *peer, afi_t afi, safi_t safi)
{
struct bgp_table *table;
struct bgp_dest *dest;
struct bgp_adj_in *ain;
struct bgp_adj_in *ain_next;
table = peer->bgp->rib[afi][safi];
/* It is possible that we have multiple paths for a prefix from a peer
* if that peer is using AddPath.
*/
for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) {
ain = dest->adj_in;
while (ain) {
ain_next = ain->next;
if (ain->peer == peer)
bgp_adj_in_remove(dest, ain);
ain = ain_next;
}
}
}
void bgp_clear_stale_route(struct peer *peer, afi_t afi, safi_t safi)
{
struct bgp_dest *dest;
struct bgp_path_info *pi;
struct bgp_table *table;
if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP || safi == SAFI_EVPN) {
for (dest = bgp_table_top(peer->bgp->rib[afi][safi]); dest;
dest = bgp_route_next(dest)) {
struct bgp_dest *rm;
/* look for neighbor in tables */
table = bgp_dest_get_bgp_table_info(dest);
if (!table)
continue;
for (rm = bgp_table_top(table); rm;
rm = bgp_route_next(rm))
for (pi = bgp_dest_get_bgp_path_info(rm); pi;
pi = pi->next) {
if (pi->peer != peer)
continue;
if (!CHECK_FLAG(pi->flags,
BGP_PATH_STALE))
break;
bgp_rib_remove(rm, pi, peer, afi, safi);
break;
}
}
} else {
for (dest = bgp_table_top(peer->bgp->rib[afi][safi]); dest;
dest = bgp_route_next(dest))
for (pi = bgp_dest_get_bgp_path_info(dest); pi;
pi = pi->next) {
if (pi->peer != peer)
continue;
if (!CHECK_FLAG(pi->flags, BGP_PATH_STALE))
break;
bgp_rib_remove(dest, pi, peer, afi, safi);
break;
}
}
}
void bgp_set_stale_route(struct peer *peer, afi_t afi, safi_t safi)
{
struct bgp_dest *dest, *ndest;
struct bgp_path_info *pi;
struct bgp_table *table;
if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP || safi == SAFI_EVPN) {
for (dest = bgp_table_top(peer->bgp->rib[afi][safi]); dest;
dest = bgp_route_next(dest)) {
table = bgp_dest_get_bgp_table_info(dest);
if (!table)
continue;
for (ndest = bgp_table_top(table); ndest;
ndest = bgp_route_next(ndest)) {
for (pi = bgp_dest_get_bgp_path_info(ndest); pi;
pi = pi->next) {
if (pi->peer != peer)
continue;
if ((CHECK_FLAG(
peer->af_sflags[afi][safi],
PEER_STATUS_ENHANCED_REFRESH))
&& !CHECK_FLAG(pi->flags,
BGP_PATH_STALE)
&& !CHECK_FLAG(
pi->flags,
BGP_PATH_UNUSEABLE)) {
if (bgp_debug_neighbor_events(
peer))
zlog_debug(
"%s: route-refresh for %s/%s, marking prefix %pFX as stale",
peer->host,
afi2str(afi),
safi2str(safi),
bgp_dest_get_prefix(
ndest));
bgp_path_info_set_flag(
ndest, pi,
BGP_PATH_STALE);
}
}
}
}
} else {
for (dest = bgp_table_top(peer->bgp->rib[afi][safi]); dest;
dest = bgp_route_next(dest)) {
for (pi = bgp_dest_get_bgp_path_info(dest); pi;
pi = pi->next) {
if (pi->peer != peer)
continue;
if ((CHECK_FLAG(peer->af_sflags[afi][safi],
PEER_STATUS_ENHANCED_REFRESH))
&& !CHECK_FLAG(pi->flags, BGP_PATH_STALE)
&& !CHECK_FLAG(pi->flags,
BGP_PATH_UNUSEABLE)) {
if (bgp_debug_neighbor_events(peer))
zlog_debug(
"%s: route-refresh for %s/%s, marking prefix %pFX as stale",
peer->host,
afi2str(afi),
safi2str(safi),
bgp_dest_get_prefix(
dest));
bgp_path_info_set_flag(dest, pi,
BGP_PATH_STALE);
}
}
}
}
}
bool bgp_outbound_policy_exists(struct peer *peer, struct bgp_filter *filter)
{
if (peer->sort == BGP_PEER_IBGP)
return true;
if (peer->sort == BGP_PEER_EBGP
&& (ROUTE_MAP_OUT_NAME(filter) || PREFIX_LIST_OUT_NAME(filter)
|| FILTER_LIST_OUT_NAME(filter)
|| DISTRIBUTE_OUT_NAME(filter)))
return true;
return false;
}
bool bgp_inbound_policy_exists(struct peer *peer, struct bgp_filter *filter)
{
if (peer->sort == BGP_PEER_IBGP)
return true;
if (peer->sort == BGP_PEER_EBGP
&& (ROUTE_MAP_IN_NAME(filter) || PREFIX_LIST_IN_NAME(filter)
|| FILTER_LIST_IN_NAME(filter)
|| DISTRIBUTE_IN_NAME(filter)))
return true;
return false;
}
static void bgp_cleanup_table(struct bgp *bgp, struct bgp_table *table,
safi_t safi)
{
struct bgp_dest *dest;
struct bgp_path_info *pi;
struct bgp_path_info *next;
for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest))
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = next) {
const struct prefix *p = bgp_dest_get_prefix(dest);
next = pi->next;
/* Unimport EVPN routes from VRFs */
if (safi == SAFI_EVPN)
bgp_evpn_unimport_route(bgp, AFI_L2VPN,
SAFI_EVPN, p, pi);
if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)
&& pi->type == ZEBRA_ROUTE_BGP
&& (pi->sub_type == BGP_ROUTE_NORMAL
|| pi->sub_type == BGP_ROUTE_AGGREGATE
|| pi->sub_type == BGP_ROUTE_IMPORTED)) {
if (bgp_fibupd_safi(safi))
bgp_zebra_withdraw(p, pi, bgp, safi);
}
bgp_path_info_reap(dest, pi);
}
}
/* Delete all kernel routes. */
void bgp_cleanup_routes(struct bgp *bgp)
{
afi_t afi;
struct bgp_dest *dest;
struct bgp_table *table;
for (afi = AFI_IP; afi < AFI_MAX; ++afi) {
if (afi == AFI_L2VPN)
continue;
bgp_cleanup_table(bgp, bgp->rib[afi][SAFI_UNICAST],
SAFI_UNICAST);
/*
* VPN and ENCAP and EVPN tables are two-level (RD is top level)
*/
if (afi != AFI_L2VPN) {
safi_t safi;
safi = SAFI_MPLS_VPN;
for (dest = bgp_table_top(bgp->rib[afi][safi]); dest;
dest = bgp_route_next(dest)) {
table = bgp_dest_get_bgp_table_info(dest);
if (table != NULL) {
bgp_cleanup_table(bgp, table, safi);
bgp_table_finish(&table);
bgp_dest_set_bgp_table_info(dest, NULL);
bgp_dest_unlock_node(dest);
}
}
safi = SAFI_ENCAP;
for (dest = bgp_table_top(bgp->rib[afi][safi]); dest;
dest = bgp_route_next(dest)) {
table = bgp_dest_get_bgp_table_info(dest);
if (table != NULL) {
bgp_cleanup_table(bgp, table, safi);
bgp_table_finish(&table);
bgp_dest_set_bgp_table_info(dest, NULL);
bgp_dest_unlock_node(dest);
}
}
}
}
for (dest = bgp_table_top(bgp->rib[AFI_L2VPN][SAFI_EVPN]); dest;
dest = bgp_route_next(dest)) {
table = bgp_dest_get_bgp_table_info(dest);
if (table != NULL) {
bgp_cleanup_table(bgp, table, SAFI_EVPN);
bgp_table_finish(&table);
bgp_dest_set_bgp_table_info(dest, NULL);
bgp_dest_unlock_node(dest);
}
}
}
void bgp_reset(void)
{
vty_reset();
bgp_zclient_reset();
access_list_reset();
prefix_list_reset();
}
static int bgp_addpath_encode_rx(struct peer *peer, afi_t afi, safi_t safi)
{
return (CHECK_FLAG(peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV)
&& CHECK_FLAG(peer->af_cap[afi][safi],
PEER_CAP_ADDPATH_AF_TX_RCV));
}
/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
value. */
int bgp_nlri_parse_ip(struct peer *peer, struct attr *attr,
struct bgp_nlri *packet)
{
uint8_t *pnt;
uint8_t *lim;
struct prefix p;
int psize;
int ret;
afi_t afi;
safi_t safi;
int addpath_encoded;
uint32_t addpath_id;
pnt = packet->nlri;
lim = pnt + packet->length;
afi = packet->afi;
safi = packet->safi;
addpath_id = 0;
addpath_encoded = bgp_addpath_encode_rx(peer, afi, safi);
/* RFC4771 6.3 The NLRI field in the UPDATE message is checked for
syntactic validity. If the field is syntactically incorrect,
then the Error Subcode is set to Invalid Network Field. */
for (; pnt < lim; pnt += psize) {
/* Clear prefix structure. */
memset(&p, 0, sizeof(struct prefix));
if (addpath_encoded) {
/* When packet overflow occurs return immediately. */
if (pnt + BGP_ADDPATH_ID_LEN >= lim)
return BGP_NLRI_PARSE_ERROR_PACKET_OVERFLOW;
memcpy(&addpath_id, pnt, BGP_ADDPATH_ID_LEN);
addpath_id = ntohl(addpath_id);
pnt += BGP_ADDPATH_ID_LEN;
}
/* Fetch prefix length. */
p.prefixlen = *pnt++;
/* afi/safi validity already verified by caller,
* bgp_update_receive */
p.family = afi2family(afi);
/* Prefix length check. */
if (p.prefixlen > prefix_blen(&p) * 8) {
flog_err(
EC_BGP_UPDATE_RCV,
"%s [Error] Update packet error (wrong prefix length %d for afi %u)",
peer->host, p.prefixlen, packet->afi);
return BGP_NLRI_PARSE_ERROR_PREFIX_LENGTH;
}
/* Packet size overflow check. */
psize = PSIZE(p.prefixlen);
/* When packet overflow occur return immediately. */
if (pnt + psize > lim) {
flog_err(
EC_BGP_UPDATE_RCV,
"%s [Error] Update packet error (prefix length %d overflows packet)",
peer->host, p.prefixlen);
return BGP_NLRI_PARSE_ERROR_PACKET_OVERFLOW;
}
/* Defensive coding, double-check the psize fits in a struct
* prefix */
if (psize > (ssize_t)sizeof(p.u)) {
flog_err(
EC_BGP_UPDATE_RCV,
"%s [Error] Update packet error (prefix length %d too large for prefix storage %zu)",
peer->host, p.prefixlen, sizeof(p.u));
return BGP_NLRI_PARSE_ERROR_PACKET_LENGTH;
}
/* Fetch prefix from NLRI packet. */
memcpy(p.u.val, pnt, psize);
/* Check address. */
if (afi == AFI_IP && safi == SAFI_UNICAST) {
if (IN_CLASSD(ntohl(p.u.prefix4.s_addr))) {
/* From RFC4271 Section 6.3:
*
* If a prefix in the NLRI field is semantically
* incorrect
* (e.g., an unexpected multicast IP address),
* an error SHOULD
* be logged locally, and the prefix SHOULD be
* ignored.
*/
flog_err(
EC_BGP_UPDATE_RCV,
"%s: IPv4 unicast NLRI is multicast address %pI4, ignoring",
peer->host, &p.u.prefix4);
continue;
}
}
/* Check address. */
if (afi == AFI_IP6 && safi == SAFI_UNICAST) {
if (IN6_IS_ADDR_LINKLOCAL(&p.u.prefix6)) {
flog_err(
EC_BGP_UPDATE_RCV,
"%s: IPv6 unicast NLRI is link-local address %pI6, ignoring",
peer->host, &p.u.prefix6);
continue;
}
if (IN6_IS_ADDR_MULTICAST(&p.u.prefix6)) {
flog_err(
EC_BGP_UPDATE_RCV,
"%s: IPv6 unicast NLRI is multicast address %pI6, ignoring",
peer->host, &p.u.prefix6);
continue;
}
}
/* Normal process. */
if (attr)
ret = bgp_update(peer, &p, addpath_id, attr, afi, safi,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
NULL, NULL, 0, 0, NULL);
else
ret = bgp_withdraw(peer, &p, addpath_id, attr, afi,
safi, ZEBRA_ROUTE_BGP,
BGP_ROUTE_NORMAL, NULL, NULL, 0,
NULL);
/* Do not send BGP notification twice when maximum-prefix count
* overflow. */
if (CHECK_FLAG(peer->sflags, PEER_STATUS_PREFIX_OVERFLOW))
return BGP_NLRI_PARSE_ERROR_PREFIX_OVERFLOW;
/* Address family configuration mismatch. */
if (ret < 0)
return BGP_NLRI_PARSE_ERROR_ADDRESS_FAMILY;
}
/* Packet length consistency check. */
if (pnt != lim) {
flog_err(
EC_BGP_UPDATE_RCV,
"%s [Error] Update packet error (prefix length mismatch with total length)",
peer->host);
return BGP_NLRI_PARSE_ERROR_PACKET_LENGTH;
}
return BGP_NLRI_PARSE_OK;
}
static struct bgp_static *bgp_static_new(void)
{
return XCALLOC(MTYPE_BGP_STATIC, sizeof(struct bgp_static));
}
static void bgp_static_free(struct bgp_static *bgp_static)
{
XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
route_map_counter_decrement(bgp_static->rmap.map);
XFREE(MTYPE_ATTR, bgp_static->eth_s_id);
XFREE(MTYPE_BGP_STATIC, bgp_static);
}
void bgp_static_update(struct bgp *bgp, const struct prefix *p,
struct bgp_static *bgp_static, afi_t afi, safi_t safi)
{
struct bgp_dest *dest;
struct bgp_path_info *pi;
struct bgp_path_info *new;
struct bgp_path_info rmap_path;
struct attr attr;
struct attr *attr_new;
route_map_result_t ret;
#ifdef ENABLE_BGP_VNC
int vnc_implicit_withdraw = 0;
#endif
assert(bgp_static);
dest = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi, p, NULL);
bgp_attr_default_set(&attr, BGP_ORIGIN_IGP);
attr.nexthop = bgp_static->igpnexthop;
attr.med = bgp_static->igpmetric;
attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC);
if (bgp_static->atomic)
attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE);
/* Store label index, if required. */
if (bgp_static->label_index != BGP_INVALID_LABEL_INDEX) {
attr.label_index = bgp_static->label_index;
attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID);
}
/* Apply route-map. */
if (bgp_static->rmap.name) {
struct attr attr_tmp = attr;
memset(&rmap_path, 0, sizeof(struct bgp_path_info));
rmap_path.peer = bgp->peer_self;
rmap_path.attr = &attr_tmp;
SET_FLAG(bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
ret = route_map_apply(bgp_static->rmap.map, p, &rmap_path);
bgp->peer_self->rmap_type = 0;
if (ret == RMAP_DENYMATCH) {
/* Free uninterned attribute. */
bgp_attr_flush(&attr_tmp);
/* Unintern original. */
aspath_unintern(&attr.aspath);
bgp_static_withdraw(bgp, p, afi, safi);
return;
}
if (bgp_in_graceful_shutdown(bgp))
bgp_attr_add_gshut_community(&attr_tmp);
attr_new = bgp_attr_intern(&attr_tmp);
} else {
if (bgp_in_graceful_shutdown(bgp))
bgp_attr_add_gshut_community(&attr);
attr_new = bgp_attr_intern(&attr);
}
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next)
if (pi->peer == bgp->peer_self && pi->type == ZEBRA_ROUTE_BGP
&& pi->sub_type == BGP_ROUTE_STATIC)
break;
if (pi) {
if (attrhash_cmp(pi->attr, attr_new)
&& !CHECK_FLAG(pi->flags, BGP_PATH_REMOVED)
&& !CHECK_FLAG(bgp->flags, BGP_FLAG_FORCE_STATIC_PROCESS)) {
bgp_dest_unlock_node(dest);
bgp_attr_unintern(&attr_new);
aspath_unintern(&attr.aspath);
return;
} else {
/* The attribute is changed. */
bgp_path_info_set_flag(dest, pi, BGP_PATH_ATTR_CHANGED);
/* Rewrite BGP route information. */
if (CHECK_FLAG(pi->flags, BGP_PATH_REMOVED))
bgp_path_info_restore(dest, pi);
else
bgp_aggregate_decrement(bgp, p, pi, afi, safi);
#ifdef ENABLE_BGP_VNC
if ((afi == AFI_IP || afi == AFI_IP6)
&& (safi == SAFI_UNICAST)) {
if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)) {
/*
* Implicit withdraw case.
* We have to do this before pi is
* changed
*/
++vnc_implicit_withdraw;
vnc_import_bgp_del_route(bgp, p, pi);
vnc_import_bgp_exterior_del_route(
bgp, p, pi);
}
}
#endif
bgp_attr_unintern(&pi->attr);
pi->attr = attr_new;
pi->uptime = bgp_clock();
#ifdef ENABLE_BGP_VNC
if ((afi == AFI_IP || afi == AFI_IP6)
&& (safi == SAFI_UNICAST)) {
if (vnc_implicit_withdraw) {
vnc_import_bgp_add_route(bgp, p, pi);
vnc_import_bgp_exterior_add_route(
bgp, p, pi);
}
}
#endif
/* Nexthop reachability check. */
if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
&& (safi == SAFI_UNICAST
|| safi == SAFI_LABELED_UNICAST)) {
struct bgp *bgp_nexthop = bgp;
if (pi->extra && pi->extra->bgp_orig)
bgp_nexthop = pi->extra->bgp_orig;
if (bgp_find_or_add_nexthop(bgp, bgp_nexthop,
afi, safi, pi, NULL,
0, p))
bgp_path_info_set_flag(dest, pi,
BGP_PATH_VALID);
else {
if (BGP_DEBUG(nht, NHT)) {
char buf1[INET6_ADDRSTRLEN];
inet_ntop(p->family,
&p->u.prefix, buf1,
INET6_ADDRSTRLEN);
zlog_debug(
"%s(%s): Route not in table, not advertising",
__func__, buf1);
}
bgp_path_info_unset_flag(
dest, pi, BGP_PATH_VALID);
}
} else {
/* Delete the NHT structure if any, if we're
* toggling between
* enabling/disabling import check. We
* deregister the route
* from NHT to avoid overloading NHT and the
* process interaction
*/
bgp_unlink_nexthop(pi);
bgp_path_info_set_flag(dest, pi,
BGP_PATH_VALID);
}
/* Process change. */
bgp_aggregate_increment(bgp, p, pi, afi, safi);
bgp_process(bgp, dest, afi, safi);
if (SAFI_UNICAST == safi
&& (bgp->inst_type == BGP_INSTANCE_TYPE_VRF
|| bgp->inst_type
== BGP_INSTANCE_TYPE_DEFAULT)) {
vpn_leak_from_vrf_update(bgp_get_default(), bgp,
pi);
}
bgp_dest_unlock_node(dest);
aspath_unintern(&attr.aspath);
return;
}
}
/* Make new BGP info. */
new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self,
attr_new, dest);
/* Nexthop reachability check. */
if (CHECK_FLAG(bgp->flags, BGP_FLAG_IMPORT_CHECK)
&& (safi == SAFI_UNICAST || safi == SAFI_LABELED_UNICAST)) {
if (bgp_find_or_add_nexthop(bgp, bgp, afi, safi, new, NULL, 0,
p))
bgp_path_info_set_flag(dest, new, BGP_PATH_VALID);
else {
if (BGP_DEBUG(nht, NHT)) {
char buf1[INET6_ADDRSTRLEN];
inet_ntop(p->family, &p->u.prefix, buf1,
INET6_ADDRSTRLEN);
zlog_debug(
"%s(%s): Route not in table, not advertising",
__func__, buf1);
}
bgp_path_info_unset_flag(dest, new, BGP_PATH_VALID);
}
} else {
/* Delete the NHT structure if any, if we're toggling between
* enabling/disabling import check. We deregister the route
* from NHT to avoid overloading NHT and the process interaction
*/
bgp_unlink_nexthop(new);
bgp_path_info_set_flag(dest, new, BGP_PATH_VALID);
}
/* Aggregate address increment. */
bgp_aggregate_increment(bgp, p, new, afi, safi);
/* Register new BGP information. */
bgp_path_info_add(dest, new);
/* route_node_get lock */
bgp_dest_unlock_node(dest);
/* Process change. */
bgp_process(bgp, dest, afi, safi);
if (SAFI_UNICAST == safi
&& (bgp->inst_type == BGP_INSTANCE_TYPE_VRF
|| bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) {
vpn_leak_from_vrf_update(bgp_get_default(), bgp, new);
}
/* Unintern original. */
aspath_unintern(&attr.aspath);
}
void bgp_static_withdraw(struct bgp *bgp, const struct prefix *p, afi_t afi,
safi_t safi)
{
struct bgp_dest *dest;
struct bgp_path_info *pi;
dest = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi, p, NULL);
/* Check selected route and self inserted route. */
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next)
if (pi->peer == bgp->peer_self && pi->type == ZEBRA_ROUTE_BGP
&& pi->sub_type == BGP_ROUTE_STATIC)
break;
/* Withdraw static BGP route from routing table. */
if (pi) {
if (SAFI_UNICAST == safi
&& (bgp->inst_type == BGP_INSTANCE_TYPE_VRF
|| bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) {
vpn_leak_from_vrf_withdraw(bgp_get_default(), bgp, pi);
}
bgp_aggregate_decrement(bgp, p, pi, afi, safi);
bgp_unlink_nexthop(pi);
bgp_path_info_delete(dest, pi);
bgp_process(bgp, dest, afi, safi);
}
/* Unlock bgp_node_lookup. */
bgp_dest_unlock_node(dest);
}
/*
* Used for SAFI_MPLS_VPN and SAFI_ENCAP
*/
static void bgp_static_withdraw_safi(struct bgp *bgp, const struct prefix *p,
afi_t afi, safi_t safi,
struct prefix_rd *prd)
{
struct bgp_dest *dest;
struct bgp_path_info *pi;
dest = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi, p, prd);
/* Check selected route and self inserted route. */
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next)
if (pi->peer == bgp->peer_self && pi->type == ZEBRA_ROUTE_BGP
&& pi->sub_type == BGP_ROUTE_STATIC)
break;
/* Withdraw static BGP route from routing table. */
if (pi) {
#ifdef ENABLE_BGP_VNC
rfapiProcessWithdraw(
pi->peer, NULL, p, prd, pi->attr, afi, safi, pi->type,
1); /* Kill, since it is an administrative change */
#endif
if (SAFI_MPLS_VPN == safi
&& bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
vpn_leak_to_vrf_withdraw(bgp, pi);
}
bgp_aggregate_decrement(bgp, p, pi, afi, safi);
bgp_path_info_delete(dest, pi);
bgp_process(bgp, dest, afi, safi);
}
/* Unlock bgp_node_lookup. */
bgp_dest_unlock_node(dest);
}
static void bgp_static_update_safi(struct bgp *bgp, const struct prefix *p,
struct bgp_static *bgp_static, afi_t afi,
safi_t safi)
{
struct bgp_dest *dest;
struct bgp_path_info *new;
struct attr *attr_new;
struct attr attr = {0};
struct bgp_path_info *pi;
#ifdef ENABLE_BGP_VNC
mpls_label_t label = 0;
#endif
uint32_t num_labels = 0;
union gw_addr add;
assert(bgp_static);
if (bgp_static->label != MPLS_INVALID_LABEL)
num_labels = 1;
dest = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi, p,
&bgp_static->prd);
bgp_attr_default_set(&attr, BGP_ORIGIN_IGP);
attr.nexthop = bgp_static->igpnexthop;
attr.med = bgp_static->igpmetric;
attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC);
if ((safi == SAFI_EVPN) || (safi == SAFI_MPLS_VPN)
|| (safi == SAFI_ENCAP)) {
if (afi == AFI_IP) {
attr.mp_nexthop_global_in = bgp_static->igpnexthop;
attr.mp_nexthop_len = IPV4_MAX_BYTELEN;
}
}
if (afi == AFI_L2VPN) {
if (bgp_static->gatewayIp.family == AF_INET)
add.ipv4.s_addr =
bgp_static->gatewayIp.u.prefix4.s_addr;
else if (bgp_static->gatewayIp.family == AF_INET6)
memcpy(&(add.ipv6), &(bgp_static->gatewayIp.u.prefix6),
sizeof(struct in6_addr));
memcpy(&attr.esi, bgp_static->eth_s_id, sizeof(esi_t));
if (bgp_static->encap_tunneltype == BGP_ENCAP_TYPE_VXLAN) {
struct bgp_encap_type_vxlan bet;
memset(&bet, 0, sizeof(struct bgp_encap_type_vxlan));
bet.vnid = p->u.prefix_evpn.prefix_addr.eth_tag;
bgp_encap_type_vxlan_to_tlv(&bet, &attr);
}
if (bgp_static->router_mac) {
bgp_add_routermac_ecom(&attr, bgp_static->router_mac);
}
}
/* Apply route-map. */
if (bgp_static->rmap.name) {
struct attr attr_tmp = attr;
struct bgp_path_info rmap_path;
route_map_result_t ret;
rmap_path.peer = bgp->peer_self;
rmap_path.attr = &attr_tmp;
SET_FLAG(bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
ret = route_map_apply(bgp_static->rmap.map, p, &rmap_path);
bgp->peer_self->rmap_type = 0;
if (ret == RMAP_DENYMATCH) {
/* Free uninterned attribute. */
bgp_attr_flush(&attr_tmp);
/* Unintern original. */
aspath_unintern(&attr.aspath);
bgp_static_withdraw_safi(bgp, p, afi, safi,
&bgp_static->prd);
return;
}
attr_new = bgp_attr_intern(&attr_tmp);
} else {
attr_new = bgp_attr_intern(&attr);
}
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next)
if (pi->peer == bgp->peer_self && pi->type == ZEBRA_ROUTE_BGP
&& pi->sub_type == BGP_ROUTE_STATIC)
break;
if (pi) {
memset(&add, 0, sizeof(union gw_addr));
if (attrhash_cmp(pi->attr, attr_new)
&& overlay_index_equal(afi, pi, &add)
&& !CHECK_FLAG(pi->flags, BGP_PATH_REMOVED)) {
bgp_dest_unlock_node(dest);
bgp_attr_unintern(&attr_new);
aspath_unintern(&attr.aspath);
return;
} else {
/* The attribute is changed. */
bgp_path_info_set_flag(dest, pi, BGP_PATH_ATTR_CHANGED);
/* Rewrite BGP route information. */
if (CHECK_FLAG(pi->flags, BGP_PATH_REMOVED))
bgp_path_info_restore(dest, pi);
else
bgp_aggregate_decrement(bgp, p, pi, afi, safi);
bgp_attr_unintern(&pi->attr);
pi->attr = attr_new;
pi->uptime = bgp_clock();
#ifdef ENABLE_BGP_VNC
if (pi->extra)
label = decode_label(&pi->extra->label[0]);
#endif
/* Process change. */
bgp_aggregate_increment(bgp, p, pi, afi, safi);
bgp_process(bgp, dest, afi, safi);
if (SAFI_MPLS_VPN == safi
&& bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
vpn_leak_to_vrf_update(bgp, pi);
}
#ifdef ENABLE_BGP_VNC
rfapiProcessUpdate(pi->peer, NULL, p, &bgp_static->prd,
pi->attr, afi, safi, pi->type,
pi->sub_type, &label);
#endif
bgp_dest_unlock_node(dest);
aspath_unintern(&attr.aspath);
return;
}
}
/* Make new BGP info. */
new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self,
attr_new, dest);
SET_FLAG(new->flags, BGP_PATH_VALID);
new->extra = bgp_path_info_extra_new();
if (num_labels) {
new->extra->label[0] = bgp_static->label;
new->extra->num_labels = num_labels;
}
#ifdef ENABLE_BGP_VNC
label = decode_label(&bgp_static->label);
#endif
/* Aggregate address increment. */
bgp_aggregate_increment(bgp, p, new, afi, safi);
/* Register new BGP information. */
bgp_path_info_add(dest, new);
/* route_node_get lock */
bgp_dest_unlock_node(dest);
/* Process change. */
bgp_process(bgp, dest, afi, safi);
if (SAFI_MPLS_VPN == safi
&& bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
vpn_leak_to_vrf_update(bgp, new);
}
#ifdef ENABLE_BGP_VNC
rfapiProcessUpdate(new->peer, NULL, p, &bgp_static->prd, new->attr, afi,
safi, new->type, new->sub_type, &label);
#endif
/* Unintern original. */
aspath_unintern(&attr.aspath);
}
/* Configure static BGP network. When user don't run zebra, static
route should be installed as valid. */
static int bgp_static_set(struct vty *vty, const char *negate,
const char *ip_str, afi_t afi, safi_t safi,
const char *rmap, int backdoor, uint32_t label_index)
{
VTY_DECLVAR_CONTEXT(bgp, bgp);
int ret;
struct prefix p;
struct bgp_static *bgp_static;
struct bgp_dest *dest;
uint8_t need_update = 0;
/* Convert IP prefix string to struct prefix. */
ret = str2prefix(ip_str, &p);
if (!ret) {
vty_out(vty, "%% Malformed prefix\n");
return CMD_WARNING_CONFIG_FAILED;
}
if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL(&p.u.prefix6)) {
vty_out(vty, "%% Malformed prefix (link-local address)\n");
return CMD_WARNING_CONFIG_FAILED;
}
apply_mask(&p);
if (negate) {
/* Set BGP static route configuration. */
dest = bgp_node_lookup(bgp->route[afi][safi], &p);
if (!dest) {
vty_out(vty, "%% Can't find static route specified\n");
return CMD_WARNING_CONFIG_FAILED;
}
bgp_static = bgp_dest_get_bgp_static_info(dest);
if ((label_index != BGP_INVALID_LABEL_INDEX)
&& (label_index != bgp_static->label_index)) {
vty_out(vty,
"%% label-index doesn't match static route\n");
bgp_dest_unlock_node(dest);
return CMD_WARNING_CONFIG_FAILED;
}
if ((rmap && bgp_static->rmap.name)
&& strcmp(rmap, bgp_static->rmap.name)) {
vty_out(vty,
"%% route-map name doesn't match static route\n");
bgp_dest_unlock_node(dest);
return CMD_WARNING_CONFIG_FAILED;
}
/* Update BGP RIB. */
if (!bgp_static->backdoor)
bgp_static_withdraw(bgp, &p, afi, safi);
/* Clear configuration. */
bgp_static_free(bgp_static);
bgp_dest_set_bgp_static_info(dest, NULL);
bgp_dest_unlock_node(dest);
bgp_dest_unlock_node(dest);
} else {
/* Set BGP static route configuration. */
dest = bgp_node_get(bgp->route[afi][safi], &p);
bgp_static = bgp_dest_get_bgp_static_info(dest);
if (bgp_static) {
/* Configuration change. */
/* Label index cannot be changed. */
if (bgp_static->label_index != label_index) {
vty_out(vty, "%% cannot change label-index\n");
return CMD_WARNING_CONFIG_FAILED;
}
/* Check previous routes are installed into BGP. */
if (bgp_static->valid
&& bgp_static->backdoor != backdoor)
need_update = 1;
bgp_static->backdoor = backdoor;
if (rmap) {
XFREE(MTYPE_ROUTE_MAP_NAME,
bgp_static->rmap.name);
route_map_counter_decrement(
bgp_static->rmap.map);
bgp_static->rmap.name =
XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
bgp_static->rmap.map =
route_map_lookup_by_name(rmap);
route_map_counter_increment(
bgp_static->rmap.map);
} else {
XFREE(MTYPE_ROUTE_MAP_NAME,
bgp_static->rmap.name);
route_map_counter_decrement(
bgp_static->rmap.map);
bgp_static->rmap.map = NULL;
bgp_static->valid = 0;
}
bgp_dest_unlock_node(dest);
} else {
/* New configuration. */
bgp_static = bgp_static_new();
bgp_static->backdoor = backdoor;
bgp_static->valid = 0;
bgp_static->igpmetric = 0;
bgp_static->igpnexthop.s_addr = INADDR_ANY;
bgp_static->label_index = label_index;
if (rmap) {
XFREE(MTYPE_ROUTE_MAP_NAME,
bgp_static->rmap.name);
route_map_counter_decrement(
bgp_static->rmap.map);
bgp_static->rmap.name =
XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
bgp_static->rmap.map =
route_map_lookup_by_name(rmap);
route_map_counter_increment(
bgp_static->rmap.map);
}
bgp_dest_set_bgp_static_info(dest, bgp_static);
}
bgp_static->valid = 1;
if (need_update)
bgp_static_withdraw(bgp, &p, afi, safi);
if (!bgp_static->backdoor)
bgp_static_update(bgp, &p, bgp_static, afi, safi);
}
return CMD_SUCCESS;
}
void bgp_static_add(struct bgp *bgp)
{
afi_t afi;
safi_t safi;
struct bgp_dest *dest;
struct bgp_dest *rm;
struct bgp_table *table;
struct bgp_static *bgp_static;
SET_FLAG(bgp->flags, BGP_FLAG_FORCE_STATIC_PROCESS);
FOREACH_AFI_SAFI (afi, safi)
for (dest = bgp_table_top(bgp->route[afi][safi]); dest;
dest = bgp_route_next(dest)) {
if (!bgp_dest_has_bgp_path_info_data(dest))
continue;
if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)
|| (safi == SAFI_EVPN)) {
table = bgp_dest_get_bgp_table_info(dest);
for (rm = bgp_table_top(table); rm;
rm = bgp_route_next(rm)) {
bgp_static =
bgp_dest_get_bgp_static_info(
rm);
bgp_static_update_safi(
bgp, bgp_dest_get_prefix(rm),
bgp_static, afi, safi);
}
} else {
bgp_static_update(
bgp, bgp_dest_get_prefix(dest),
bgp_dest_get_bgp_static_info(dest), afi,
safi);
}
}
UNSET_FLAG(bgp->flags, BGP_FLAG_FORCE_STATIC_PROCESS);
}
/* Called from bgp_delete(). Delete all static routes from the BGP
instance. */
void bgp_static_delete(struct bgp *bgp)
{
afi_t afi;
safi_t safi;
struct bgp_dest *dest;
struct bgp_dest *rm;
struct bgp_table *table;
struct bgp_static *bgp_static;
FOREACH_AFI_SAFI (afi, safi)
for (dest = bgp_table_top(bgp->route[afi][safi]); dest;
dest = bgp_route_next(dest)) {
if (!bgp_dest_has_bgp_path_info_data(dest))
continue;
if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)
|| (safi == SAFI_EVPN)) {
table = bgp_dest_get_bgp_table_info(dest);
for (rm = bgp_table_top(table); rm;
rm = bgp_route_next(rm)) {
bgp_static =
bgp_dest_get_bgp_static_info(
rm);
if (!bgp_static)
continue;
bgp_static_withdraw_safi(
bgp, bgp_dest_get_prefix(rm),
AFI_IP, safi,
(struct prefix_rd *)
bgp_dest_get_prefix(
dest));
bgp_static_free(bgp_static);
bgp_dest_set_bgp_static_info(rm,
NULL);
bgp_dest_unlock_node(rm);
}
} else {
bgp_static = bgp_dest_get_bgp_static_info(dest);
bgp_static_withdraw(bgp,
bgp_dest_get_prefix(dest),
afi, safi);
bgp_static_free(bgp_static);
bgp_dest_set_bgp_static_info(dest, NULL);
bgp_dest_unlock_node(dest);
}
}
}
void bgp_static_redo_import_check(struct bgp *bgp)
{
afi_t afi;
safi_t safi;
struct bgp_dest *dest;
struct bgp_dest *rm;
struct bgp_table *table;
struct bgp_static *bgp_static;
/* Use this flag to force reprocessing of the route */
SET_FLAG(bgp->flags, BGP_FLAG_FORCE_STATIC_PROCESS);
FOREACH_AFI_SAFI (afi, safi) {
for (dest = bgp_table_top(bgp->route[afi][safi]); dest;
dest = bgp_route_next(dest)) {
if (!bgp_dest_has_bgp_path_info_data(dest))
continue;
if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)
|| (safi == SAFI_EVPN)) {
table = bgp_dest_get_bgp_table_info(dest);
for (rm = bgp_table_top(table); rm;
rm = bgp_route_next(rm)) {
bgp_static =
bgp_dest_get_bgp_static_info(
rm);
bgp_static_update_safi(
bgp, bgp_dest_get_prefix(rm),
bgp_static, afi, safi);
}
} else {
bgp_static = bgp_dest_get_bgp_static_info(dest);
bgp_static_update(bgp,
bgp_dest_get_prefix(dest),
bgp_static, afi, safi);
}
}
}
UNSET_FLAG(bgp->flags, BGP_FLAG_FORCE_STATIC_PROCESS);
}
static void bgp_purge_af_static_redist_routes(struct bgp *bgp, afi_t afi,
safi_t safi)
{
struct bgp_table *table;
struct bgp_dest *dest;
struct bgp_path_info *pi;
/* Do not install the aggregate route if BGP is in the
* process of termination.
*/
if (CHECK_FLAG(bgp->flags, BGP_FLAG_DELETE_IN_PROGRESS)
|| (bgp->peer_self == NULL))
return;
table = bgp->rib[afi][safi];
for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) {
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) {
if (pi->peer == bgp->peer_self
&& ((pi->type == ZEBRA_ROUTE_BGP
&& pi->sub_type == BGP_ROUTE_STATIC)
|| (pi->type != ZEBRA_ROUTE_BGP
&& pi->sub_type
== BGP_ROUTE_REDISTRIBUTE))) {
bgp_aggregate_decrement(
bgp, bgp_dest_get_prefix(dest), pi, afi,
safi);
bgp_unlink_nexthop(pi);
bgp_path_info_delete(dest, pi);
bgp_process(bgp, dest, afi, safi);
}
}
}
}
/*
* Purge all networks and redistributed routes from routing table.
* Invoked upon the instance going down.
*/
void bgp_purge_static_redist_routes(struct bgp *bgp)
{
afi_t afi;
safi_t safi;
FOREACH_AFI_SAFI (afi, safi)
bgp_purge_af_static_redist_routes(bgp, afi, safi);
}
/*
* gpz 110624
* Currently this is used to set static routes for VPN and ENCAP.
* I think it can probably be factored with bgp_static_set.
*/
int bgp_static_set_safi(afi_t afi, safi_t safi, struct vty *vty,
const char *ip_str, const char *rd_str,
const char *label_str, const char *rmap_str,
int evpn_type, const char *esi, const char *gwip,
const char *ethtag, const char *routermac)
{
VTY_DECLVAR_CONTEXT(bgp, bgp);
int ret;
struct prefix p;
struct prefix_rd prd;
struct bgp_dest *pdest;
struct bgp_dest *dest;
struct bgp_table *table;
struct bgp_static *bgp_static;
mpls_label_t label = MPLS_INVALID_LABEL;
struct prefix gw_ip;
/* validate ip prefix */
ret = str2prefix(ip_str, &p);
if (!ret) {
vty_out(vty, "%% Malformed prefix\n");
return CMD_WARNING_CONFIG_FAILED;
}
apply_mask(&p);
if ((afi == AFI_L2VPN)
&& (bgp_build_evpn_prefix(evpn_type,
ethtag != NULL ? atol(ethtag) : 0, &p))) {
vty_out(vty, "%% L2VPN prefix could not be forged\n");
return CMD_WARNING_CONFIG_FAILED;
}
ret = str2prefix_rd(rd_str, &prd);
if (!ret) {
vty_out(vty, "%% Malformed rd\n");
return CMD_WARNING_CONFIG_FAILED;
}
if (label_str) {
unsigned long label_val;
label_val = strtoul(label_str, NULL, 10);
encode_label(label_val, &label);
}
if (safi == SAFI_EVPN) {
if (esi && str2esi(esi, NULL) == 0) {
vty_out(vty, "%% Malformed ESI\n");
return CMD_WARNING_CONFIG_FAILED;
}
if (routermac && prefix_str2mac(routermac, NULL) == 0) {
vty_out(vty, "%% Malformed Router MAC\n");
return CMD_WARNING_CONFIG_FAILED;
}
if (gwip) {
memset(&gw_ip, 0, sizeof(struct prefix));
ret = str2prefix(gwip, &gw_ip);
if (!ret) {
vty_out(vty, "%% Malformed GatewayIp\n");
return CMD_WARNING_CONFIG_FAILED;
}
if ((gw_ip.family == AF_INET
&& is_evpn_prefix_ipaddr_v6(
(struct prefix_evpn *)&p))
|| (gw_ip.family == AF_INET6
&& is_evpn_prefix_ipaddr_v4(
(struct prefix_evpn *)&p))) {
vty_out(vty,
"%% GatewayIp family differs with IP prefix\n");
return CMD_WARNING_CONFIG_FAILED;
}
}
}
pdest = bgp_node_get(bgp->route[afi][safi], (struct prefix *)&prd);
if (!bgp_dest_has_bgp_path_info_data(pdest))
bgp_dest_set_bgp_table_info(pdest,
bgp_table_init(bgp, afi, safi));
table = bgp_dest_get_bgp_table_info(pdest);
dest = bgp_node_get(table, &p);
if (bgp_dest_has_bgp_path_info_data(dest)) {
vty_out(vty, "%% Same network configuration exists\n");
bgp_dest_unlock_node(dest);
} else {
/* New configuration. */
bgp_static = bgp_static_new();
bgp_static->backdoor = 0;
bgp_static->valid = 0;
bgp_static->igpmetric = 0;
bgp_static->igpnexthop.s_addr = INADDR_ANY;
bgp_static->label = label;
bgp_static->prd = prd;
if (rmap_str) {
XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
route_map_counter_decrement(bgp_static->rmap.map);
bgp_static->rmap.name =
XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
bgp_static->rmap.map =
route_map_lookup_by_name(rmap_str);
route_map_counter_increment(bgp_static->rmap.map);
}
if (safi == SAFI_EVPN) {
if (esi) {
bgp_static->eth_s_id =
XCALLOC(MTYPE_ATTR,
sizeof(esi_t));
str2esi(esi, bgp_static->eth_s_id);
}
if (routermac) {
bgp_static->router_mac =
XCALLOC(MTYPE_ATTR, ETH_ALEN + 1);
(void)prefix_str2mac(routermac,
bgp_static->router_mac);
}
if (gwip)
prefix_copy(&bgp_static->gatewayIp, &gw_ip);
}
bgp_dest_set_bgp_static_info(dest, bgp_static);
bgp_static->valid = 1;
bgp_static_update_safi(bgp, &p, bgp_static, afi, safi);
}
return CMD_SUCCESS;
}
/* Configure static BGP network. */
int bgp_static_unset_safi(afi_t afi, safi_t safi, struct vty *vty,
const char *ip_str, const char *rd_str,
const char *label_str, int evpn_type, const char *esi,
const char *gwip, const char *ethtag)
{
VTY_DECLVAR_CONTEXT(bgp, bgp);
int ret;
struct prefix p;
struct prefix_rd prd;
struct bgp_dest *pdest;
struct bgp_dest *dest;
struct bgp_table *table;
struct bgp_static *bgp_static;
mpls_label_t label = MPLS_INVALID_LABEL;
/* Convert IP prefix string to struct prefix. */
ret = str2prefix(ip_str, &p);
if (!ret) {
vty_out(vty, "%% Malformed prefix\n");
return CMD_WARNING_CONFIG_FAILED;
}
apply_mask(&p);
if ((afi == AFI_L2VPN)
&& (bgp_build_evpn_prefix(evpn_type,
ethtag != NULL ? atol(ethtag) : 0, &p))) {
vty_out(vty, "%% L2VPN prefix could not be forged\n");
return CMD_WARNING_CONFIG_FAILED;
}
ret = str2prefix_rd(rd_str, &prd);
if (!ret) {
vty_out(vty, "%% Malformed rd\n");
return CMD_WARNING_CONFIG_FAILED;
}
if (label_str) {
unsigned long label_val;
label_val = strtoul(label_str, NULL, 10);
encode_label(label_val, &label);
}
pdest = bgp_node_get(bgp->route[afi][safi], (struct prefix *)&prd);
if (!bgp_dest_has_bgp_path_info_data(pdest))
bgp_dest_set_bgp_table_info(pdest,
bgp_table_init(bgp, afi, safi));
else
bgp_dest_unlock_node(pdest);
table = bgp_dest_get_bgp_table_info(pdest);
dest = bgp_node_lookup(table, &p);
if (dest) {
bgp_static_withdraw_safi(bgp, &p, afi, safi, &prd);
bgp_static = bgp_dest_get_bgp_static_info(dest);
bgp_static_free(bgp_static);
bgp_dest_set_bgp_static_info(dest, NULL);
bgp_dest_unlock_node(dest);
bgp_dest_unlock_node(dest);
} else
vty_out(vty, "%% Can't find the route\n");
return CMD_SUCCESS;
}
static int bgp_table_map_set(struct vty *vty, afi_t afi, safi_t safi,
const char *rmap_name)
{
VTY_DECLVAR_CONTEXT(bgp, bgp);
struct bgp_rmap *rmap;
rmap = &bgp->table_map[afi][safi];
if (rmap_name) {
XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
route_map_counter_decrement(rmap->map);
rmap->name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_name);
rmap->map = route_map_lookup_by_name(rmap_name);
route_map_counter_increment(rmap->map);
} else {
XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
route_map_counter_decrement(rmap->map);
rmap->map = NULL;
}
if (bgp_fibupd_safi(safi))
bgp_zebra_announce_table(bgp, afi, safi);
return CMD_SUCCESS;
}
static int bgp_table_map_unset(struct vty *vty, afi_t afi, safi_t safi,
const char *rmap_name)
{
VTY_DECLVAR_CONTEXT(bgp, bgp);
struct bgp_rmap *rmap;
rmap = &bgp->table_map[afi][safi];
XFREE(MTYPE_ROUTE_MAP_NAME, rmap->name);
route_map_counter_decrement(rmap->map);
rmap->map = NULL;
if (bgp_fibupd_safi(safi))
bgp_zebra_announce_table(bgp, afi, safi);
return CMD_SUCCESS;
}
void bgp_config_write_table_map(struct vty *vty, struct bgp *bgp, afi_t afi,
safi_t safi)
{
if (bgp->table_map[afi][safi].name) {
vty_out(vty, " table-map %s\n",
bgp->table_map[afi][safi].name);
}
}
DEFUN (bgp_table_map,
bgp_table_map_cmd,
"table-map WORD",
"BGP table to RIB route download filter\n"
"Name of the route map\n")
{
int idx_word = 1;
return bgp_table_map_set(vty, bgp_node_afi(vty), bgp_node_safi(vty),
argv[idx_word]->arg);
}
DEFUN (no_bgp_table_map,
no_bgp_table_map_cmd,
"no table-map WORD",
NO_STR
"BGP table to RIB route download filter\n"
"Name of the route map\n")
{
int idx_word = 2;
return bgp_table_map_unset(vty, bgp_node_afi(vty), bgp_node_safi(vty),
argv[idx_word]->arg);
}
DEFPY(bgp_network,
bgp_network_cmd,
"[no] network \
<A.B.C.D/M$prefix|A.B.C.D$address [mask A.B.C.D$netmask]> \
[{route-map WORD$map_name|label-index (0-1048560)$label_index| \
backdoor$backdoor}]",
NO_STR
"Specify a network to announce via BGP\n"
"IPv4 prefix\n"
"Network number\n"
"Network mask\n"
"Network mask\n"
"Route-map to modify the attributes\n"
"Name of the route map\n"
"Label index to associate with the prefix\n"
"Label index value\n"
"Specify a BGP backdoor route\n")
{
char addr_prefix_str[BUFSIZ];
if (address_str) {
int ret;
ret = netmask_str2prefix_str(address_str, netmask_str,
addr_prefix_str,
sizeof(addr_prefix_str));
if (!ret) {
vty_out(vty, "%% Inconsistent address and mask\n");
return CMD_WARNING_CONFIG_FAILED;
}
}
return bgp_static_set(
vty, no, address_str ? addr_prefix_str : prefix_str, AFI_IP,
bgp_node_safi(vty), map_name, backdoor ? 1 : 0,
label_index ? (uint32_t)label_index : BGP_INVALID_LABEL_INDEX);
}
DEFPY(ipv6_bgp_network,
ipv6_bgp_network_cmd,
"[no] network X:X::X:X/M$prefix \
[{route-map WORD$map_name|label-index (0-1048560)$label_index}]",
NO_STR
"Specify a network to announce via BGP\n"
"IPv6 prefix\n"
"Route-map to modify the attributes\n"
"Name of the route map\n"
"Label index to associate with the prefix\n"
"Label index value\n")
{
return bgp_static_set(
vty, no, prefix_str, AFI_IP6, bgp_node_safi(vty), map_name, 0,
label_index ? (uint32_t)label_index : BGP_INVALID_LABEL_INDEX);
}
static struct bgp_aggregate *bgp_aggregate_new(void)
{
return XCALLOC(MTYPE_BGP_AGGREGATE, sizeof(struct bgp_aggregate));
}
static void bgp_aggregate_free(struct bgp_aggregate *aggregate)
{
XFREE(MTYPE_ROUTE_MAP_NAME, aggregate->suppress_map_name);
route_map_counter_decrement(aggregate->suppress_map);
XFREE(MTYPE_ROUTE_MAP_NAME, aggregate->rmap.name);
route_map_counter_decrement(aggregate->rmap.map);
XFREE(MTYPE_BGP_AGGREGATE, aggregate);
}
/**
* Helper function to avoid repeated code: prepare variables for a
* `route_map_apply` call.
*
* \returns `true` on route map match, otherwise `false`.
*/
static bool aggr_suppress_map_test(struct bgp *bgp,
struct bgp_aggregate *aggregate,
struct bgp_path_info *pi)
{
const struct prefix *p = bgp_dest_get_prefix(pi->net);
route_map_result_t rmr = RMAP_DENYMATCH;
struct bgp_path_info rmap_path = {};
struct attr attr = {};
/* No route map entries created, just don't match. */
if (aggregate->suppress_map == NULL)
return false;
/* Call route map matching and return result. */
attr.aspath = aspath_empty();
rmap_path.peer = bgp->peer_self;
rmap_path.attr = &attr;
SET_FLAG(bgp->peer_self->rmap_type, PEER_RMAP_TYPE_AGGREGATE);
rmr = route_map_apply(aggregate->suppress_map, p, &rmap_path);
bgp->peer_self->rmap_type = 0;
bgp_attr_flush(&attr);
return rmr == RMAP_PERMITMATCH;
}
/** Test whether the aggregation has suppressed this path or not. */
static bool aggr_suppress_exists(struct bgp_aggregate *aggregate,
struct bgp_path_info *pi)
{
if (pi->extra == NULL || pi->extra->aggr_suppressors == NULL)
return false;
return listnode_lookup(pi->extra->aggr_suppressors, aggregate) != NULL;
}
/**
* Suppress this path and keep the reference.
*
* \returns `true` if needs processing otherwise `false`.
*/
static bool aggr_suppress_path(struct bgp_aggregate *aggregate,
struct bgp_path_info *pi)
{
struct bgp_path_info_extra *pie;
/* Path is already suppressed by this aggregation. */
if (aggr_suppress_exists(aggregate, pi))
return false;
pie = bgp_path_info_extra_get(pi);
/* This is the first suppression, allocate memory and list it. */
if (pie->aggr_suppressors == NULL)
pie->aggr_suppressors = list_new();
listnode_add(pie->aggr_suppressors, aggregate);
/* Only mark for processing if suppressed. */
if (listcount(pie->aggr_suppressors) == 1) {
if (BGP_DEBUG(update, UPDATE_OUT))
zlog_debug("aggregate-address suppressing: %pFX",
bgp_dest_get_prefix(pi->net));
bgp_path_info_set_flag(pi->net, pi, BGP_PATH_ATTR_CHANGED);
return true;
}
return false;
}
/**
* Unsuppress this path and remove the reference.
*
* \returns `true` if needs processing otherwise `false`.
*/
static bool aggr_unsuppress_path(struct bgp_aggregate *aggregate,
struct bgp_path_info *pi)
{
/* Path wasn't suppressed. */
if (!aggr_suppress_exists(aggregate, pi))
return false;
listnode_delete(pi->extra->aggr_suppressors, aggregate);
/* Unsuppress and free extra memory if last item. */
if (listcount(pi->extra->aggr_suppressors) == 0) {
if (BGP_DEBUG(update, UPDATE_OUT))
zlog_debug("aggregate-address unsuppressing: %pFX",
bgp_dest_get_prefix(pi->net));
list_delete(&pi->extra->aggr_suppressors);
bgp_path_info_set_flag(pi->net, pi, BGP_PATH_ATTR_CHANGED);
return true;
}
return false;
}
static bool bgp_aggregate_info_same(struct bgp_path_info *pi, uint8_t origin,
struct aspath *aspath,
struct community *comm,
struct ecommunity *ecomm,
struct lcommunity *lcomm)
{
static struct aspath *ae = NULL;
if (!ae)
ae = aspath_empty();
if (!pi)
return false;
if (origin != pi->attr->origin)
return false;
if (!aspath_cmp(pi->attr->aspath, (aspath) ? aspath : ae))
return false;
if (!community_cmp(pi->attr->community, comm))
return false;
if (!ecommunity_cmp(pi->attr->ecommunity, ecomm))
return false;
if (!lcommunity_cmp(pi->attr->lcommunity, lcomm))
return false;
if (!CHECK_FLAG(pi->flags, BGP_PATH_VALID))
return false;
return true;
}
static void bgp_aggregate_install(
struct bgp *bgp, afi_t afi, safi_t safi, const struct prefix *p,
uint8_t origin, struct aspath *aspath, struct community *community,
struct ecommunity *ecommunity, struct lcommunity *lcommunity,
uint8_t atomic_aggregate, struct bgp_aggregate *aggregate)
{
struct bgp_dest *dest;
struct bgp_table *table;
struct bgp_path_info *pi, *orig, *new;
struct attr *attr;
table = bgp->rib[afi][safi];
dest = bgp_node_get(table, p);
for (orig = pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next)
if (pi->peer == bgp->peer_self && pi->type == ZEBRA_ROUTE_BGP
&& pi->sub_type == BGP_ROUTE_AGGREGATE)
break;
/*
* If we have paths with different MEDs, then don't install
* (or uninstall) the aggregate route.
*/
if (aggregate->match_med && aggregate->med_mismatched)
goto uninstall_aggregate_route;
if (aggregate->count > 0) {
/*
* If the aggregate information has not changed
* no need to re-install it again.
*/
if (bgp_aggregate_info_same(orig, origin, aspath, community,
ecommunity, lcommunity)) {
bgp_dest_unlock_node(dest);
if (aspath)
aspath_free(aspath);
if (community)
community_free(&community);
if (ecommunity)
ecommunity_free(&ecommunity);
if (lcommunity)
lcommunity_free(&lcommunity);
return;
}
/*
* Mark the old as unusable
*/
if (pi)
bgp_path_info_delete(dest, pi);
attr = bgp_attr_aggregate_intern(
bgp, origin, aspath, community, ecommunity, lcommunity,
aggregate, atomic_aggregate, p);
if (!attr) {
bgp_aggregate_delete(bgp, p, afi, safi, aggregate);
if (BGP_DEBUG(update_groups, UPDATE_GROUPS))
zlog_debug("%s: %pFX null attribute", __func__,
p);
return;
}
new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, 0,
bgp->peer_self, attr, dest);
SET_FLAG(new->flags, BGP_PATH_VALID);
bgp_path_info_add(dest, new);
bgp_process(bgp, dest, afi, safi);
} else {
uninstall_aggregate_route:
for (pi = orig; pi; pi = pi->next)
if (pi->peer == bgp->peer_self
&& pi->type == ZEBRA_ROUTE_BGP
&& pi->sub_type == BGP_ROUTE_AGGREGATE)
break;
/* Withdraw static BGP route from routing table. */
if (pi) {
bgp_path_info_delete(dest, pi);
bgp_process(bgp, dest, afi, safi);
}
}
bgp_dest_unlock_node(dest);
}
/**
* Check if the current path has different MED than other known paths.
*
* \returns `true` if the MED matched the others else `false`.
*/
static bool bgp_aggregate_med_match(struct bgp_aggregate *aggregate,
struct bgp *bgp, struct bgp_path_info *pi)
{
uint32_t cur_med = bgp_med_value(pi->attr, bgp);
/* This is the first route being analyzed. */
if (!aggregate->med_initialized) {
aggregate->med_initialized = true;
aggregate->med_mismatched = false;
aggregate->med_matched_value = cur_med;
} else {
/* Check if routes with different MED showed up. */
if (cur_med != aggregate->med_matched_value)
aggregate->med_mismatched = true;
}
return !aggregate->med_mismatched;
}
/**
* Initializes and tests all routes in the aggregate address path for MED
* values.
*
* \returns `true` if all MEDs are the same otherwise `false`.
*/
static bool bgp_aggregate_test_all_med(struct bgp_aggregate *aggregate,
struct bgp *bgp, const struct prefix *p,
afi_t afi, safi_t safi)
{
struct bgp_table *table = bgp->rib[afi][safi];
const struct prefix *dest_p;
struct bgp_dest *dest, *top;
struct bgp_path_info *pi;
bool med_matched = true;
aggregate->med_initialized = false;
top = bgp_node_get(table, p);
for (dest = bgp_node_get(table, p); dest;
dest = bgp_route_next_until(dest, top)) {
dest_p = bgp_dest_get_prefix(dest);
if (dest_p->prefixlen <= p->prefixlen)
continue;
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) {
if (BGP_PATH_HOLDDOWN(pi))
continue;
if (pi->sub_type == BGP_ROUTE_AGGREGATE)
continue;
if (!bgp_aggregate_med_match(aggregate, bgp, pi)) {
med_matched = false;
break;
}
}
if (!med_matched)
break;
}
bgp_dest_unlock_node(top);
return med_matched;
}
/**
* Toggles the route suppression status for this aggregate address
* configuration.
*/
void bgp_aggregate_toggle_suppressed(struct bgp_aggregate *aggregate,
struct bgp *bgp, const struct prefix *p,
afi_t afi, safi_t safi, bool suppress)
{
struct bgp_table *table = bgp->rib[afi][safi];
const struct prefix *dest_p;
struct bgp_dest *dest, *top;
struct bgp_path_info *pi;
bool toggle_suppression;
/* We've found a different MED we must revert any suppressed routes. */
top = bgp_node_get(table, p);
for (dest = bgp_node_get(table, p); dest;
dest = bgp_route_next_until(dest, top)) {
dest_p = bgp_dest_get_prefix(dest);
if (dest_p->prefixlen <= p->prefixlen)
continue;
toggle_suppression = false;
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) {
if (BGP_PATH_HOLDDOWN(pi))
continue;
if (pi->sub_type == BGP_ROUTE_AGGREGATE)
continue;
/* We are toggling suppression back. */
if (suppress) {
/* Suppress route if not suppressed already. */
if (aggr_suppress_path(aggregate, pi))
toggle_suppression = true;
continue;
}
/* Install route if there is no more suppression. */
if (aggr_unsuppress_path(aggregate, pi))
toggle_suppression = true;
}
if (toggle_suppression)
bgp_process(bgp, dest, afi, safi);
}
bgp_dest_unlock_node(top);
}
/**
* Aggregate address MED matching incremental test: this function is called
* when the initial aggregation occurred and we are only testing a single
* new path.
*
* In addition to testing and setting the MED validity it also installs back
* suppressed routes (if summary is configured).
*
* Must not be called in `bgp_aggregate_route`.
*/
static void bgp_aggregate_med_update(struct bgp_aggregate *aggregate,
struct bgp *bgp, const struct prefix *p,
afi_t afi, safi_t safi,
struct bgp_path_info *pi, bool is_adding)
{
/* MED matching disabled. */
if (!aggregate->match_med)
return;
/* Aggregation with different MED, nothing to do. */
if (aggregate->med_mismatched)
return;
/*
* Test the current entry:
*
* is_adding == true: if the new entry doesn't match then we must
* install all suppressed routes.
*
* is_adding == false: if the entry being removed was the last
* unmatching entry then we can suppress all routes.
*/
if (!is_adding) {
if (bgp_aggregate_test_all_med(aggregate, bgp, p, afi, safi)
&& aggregate->summary_only)
bgp_aggregate_toggle_suppressed(aggregate, bgp, p, afi,
safi, true);
} else
bgp_aggregate_med_match(aggregate, bgp, pi);
/* No mismatches, just quit. */
if (!aggregate->med_mismatched)
return;
/* Route summarization is disabled. */
if (!aggregate->summary_only)
return;
bgp_aggregate_toggle_suppressed(aggregate, bgp, p, afi, safi, false);
}
/* Update an aggregate as routes are added/removed from the BGP table */
void bgp_aggregate_route(struct bgp *bgp, const struct prefix *p, afi_t afi,
safi_t safi, struct bgp_aggregate *aggregate)
{
struct bgp_table *table;
struct bgp_dest *top;
struct bgp_dest *dest;
uint8_t origin;
struct aspath *aspath = NULL;
struct community *community = NULL;
struct ecommunity *ecommunity = NULL;
struct lcommunity *lcommunity = NULL;
struct bgp_path_info *pi;
unsigned long match = 0;
uint8_t atomic_aggregate = 0;
/* If the bgp instance is being deleted or self peer is deleted
* then do not create aggregate route
*/
if (CHECK_FLAG(bgp->flags, BGP_FLAG_DELETE_IN_PROGRESS)
|| (bgp->peer_self == NULL))
return;
/* Initialize and test routes for MED difference. */
if (aggregate->match_med)
bgp_aggregate_test_all_med(aggregate, bgp, p, afi, safi);
/*
* Reset aggregate count: we might've been called from route map
* update so in that case we must retest all more specific routes.
*
* \see `bgp_route_map_process_update`.
*/
aggregate->count = 0;
aggregate->incomplete_origin_count = 0;
aggregate->incomplete_origin_count = 0;
aggregate->egp_origin_count = 0;
/* ORIGIN attribute: If at least one route among routes that are
aggregated has ORIGIN with the value INCOMPLETE, then the
aggregated route must have the ORIGIN attribute with the value
INCOMPLETE. Otherwise, if at least one route among routes that
are aggregated has ORIGIN with the value EGP, then the aggregated
route must have the origin attribute with the value EGP. In all
other case the value of the ORIGIN attribute of the aggregated
route is INTERNAL. */
origin = BGP_ORIGIN_IGP;
table = bgp->rib[afi][safi];
top = bgp_node_get(table, p);
for (dest = bgp_node_get(table, p); dest;
dest = bgp_route_next_until(dest, top)) {
const struct prefix *dest_p = bgp_dest_get_prefix(dest);
if (dest_p->prefixlen <= p->prefixlen)
continue;
/* If suppress fib is enabled and route not installed
* in FIB, skip the route
*/
if (!bgp_check_advertise(bgp, dest))
continue;
match = 0;
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) {
if (BGP_PATH_HOLDDOWN(pi))
continue;
if (pi->attr->flag
& ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
atomic_aggregate = 1;
if (pi->sub_type == BGP_ROUTE_AGGREGATE)
continue;
/*
* summary-only aggregate route suppress
* aggregated route announcements.
*
* MED matching:
* Don't create summaries if MED didn't match
* otherwise neither the specific routes and the
* aggregation will be announced.
*/
if (aggregate->summary_only
&& AGGREGATE_MED_VALID(aggregate)) {
if (aggr_suppress_path(aggregate, pi))
match++;
}
/*
* Suppress more specific routes that match the route
* map results.
*
* MED matching:
* Don't suppress routes if MED matching is enabled and
* it mismatched otherwise we might end up with no
* routes for this path.
*/
if (aggregate->suppress_map_name
&& AGGREGATE_MED_VALID(aggregate)
&& aggr_suppress_map_test(bgp, aggregate, pi)) {
if (aggr_suppress_path(aggregate, pi))
match++;
}
aggregate->count++;
/*
* If at least one route among routes that are
* aggregated has ORIGIN with the value INCOMPLETE,
* then the aggregated route MUST have the ORIGIN
* attribute with the value INCOMPLETE. Otherwise, if
* at least one route among routes that are aggregated
* has ORIGIN with the value EGP, then the aggregated
* route MUST have the ORIGIN attribute with the value
* EGP.
*/
switch (pi->attr->origin) {
case BGP_ORIGIN_INCOMPLETE:
aggregate->incomplete_origin_count++;
break;
case BGP_ORIGIN_EGP:
aggregate->egp_origin_count++;
break;
default:
/*Do nothing.
*/
break;
}
if (!aggregate->as_set)
continue;
/*
* as-set aggregate route generate origin, as path,
* and community aggregation.
*/
/* Compute aggregate route's as-path.
*/
bgp_compute_aggregate_aspath_hash(aggregate,
pi->attr->aspath);
/* Compute aggregate route's community.
*/
if (pi->attr->community)
bgp_compute_aggregate_community_hash(
aggregate,
pi->attr->community);
/* Compute aggregate route's extended community.
*/
if (pi->attr->ecommunity)
bgp_compute_aggregate_ecommunity_hash(
aggregate,
pi->attr->ecommunity);
/* Compute aggregate route's large community.
*/
if (pi->attr->lcommunity)
bgp_compute_aggregate_lcommunity_hash(
aggregate,
pi->attr->lcommunity);
}
if (match)
bgp_process(bgp, dest, afi, safi);
}
if (aggregate->as_set) {
bgp_compute_aggregate_aspath_val(aggregate);
bgp_compute_aggregate_community_val(aggregate);
bgp_compute_aggregate_ecommunity_val(aggregate);
bgp_compute_aggregate_lcommunity_val(aggregate);
}
bgp_dest_unlock_node(top);
if (aggregate->incomplete_origin_count > 0)
origin = BGP_ORIGIN_INCOMPLETE;
else if (aggregate->egp_origin_count > 0)
origin = BGP_ORIGIN_EGP;
if (aggregate->origin != BGP_ORIGIN_UNSPECIFIED)
origin = aggregate->origin;
if (aggregate->as_set) {
if (aggregate->aspath)
/* Retrieve aggregate route's as-path.
*/
aspath = aspath_dup(aggregate->aspath);
if (aggregate->community)
/* Retrieve aggregate route's community.
*/
community = community_dup(aggregate->community);
if (aggregate->ecommunity)
/* Retrieve aggregate route's ecommunity.
*/
ecommunity = ecommunity_dup(aggregate->ecommunity);
if (aggregate->lcommunity)
/* Retrieve aggregate route's lcommunity.
*/
lcommunity = lcommunity_dup(aggregate->lcommunity);
}
bgp_aggregate_install(bgp, afi, safi, p, origin, aspath, community,
ecommunity, lcommunity, atomic_aggregate,
aggregate);
}
void bgp_aggregate_delete(struct bgp *bgp, const struct prefix *p, afi_t afi,
safi_t safi, struct bgp_aggregate *aggregate)
{
struct bgp_table *table;
struct bgp_dest *top;
struct bgp_dest *dest;
struct bgp_path_info *pi;
unsigned long match;
table = bgp->rib[afi][safi];
/* If routes exists below this node, generate aggregate routes. */
top = bgp_node_get(table, p);
for (dest = bgp_node_get(table, p); dest;
dest = bgp_route_next_until(dest, top)) {
const struct prefix *dest_p = bgp_dest_get_prefix(dest);
if (dest_p->prefixlen <= p->prefixlen)
continue;
match = 0;
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) {
if (BGP_PATH_HOLDDOWN(pi))
continue;
if (pi->sub_type == BGP_ROUTE_AGGREGATE)
continue;
if (aggregate->summary_only && pi->extra
&& AGGREGATE_MED_VALID(aggregate)) {
if (aggr_unsuppress_path(aggregate, pi))
match++;
}
if (aggregate->suppress_map_name
&& AGGREGATE_MED_VALID(aggregate)
&& aggr_suppress_map_test(bgp, aggregate, pi)) {
if (aggr_unsuppress_path(aggregate, pi))
match++;
}
aggregate->count--;
if (pi->attr->origin == BGP_ORIGIN_INCOMPLETE)
aggregate->incomplete_origin_count--;
else if (pi->attr->origin == BGP_ORIGIN_EGP)
aggregate->egp_origin_count--;
if (aggregate->as_set) {
/* Remove as-path from aggregate.
*/
bgp_remove_aspath_from_aggregate_hash(
aggregate,
pi->attr->aspath);
if (pi->attr->community)
/* Remove community from aggregate.
*/
bgp_remove_comm_from_aggregate_hash(
aggregate,
pi->attr->community);
if (pi->attr->ecommunity)
/* Remove ecommunity from aggregate.
*/
bgp_remove_ecomm_from_aggregate_hash(
aggregate,
pi->attr->ecommunity);
if (pi->attr->lcommunity)
/* Remove lcommunity from aggregate.
*/
bgp_remove_lcomm_from_aggregate_hash(
aggregate,
pi->attr->lcommunity);
}
}
/* If this node was suppressed, process the change. */
if (match)
bgp_process(bgp, dest, afi, safi);
}
if (aggregate->as_set) {
aspath_free(aggregate->aspath);
aggregate->aspath = NULL;
if (aggregate->community)
community_free(&aggregate->community);
if (aggregate->ecommunity)
ecommunity_free(&aggregate->ecommunity);
if (aggregate->lcommunity)
lcommunity_free(&aggregate->lcommunity);
}
bgp_dest_unlock_node(top);
}
static void bgp_add_route_to_aggregate(struct bgp *bgp,
const struct prefix *aggr_p,
struct bgp_path_info *pinew, afi_t afi,
safi_t safi,
struct bgp_aggregate *aggregate)
{
uint8_t origin;
struct aspath *aspath = NULL;
uint8_t atomic_aggregate = 0;
struct community *community = NULL;
struct ecommunity *ecommunity = NULL;
struct lcommunity *lcommunity = NULL;
/* If the bgp instance is being deleted or self peer is deleted
* then do not create aggregate route
*/
if (CHECK_FLAG(bgp->flags, BGP_FLAG_DELETE_IN_PROGRESS)
|| (bgp->peer_self == NULL))
return;
/* ORIGIN attribute: If at least one route among routes that are
* aggregated has ORIGIN with the value INCOMPLETE, then the
* aggregated route must have the ORIGIN attribute with the value
* INCOMPLETE. Otherwise, if at least one route among routes that
* are aggregated has ORIGIN with the value EGP, then the aggregated
* route must have the origin attribute with the value EGP. In all
* other case the value of the ORIGIN attribute of the aggregated
* route is INTERNAL.
*/
origin = BGP_ORIGIN_IGP;
aggregate->count++;
/*
* This must be called before `summary` check to avoid
* "suppressing" twice.
*/
if (aggregate->match_med)
bgp_aggregate_med_update(aggregate, bgp, aggr_p, afi, safi,
pinew, true);
if (aggregate->summary_only && AGGREGATE_MED_VALID(aggregate))
aggr_suppress_path(aggregate, pinew);
if (aggregate->suppress_map_name && AGGREGATE_MED_VALID(aggregate)
&& aggr_suppress_map_test(bgp, aggregate, pinew))
aggr_suppress_path(aggregate, pinew);
switch (pinew->attr->origin) {
case BGP_ORIGIN_INCOMPLETE:
aggregate->incomplete_origin_count++;
break;
case BGP_ORIGIN_EGP:
aggregate->egp_origin_count++;
break;
default:
/* Do nothing.
*/
break;
}
if (aggregate->incomplete_origin_count > 0)
origin = BGP_ORIGIN_INCOMPLETE;
else if (aggregate->egp_origin_count > 0)
origin = BGP_ORIGIN_EGP;
if (aggregate->origin != BGP_ORIGIN_UNSPECIFIED)
origin = aggregate->origin;
if (aggregate->as_set) {
/* Compute aggregate route's as-path.
*/
bgp_compute_aggregate_aspath(aggregate,
pinew->attr->aspath);
/* Compute aggregate route's community.
*/
if (pinew->attr->community)
bgp_compute_aggregate_community(
aggregate,
pinew->attr->community);
/* Compute aggregate route's extended community.
*/
if (pinew->attr->ecommunity)
bgp_compute_aggregate_ecommunity(
aggregate,
pinew->attr->ecommunity);
/* Compute aggregate route's large community.
*/
if (pinew->attr->lcommunity)
bgp_compute_aggregate_lcommunity(
aggregate,
pinew->attr->lcommunity);
/* Retrieve aggregate route's as-path.
*/
if (aggregate->aspath)
aspath = aspath_dup(aggregate->aspath);
/* Retrieve aggregate route's community.
*/
if (aggregate->community)
community = community_dup(aggregate->community);
/* Retrieve aggregate route's ecommunity.
*/
if (aggregate->ecommunity)
ecommunity = ecommunity_dup(aggregate->ecommunity);
/* Retrieve aggregate route's lcommunity.
*/
if (aggregate->lcommunity)
lcommunity = lcommunity_dup(aggregate->lcommunity);
}
bgp_aggregate_install(bgp, afi, safi, aggr_p, origin,
aspath, community, ecommunity,
lcommunity, atomic_aggregate, aggregate);
}
static void bgp_remove_route_from_aggregate(struct bgp *bgp, afi_t afi,
safi_t safi,
struct bgp_path_info *pi,
struct bgp_aggregate *aggregate,
const struct prefix *aggr_p)
{
uint8_t origin;
struct aspath *aspath = NULL;
uint8_t atomic_aggregate = 0;
struct community *community = NULL;
struct ecommunity *ecommunity = NULL;
struct lcommunity *lcommunity = NULL;
unsigned long match = 0;
/* If the bgp instance is being deleted or self peer is deleted
* then do not create aggregate route
*/
if (CHECK_FLAG(bgp->flags, BGP_FLAG_DELETE_IN_PROGRESS)
|| (bgp->peer_self == NULL))
return;
if (BGP_PATH_HOLDDOWN(pi))
return;
if (pi->sub_type == BGP_ROUTE_AGGREGATE)
return;
if (aggregate->summary_only && AGGREGATE_MED_VALID(aggregate))
if (aggr_unsuppress_path(aggregate, pi))
match++;
if (aggregate->suppress_map_name && AGGREGATE_MED_VALID(aggregate)
&& aggr_suppress_map_test(bgp, aggregate, pi))
if (aggr_unsuppress_path(aggregate, pi))
match++;
/*
* This must be called after `summary`, `suppress-map` check to avoid
* "unsuppressing" twice.
*/
if (aggregate->match_med)
bgp_aggregate_med_update(aggregate, bgp, aggr_p, afi, safi, pi,
true);
if (aggregate->count > 0)
aggregate->count--;
if (pi->attr->origin == BGP_ORIGIN_INCOMPLETE)
aggregate->incomplete_origin_count--;
else if (pi->attr->origin == BGP_ORIGIN_EGP)
aggregate->egp_origin_count--;
if (aggregate->as_set) {
/* Remove as-path from aggregate.
*/
bgp_remove_aspath_from_aggregate(aggregate,
pi->attr->aspath);
if (pi->attr->community)
/* Remove community from aggregate.
*/
bgp_remove_community_from_aggregate(
aggregate,
pi->attr->community);
if (pi->attr->ecommunity)
/* Remove ecommunity from aggregate.
*/
bgp_remove_ecommunity_from_aggregate(
aggregate,
pi->attr->ecommunity);
if (pi->attr->lcommunity)
/* Remove lcommunity from aggregate.
*/
bgp_remove_lcommunity_from_aggregate(
aggregate,
pi->attr->lcommunity);
}
/* If this node was suppressed, process the change. */
if (match)
bgp_process(bgp, pi->net, afi, safi);
origin = BGP_ORIGIN_IGP;
if (aggregate->incomplete_origin_count > 0)
origin = BGP_ORIGIN_INCOMPLETE;
else if (aggregate->egp_origin_count > 0)
origin = BGP_ORIGIN_EGP;
if (aggregate->origin != BGP_ORIGIN_UNSPECIFIED)
origin = aggregate->origin;
if (aggregate->as_set) {
/* Retrieve aggregate route's as-path.
*/
if (aggregate->aspath)
aspath = aspath_dup(aggregate->aspath);
/* Retrieve aggregate route's community.
*/
if (aggregate->community)
community = community_dup(aggregate->community);
/* Retrieve aggregate route's ecommunity.
*/
if (aggregate->ecommunity)
ecommunity = ecommunity_dup(aggregate->ecommunity);
/* Retrieve aggregate route's lcommunity.
*/
if (aggregate->lcommunity)
lcommunity = lcommunity_dup(aggregate->lcommunity);
}
bgp_aggregate_install(bgp, afi, safi, aggr_p, origin,
aspath, community, ecommunity,
lcommunity, atomic_aggregate, aggregate);
}
void bgp_aggregate_increment(struct bgp *bgp, const struct prefix *p,
struct bgp_path_info *pi, afi_t afi, safi_t safi)
{
struct bgp_dest *child;
struct bgp_dest *dest;
struct bgp_aggregate *aggregate;
struct bgp_table *table;
table = bgp->aggregate[afi][safi];
/* No aggregates configured. */
if (bgp_table_top_nolock(table) == NULL)
return;
if (p->prefixlen == 0)
return;
if (BGP_PATH_HOLDDOWN(pi))
return;
/* If suppress fib is enabled and route not installed
* in FIB, do not update the aggregate route
*/
if (!bgp_check_advertise(bgp, pi->net))
return;
child = bgp_node_get(table, p);
/* Aggregate address configuration check. */
for (dest = child; dest; dest = bgp_dest_parent_nolock(dest)) {
const struct prefix *dest_p = bgp_dest_get_prefix(dest);
aggregate = bgp_dest_get_bgp_aggregate_info(dest);
if (aggregate != NULL && dest_p->prefixlen < p->prefixlen) {
bgp_add_route_to_aggregate(bgp, dest_p, pi, afi, safi,
aggregate);
}
}
bgp_dest_unlock_node(child);
}
void bgp_aggregate_decrement(struct bgp *bgp, const struct prefix *p,
struct bgp_path_info *del, afi_t afi, safi_t safi)
{
struct bgp_dest *child;
struct bgp_dest *dest;
struct bgp_aggregate *aggregate;
struct bgp_table *table;
table = bgp->aggregate[afi][safi];
/* No aggregates configured. */
if (bgp_table_top_nolock(table) == NULL)
return;
if (p->prefixlen == 0)
return;
child = bgp_node_get(table, p);
/* Aggregate address configuration check. */
for (dest = child; dest; dest = bgp_dest_parent_nolock(dest)) {
const struct prefix *dest_p = bgp_dest_get_prefix(dest);
aggregate = bgp_dest_get_bgp_aggregate_info(dest);
if (aggregate != NULL && dest_p->prefixlen < p->prefixlen) {
bgp_remove_route_from_aggregate(bgp, afi, safi, del,
aggregate, dest_p);
}
}
bgp_dest_unlock_node(child);
}
/* Aggregate route attribute. */
#define AGGREGATE_SUMMARY_ONLY 1
#define AGGREGATE_AS_SET 1
#define AGGREGATE_AS_UNSET 0
static const char *bgp_origin2str(uint8_t origin)
{
switch (origin) {
case BGP_ORIGIN_IGP:
return "igp";
case BGP_ORIGIN_EGP:
return "egp";
case BGP_ORIGIN_INCOMPLETE:
return "incomplete";
}
return "n/a";
}
static const char *bgp_rpki_validation2str(enum rpki_states v_state)
{
switch (v_state) {
case RPKI_NOT_BEING_USED:
return "not used";
case RPKI_VALID:
return "valid";
case RPKI_NOTFOUND:
return "not found";
case RPKI_INVALID:
return "invalid";
}
assert(!"We should never get here this is a dev escape");
return "ERROR";
}
static int bgp_aggregate_unset(struct vty *vty, const char *prefix_str,
afi_t afi, safi_t safi)
{
VTY_DECLVAR_CONTEXT(bgp, bgp);
int ret;
struct prefix p;
struct bgp_dest *dest;
struct bgp_aggregate *aggregate;
/* Convert string to prefix structure. */
ret = str2prefix(prefix_str, &p);
if (!ret) {
vty_out(vty, "Malformed prefix\n");
return CMD_WARNING_CONFIG_FAILED;
}
apply_mask(&p);
/* Old configuration check. */
dest = bgp_node_lookup(bgp->aggregate[afi][safi], &p);
if (!dest) {
vty_out(vty,
"%% There is no aggregate-address configuration.\n");
return CMD_WARNING_CONFIG_FAILED;
}
aggregate = bgp_dest_get_bgp_aggregate_info(dest);
bgp_aggregate_delete(bgp, &p, afi, safi, aggregate);
bgp_aggregate_install(bgp, afi, safi, &p, 0, NULL, NULL,
NULL, NULL, 0, aggregate);
/* Unlock aggregate address configuration. */
bgp_dest_set_bgp_aggregate_info(dest, NULL);
if (aggregate->community)
community_free(&aggregate->community);
if (aggregate->community_hash) {
/* Delete all communities in the hash.
*/
hash_clean(aggregate->community_hash,
bgp_aggr_community_remove);
/* Free up the community_hash.
*/
hash_free(aggregate->community_hash);
}
if (aggregate->ecommunity)
ecommunity_free(&aggregate->ecommunity);
if (aggregate->ecommunity_hash) {
/* Delete all ecommunities in the hash.
*/
hash_clean(aggregate->ecommunity_hash,
bgp_aggr_ecommunity_remove);
/* Free up the ecommunity_hash.
*/
hash_free(aggregate->ecommunity_hash);
}
if (aggregate->lcommunity)
lcommunity_free(&aggregate->lcommunity);
if (aggregate->lcommunity_hash) {
/* Delete all lcommunities in the hash.
*/
hash_clean(aggregate->lcommunity_hash,
bgp_aggr_lcommunity_remove);
/* Free up the lcommunity_hash.
*/
hash_free(aggregate->lcommunity_hash);
}
if (aggregate->aspath)
aspath_free(aggregate->aspath);
if (aggregate->aspath_hash) {
/* Delete all as-paths in the hash.
*/
hash_clean(aggregate->aspath_hash,
bgp_aggr_aspath_remove);
/* Free up the aspath_hash.
*/
hash_free(aggregate->aspath_hash);
}
bgp_aggregate_free(aggregate);
bgp_dest_unlock_node(dest);
bgp_dest_unlock_node(dest);
return CMD_SUCCESS;
}
static int bgp_aggregate_set(struct vty *vty, const char *prefix_str, afi_t afi,
safi_t safi, const char *rmap,
uint8_t summary_only, uint8_t as_set,
uint8_t origin, bool match_med,
const char *suppress_map)
{
VTY_DECLVAR_CONTEXT(bgp, bgp);
int ret;
struct prefix p;
struct bgp_dest *dest;
struct bgp_aggregate *aggregate;
uint8_t as_set_new = as_set;
if (suppress_map && summary_only) {
vty_out(vty,
"'summary-only' and 'suppress-map' can't be used at the same time\n");
return CMD_WARNING_CONFIG_FAILED;
}
/* Convert string to prefix structure. */
ret = str2prefix(prefix_str, &p);
if (!ret) {
vty_out(vty, "Malformed prefix\n");
return CMD_WARNING_CONFIG_FAILED;
}
apply_mask(&p);
if ((afi == AFI_IP && p.prefixlen == IPV4_MAX_BITLEN) ||
(afi == AFI_IP6 && p.prefixlen == IPV6_MAX_BITLEN)) {
vty_out(vty, "Specified prefix: %s will not result in any useful aggregation, disallowing\n",
prefix_str);
return CMD_WARNING_CONFIG_FAILED;
}
/* Old configuration check. */
dest = bgp_node_get(bgp->aggregate[afi][safi], &p);
aggregate = bgp_dest_get_bgp_aggregate_info(dest);
if (aggregate) {
vty_out(vty, "There is already same aggregate network.\n");
/* try to remove the old entry */
ret = bgp_aggregate_unset(vty, prefix_str, afi, safi);
if (ret) {
vty_out(vty, "Error deleting aggregate.\n");
bgp_dest_unlock_node(dest);
return CMD_WARNING_CONFIG_FAILED;
}
}
/* Make aggregate address structure. */
aggregate = bgp_aggregate_new();
aggregate->summary_only = summary_only;
aggregate->match_med = match_med;
/* Network operators MUST NOT locally generate any new
* announcements containing AS_SET or AS_CONFED_SET. If they have
* announced routes with AS_SET or AS_CONFED_SET in them, then they
* SHOULD withdraw those routes and re-announce routes for the
* aggregate or component prefixes (i.e., the more-specific routes
* subsumed by the previously aggregated route) without AS_SET
* or AS_CONFED_SET in the updates.
*/
if (bgp->reject_as_sets) {
if (as_set == AGGREGATE_AS_SET) {
as_set_new = AGGREGATE_AS_UNSET;
zlog_warn(
"%s: Ignoring as-set because `bgp reject-as-sets` is enabled.",
__func__);
vty_out(vty,
"Ignoring as-set because `bgp reject-as-sets` is enabled.\n");
}
}
aggregate->as_set = as_set_new;
aggregate->safi = safi;
/* Override ORIGIN attribute if defined.
* E.g.: Cisco and Juniper set ORIGIN for aggregated address
* to IGP which is not what rfc4271 says.
* This enables the same behavior, optionally.
*/
aggregate->origin = origin;
if (rmap) {
XFREE(MTYPE_ROUTE_MAP_NAME, aggregate->rmap.name);
route_map_counter_decrement(aggregate->rmap.map);
aggregate->rmap.name =
XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap);
aggregate->rmap.map = route_map_lookup_by_name(rmap);
route_map_counter_increment(aggregate->rmap.map);
}
if (suppress_map) {
XFREE(MTYPE_ROUTE_MAP_NAME, aggregate->suppress_map_name);
route_map_counter_decrement(aggregate->suppress_map);
aggregate->suppress_map_name =
XSTRDUP(MTYPE_ROUTE_MAP_NAME, suppress_map);
aggregate->suppress_map =
route_map_lookup_by_name(aggregate->suppress_map_name);
route_map_counter_increment(aggregate->suppress_map);
}
bgp_dest_set_bgp_aggregate_info(dest, aggregate);
/* Aggregate address insert into BGP routing table. */
bgp_aggregate_route(bgp, &p, afi, safi, aggregate);
return CMD_SUCCESS;
}
DEFPY(aggregate_addressv4, aggregate_addressv4_cmd,
"[no] aggregate-address <A.B.C.D/M$prefix|A.B.C.D$addr A.B.C.D$mask> [{"
"as-set$as_set_s"
"|summary-only$summary_only"
"|route-map WORD$rmap_name"
"|origin <egp|igp|incomplete>$origin_s"
"|matching-MED-only$match_med"
"|suppress-map WORD$suppress_map"
"}]",
NO_STR
"Configure BGP aggregate entries\n"
"Aggregate prefix\n" "Aggregate address\n" "Aggregate mask\n"
"Generate AS set path information\n"
"Filter more specific routes from updates\n"
"Apply route map to aggregate network\n"
"Route map name\n"
"BGP origin code\n"
"Remote EGP\n"
"Local IGP\n"
"Unknown heritage\n"
"Only aggregate routes with matching MED\n"
"Suppress the selected more specific routes\n"
"Route map with the route selectors\n")
{
const char *prefix_s = NULL;
safi_t safi = bgp_node_safi(vty);
uint8_t origin = BGP_ORIGIN_UNSPECIFIED;
int as_set = AGGREGATE_AS_UNSET;
char prefix_buf[PREFIX2STR_BUFFER];
if (addr_str) {
if (netmask_str2prefix_str(addr_str, mask_str, prefix_buf,
sizeof(prefix_buf))
== 0) {
vty_out(vty, "%% Inconsistent address and mask\n");
return CMD_WARNING_CONFIG_FAILED;
}
prefix_s = prefix_buf;
} else
prefix_s = prefix_str;
if (origin_s) {
if (strcmp(origin_s, "egp") == 0)
origin = BGP_ORIGIN_EGP;
else if (strcmp(origin_s, "igp") == 0)
origin = BGP_ORIGIN_IGP;
else if (strcmp(origin_s, "incomplete") == 0)
origin = BGP_ORIGIN_INCOMPLETE;
}
if (as_set_s)
as_set = AGGREGATE_AS_SET;
/* Handle configuration removal, otherwise installation. */
if (no)
return bgp_aggregate_unset(vty, prefix_s, AFI_IP, safi);
return bgp_aggregate_set(vty, prefix_s, AFI_IP, safi, rmap_name,
summary_only != NULL, as_set, origin,
match_med != NULL, suppress_map);
}
DEFPY(aggregate_addressv6, aggregate_addressv6_cmd,
"[no] aggregate-address X:X::X:X/M$prefix [{"
"as-set$as_set_s"
"|summary-only$summary_only"
"|route-map WORD$rmap_name"
"|origin <egp|igp|incomplete>$origin_s"
"|matching-MED-only$match_med"
"|suppress-map WORD$suppress_map"
"}]",
NO_STR
"Configure BGP aggregate entries\n"
"Aggregate prefix\n"
"Generate AS set path information\n"
"Filter more specific routes from updates\n"
"Apply route map to aggregate network\n"
"Route map name\n"
"BGP origin code\n"
"Remote EGP\n"
"Local IGP\n"
"Unknown heritage\n"
"Only aggregate routes with matching MED\n"
"Suppress the selected more specific routes\n"
"Route map with the route selectors\n")
{
uint8_t origin = BGP_ORIGIN_UNSPECIFIED;
int as_set = AGGREGATE_AS_UNSET;
if (origin_s) {
if (strcmp(origin_s, "egp") == 0)
origin = BGP_ORIGIN_EGP;
else if (strcmp(origin_s, "igp") == 0)
origin = BGP_ORIGIN_IGP;
else if (strcmp(origin_s, "incomplete") == 0)
origin = BGP_ORIGIN_INCOMPLETE;
}
if (as_set_s)
as_set = AGGREGATE_AS_SET;
/* Handle configuration removal, otherwise installation. */
if (no)
return bgp_aggregate_unset(vty, prefix_str, AFI_IP6,
SAFI_UNICAST);
return bgp_aggregate_set(vty, prefix_str, AFI_IP6, SAFI_UNICAST,
rmap_name, summary_only != NULL, as_set,
origin, match_med != NULL, suppress_map);
}
/* Redistribute route treatment. */
void bgp_redistribute_add(struct bgp *bgp, struct prefix *p,
const union g_addr *nexthop, ifindex_t ifindex,
enum nexthop_types_t nhtype, uint8_t distance,
enum blackhole_type bhtype, uint32_t metric,
uint8_t type, unsigned short instance,
route_tag_t tag)
{
struct bgp_path_info *new;
struct bgp_path_info *bpi;
struct bgp_path_info rmap_path;
struct bgp_dest *bn;
struct attr attr;
struct attr *new_attr;
afi_t afi;
route_map_result_t ret;
struct bgp_redist *red;
/* Make default attribute. */
bgp_attr_default_set(&attr, BGP_ORIGIN_INCOMPLETE);
/*
* This must not be NULL to satisfy Coverity SA
*/
assert(attr.aspath);
switch (nhtype) {
case NEXTHOP_TYPE_IFINDEX:
break;
case NEXTHOP_TYPE_IPV4:
case NEXTHOP_TYPE_IPV4_IFINDEX:
attr.nexthop = nexthop->ipv4;
break;
case NEXTHOP_TYPE_IPV6:
case NEXTHOP_TYPE_IPV6_IFINDEX:
attr.mp_nexthop_global = nexthop->ipv6;
attr.mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
break;
case NEXTHOP_TYPE_BLACKHOLE:
switch (p->family) {
case AF_INET:
attr.nexthop.s_addr = INADDR_ANY;
break;
case AF_INET6:
memset(&attr.mp_nexthop_global, 0,
sizeof(attr.mp_nexthop_global));
attr.mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL;
break;
}
attr.bh_type = bhtype;
break;
}
attr.nh_type = nhtype;
attr.nh_ifindex = ifindex;
attr.med = metric;
attr.distance = distance;
attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC);
attr.tag = tag;
afi = family2afi(p->family);
red = bgp_redist_lookup(bgp, afi, type, instance);
if (red) {
struct attr attr_new;
/* Copy attribute for modification. */
attr_new = attr;
if (red->redist_metric_flag)
attr_new.med = red->redist_metric;
/* Apply route-map. */
if (red->rmap.name) {
memset(&rmap_path, 0, sizeof(struct bgp_path_info));
rmap_path.peer = bgp->peer_self;
rmap_path.attr = &attr_new;
SET_FLAG(bgp->peer_self->rmap_type,
PEER_RMAP_TYPE_REDISTRIBUTE);
ret = route_map_apply(red->rmap.map, p, &rmap_path);
bgp->peer_self->rmap_type = 0;
if (ret == RMAP_DENYMATCH) {
/* Free uninterned attribute. */
bgp_attr_flush(&attr_new);
/* Unintern original. */
aspath_unintern(&attr.aspath);
bgp_redistribute_delete(bgp, p, type, instance);
return;
}
}
if (bgp_in_graceful_shutdown(bgp))
bgp_attr_add_gshut_community(&attr_new);
bn = bgp_afi_node_get(bgp->rib[afi][SAFI_UNICAST], afi,
SAFI_UNICAST, p, NULL);
new_attr = bgp_attr_intern(&attr_new);
for (bpi = bgp_dest_get_bgp_path_info(bn); bpi; bpi = bpi->next)
if (bpi->peer == bgp->peer_self
&& bpi->sub_type == BGP_ROUTE_REDISTRIBUTE)
break;
if (bpi) {
/* Ensure the (source route) type is updated. */
bpi->type = type;
if (attrhash_cmp(bpi->attr, new_attr)
&& !CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED)) {
bgp_attr_unintern(&new_attr);
aspath_unintern(&attr.aspath);
bgp_dest_unlock_node(bn);
return;
} else {
/* The attribute is changed. */
bgp_path_info_set_flag(bn, bpi,
BGP_PATH_ATTR_CHANGED);
/* Rewrite BGP route information. */
if (CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED))
bgp_path_info_restore(bn, bpi);
else
bgp_aggregate_decrement(
bgp, p, bpi, afi, SAFI_UNICAST);
bgp_attr_unintern(&bpi->attr);
bpi->attr = new_attr;
bpi->uptime = bgp_clock();
/* Process change. */
bgp_aggregate_increment(bgp, p, bpi, afi,
SAFI_UNICAST);
bgp_process(bgp, bn, afi, SAFI_UNICAST);
bgp_dest_unlock_node(bn);
aspath_unintern(&attr.aspath);
if ((bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
|| (bgp->inst_type
== BGP_INSTANCE_TYPE_DEFAULT)) {
vpn_leak_from_vrf_update(
bgp_get_default(), bgp, bpi);
}
return;
}
}
new = info_make(type, BGP_ROUTE_REDISTRIBUTE, instance,
bgp->peer_self, new_attr, bn);
SET_FLAG(new->flags, BGP_PATH_VALID);
bgp_aggregate_increment(bgp, p, new, afi, SAFI_UNICAST);
bgp_path_info_add(bn, new);
bgp_dest_unlock_node(bn);
bgp_process(bgp, bn, afi, SAFI_UNICAST);
if ((bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
|| (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) {
vpn_leak_from_vrf_update(bgp_get_default(), bgp, new);
}
}
/* Unintern original. */
aspath_unintern(&attr.aspath);
}
void bgp_redistribute_delete(struct bgp *bgp, struct prefix *p, uint8_t type,
unsigned short instance)
{
afi_t afi;
struct bgp_dest *dest;
struct bgp_path_info *pi;
struct bgp_redist *red;
afi = family2afi(p->family);
red = bgp_redist_lookup(bgp, afi, type, instance);
if (red) {
dest = bgp_afi_node_get(bgp->rib[afi][SAFI_UNICAST], afi,
SAFI_UNICAST, p, NULL);
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next)
if (pi->peer == bgp->peer_self && pi->type == type)
break;
if (pi) {
if ((bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
|| (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) {
vpn_leak_from_vrf_withdraw(bgp_get_default(),
bgp, pi);
}
bgp_aggregate_decrement(bgp, p, pi, afi, SAFI_UNICAST);
bgp_path_info_delete(dest, pi);
bgp_process(bgp, dest, afi, SAFI_UNICAST);
}
bgp_dest_unlock_node(dest);
}
}
/* Withdraw specified route type's route. */
void bgp_redistribute_withdraw(struct bgp *bgp, afi_t afi, int type,
unsigned short instance)
{
struct bgp_dest *dest;
struct bgp_path_info *pi;
struct bgp_table *table;
table = bgp->rib[afi][SAFI_UNICAST];
for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) {
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next)
if (pi->peer == bgp->peer_self && pi->type == type
&& pi->instance == instance)
break;
if (pi) {
if ((bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
|| (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) {
vpn_leak_from_vrf_withdraw(bgp_get_default(),
bgp, pi);
}
bgp_aggregate_decrement(bgp, bgp_dest_get_prefix(dest),
pi, afi, SAFI_UNICAST);
bgp_path_info_delete(dest, pi);
bgp_process(bgp, dest, afi, SAFI_UNICAST);
}
}
}
/* Static function to display route. */
static void route_vty_out_route(struct bgp_dest *dest, const struct prefix *p,
struct vty *vty, json_object *json, bool wide)
{
int len = 0;
char buf[BUFSIZ];
char buf2[BUFSIZ];
if (p->family == AF_INET) {
if (!json) {
len = vty_out(vty, "%pFX", p);
} else {
json_object_string_add(json, "prefix",
inet_ntop(p->family,
&p->u.prefix, buf,
BUFSIZ));
json_object_int_add(json, "prefixLen", p->prefixlen);
prefix2str(p, buf2, PREFIX_STRLEN);
json_object_string_add(json, "network", buf2);
json_object_int_add(json, "version", dest->version);
}
} else if (p->family == AF_ETHERNET) {
len = vty_out(vty, "%pFX", p);
} else if (p->family == AF_EVPN) {
if (!json)
len = vty_out(vty, "%pFX", (struct prefix_evpn *)p);
else
bgp_evpn_route2json((struct prefix_evpn *)p, json);
} else if (p->family == AF_FLOWSPEC) {
route_vty_out_flowspec(vty, p, NULL,
json ?
NLRI_STRING_FORMAT_JSON_SIMPLE :
NLRI_STRING_FORMAT_MIN, json);
} else {
if (!json)
len = vty_out(vty, "%pFX", p);
else {
json_object_string_add(json, "prefix",
inet_ntop(p->family,
&p->u.prefix, buf,
BUFSIZ));
json_object_int_add(json, "prefixLen", p->prefixlen);
prefix2str(p, buf2, PREFIX_STRLEN);
json_object_string_add(json, "network", buf2);
json_object_int_add(json, "version", dest->version);
}
}
if (!json) {
len = wide ? (45 - len) : (17 - len);
if (len < 1)
vty_out(vty, "\n%*s", 20, " ");
else
vty_out(vty, "%*s", len, " ");
}
}
enum bgp_display_type {
normal_list,
};
static const char *
bgp_path_selection_reason2str(enum bgp_path_selection_reason reason)
{
switch (reason) {
case bgp_path_selection_none:
return "Nothing to Select";
case bgp_path_selection_first:
return "First path received";
case bgp_path_selection_evpn_sticky_mac:
return "EVPN Sticky Mac";
case bgp_path_selection_evpn_seq:
return "EVPN sequence number";
case bgp_path_selection_evpn_lower_ip:
return "EVPN lower IP";
case bgp_path_selection_evpn_local_path:
return "EVPN local ES path";
case bgp_path_selection_evpn_non_proxy:
return "EVPN non proxy";
case bgp_path_selection_weight:
return "Weight";
case bgp_path_selection_local_pref:
return "Local Pref";
case bgp_path_selection_local_route:
return "Local Route";
case bgp_path_selection_confed_as_path:
return "Confederation based AS Path";
case bgp_path_selection_as_path:
return "AS Path";
case bgp_path_selection_origin:
return "Origin";
case bgp_path_selection_med:
return "MED";
case bgp_path_selection_peer:
return "Peer Type";
case bgp_path_selection_confed:
return "Confed Peer Type";
case bgp_path_selection_igp_metric:
return "IGP Metric";
case bgp_path_selection_older:
return "Older Path";
case bgp_path_selection_router_id:
return "Router ID";
case bgp_path_selection_cluster_length:
return "Cluster length";
case bgp_path_selection_stale:
return "Path Staleness";
case bgp_path_selection_local_configured:
return "Locally configured route";
case bgp_path_selection_neighbor_ip:
return "Neighbor IP";
case bgp_path_selection_default:
return "Nothing left to compare";
}
return "Invalid (internal error)";
}
/* Print the short form route status for a bgp_path_info */
static void route_vty_short_status_out(struct vty *vty,
struct bgp_path_info *path,
const struct prefix *p,
json_object *json_path)
{
enum rpki_states rpki_state = RPKI_NOT_BEING_USED;
if (json_path) {
/* Route status display. */
if (CHECK_FLAG(path->flags, BGP_PATH_REMOVED))
json_object_boolean_true_add(json_path, "removed");
if (CHECK_FLAG(path->flags, BGP_PATH_STALE))
json_object_boolean_true_add(json_path, "stale");
if (path->extra && bgp_path_suppressed(path))
json_object_boolean_true_add(json_path, "suppressed");
if (CHECK_FLAG(path->flags, BGP_PATH_VALID)
&& !CHECK_FLAG(path->flags, BGP_PATH_HISTORY))
json_object_boolean_true_add(json_path, "valid");
/* Selected */
if (CHECK_FLAG(path->flags, BGP_PATH_HISTORY))
json_object_boolean_true_add(json_path, "history");
if (CHECK_FLAG(path->flags, BGP_PATH_DAMPED))
json_object_boolean_true_add(json_path, "damped");
if (CHECK_FLAG(path->flags, BGP_PATH_SELECTED)) {
json_object_boolean_true_add(json_path, "bestpath");
json_object_string_add(json_path, "selectionReason",
bgp_path_selection_reason2str(
path->net->reason));
}
if (CHECK_FLAG(path->flags, BGP_PATH_MULTIPATH))
json_object_boolean_true_add(json_path, "multipath");
/* Internal route. */
if ((path->peer->as)
&& (path->peer->as == path->peer->local_as))
json_object_string_add(json_path, "pathFrom",
"internal");
else
json_object_string_add(json_path, "pathFrom",
"external");
return;
}
/* RPKI validation state */
rpki_state =
hook_call(bgp_rpki_prefix_status, path->peer, path->attr, p);
if (rpki_state == RPKI_VALID)
vty_out(vty, "V");
else if (rpki_state == RPKI_INVALID)
vty_out(vty, "I");
else if (rpki_state == RPKI_NOTFOUND)
vty_out(vty, "N");
/* Route status display. */
if (CHECK_FLAG(path->flags, BGP_PATH_REMOVED))
vty_out(vty, "R");
else if (CHECK_FLAG(path->flags, BGP_PATH_STALE))
vty_out(vty, "S");
else if (bgp_path_suppressed(path))
vty_out(vty, "s");
else if (CHECK_FLAG(path->flags, BGP_PATH_VALID)
&& !CHECK_FLAG(path->flags, BGP_PATH_HISTORY))
vty_out(vty, "*");
else
vty_out(vty, " ");
/* Selected */
if (CHECK_FLAG(path->flags, BGP_PATH_HISTORY))
vty_out(vty, "h");
else if (CHECK_FLAG(path->flags, BGP_PATH_DAMPED))
vty_out(vty, "d");
else if (CHECK_FLAG(path->flags, BGP_PATH_SELECTED))
vty_out(vty, ">");
else if (CHECK_FLAG(path->flags, BGP_PATH_MULTIPATH))
vty_out(vty, "=");
else
vty_out(vty, " ");
/* Internal route. */
if (path->peer && (path->peer->as)
&& (path->peer->as == path->peer->local_as))
vty_out(vty, "i");
else
vty_out(vty, " ");
}
static char *bgp_nexthop_hostname(struct peer *peer,
struct bgp_nexthop_cache *bnc)
{
if (peer->hostname
&& CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHOW_NEXTHOP_HOSTNAME))
return peer->hostname;
return NULL;
}
/* called from terminal list command */
void route_vty_out(struct vty *vty, const struct prefix *p,
struct bgp_path_info *path, int display, safi_t safi,
json_object *json_paths, bool wide)
{
int len;
struct attr *attr = path->attr;
json_object *json_path = NULL;
json_object *json_nexthops = NULL;
json_object *json_nexthop_global = NULL;
json_object *json_nexthop_ll = NULL;
json_object *json_ext_community = NULL;
char vrf_id_str[VRF_NAMSIZ] = {0};
bool nexthop_self =
CHECK_FLAG(path->flags, BGP_PATH_ANNC_NH_SELF) ? true : false;
bool nexthop_othervrf = false;
vrf_id_t nexthop_vrfid = VRF_DEFAULT;
const char *nexthop_vrfname = VRF_DEFAULT_NAME;
char *nexthop_hostname =
bgp_nexthop_hostname(path->peer, path->nexthop);
char esi_buf[ESI_STR_LEN];
if (json_paths)
json_path = json_object_new_object();
/* short status lead text */
route_vty_short_status_out(vty, path, p, json_path);
if (!json_paths) {
/* print prefix and mask */
if (!display)
route_vty_out_route(path->net, p, vty, json_path, wide);
else
vty_out(vty, "%*s", (wide ? 45 : 17), " ");
} else {
route_vty_out_route(path->net, p, vty, json_path, wide);
}
/*
* If vrf id of nexthop is different from that of prefix,
* set up printable string to append
*/
if (path->extra && path->extra->bgp_orig) {
const char *self = "";
if (nexthop_self)
self = "<";
nexthop_othervrf = true;
nexthop_vrfid = path->extra->bgp_orig->vrf_id;
if (path->extra->bgp_orig->vrf_id == VRF_UNKNOWN)
snprintf(vrf_id_str, sizeof(vrf_id_str),
"@%s%s", VRFID_NONE_STR, self);
else
snprintf(vrf_id_str, sizeof(vrf_id_str), "@%u%s",
path->extra->bgp_orig->vrf_id, self);
if (path->extra->bgp_orig->inst_type
!= BGP_INSTANCE_TYPE_DEFAULT)
nexthop_vrfname = path->extra->bgp_orig->name;
} else {
const char *self = "";
if (nexthop_self)
self = "<";
snprintf(vrf_id_str, sizeof(vrf_id_str), "%s", self);
}
/*
* For ENCAP and EVPN routes, nexthop address family is not
* neccessarily the same as the prefix address family.
* Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
* EVPN routes are also exchanged with a MP nexthop. Currently,
* this
* is only IPv4, the value will be present in either
* attr->nexthop or
* attr->mp_nexthop_global_in
*/
if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN)) {
char buf[BUFSIZ];
char nexthop[128];
int af = NEXTHOP_FAMILY(attr->mp_nexthop_len);
switch (af) {
case AF_INET:
snprintf(nexthop, sizeof(nexthop), "%s",
inet_ntop(af, &attr->mp_nexthop_global_in, buf,
BUFSIZ));
break;
case AF_INET6:
snprintf(nexthop, sizeof(nexthop), "%s",
inet_ntop(af, &attr->mp_nexthop_global, buf,
BUFSIZ));
break;
default:
snprintf(nexthop, sizeof(nexthop), "?");
break;
}
if (json_paths) {
json_nexthop_global = json_object_new_object();
json_object_string_add(json_nexthop_global, "ip",
nexthop);
if (path->peer->hostname)
json_object_string_add(json_nexthop_global,
"hostname",
path->peer->hostname);
json_object_string_add(json_nexthop_global, "afi",
(af == AF_INET) ? "ipv4"
: "ipv6");
json_object_boolean_true_add(json_nexthop_global,
"used");
} else {
if (nexthop_hostname)
len = vty_out(vty, "%s(%s)%s", nexthop,
nexthop_hostname, vrf_id_str);
else
len = vty_out(vty, "%s%s", nexthop, vrf_id_str);
len = wide ? (41 - len) : (16 - len);
if (len < 1)
vty_out(vty, "\n%*s", 36, " ");
else
vty_out(vty, "%*s", len, " ");
}
} else if (safi == SAFI_EVPN) {
if (json_paths) {
char buf[BUFSIZ] = {0};
json_nexthop_global = json_object_new_object();
json_object_string_add(json_nexthop_global, "ip",
inet_ntop(AF_INET,
&attr->nexthop, buf,
sizeof(buf)));
if (path->peer->hostname)
json_object_string_add(json_nexthop_global,
"hostname",
path->peer->hostname);
json_object_string_add(json_nexthop_global, "afi",
"ipv4");
json_object_boolean_true_add(json_nexthop_global,
"used");
} else {
if (nexthop_hostname)
len = vty_out(vty, "%pI4(%s)%s", &attr->nexthop,
nexthop_hostname, vrf_id_str);
else
len = vty_out(vty, "%pI4%s", &attr->nexthop,
vrf_id_str);
len = wide ? (41 - len) : (16 - len);
if (len < 1)
vty_out(vty, "\n%*s", 36, " ");
else
vty_out(vty, "%*s", len, " ");
}
} else if (safi == SAFI_FLOWSPEC) {
if (attr->nexthop.s_addr != INADDR_ANY) {
if (json_paths) {
char buf[BUFSIZ] = {0};
json_nexthop_global = json_object_new_object();
json_object_string_add(json_nexthop_global,
"afi", "ipv4");
json_object_string_add(
json_nexthop_global, "ip",
inet_ntop(AF_INET, &attr->nexthop, buf,
sizeof(buf)));
if (path->peer->hostname)
json_object_string_add(
json_nexthop_global, "hostname",
path->peer->hostname);
json_object_boolean_true_add(
json_nexthop_global,
"used");
} else {
if (nexthop_hostname)
len = vty_out(vty, "%pI4(%s)%s",
&attr->nexthop,
nexthop_hostname,
vrf_id_str);
else
len = vty_out(vty, "%pI4%s",
&attr->nexthop,
vrf_id_str);
len = wide ? (41 - len) : (16 - len);
if (len < 1)
vty_out(vty, "\n%*s", 36, " ");
else
vty_out(vty, "%*s", len, " ");
}
}
} else if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr)) {
if (json_paths) {
char buf[BUFSIZ] = {0};
json_nexthop_global = json_object_new_object();
json_object_string_add(json_nexthop_global, "ip",
inet_ntop(AF_INET,
&attr->nexthop, buf,
sizeof(buf)));
if (path->peer->hostname)
json_object_string_add(json_nexthop_global,
"hostname",
path->peer->hostname);
json_object_string_add(json_nexthop_global, "afi",
"ipv4");
json_object_boolean_true_add(json_nexthop_global,
"used");
} else {
if (nexthop_hostname)
len = vty_out(vty, "%pI4(%s)%s", &attr->nexthop,
nexthop_hostname, vrf_id_str);
else
len = vty_out(vty, "%pI4%s", &attr->nexthop,
vrf_id_str);
len = wide ? (41 - len) : (16 - len);
if (len < 1)
vty_out(vty, "\n%*s", 36, " ");
else
vty_out(vty, "%*s", len, " ");
}
}
/* IPv6 Next Hop */
else if (p->family == AF_INET6 || BGP_ATTR_NEXTHOP_AFI_IP6(attr)) {
char buf[BUFSIZ];
if (json_paths) {
json_nexthop_global = json_object_new_object();
json_object_string_add(
json_nexthop_global, "ip",
inet_ntop(AF_INET6, &attr->mp_nexthop_global,
buf, BUFSIZ));
if (path->peer->hostname)
json_object_string_add(json_nexthop_global,
"hostname",
path->peer->hostname);
json_object_string_add(json_nexthop_global, "afi",
"ipv6");
json_object_string_add(json_nexthop_global, "scope",
"global");
/* We display both LL & GL if both have been
* received */
if ((attr->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
|| (path->peer->conf_if)) {
json_nexthop_ll = json_object_new_object();
json_object_string_add(
json_nexthop_ll, "ip",
inet_ntop(AF_INET6,
&attr->mp_nexthop_local, buf,
BUFSIZ));
if (path->peer->hostname)
json_object_string_add(
json_nexthop_ll, "hostname",
path->peer->hostname);
json_object_string_add(json_nexthop_ll, "afi",
"ipv6");
json_object_string_add(json_nexthop_ll, "scope",
"link-local");
if ((IPV6_ADDR_CMP(&attr->mp_nexthop_global,
&attr->mp_nexthop_local)
!= 0)
&& !attr->mp_nexthop_prefer_global)
json_object_boolean_true_add(
json_nexthop_ll, "used");
else
json_object_boolean_true_add(
json_nexthop_global, "used");
} else
json_object_boolean_true_add(
json_nexthop_global, "used");
} else {
/* Display LL if LL/Global both in table unless
* prefer-global is set */
if (((attr->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
&& !attr->mp_nexthop_prefer_global)
|| (path->peer->conf_if)) {
if (path->peer->conf_if) {
len = vty_out(vty, "%s",
path->peer->conf_if);
/* len of IPv6 addr + max len of def
* ifname */
len = wide ? (41 - len) : (16 - len);
if (len < 1)
vty_out(vty, "\n%*s", 36, " ");
else
vty_out(vty, "%*s", len, " ");
} else {
if (nexthop_hostname)
len = vty_out(
vty, "%pI6(%s)%s",
&attr->mp_nexthop_local,
nexthop_hostname,
vrf_id_str);
else
len = vty_out(
vty, "%pI6%s",
&attr->mp_nexthop_local,
vrf_id_str);
len = wide ? (41 - len) : (16 - len);
if (len < 1)
vty_out(vty, "\n%*s", 36, " ");
else
vty_out(vty, "%*s", len, " ");
}
} else {
if (nexthop_hostname)
len = vty_out(vty, "%pI6(%s)%s",
&attr->mp_nexthop_global,
nexthop_hostname,
vrf_id_str);
else
len = vty_out(vty, "%pI6%s",
&attr->mp_nexthop_global,
vrf_id_str);
len = wide ? (41 - len) : (16 - len);
if (len < 1)
vty_out(vty, "\n%*s", 36, " ");
else
vty_out(vty, "%*s", len, " ");
}
}
}
/* MED/Metric */
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
if (json_paths)
json_object_int_add(json_path, "metric", attr->med);
else if (wide)
vty_out(vty, "%7u", attr->med);
else
vty_out(vty, "%10u", attr->med);
else if (!json_paths) {
if (wide)
vty_out(vty, "%*s", 7, " ");
else
vty_out(vty, "%*s", 10, " ");
}
/* Local Pref */
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
if (json_paths)
json_object_int_add(json_path, "locPrf",
attr->local_pref);
else
vty_out(vty, "%7u", attr->local_pref);
else if (!json_paths)
vty_out(vty, " ");
if (json_paths)
json_object_int_add(json_path, "weight", attr->weight);
else
vty_out(vty, "%7u ", attr->weight);
if (json_paths) {
char buf[BUFSIZ];
json_object_string_add(
json_path, "peerId",
sockunion2str(&path->peer->su, buf, SU_ADDRSTRLEN));
}
/* Print aspath */
if (attr->aspath) {
if (json_paths)
json_object_string_add(json_path, "path",
attr->aspath->str);
else
aspath_print_vty(vty, "%s", attr->aspath, " ");
}
/* Print origin */
if (json_paths)
json_object_string_add(json_path, "origin",
bgp_origin_long_str[attr->origin]);
else
vty_out(vty, "%s", bgp_origin_str[attr->origin]);
if (json_paths) {
if (bgp_evpn_is_esi_valid(&attr->esi)) {
json_object_string_add(json_path, "esi",
esi_to_str(&attr->esi,
esi_buf, sizeof(esi_buf)));
}
if (safi == SAFI_EVPN &&
attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)) {
json_ext_community = json_object_new_object();
json_object_string_add(json_ext_community,
"string",
attr->ecommunity->str);
json_object_object_add(json_path,
"extendedCommunity",
json_ext_community);
}
if (nexthop_self)
json_object_boolean_true_add(json_path,
"announceNexthopSelf");
if (nexthop_othervrf) {
json_object_string_add(json_path, "nhVrfName",
nexthop_vrfname);
json_object_int_add(json_path, "nhVrfId",
((nexthop_vrfid == VRF_UNKNOWN)
? -1
: (int)nexthop_vrfid));
}
}
if (json_paths) {
if (json_nexthop_global || json_nexthop_ll) {
json_nexthops = json_object_new_array();
if (json_nexthop_global)
json_object_array_add(json_nexthops,
json_nexthop_global);
if (json_nexthop_ll)
json_object_array_add(json_nexthops,
json_nexthop_ll);
json_object_object_add(json_path, "nexthops",
json_nexthops);
}
json_object_array_add(json_paths, json_path);
} else {
vty_out(vty, "\n");
if (safi == SAFI_EVPN) {
if (bgp_evpn_is_esi_valid(&attr->esi)) {
/* XXX - add these params to the json out */
vty_out(vty, "%*s", 20, " ");
vty_out(vty, "ESI:%s",
esi_to_str(&attr->esi, esi_buf,
sizeof(esi_buf)));
vty_out(vty, "\n");
}
if (attr->flag &
ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)) {
vty_out(vty, "%*s", 20, " ");
vty_out(vty, "%s\n", attr->ecommunity->str);
}
}
#ifdef ENABLE_BGP_VNC
/* prints an additional line, indented, with VNC info, if
* present */
if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
rfapi_vty_out_vncinfo(vty, p, path, safi);
#endif
}
}
/* called from terminal list command */
void route_vty_out_tmp(struct vty *vty, struct bgp_dest *dest,
const struct prefix *p, struct attr *attr, safi_t safi,
bool use_json, json_object *json_ar, bool wide)
{
json_object *json_status = NULL;
json_object *json_net = NULL;
int len;
char buff[BUFSIZ];
/* Route status display. */
if (use_json) {
json_status = json_object_new_object();
json_net = json_object_new_object();
} else {
vty_out(vty, "*");
vty_out(vty, ">");
vty_out(vty, " ");
}
/* print prefix and mask */
if (use_json) {
if (safi == SAFI_EVPN)
bgp_evpn_route2json((struct prefix_evpn *)p, json_net);
else if (p->family == AF_INET || p->family == AF_INET6) {
json_object_string_add(
json_net, "addrPrefix",
inet_ntop(p->family, &p->u.prefix, buff,
BUFSIZ));
json_object_int_add(json_net, "prefixLen",
p->prefixlen);
prefix2str(p, buff, PREFIX_STRLEN);
json_object_string_add(json_net, "network", buff);
}
} else
route_vty_out_route(dest, p, vty, NULL, wide);
/* Print attribute */
if (attr) {
if (use_json) {
char buf[BUFSIZ] = {0};
if (p->family == AF_INET
&& (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP
|| !BGP_ATTR_NEXTHOP_AFI_IP6(attr))) {
if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
json_object_string_add(
json_net, "nextHop",
inet_ntop(
AF_INET,
&attr->mp_nexthop_global_in,
buf, sizeof(buf)));
else
json_object_string_add(
json_net, "nextHop",
inet_ntop(AF_INET,
&attr->nexthop, buf,
sizeof(buf)));
} else if (p->family == AF_INET6
|| BGP_ATTR_NEXTHOP_AFI_IP6(attr)) {
char buf[BUFSIZ];
json_object_string_add(
json_net, "nextHopGlobal",
inet_ntop(AF_INET6,
&attr->mp_nexthop_global, buf,
BUFSIZ));
} else if (p->family == AF_EVPN
&& !BGP_ATTR_NEXTHOP_AFI_IP6(attr)) {
char buf[BUFSIZ] = {0};
json_object_string_add(
json_net, "nextHop",
inet_ntop(AF_INET,
&attr->mp_nexthop_global_in,
buf, sizeof(buf)));
}
if (attr->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
json_object_int_add(json_net, "metric",
attr->med);
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
json_object_int_add(json_net, "locPrf",
attr->local_pref);
json_object_int_add(json_net, "weight", attr->weight);
/* Print aspath */
if (attr->aspath)
json_object_string_add(json_net, "path",
attr->aspath->str);
/* Print origin */
json_object_string_add(json_net, "bgpOriginCode",
bgp_origin_str[attr->origin]);
} else {
if (p->family == AF_INET
&& (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP
|| safi == SAFI_EVPN
|| !BGP_ATTR_NEXTHOP_AFI_IP6(attr))) {
if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP
|| safi == SAFI_EVPN)
vty_out(vty, "%-16pI4",
&attr->mp_nexthop_global_in);
else if (wide)
vty_out(vty, "%-41pI4", &attr->nexthop);
else
vty_out(vty, "%-16pI4", &attr->nexthop);
} else if (p->family == AF_INET6
|| BGP_ATTR_NEXTHOP_AFI_IP6(attr)) {
char buf[BUFSIZ];
len = vty_out(
vty, "%s",
inet_ntop(AF_INET6,
&attr->mp_nexthop_global, buf,
BUFSIZ));
len = wide ? (41 - len) : (16 - len);
if (len < 1)
vty_out(vty, "\n%*s", 36, " ");
else
vty_out(vty, "%*s", len, " ");
}
if (attr->flag
& ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
if (wide)
vty_out(vty, "%7u", attr->med);
else
vty_out(vty, "%10u", attr->med);
else if (wide)
vty_out(vty, " ");
else
vty_out(vty, " ");
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
vty_out(vty, "%7u", attr->local_pref);
else
vty_out(vty, " ");
vty_out(vty, "%7u ", attr->weight);
/* Print aspath */
if (attr->aspath)
aspath_print_vty(vty, "%s", attr->aspath, " ");
/* Print origin */
vty_out(vty, "%s", bgp_origin_str[attr->origin]);
}
}
if (use_json) {
json_object_boolean_true_add(json_status, "*");
json_object_boolean_true_add(json_status, ">");
json_object_object_add(json_net, "appliedStatusSymbols",
json_status);
prefix2str(p, buff, PREFIX_STRLEN);
json_object_object_add(json_ar, buff, json_net);
} else
vty_out(vty, "\n");
}
void route_vty_out_tag(struct vty *vty, const struct prefix *p,
struct bgp_path_info *path, int display, safi_t safi,
json_object *json)
{
json_object *json_out = NULL;
struct attr *attr;
mpls_label_t label = MPLS_INVALID_LABEL;
if (!path->extra)
return;
if (json)
json_out = json_object_new_object();
/* short status lead text */
route_vty_short_status_out(vty, path, p, json_out);
/* print prefix and mask */
if (json == NULL) {
if (!display)
route_vty_out_route(path->net, p, vty, NULL, false);
else
vty_out(vty, "%*s", 17, " ");
}
/* Print attribute */
attr = path->attr;
if (((p->family == AF_INET)
&& ((safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)))
|| (safi == SAFI_EVPN && !BGP_ATTR_NEXTHOP_AFI_IP6(attr))
|| (!BGP_ATTR_NEXTHOP_AFI_IP6(attr))) {
char buf[BUFSIZ] = {0};
if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP
|| safi == SAFI_EVPN) {
if (json)
json_object_string_add(
json_out, "mpNexthopGlobalIn",
inet_ntop(AF_INET,
&attr->mp_nexthop_global_in,
buf, sizeof(buf)));
else
vty_out(vty, "%-16pI4",
&attr->mp_nexthop_global_in);
} else {
if (json)
json_object_string_add(
json_out, "nexthop",
inet_ntop(AF_INET, &attr->nexthop, buf,
sizeof(buf)));
else
vty_out(vty, "%-16pI4", &attr->nexthop);
}
} else if (((p->family == AF_INET6)
&& ((safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)))
|| (safi == SAFI_EVPN && BGP_ATTR_NEXTHOP_AFI_IP6(attr))
|| (BGP_ATTR_NEXTHOP_AFI_IP6(attr))) {
char buf_a[512];
if (attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL) {
if (json)
json_object_string_add(
json_out, "mpNexthopGlobalIn",
inet_ntop(AF_INET6,
&attr->mp_nexthop_global,
buf_a, sizeof(buf_a)));
else
vty_out(vty, "%s",
inet_ntop(AF_INET6,
&attr->mp_nexthop_global,
buf_a, sizeof(buf_a)));
} else if (attr->mp_nexthop_len
== BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) {
snprintfrr(buf_a, sizeof(buf_a), "%pI6(%pI6)",
&attr->mp_nexthop_global,
&attr->mp_nexthop_local);
if (json)
json_object_string_add(json_out,
"mpNexthopGlobalLocal",
buf_a);
else
vty_out(vty, "%s", buf_a);
}
}
label = decode_label(&path->extra->label[0]);
if (bgp_is_valid_label(&label)) {
if (json) {
json_object_int_add(json_out, "notag", label);
json_object_array_add(json, json_out);
} else {
vty_out(vty, "notag/%d", label);
vty_out(vty, "\n");
}
} else if (!json)
vty_out(vty, "\n");
}
void route_vty_out_overlay(struct vty *vty, const struct prefix *p,
struct bgp_path_info *path, int display,
json_object *json_paths)
{
struct attr *attr;
char buf[BUFSIZ] = {0};
json_object *json_path = NULL;
json_object *json_nexthop = NULL;
json_object *json_overlay = NULL;
if (!path->extra)
return;
if (json_paths) {
json_path = json_object_new_object();
json_overlay = json_object_new_object();
json_nexthop = json_object_new_object();
}
/* short status lead text */
route_vty_short_status_out(vty, path, p, json_path);
/* print prefix and mask */
if (!display)
route_vty_out_route(path->net, p, vty, json_path, false);
else
vty_out(vty, "%*s", 17, " ");
/* Print attribute */
attr = path->attr;
char buf1[BUFSIZ];
int af = NEXTHOP_FAMILY(attr->mp_nexthop_len);
switch (af) {
case AF_INET:
inet_ntop(af, &attr->mp_nexthop_global_in, buf, BUFSIZ);
if (!json_path) {
vty_out(vty, "%-16s", buf);
} else {
json_object_string_add(json_nexthop, "ip", buf);
json_object_string_add(json_nexthop, "afi", "ipv4");
json_object_object_add(json_path, "nexthop",
json_nexthop);
}
break;
case AF_INET6:
inet_ntop(af, &attr->mp_nexthop_global, buf, BUFSIZ);
inet_ntop(af, &attr->mp_nexthop_local, buf1, BUFSIZ);
if (!json_path) {
vty_out(vty, "%s(%s)", buf, buf1);
} else {
json_object_string_add(json_nexthop, "ipv6Global", buf);
json_object_string_add(json_nexthop, "ipv6LinkLocal",
buf1);
json_object_string_add(json_nexthop, "afi", "ipv6");
json_object_object_add(json_path, "nexthop",
json_nexthop);
}
break;
default:
if (!json_path) {
vty_out(vty, "?");
} else {
json_object_string_add(json_nexthop, "Error",
"Unsupported address-family");
}
}
const struct bgp_route_evpn *eo = bgp_attr_get_evpn_overlay(attr);
if (is_evpn_prefix_ipaddr_v4((struct prefix_evpn *)p))
inet_ntop(AF_INET, &eo->gw_ip.ipv4, buf, BUFSIZ);
else if (is_evpn_prefix_ipaddr_v6((struct prefix_evpn *)p))
inet_ntop(AF_INET6, &eo->gw_ip.ipv6, buf, BUFSIZ);
if (!json_path)
vty_out(vty, "/%s", buf);
else
json_object_string_add(json_overlay, "gw", buf);
if (attr->ecommunity) {
char *mac = NULL;
struct ecommunity_val *routermac = ecommunity_lookup(
attr->ecommunity, ECOMMUNITY_ENCODE_EVPN,
ECOMMUNITY_EVPN_SUBTYPE_ROUTERMAC);
if (routermac)
mac = ecom_mac2str((char *)routermac->val);
if (mac) {
if (!json_path) {
vty_out(vty, "/%s", mac);
} else {
json_object_string_add(json_overlay, "rmac",
mac);
}
XFREE(MTYPE_TMP, mac);
}
}
if (!json_path) {
vty_out(vty, "\n");
} else {
json_object_object_add(json_path, "overlay", json_overlay);
json_object_array_add(json_paths, json_path);
}
}
/* dampening route */
static void damp_route_vty_out(struct vty *vty, const struct prefix *p,
struct bgp_path_info *path, int display,
afi_t afi, safi_t safi, bool use_json,
json_object *json_paths)
{
struct attr *attr = path->attr;
int len;
char timebuf[BGP_UPTIME_LEN];
json_object *json_path = NULL;
if (use_json)
json_path = json_object_new_object();
/* short status lead text */
route_vty_short_status_out(vty, path, p, json_path);
/* print prefix and mask */
if (!use_json) {
if (!display)
route_vty_out_route(path->net, p, vty, NULL, false);
else
vty_out(vty, "%*s", 17, " ");
len = vty_out(vty, "%s", path->peer->host);
len = 17 - len;
if (len < 1)
vty_out(vty, "\n%*s", 34, " ");
else
vty_out(vty, "%*s", len, " ");
vty_out(vty, "%s ",
bgp_damp_reuse_time_vty(vty, path, timebuf,
BGP_UPTIME_LEN, afi, safi,
use_json, NULL));
if (attr->aspath)
aspath_print_vty(vty, "%s", attr->aspath, " ");
vty_out(vty, "%s", bgp_origin_str[attr->origin]);
vty_out(vty, "\n");
} else {
bgp_damp_reuse_time_vty(vty, path, timebuf, BGP_UPTIME_LEN, afi,
safi, use_json, json_path);
if (attr->aspath)
json_object_string_add(json_path, "asPath",
attr->aspath->str);
json_object_string_add(json_path, "origin",
bgp_origin_str[attr->origin]);
json_object_string_add(json_path, "peerHost", path->peer->host);
json_object_array_add(json_paths, json_path);
}
}
/* flap route */
static void flap_route_vty_out(struct vty *vty, const struct prefix *p,
struct bgp_path_info *path, int display,
afi_t afi, safi_t safi, bool use_json,
json_object *json_paths)
{
struct attr *attr = path->attr;
struct bgp_damp_info *bdi;
char timebuf[BGP_UPTIME_LEN];
int len;
json_object *json_path = NULL;
if (!path->extra)
return;
if (use_json)
json_path = json_object_new_object();
bdi = path->extra->damp_info;
/* short status lead text */
route_vty_short_status_out(vty, path, p, json_path);
if (!use_json) {
if (!display)
route_vty_out_route(path->net, p, vty, NULL, false);
else
vty_out(vty, "%*s", 17, " ");
len = vty_out(vty, "%s", path->peer->host);
len = 16 - len;
if (len < 1)
vty_out(vty, "\n%*s", 33, " ");
else
vty_out(vty, "%*s", len, " ");
len = vty_out(vty, "%d", bdi->flap);
len = 5 - len;
if (len < 1)
vty_out(vty, " ");
else
vty_out(vty, "%*s", len, " ");
vty_out(vty, "%s ", peer_uptime(bdi->start_time, timebuf,
BGP_UPTIME_LEN, 0, NULL));
if (CHECK_FLAG(path->flags, BGP_PATH_DAMPED)
&& !CHECK_FLAG(path->flags, BGP_PATH_HISTORY))
vty_out(vty, "%s ",
bgp_damp_reuse_time_vty(vty, path, timebuf,
BGP_UPTIME_LEN, afi,
safi, use_json, NULL));
else
vty_out(vty, "%*s ", 8, " ");
if (attr->aspath)
aspath_print_vty(vty, "%s", attr->aspath, " ");
vty_out(vty, "%s", bgp_origin_str[attr->origin]);
vty_out(vty, "\n");
} else {
json_object_string_add(json_path, "peerHost", path->peer->host);
json_object_int_add(json_path, "bdiFlap", bdi->flap);
peer_uptime(bdi->start_time, timebuf, BGP_UPTIME_LEN, use_json,
json_path);
if (CHECK_FLAG(path->flags, BGP_PATH_DAMPED)
&& !CHECK_FLAG(path->flags, BGP_PATH_HISTORY))
bgp_damp_reuse_time_vty(vty, path, timebuf,
BGP_UPTIME_LEN, afi, safi,
use_json, json_path);
if (attr->aspath)
json_object_string_add(json_path, "asPath",
attr->aspath->str);
json_object_string_add(json_path, "origin",
bgp_origin_str[attr->origin]);
json_object_array_add(json_paths, json_path);
}
}
static void route_vty_out_advertised_to(struct vty *vty, struct peer *peer,
int *first, const char *header,
json_object *json_adv_to)
{
char buf1[INET6_ADDRSTRLEN];
json_object *json_peer = NULL;
if (json_adv_to) {
/* 'advertised-to' is a dictionary of peers we have advertised
* this
* prefix too. The key is the peer's IP or swpX, the value is
* the
* hostname if we know it and "" if not.
*/
json_peer = json_object_new_object();
if (peer->hostname)
json_object_string_add(json_peer, "hostname",
peer->hostname);
if (peer->conf_if)
json_object_object_add(json_adv_to, peer->conf_if,
json_peer);
else
json_object_object_add(
json_adv_to,
sockunion2str(&peer->su, buf1, SU_ADDRSTRLEN),
json_peer);
} else {
if (*first) {
vty_out(vty, "%s", header);
*first = 0;
}
if (peer->hostname
&& CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHOW_HOSTNAME)) {
if (peer->conf_if)
vty_out(vty, " %s(%s)", peer->hostname,
peer->conf_if);
else
vty_out(vty, " %s(%s)", peer->hostname,
sockunion2str(&peer->su, buf1,
SU_ADDRSTRLEN));
} else {
if (peer->conf_if)
vty_out(vty, " %s", peer->conf_if);
else
vty_out(vty, " %s",
sockunion2str(&peer->su, buf1,
SU_ADDRSTRLEN));
}
}
}
static void route_vty_out_tx_ids(struct vty *vty,
struct bgp_addpath_info_data *d)
{
int i;
for (i = 0; i < BGP_ADDPATH_MAX; i++) {
vty_out(vty, "TX-%s %u%s", bgp_addpath_names(i)->human_name,
d->addpath_tx_id[i],
i < BGP_ADDPATH_MAX - 1 ? " " : "\n");
}
}
static void route_vty_out_detail_es_info(struct vty *vty,
struct bgp_path_info *pi,
struct attr *attr,
json_object *json_path)
{
char esi_buf[ESI_STR_LEN];
bool es_local = !!CHECK_FLAG(attr->es_flags, ATTR_ES_IS_LOCAL);
bool peer_router = !!CHECK_FLAG(attr->es_flags,
ATTR_ES_PEER_ROUTER);
bool peer_active = !!CHECK_FLAG(attr->es_flags,
ATTR_ES_PEER_ACTIVE);
bool peer_proxy = !!CHECK_FLAG(attr->es_flags,
ATTR_ES_PEER_PROXY);
esi_to_str(&attr->esi, esi_buf, sizeof(esi_buf));
if (json_path) {
json_object *json_es_info = NULL;
json_object_string_add(
json_path, "esi",
esi_buf);
if (es_local || bgp_evpn_attr_is_sync(attr)) {
json_es_info = json_object_new_object();
if (es_local)
json_object_boolean_true_add(
json_es_info, "localEs");
if (peer_active)
json_object_boolean_true_add(
json_es_info, "peerActive");
if (peer_proxy)
json_object_boolean_true_add(
json_es_info, "peerProxy");
if (peer_router)
json_object_boolean_true_add(
json_es_info, "peerRouter");
if (attr->mm_sync_seqnum)
json_object_int_add(
json_es_info, "peerSeq",
attr->mm_sync_seqnum);
json_object_object_add(
json_path, "es_info",
json_es_info);
}
} else {
if (bgp_evpn_attr_is_sync(attr))
vty_out(vty,
" ESI %s %s peer-info: (%s%s%sMM: %d)\n",
esi_buf,
es_local ? "local-es":"",
peer_proxy ? "proxy " : "",
peer_active ? "active ":"",
peer_router ? "router ":"",
attr->mm_sync_seqnum);
else
vty_out(vty, " ESI %s %s\n",
esi_buf,
es_local ? "local-es":"");
}
}
void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
struct bgp_path_info *path, afi_t afi, safi_t safi,
enum rpki_states rpki_curr_state,
json_object *json_paths)
{
char buf[INET6_ADDRSTRLEN];
char buf1[BUFSIZ];
struct attr *attr = path->attr;
int sockunion_vty_out(struct vty *, union sockunion *);
time_t tbuf;
json_object *json_bestpath = NULL;
json_object *json_cluster_list = NULL;
json_object *json_cluster_list_list = NULL;
json_object *json_ext_community = NULL;
json_object *json_last_update = NULL;
json_object *json_pmsi = NULL;
json_object *json_nexthop_global = NULL;
json_object *json_nexthop_ll = NULL;
json_object *json_nexthops = NULL;
json_object *json_path = NULL;
json_object *json_peer = NULL;
json_object *json_string = NULL;
json_object *json_adv_to = NULL;
int first = 0;
struct listnode *node, *nnode;
struct peer *peer;
int addpath_capable;
int has_adj;
unsigned int first_as;
bool nexthop_self =
CHECK_FLAG(path->flags, BGP_PATH_ANNC_NH_SELF) ? true : false;
int i;
char *nexthop_hostname =
bgp_nexthop_hostname(path->peer, path->nexthop);
if (json_paths) {
json_path = json_object_new_object();
json_peer = json_object_new_object();
json_nexthop_global = json_object_new_object();
}
if (safi == SAFI_EVPN) {
if (!json_paths)
vty_out(vty, " Route %pRN", bn);
}
if (path->extra) {
char tag_buf[30];
tag_buf[0] = '\0';
if (path->extra && path->extra->num_labels) {
bgp_evpn_label2str(path->extra->label,
path->extra->num_labels, tag_buf,
sizeof(tag_buf));
}
if (safi == SAFI_EVPN) {
if (!json_paths) {
if (tag_buf[0] != '\0')
vty_out(vty, " VNI %s", tag_buf);
} else {
if (tag_buf[0])
json_object_string_add(json_path, "VNI",
tag_buf);
}
}
if (path->extra && path->extra->parent && !json_paths) {
struct bgp_path_info *parent_ri;
struct bgp_dest *dest, *pdest;
parent_ri = (struct bgp_path_info *)path->extra->parent;
dest = parent_ri->net;
if (dest && dest->pdest) {
pdest = dest->pdest;
prefix_rd2str(
(struct prefix_rd *)bgp_dest_get_prefix(
pdest),
buf1, sizeof(buf1));
if (is_pi_family_evpn(parent_ri)) {
vty_out(vty,
" Imported from %s:%pFX, VNI %s",
buf1,
(struct prefix_evpn *)
bgp_dest_get_prefix(
dest),
tag_buf);
if (attr->es_flags & ATTR_ES_L3_NHG)
vty_out(vty, ", L3NHG %s",
(attr->es_flags
& ATTR_ES_L3_NHG_ACTIVE)
? "active"
: "inactive");
vty_out(vty, "\n");
} else
vty_out(vty,
" Imported from %s:%pFX\n",
buf1,
(struct prefix_evpn *)
bgp_dest_get_prefix(
dest));
}
}
}
if (safi == SAFI_EVPN
&& attr->evpn_overlay.type == OVERLAY_INDEX_GATEWAY_IP) {
char gwip_buf[INET6_ADDRSTRLEN];
if (is_evpn_prefix_ipaddr_v4((struct prefix_evpn *)&bn->p))
inet_ntop(AF_INET, &attr->evpn_overlay.gw_ip.ipv4,
gwip_buf, sizeof(gwip_buf));
else
inet_ntop(AF_INET6, &attr->evpn_overlay.gw_ip.ipv6,
gwip_buf, sizeof(gwip_buf));
if (json_paths)
json_object_string_add(json_path, "gatewayIP",
gwip_buf);
else
vty_out(vty, " Gateway IP %s", gwip_buf);
}
if (safi == SAFI_EVPN)
vty_out(vty, "\n");
/* Line1 display AS-path, Aggregator */
if (attr->aspath) {
if (json_paths) {
if (!attr->aspath->json)
aspath_str_update(attr->aspath, true);
json_object_lock(attr->aspath->json);
json_object_object_add(json_path, "aspath",
attr->aspath->json);
} else {
if (attr->aspath->segments)
aspath_print_vty(vty, " %s", attr->aspath, "");
else
vty_out(vty, " Local");
}
}
if (CHECK_FLAG(path->flags, BGP_PATH_REMOVED)) {
if (json_paths)
json_object_boolean_true_add(json_path, "removed");
else
vty_out(vty, ", (removed)");
}
if (CHECK_FLAG(path->flags, BGP_PATH_STALE)) {
if (json_paths)
json_object_boolean_true_add(json_path, "stale");
else
vty_out(vty, ", (stale)");
}
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR))) {
if (json_paths) {
char buf[BUFSIZ] = {0};
json_object_int_add(json_path, "aggregatorAs",
attr->aggregator_as);
json_object_string_add(json_path, "aggregatorId",
inet_ntop(AF_INET,
&attr->aggregator_addr,
buf, sizeof(buf)));
} else {
vty_out(vty, ", (aggregated by %u %pI4)",
attr->aggregator_as, &attr->aggregator_addr);
}
}
if (CHECK_FLAG(path->peer->af_flags[afi][safi],
PEER_FLAG_REFLECTOR_CLIENT)) {
if (json_paths)
json_object_boolean_true_add(json_path,
"rxedFromRrClient");
else
vty_out(vty, ", (Received from a RR-client)");
}
if (CHECK_FLAG(path->peer->af_flags[afi][safi],
PEER_FLAG_RSERVER_CLIENT)) {
if (json_paths)
json_object_boolean_true_add(json_path,
"rxedFromRsClient");
else
vty_out(vty, ", (Received from a RS-client)");
}
if (CHECK_FLAG(path->flags, BGP_PATH_HISTORY)) {
if (json_paths)
json_object_boolean_true_add(json_path,
"dampeningHistoryEntry");
else
vty_out(vty, ", (history entry)");
} else if (CHECK_FLAG(path->flags, BGP_PATH_DAMPED)) {
if (json_paths)
json_object_boolean_true_add(json_path,
"dampeningSuppressed");
else
vty_out(vty, ", (suppressed due to dampening)");
}
if (!json_paths)
vty_out(vty, "\n");
/* Line2 display Next-hop, Neighbor, Router-id */
/* Display the nexthop */
const struct prefix *bn_p = bgp_dest_get_prefix(bn);
if ((bn_p->family == AF_INET || bn_p->family == AF_ETHERNET
|| bn_p->family == AF_EVPN)
&& (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP || safi == SAFI_EVPN
|| !BGP_ATTR_NEXTHOP_AFI_IP6(attr))) {
char buf[BUFSIZ] = {0};
if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP
|| safi == SAFI_EVPN) {
if (json_paths) {
json_object_string_add(
json_nexthop_global, "ip",
inet_ntop(AF_INET,
&attr->mp_nexthop_global_in,
buf, sizeof(buf)));
if (path->peer->hostname)
json_object_string_add(
json_nexthop_global, "hostname",
path->peer->hostname);
} else {
if (nexthop_hostname)
vty_out(vty, " %pI4(%s)",
&attr->mp_nexthop_global_in,
nexthop_hostname);
else
vty_out(vty, " %pI4",
&attr->mp_nexthop_global_in);
}
} else {
if (json_paths) {
json_object_string_add(
json_nexthop_global, "ip",
inet_ntop(AF_INET, &attr->nexthop, buf,
sizeof(buf)));
if (path->peer->hostname)
json_object_string_add(
json_nexthop_global, "hostname",
path->peer->hostname);
} else {
if (nexthop_hostname)
vty_out(vty, " %pI4(%s)",
&attr->nexthop,
nexthop_hostname);
else
vty_out(vty, " %pI4",
&attr->nexthop);
}
}
if (json_paths)
json_object_string_add(json_nexthop_global, "afi",
"ipv4");
} else {
if (json_paths) {
json_object_string_add(
json_nexthop_global, "ip",
inet_ntop(AF_INET6, &attr->mp_nexthop_global,
buf, INET6_ADDRSTRLEN));
if (path->peer->hostname)
json_object_string_add(json_nexthop_global,
"hostname",
path->peer->hostname);
json_object_string_add(json_nexthop_global, "afi",
"ipv6");
json_object_string_add(json_nexthop_global, "scope",
"global");
} else {
if (nexthop_hostname)
vty_out(vty, " %pI6(%s)",
&attr->mp_nexthop_global,
nexthop_hostname);
else
vty_out(vty, " %pI6",
&attr->mp_nexthop_global);
}
}
/* Display the IGP cost or 'inaccessible' */
if (!CHECK_FLAG(path->flags, BGP_PATH_VALID)) {
if (json_paths)
json_object_boolean_false_add(json_nexthop_global,
"accessible");
else
vty_out(vty, " (inaccessible)");
} else {
if (path->extra && path->extra->igpmetric) {
if (json_paths)
json_object_int_add(json_nexthop_global,
"metric",
path->extra->igpmetric);
else
vty_out(vty, " (metric %u)",
path->extra->igpmetric);
}
/* IGP cost is 0, display this only for json */
else {
if (json_paths)
json_object_int_add(json_nexthop_global,
"metric", 0);
}
if (json_paths)
json_object_boolean_true_add(json_nexthop_global,
"accessible");
}
/* Display peer "from" output */
/* This path was originated locally */
if (path->peer == bgp->peer_self) {
if (safi == SAFI_EVPN
|| (bn_p->family == AF_INET
&& !BGP_ATTR_NEXTHOP_AFI_IP6(attr))) {
if (json_paths)
json_object_string_add(json_peer, "peerId",
"0.0.0.0");
else
vty_out(vty, " from 0.0.0.0 ");
} else {
if (json_paths)
json_object_string_add(json_peer, "peerId",
"::");
else
vty_out(vty, " from :: ");
}
if (json_paths) {
char buf[BUFSIZ] = {0};
json_object_string_add(json_peer, "routerId",
inet_ntop(AF_INET,
&bgp->router_id, buf,
sizeof(buf)));
} else {
vty_out(vty, "(%pI4)", &bgp->router_id);
}
}
/* We RXed this path from one of our peers */
else {
if (json_paths) {
json_object_string_add(json_peer, "peerId",
sockunion2str(&path->peer->su,
buf,
SU_ADDRSTRLEN));
json_object_string_add(json_peer, "routerId",
inet_ntop(AF_INET,
&path->peer->remote_id,
buf1, sizeof(buf1)));
if (path->peer->hostname)
json_object_string_add(json_peer, "hostname",
path->peer->hostname);
if (path->peer->domainname)
json_object_string_add(json_peer, "domainname",
path->peer->domainname);
if (path->peer->conf_if)
json_object_string_add(json_peer, "interface",
path->peer->conf_if);
} else {
if (path->peer->conf_if) {
if (path->peer->hostname
&& CHECK_FLAG(path->peer->bgp->flags,
BGP_FLAG_SHOW_HOSTNAME))
vty_out(vty, " from %s(%s)",
path->peer->hostname,
path->peer->conf_if);
else
vty_out(vty, " from %s",
path->peer->conf_if);
} else {
if (path->peer->hostname
&& CHECK_FLAG(path->peer->bgp->flags,
BGP_FLAG_SHOW_HOSTNAME))
vty_out(vty, " from %s(%s)",
path->peer->hostname,
path->peer->host);
else
vty_out(vty, " from %s",
sockunion2str(&path->peer->su,
buf,
SU_ADDRSTRLEN));
}
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
vty_out(vty, " (%pI4)", &attr->originator_id);
else
vty_out(vty, " (%s)",
inet_ntop(AF_INET,
&path->peer->remote_id, buf1,
sizeof(buf1)));
}
}
/*
* Note when vrfid of nexthop is different from that of prefix
*/
if (path->extra && path->extra->bgp_orig) {
vrf_id_t nexthop_vrfid = path->extra->bgp_orig->vrf_id;
if (json_paths) {
const char *vn;
if (path->extra->bgp_orig->inst_type
== BGP_INSTANCE_TYPE_DEFAULT)
vn = VRF_DEFAULT_NAME;
else
vn = path->extra->bgp_orig->name;
json_object_string_add(json_path, "nhVrfName", vn);
if (nexthop_vrfid == VRF_UNKNOWN) {
json_object_int_add(json_path, "nhVrfId", -1);
} else {
json_object_int_add(json_path, "nhVrfId",
(int)nexthop_vrfid);
}
} else {
if (nexthop_vrfid == VRF_UNKNOWN)
vty_out(vty, " vrf ?");
else {
struct vrf *vrf;
vrf = vrf_lookup_by_id(nexthop_vrfid);
vty_out(vty, " vrf %s(%u)",
VRF_LOGNAME(vrf), nexthop_vrfid);
}
}
}
if (nexthop_self) {
if (json_paths) {
json_object_boolean_true_add(json_path,
"announceNexthopSelf");
} else {
vty_out(vty, " announce-nh-self");
}
}
if (!json_paths)
vty_out(vty, "\n");
/* display the link-local nexthop */
if (attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) {
if (json_paths) {
json_nexthop_ll = json_object_new_object();
json_object_string_add(
json_nexthop_ll, "ip",
inet_ntop(AF_INET6, &attr->mp_nexthop_local,
buf, INET6_ADDRSTRLEN));
if (path->peer->hostname)
json_object_string_add(json_nexthop_ll,
"hostname",
path->peer->hostname);
json_object_string_add(json_nexthop_ll, "afi", "ipv6");
json_object_string_add(json_nexthop_ll, "scope",
"link-local");
json_object_boolean_true_add(json_nexthop_ll,
"accessible");
if (!attr->mp_nexthop_prefer_global)
json_object_boolean_true_add(json_nexthop_ll,
"used");
else
json_object_boolean_true_add(
json_nexthop_global, "used");
} else {
vty_out(vty, " (%s) %s\n",
inet_ntop(AF_INET6, &attr->mp_nexthop_local,
buf, INET6_ADDRSTRLEN),
attr->mp_nexthop_prefer_global
? "(prefer-global)"
: "(used)");
}
}
/* If we do not have a link-local nexthop then we must flag the
global as "used" */
else {
if (json_paths)
json_object_boolean_true_add(json_nexthop_global,
"used");
}
if (safi == SAFI_EVPN &&
bgp_evpn_is_esi_valid(&attr->esi)) {
route_vty_out_detail_es_info(vty, path, attr, json_path);
}
/* Line 3 display Origin, Med, Locpref, Weight, Tag, valid,
* Int/Ext/Local, Atomic, best */
if (json_paths)
json_object_string_add(json_path, "origin",
bgp_origin_long_str[attr->origin]);
else
vty_out(vty, " Origin %s",
bgp_origin_long_str[attr->origin]);
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC)) {
if (json_paths)
json_object_int_add(json_path, "metric", attr->med);
else
vty_out(vty, ", metric %u", attr->med);
}
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)) {
if (json_paths)
json_object_int_add(json_path, "locPrf",
attr->local_pref);
else
vty_out(vty, ", localpref %u", attr->local_pref);
}
if (attr->weight != 0) {
if (json_paths)
json_object_int_add(json_path, "weight", attr->weight);
else
vty_out(vty, ", weight %u", attr->weight);
}
if (attr->tag != 0) {
if (json_paths)
json_object_int_add(json_path, "tag", attr->tag);
else
vty_out(vty, ", tag %" ROUTE_TAG_PRI, attr->tag);
}
if (!CHECK_FLAG(path->flags, BGP_PATH_VALID)) {
if (json_paths)
json_object_boolean_false_add(json_path, "valid");
else
vty_out(vty, ", invalid");
} else if (!CHECK_FLAG(path->flags, BGP_PATH_HISTORY)) {
if (json_paths)
json_object_boolean_true_add(json_path, "valid");
else
vty_out(vty, ", valid");
}
if (json_paths)
json_object_int_add(json_path, "version", bn->version);
if (path->peer != bgp->peer_self) {
if (path->peer->as == path->peer->local_as) {
if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)) {
if (json_paths)
json_object_string_add(
json_peer, "type",
"confed-internal");
else
vty_out(vty, ", confed-internal");
} else {
if (json_paths)
json_object_string_add(
json_peer, "type", "internal");
else
vty_out(vty, ", internal");
}
} else {
if (bgp_confederation_peers_check(bgp,
path->peer->as)) {
if (json_paths)
json_object_string_add(
json_peer, "type",
"confed-external");
else
vty_out(vty, ", confed-external");
} else {
if (json_paths)
json_object_string_add(
json_peer, "type", "external");
else
vty_out(vty, ", external");
}
}
} else if (path->sub_type == BGP_ROUTE_AGGREGATE) {
if (json_paths) {
json_object_boolean_true_add(json_path, "aggregated");
json_object_boolean_true_add(json_path, "local");
} else {
vty_out(vty, ", aggregated, local");
}
} else if (path->type != ZEBRA_ROUTE_BGP) {
if (json_paths)
json_object_boolean_true_add(json_path, "sourced");
else
vty_out(vty, ", sourced");
} else {
if (json_paths) {
json_object_boolean_true_add(json_path, "sourced");
json_object_boolean_true_add(json_path, "local");
} else {
vty_out(vty, ", sourced, local");
}
}
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE)) {
if (json_paths)
json_object_boolean_true_add(json_path,
"atomicAggregate");
else
vty_out(vty, ", atomic-aggregate");
}
if (CHECK_FLAG(path->flags, BGP_PATH_MULTIPATH)
|| (CHECK_FLAG(path->flags, BGP_PATH_SELECTED)
&& bgp_path_info_mpath_count(path))) {
if (json_paths)
json_object_boolean_true_add(json_path, "multipath");
else
vty_out(vty, ", multipath");
}
// Mark the bestpath(s)
if (CHECK_FLAG(path->flags, BGP_PATH_DMED_SELECTED)) {
first_as = aspath_get_first_as(attr->aspath);
if (json_paths) {
if (!json_bestpath)
json_bestpath = json_object_new_object();
json_object_int_add(json_bestpath, "bestpathFromAs",
first_as);
} else {
if (first_as)
vty_out(vty, ", bestpath-from-AS %u", first_as);
else
vty_out(vty, ", bestpath-from-AS Local");
}
}
if (CHECK_FLAG(path->flags, BGP_PATH_SELECTED)) {
if (json_paths) {
if (!json_bestpath)
json_bestpath = json_object_new_object();
json_object_boolean_true_add(json_bestpath, "overall");
json_object_string_add(
json_bestpath, "selectionReason",
bgp_path_selection_reason2str(bn->reason));
} else {
vty_out(vty, ", best");
vty_out(vty, " (%s)",
bgp_path_selection_reason2str(bn->reason));
}
}
if (rpki_curr_state != RPKI_NOT_BEING_USED) {
if (json_paths)
json_object_string_add(
json_path, "rpkiValidationState",
bgp_rpki_validation2str(rpki_curr_state));
else
vty_out(vty, ", rpki validation-state: %s",
bgp_rpki_validation2str(rpki_curr_state));
}
if (json_bestpath)
json_object_object_add(json_path, "bestpath", json_bestpath);
if (!json_paths)
vty_out(vty, "\n");
/* Line 4 display Community */
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)) {
if (json_paths) {
if (!attr->community->json)
community_str(attr->community, true);
json_object_lock(attr->community->json);
json_object_object_add(json_path, "community",
attr->community->json);
} else {
vty_out(vty, " Community: %s\n",
attr->community->str);
}
}
/* Line 5 display Extended-community */
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)) {
if (json_paths) {
json_ext_community = json_object_new_object();
json_object_string_add(json_ext_community, "string",
attr->ecommunity->str);
json_object_object_add(json_path, "extendedCommunity",
json_ext_community);
} else {
vty_out(vty, " Extended Community: %s\n",
attr->ecommunity->str);
}
}
/* Line 6 display Large community */
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES)) {
if (json_paths) {
if (!attr->lcommunity->json)
lcommunity_str(attr->lcommunity, true);
json_object_lock(attr->lcommunity->json);
json_object_object_add(json_path, "largeCommunity",
attr->lcommunity->json);
} else {
vty_out(vty, " Large Community: %s\n",
attr->lcommunity->str);
}
}
/* Line 7 display Originator, Cluster-id */
if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
|| (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))) {
char buf[BUFSIZ] = {0};
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) {
if (json_paths)
json_object_string_add(
json_path, "originatorId",
inet_ntop(AF_INET, &attr->originator_id,
buf, sizeof(buf)));
else
vty_out(vty, " Originator: %pI4",
&attr->originator_id);
}
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)) {
struct cluster_list *cluster =
bgp_attr_get_cluster(attr);
int i;
if (json_paths) {
json_cluster_list = json_object_new_object();
json_cluster_list_list =
json_object_new_array();
for (i = 0; i < cluster->length / 4; i++) {
json_string = json_object_new_string(
inet_ntop(AF_INET,
&cluster->list[i],
buf, sizeof(buf)));
json_object_array_add(
json_cluster_list_list,
json_string);
}
/*
* struct cluster_list does not have
* "str" variable like aspath and community
* do. Add this someday if someone asks
* for it.
* json_object_string_add(json_cluster_list,
* "string", cluster->str);
*/
json_object_object_add(json_cluster_list,
"list",
json_cluster_list_list);
json_object_object_add(json_path, "clusterList",
json_cluster_list);
} else {
vty_out(vty, ", Cluster list: ");
for (i = 0; i < cluster->length / 4; i++) {
vty_out(vty, "%pI4 ",
&cluster->list[i]);
}
}
}
if (!json_paths)
vty_out(vty, "\n");
}
if (path->extra && path->extra->damp_info)
bgp_damp_info_vty(vty, path, afi, safi, json_path);
/* Remote Label */
if (path->extra && bgp_is_valid_label(&path->extra->label[0])
&& (safi != SAFI_EVPN && !is_route_parent_evpn(path))) {
mpls_label_t label = label_pton(&path->extra->label[0]);
if (json_paths)
json_object_int_add(json_path, "remoteLabel", label);
else
vty_out(vty, " Remote label: %d\n", label);
}
/* Remote SID */
if (path->extra && path->extra->num_sids > 0 && safi != SAFI_EVPN) {
inet_ntop(AF_INET6, &path->extra->sid[0].sid, buf, sizeof(buf));
if (json_paths)
json_object_string_add(json_path, "remoteSid", buf);
else
vty_out(vty, " Remote SID: %s\n", buf);
}
/* Label Index */
if (attr->label_index != BGP_INVALID_LABEL_INDEX) {
if (json_paths)
json_object_int_add(json_path, "labelIndex",
attr->label_index);
else
vty_out(vty, " Label Index: %d\n",
attr->label_index);
}
/* Line 8 display Addpath IDs */
if (path->addpath_rx_id
|| bgp_addpath_info_has_ids(&path->tx_addpath)) {
if (json_paths) {
json_object_int_add(json_path, "addpathRxId",
path->addpath_rx_id);
/* Keep backwards compatibility with the old API
* by putting TX All's ID in the old field
*/
json_object_int_add(
json_path, "addpathTxId",
path->tx_addpath
.addpath_tx_id[BGP_ADDPATH_ALL]);
/* ... but create a specific field for each
* strategy
*/
for (i = 0; i < BGP_ADDPATH_MAX; i++) {
json_object_int_add(
json_path,
bgp_addpath_names(i)->id_json_name,
path->tx_addpath.addpath_tx_id[i]);
}
} else {
vty_out(vty, " AddPath ID: RX %u, ",
path->addpath_rx_id);
route_vty_out_tx_ids(vty, &path->tx_addpath);
}
}
/* If we used addpath to TX a non-bestpath we need to display
* "Advertised to" on a path-by-path basis
*/
if (bgp_addpath_is_addpath_used(&bgp->tx_addpath, afi, safi)) {
first = 1;
for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
addpath_capable =
bgp_addpath_encode_tx(peer, afi, safi);
has_adj = bgp_adj_out_lookup(
peer, path->net,
bgp_addpath_id_for_peer(peer, afi, safi,
&path->tx_addpath));
if ((addpath_capable && has_adj)
|| (!addpath_capable && has_adj
&& CHECK_FLAG(path->flags,
BGP_PATH_SELECTED))) {
if (json_path && !json_adv_to)
json_adv_to = json_object_new_object();
route_vty_out_advertised_to(
vty, peer, &first,
" Advertised to:", json_adv_to);
}
}
if (json_path) {
if (json_adv_to) {
json_object_object_add(
json_path, "advertisedTo", json_adv_to);
}
} else {
if (!first) {
vty_out(vty, "\n");
}
}
}
/* Line 9 display Uptime */
tbuf = time(NULL) - (bgp_clock() - path->uptime);
if (json_paths) {
json_last_update = json_object_new_object();
json_object_int_add(json_last_update, "epoch", tbuf);
json_object_string_add(json_last_update, "string",
ctime(&tbuf));
json_object_object_add(json_path, "lastUpdate",
json_last_update);
} else
vty_out(vty, " Last update: %s", ctime(&tbuf));
/* Line 10 display PMSI tunnel attribute, if present */
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL)) {
const char *str = lookup_msg(bgp_pmsi_tnltype_str,
bgp_attr_get_pmsi_tnl_type(attr),
PMSI_TNLTYPE_STR_DEFAULT);
if (json_paths) {
json_pmsi = json_object_new_object();
json_object_string_add(json_pmsi, "tunnelType", str);
json_object_int_add(json_pmsi, "label",
label2vni(&attr->label));
json_object_object_add(json_path, "pmsi", json_pmsi);
} else
vty_out(vty, " PMSI Tunnel Type: %s, label: %d\n",
str, label2vni(&attr->label));
}
/* Output some debug about internal state of the dest flags */
if (json_paths) {
if (CHECK_FLAG(bn->flags, BGP_NODE_PROCESS_SCHEDULED))
json_object_boolean_true_add(json_path, "processScheduled");
if (CHECK_FLAG(bn->flags, BGP_NODE_USER_CLEAR))
json_object_boolean_true_add(json_path, "userCleared");
if (CHECK_FLAG(bn->flags, BGP_NODE_LABEL_CHANGED))
json_object_boolean_true_add(json_path, "labelChanged");
if (CHECK_FLAG(bn->flags, BGP_NODE_REGISTERED_FOR_LABEL))
json_object_boolean_true_add(json_path, "registeredForLabel");
if (CHECK_FLAG(bn->flags, BGP_NODE_SELECT_DEFER))
json_object_boolean_true_add(json_path, "selectDefered");
if (CHECK_FLAG(bn->flags, BGP_NODE_FIB_INSTALLED))
json_object_boolean_true_add(json_path, "fibInstalled");
if (CHECK_FLAG(bn->flags, BGP_NODE_FIB_INSTALL_PENDING))
json_object_boolean_true_add(json_path, "fibPending");
}
/* We've constructed the json object for this path, add it to the json
* array of paths
*/
if (json_paths) {
if (json_nexthop_global || json_nexthop_ll) {
json_nexthops = json_object_new_array();
if (json_nexthop_global)
json_object_array_add(json_nexthops,
json_nexthop_global);
if (json_nexthop_ll)
json_object_array_add(json_nexthops,
json_nexthop_ll);
json_object_object_add(json_path, "nexthops",
json_nexthops);
}
json_object_object_add(json_path, "peer", json_peer);
json_object_array_add(json_paths, json_path);
}
}
#define BGP_SHOW_HEADER_CSV "Flags, Network, Next Hop, Metric, LocPrf, Weight, Path"
#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path\n"
#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path\n"
static int bgp_show_prefix_list(struct vty *vty, struct bgp *bgp,
const char *prefix_list_str, afi_t afi,
safi_t safi, enum bgp_show_type type);
static int bgp_show_filter_list(struct vty *vty, struct bgp *bgp,
const char *filter, afi_t afi, safi_t safi,
enum bgp_show_type type);
static int bgp_show_route_map(struct vty *vty, struct bgp *bgp,
const char *rmap_str, afi_t afi, safi_t safi,
enum bgp_show_type type);
static int bgp_show_community_list(struct vty *vty, struct bgp *bgp,
const char *com, int exact, afi_t afi,
safi_t safi);
static int bgp_show_prefix_longer(struct vty *vty, struct bgp *bgp,
const char *prefix, afi_t afi, safi_t safi,
enum bgp_show_type type);
static int bgp_show_regexp(struct vty *vty, struct bgp *bgp, const char *regstr,
afi_t afi, safi_t safi, enum bgp_show_type type,
bool use_json);
static int bgp_show_community(struct vty *vty, struct bgp *bgp,
const char *comstr, int exact, afi_t afi,
safi_t safi, uint16_t show_flags);
static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi,
struct bgp_table *table, enum bgp_show_type type,
void *output_arg, char *rd, int is_last,
unsigned long *output_cum, unsigned long *total_cum,
unsigned long *json_header_depth, uint16_t show_flags,
enum rpki_states rpki_target_state)
{
struct bgp_path_info *pi;
struct bgp_dest *dest;
int header = 1;
int display;
unsigned long output_count = 0;
unsigned long total_count = 0;
struct prefix *p;
json_object *json_paths = NULL;
int first = 1;
bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
bool wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
bool all = CHECK_FLAG(show_flags, BGP_SHOW_OPT_AFI_ALL);
if (output_cum && *output_cum != 0)
header = 0;
if (use_json && !*json_header_depth) {
if (all)
*json_header_depth = 1;
else {
vty_out(vty, "{\n");
*json_header_depth = 2;
}
vty_out(vty,
" \"vrfId\": %d,\n \"vrfName\": \"%s\",\n \"tableVersion\": %" PRId64
",\n \"routerId\": \"%pI4\",\n \"defaultLocPrf\": %u,\n"
" \"localAS\": %u,\n \"routes\": { ",
bgp->vrf_id == VRF_UNKNOWN ? -1 : (int)bgp->vrf_id,
bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT
? VRF_DEFAULT_NAME
: bgp->name,
table->version, &bgp->router_id,
bgp->default_local_pref, bgp->as);
if (rd) {
vty_out(vty, " \"routeDistinguishers\" : {");
++*json_header_depth;
}
}
if (use_json && rd) {
vty_out(vty, " \"%s\" : { ", rd);
}
/* Start processing of routes. */
for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) {
const struct prefix *dest_p = bgp_dest_get_prefix(dest);
enum rpki_states rpki_curr_state = RPKI_NOT_BEING_USED;
pi = bgp_dest_get_bgp_path_info(dest);
if (pi == NULL)
continue;
display = 0;
if (use_json)
json_paths = json_object_new_array();
else
json_paths = NULL;
for (; pi; pi = pi->next) {
total_count++;
if (type == bgp_show_type_prefix_version) {
uint32_t version =
strtoul(output_arg, NULL, 10);
if (dest->version < version)
continue;
}
if (type == bgp_show_type_community_alias) {
char *alias = output_arg;
char **communities;
int num;
bool found = false;
if (pi->attr->community) {
frrstr_split(pi->attr->community->str,
" ", &communities, &num);
for (int i = 0; i < num; i++) {
const char *com2alias =
bgp_community2alias(
communities[i]);
if (!found
&& strcmp(alias, com2alias)
== 0)
found = true;
XFREE(MTYPE_TMP,
communities[i]);
}
XFREE(MTYPE_TMP, communities);
}
if (!found && pi->attr->lcommunity) {
frrstr_split(pi->attr->lcommunity->str,
" ", &communities, &num);
for (int i = 0; i < num; i++) {
const char *com2alias =
bgp_community2alias(
communities[i]);
if (!found
&& strcmp(alias, com2alias)
== 0)
found = true;
XFREE(MTYPE_TMP,
communities[i]);
}
XFREE(MTYPE_TMP, communities);
}
if (!found)
continue;
}
if (type == bgp_show_type_rpki) {
if (dest_p->family == AF_INET
|| dest_p->family == AF_INET6)
rpki_curr_state = hook_call(
bgp_rpki_prefix_status,
pi->peer, pi->attr, dest_p);
if (rpki_target_state != RPKI_NOT_BEING_USED
&& rpki_curr_state != rpki_target_state)
continue;
}
if (type == bgp_show_type_flap_statistics
|| type == bgp_show_type_flap_neighbor
|| type == bgp_show_type_dampend_paths
|| type == bgp_show_type_damp_neighbor) {
if (!(pi->extra && pi->extra->damp_info))
continue;
}
if (type == bgp_show_type_regexp) {
regex_t *regex = output_arg;
if (bgp_regexec(regex, pi->attr->aspath)
== REG_NOMATCH)
continue;
}
if (type == bgp_show_type_prefix_list) {
struct prefix_list *plist = output_arg;
if (prefix_list_apply(plist, dest_p)
!= PREFIX_PERMIT)
continue;
}
if (type == bgp_show_type_filter_list) {
struct as_list *as_list = output_arg;
if (as_list_apply(as_list, pi->attr->aspath)
!= AS_FILTER_PERMIT)
continue;
}
if (type == bgp_show_type_route_map) {
struct route_map *rmap = output_arg;
struct bgp_path_info path;
struct attr dummy_attr;
route_map_result_t ret;
dummy_attr = *pi->attr;
path.peer = pi->peer;
path.attr = &dummy_attr;
ret = route_map_apply(rmap, dest_p, &path);
bgp_attr_flush(&dummy_attr);
if (ret == RMAP_DENYMATCH)
continue;
}
if (type == bgp_show_type_neighbor
|| type == bgp_show_type_flap_neighbor
|| type == bgp_show_type_damp_neighbor) {
union sockunion *su = output_arg;
if (pi->peer == NULL
|| pi->peer->su_remote == NULL
|| !sockunion_same(pi->peer->su_remote, su))
continue;
}
if (type == bgp_show_type_cidr_only) {
uint32_t destination;
destination = ntohl(dest_p->u.prefix4.s_addr);
if (IN_CLASSC(destination)
&& dest_p->prefixlen == 24)
continue;
if (IN_CLASSB(destination)
&& dest_p->prefixlen == 16)
continue;
if (IN_CLASSA(destination)
&& dest_p->prefixlen == 8)
continue;
}
if (type == bgp_show_type_prefix_longer) {
p = output_arg;
if (!prefix_match(p, dest_p))
continue;
}
if (type == bgp_show_type_community_all) {
if (!pi->attr->community)
continue;
}
if (type == bgp_show_type_community) {
struct community *com = output_arg;
if (!pi->attr->community
|| !community_match(pi->attr->community,
com))
continue;
}
if (type == bgp_show_type_community_exact) {
struct community *com = output_arg;
if (!pi->attr->community
|| !community_cmp(pi->attr->community, com))
continue;
}
if (type == bgp_show_type_community_list) {
struct community_list *list = output_arg;
if (!community_list_match(pi->attr->community,
list))
continue;
}
if (type == bgp_show_type_community_list_exact) {
struct community_list *list = output_arg;
if (!community_list_exact_match(
pi->attr->community, list))
continue;
}
if (type == bgp_show_type_lcommunity) {
struct lcommunity *lcom = output_arg;
if (!pi->attr->lcommunity
|| !lcommunity_match(pi->attr->lcommunity,
lcom))
continue;
}
if (type == bgp_show_type_lcommunity_exact) {
struct lcommunity *lcom = output_arg;
if (!pi->attr->lcommunity
|| !lcommunity_cmp(pi->attr->lcommunity,
lcom))
continue;
}
if (type == bgp_show_type_lcommunity_list) {
struct community_list *list = output_arg;
if (!lcommunity_list_match(pi->attr->lcommunity,
list))
continue;
}
if (type
== bgp_show_type_lcommunity_list_exact) {
struct community_list *list = output_arg;
if (!lcommunity_list_exact_match(
pi->attr->lcommunity, list))
continue;
}
if (type == bgp_show_type_lcommunity_all) {
if (!pi->attr->lcommunity)
continue;
}
if (type == bgp_show_type_dampend_paths
|| type == bgp_show_type_damp_neighbor) {
if (!CHECK_FLAG(pi->flags, BGP_PATH_DAMPED)
|| CHECK_FLAG(pi->flags, BGP_PATH_HISTORY))
continue;
}
if (!use_json && header) {
vty_out(vty,
"BGP table version is %" PRIu64
", local router ID is %pI4, vrf id ",
table->version, &bgp->router_id);
if (bgp->vrf_id == VRF_UNKNOWN)
vty_out(vty, "%s", VRFID_NONE_STR);
else
vty_out(vty, "%u", bgp->vrf_id);
vty_out(vty, "\n");
vty_out(vty, "Default local pref %u, ",
bgp->default_local_pref);
vty_out(vty, "local AS %u\n", bgp->as);
vty_out(vty, BGP_SHOW_SCODE_HEADER);
vty_out(vty, BGP_SHOW_NCODE_HEADER);
vty_out(vty, BGP_SHOW_OCODE_HEADER);
vty_out(vty, BGP_SHOW_RPKI_HEADER);
if (type == bgp_show_type_dampend_paths
|| type == bgp_show_type_damp_neighbor)
vty_out(vty, BGP_SHOW_DAMP_HEADER);
else if (type == bgp_show_type_flap_statistics
|| type == bgp_show_type_flap_neighbor)
vty_out(vty, BGP_SHOW_FLAP_HEADER);
else
vty_out(vty, (wide ? BGP_SHOW_HEADER_WIDE
: BGP_SHOW_HEADER));
header = 0;
}
if (rd != NULL && !display && !output_count) {
if (!use_json)
vty_out(vty,
"Route Distinguisher: %s\n",
rd);
}
if (type == bgp_show_type_dampend_paths
|| type == bgp_show_type_damp_neighbor)
damp_route_vty_out(vty, dest_p, pi, display,
AFI_IP, safi, use_json,
json_paths);
else if (type == bgp_show_type_flap_statistics
|| type == bgp_show_type_flap_neighbor)
flap_route_vty_out(vty, dest_p, pi, display,
AFI_IP, safi, use_json,
json_paths);
else {
if (CHECK_FLAG(show_flags, BGP_SHOW_OPT_DETAIL))
route_vty_out_detail(
vty, bgp, dest, pi,
family2afi(dest_p->family),
safi, RPKI_NOT_BEING_USED,
json_paths);
else
route_vty_out(vty, dest_p, pi, display,
safi, json_paths, wide);
}
display++;
}
if (display) {
output_count++;
if (!use_json)
continue;
/* encode prefix */
if (dest_p->family == AF_FLOWSPEC) {
char retstr[BGP_FLOWSPEC_STRING_DISPLAY_MAX];
bgp_fs_nlri_get_string(
(unsigned char *)
dest_p->u.prefix_flowspec.ptr,
dest_p->u.prefix_flowspec.prefixlen,
retstr, NLRI_STRING_FORMAT_MIN, NULL,
family2afi(dest_p->u
.prefix_flowspec.family));
if (first)
vty_out(vty, "\"%s/%d\": ", retstr,
dest_p->u.prefix_flowspec
.prefixlen);
else
vty_out(vty, ",\"%s/%d\": ", retstr,
dest_p->u.prefix_flowspec
.prefixlen);
} else {
if (first)
vty_out(vty, "\"%pFX\": ", dest_p);
else
vty_out(vty, ",\"%pFX\": ", dest_p);
}
vty_out(vty, "%s",
json_object_to_json_string_ext(
json_paths, JSON_C_TO_STRING_PRETTY));
json_object_free(json_paths);
json_paths = NULL;
first = 0;
} else
json_object_free(json_paths);
}
if (output_cum) {
output_count += *output_cum;
*output_cum = output_count;
}
if (total_cum) {
total_count += *total_cum;
*total_cum = total_count;
}
if (use_json) {
if (rd) {
vty_out(vty, " }%s ", (is_last ? "" : ","));
}
if (is_last) {
unsigned long i;
for (i = 0; i < *json_header_depth; ++i)
vty_out(vty, " } ");
if (!all)
vty_out(vty, "\n");
}
} else {
if (is_last) {
/* No route is displayed */
if (output_count == 0) {
if (type == bgp_show_type_normal)
vty_out(vty,
"No BGP prefixes displayed, %ld exist\n",
total_count);
} else
vty_out(vty,
"\nDisplayed %ld routes and %ld total paths\n",
output_count, total_count);
}
}
return CMD_SUCCESS;
}
int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, safi_t safi,
struct bgp_table *table, struct prefix_rd *prd_match,
enum bgp_show_type type, void *output_arg, bool use_json)
{
struct bgp_dest *dest, *next;
unsigned long output_cum = 0;
unsigned long total_cum = 0;
unsigned long json_header_depth = 0;
struct bgp_table *itable;
bool show_msg;
uint16_t show_flags = 0;
show_msg = (!use_json && type == bgp_show_type_normal);
if (use_json)
SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
for (dest = bgp_table_top(table); dest; dest = next) {
const struct prefix *dest_p = bgp_dest_get_prefix(dest);
next = bgp_route_next(dest);
if (prd_match && memcmp(dest_p->u.val, prd_match->val, 8) != 0)
continue;
itable = bgp_dest_get_bgp_table_info(dest);
if (itable != NULL) {
struct prefix_rd prd;
char rd[RD_ADDRSTRLEN];
memcpy(&prd, dest_p, sizeof(struct prefix_rd));
prefix_rd2str(&prd, rd, sizeof(rd));
bgp_show_table(vty, bgp, safi, itable, type, output_arg,
rd, next == NULL, &output_cum,
&total_cum, &json_header_depth,
show_flags, RPKI_NOT_BEING_USED);
if (next == NULL)
show_msg = false;
}
}
if (show_msg) {
if (output_cum == 0)
vty_out(vty, "No BGP prefixes displayed, %ld exist\n",
total_cum);
else
vty_out(vty,
"\nDisplayed %ld routes and %ld total paths\n",
output_cum, total_cum);
}
return CMD_SUCCESS;
}
static int bgp_show(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
enum bgp_show_type type, void *output_arg,
uint16_t show_flags, enum rpki_states rpki_target_state)
{
struct bgp_table *table;
unsigned long json_header_depth = 0;
bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
if (bgp == NULL) {
bgp = bgp_get_default();
}
if (bgp == NULL) {
if (!use_json)
vty_out(vty, "No BGP process is configured\n");
else
vty_out(vty, "{}\n");
return CMD_WARNING;
}
/* Labeled-unicast routes live in the unicast table. */
if (safi == SAFI_LABELED_UNICAST)
safi = SAFI_UNICAST;
table = bgp->rib[afi][safi];
/* use MPLS and ENCAP specific shows until they are merged */
if (safi == SAFI_MPLS_VPN) {
return bgp_show_table_rd(vty, bgp, safi, table, NULL, type,
output_arg, use_json);
}
if (safi == SAFI_FLOWSPEC && type == bgp_show_type_detail) {
return bgp_show_table_flowspec(vty, bgp, afi, table, type,
output_arg, use_json,
1, NULL, NULL);
}
return bgp_show_table(vty, bgp, safi, table, type, output_arg, NULL, 1,
NULL, NULL, &json_header_depth, show_flags,
rpki_target_state);
}
static void bgp_show_all_instances_routes_vty(struct vty *vty, afi_t afi,
safi_t safi, uint16_t show_flags)
{
struct listnode *node, *nnode;
struct bgp *bgp;
int is_first = 1;
bool route_output = false;
bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
if (use_json)
vty_out(vty, "{\n");
for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
route_output = true;
if (use_json) {
if (!is_first)
vty_out(vty, ",\n");
else
is_first = 0;
vty_out(vty, "\"%s\":",
(bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
? VRF_DEFAULT_NAME
: bgp->name);
} else {
vty_out(vty, "\nInstance %s:\n",
(bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
? VRF_DEFAULT_NAME
: bgp->name);
}
bgp_show(vty, bgp, afi, safi, bgp_show_type_normal, NULL,
show_flags, RPKI_NOT_BEING_USED);
}
if (use_json)
vty_out(vty, "}\n");
else if (!route_output)
vty_out(vty, "%% BGP instance not found\n");
}
/* Header of detailed BGP route information */
void route_vty_out_detail_header(struct vty *vty, struct bgp *bgp,
struct bgp_dest *dest, struct prefix_rd *prd,
afi_t afi, safi_t safi, json_object *json)
{
struct bgp_path_info *pi;
const struct prefix *p;
struct peer *peer;
struct listnode *node, *nnode;
char buf1[RD_ADDRSTRLEN];
char prefix_str[BUFSIZ];
int count = 0;
int best = 0;
int suppress = 0;
int accept_own = 0;
int route_filter_translated_v4 = 0;
int route_filter_v4 = 0;
int route_filter_translated_v6 = 0;
int route_filter_v6 = 0;
int llgr_stale = 0;
int no_llgr = 0;
int accept_own_nexthop = 0;
int blackhole = 0;
int no_export = 0;
int no_advertise = 0;
int local_as = 0;
int no_peer = 0;
int first = 1;
int has_valid_label = 0;
mpls_label_t label = 0;
json_object *json_adv_to = NULL;
p = bgp_dest_get_prefix(dest);
has_valid_label = bgp_is_valid_label(&dest->local_label);
if (has_valid_label)
label = label_pton(&dest->local_label);
if (safi == SAFI_EVPN) {
if (!json) {
vty_out(vty, "BGP routing table entry for %s%s%pFX\n",
prd ? prefix_rd2str(prd, buf1, sizeof(buf1))
: "",
prd ? ":" : "", (struct prefix_evpn *)p);
} else {
json_object_string_add(json, "rd",
prd ? prefix_rd2str(prd, buf1, sizeof(buf1)) :
"");
bgp_evpn_route2json((struct prefix_evpn *)p, json);
}
} else {
if (!json) {
vty_out(vty,
"BGP routing table entry for %s%s%pFX, version %" PRIu64
"\n",
((safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
? prefix_rd2str(prd, buf1,
sizeof(buf1))
: ""),
safi == SAFI_MPLS_VPN ? ":" : "", p,
dest->version);
} else {
json_object_string_add(json, "prefix",
prefix2str(p, prefix_str, sizeof(prefix_str)));
json_object_int_add(json, "version", dest->version);
}
}
if (has_valid_label) {
if (json)
json_object_int_add(json, "localLabel", label);
else
vty_out(vty, "Local label: %d\n", label);
}
if (!json)
if (bgp_labeled_safi(safi) && safi != SAFI_EVPN)
vty_out(vty, "not allocated\n");
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) {
count++;
if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)) {
best = count;
if (bgp_path_suppressed(pi))
suppress = 1;
if (pi->attr->community == NULL)
continue;
no_advertise += community_include(
pi->attr->community, COMMUNITY_NO_ADVERTISE);
no_export += community_include(pi->attr->community,
COMMUNITY_NO_EXPORT);
local_as += community_include(pi->attr->community,
COMMUNITY_LOCAL_AS);
accept_own += community_include(pi->attr->community,
COMMUNITY_ACCEPT_OWN);
route_filter_translated_v4 += community_include(
pi->attr->community,
COMMUNITY_ROUTE_FILTER_TRANSLATED_v4);
route_filter_translated_v6 += community_include(
pi->attr->community,
COMMUNITY_ROUTE_FILTER_TRANSLATED_v6);
route_filter_v4 += community_include(
pi->attr->community, COMMUNITY_ROUTE_FILTER_v4);
route_filter_v6 += community_include(
pi->attr->community, COMMUNITY_ROUTE_FILTER_v6);
llgr_stale += community_include(pi->attr->community,
COMMUNITY_LLGR_STALE);
no_llgr += community_include(pi->attr->community,
COMMUNITY_NO_LLGR);
accept_own_nexthop +=
community_include(pi->attr->community,
COMMUNITY_ACCEPT_OWN_NEXTHOP);
blackhole += community_include(pi->attr->community,
COMMUNITY_BLACKHOLE);
no_peer += community_include(pi->attr->community,
COMMUNITY_NO_PEER);
}
}
if (!json) {
vty_out(vty, "Paths: (%d available", count);
if (best) {
vty_out(vty, ", best #%d", best);
if (safi == SAFI_UNICAST) {
if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
vty_out(vty, ", table %s",
VRF_DEFAULT_NAME);
else
vty_out(vty, ", vrf %s",
bgp->name);
}
} else
vty_out(vty, ", no best path");
if (accept_own)
vty_out(vty,
", accept own local route exported and imported in different VRF");
else if (route_filter_translated_v4)
vty_out(vty,
", mark translated RTs for VPNv4 route filtering");
else if (route_filter_v4)
vty_out(vty,
", attach RT as-is for VPNv4 route filtering");
else if (route_filter_translated_v6)
vty_out(vty,
", mark translated RTs for VPNv6 route filtering");
else if (route_filter_v6)
vty_out(vty,
", attach RT as-is for VPNv6 route filtering");
else if (llgr_stale)
vty_out(vty,
", mark routes to be retained for a longer time. Requeres support for Long-lived BGP Graceful Restart");
else if (no_llgr)
vty_out(vty,
", mark routes to not be treated according to Long-lived BGP Graceful Restart operations");
else if (accept_own_nexthop)
vty_out(vty,
", accept local nexthop");
else if (blackhole)
vty_out(vty, ", inform peer to blackhole prefix");
else if (no_export)
vty_out(vty, ", not advertised to EBGP peer");
else if (no_advertise)
vty_out(vty, ", not advertised to any peer");
else if (local_as)
vty_out(vty, ", not advertised outside local AS");
else if (no_peer)
vty_out(vty,
", inform EBGP peer not to advertise to their EBGP peers");
if (suppress)
vty_out(vty,
", Advertisements suppressed by an aggregate.");
vty_out(vty, ")\n");
}
/* If we are not using addpath then we can display Advertised to and
* that will
* show what peers we advertised the bestpath to. If we are using
* addpath
* though then we must display Advertised to on a path-by-path basis. */
if (!bgp_addpath_is_addpath_used(&bgp->tx_addpath, afi, safi)) {
for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
if (bgp_adj_out_lookup(peer, dest, 0)) {
if (json && !json_adv_to)
json_adv_to = json_object_new_object();
route_vty_out_advertised_to(
vty, peer, &first,
" Advertised to non peer-group peers:\n ",
json_adv_to);
}
}
if (json) {
if (json_adv_to) {
json_object_object_add(json, "advertisedTo",
json_adv_to);
}
} else {
if (first)
vty_out(vty, " Not advertised to any peer");
vty_out(vty, "\n");
}
}
}
static void bgp_show_path_info(struct prefix_rd *pfx_rd,
struct bgp_dest *bgp_node, struct vty *vty,
struct bgp *bgp, afi_t afi, safi_t safi,
json_object *json, enum bgp_path_type pathtype,
int *display, enum rpki_states rpki_target_state)
{
struct bgp_path_info *pi;
int header = 1;
char rdbuf[RD_ADDRSTRLEN];
json_object *json_header = NULL;
json_object *json_paths = NULL;
const struct prefix *p = bgp_dest_get_prefix(bgp_node);
for (pi = bgp_dest_get_bgp_path_info(bgp_node); pi; pi = pi->next) {
enum rpki_states rpki_curr_state = RPKI_NOT_BEING_USED;
if (p->family == AF_INET || p->family == AF_INET6)
rpki_curr_state = hook_call(bgp_rpki_prefix_status,
pi->peer, pi->attr, p);
if (rpki_target_state != RPKI_NOT_BEING_USED
&& rpki_curr_state != rpki_target_state)
continue;
if (json && !json_paths) {
/* Instantiate json_paths only if path is valid */
json_paths = json_object_new_array();
if (pfx_rd) {
prefix_rd2str(pfx_rd, rdbuf, sizeof(rdbuf));
json_header = json_object_new_object();
} else
json_header = json;
}
if (header) {
route_vty_out_detail_header(
vty, bgp, bgp_node, pfx_rd,
AFI_IP, safi, json_header);
header = 0;
}
(*display)++;
if (pathtype == BGP_PATH_SHOW_ALL
|| (pathtype == BGP_PATH_SHOW_BESTPATH
&& CHECK_FLAG(pi->flags, BGP_PATH_SELECTED))
|| (pathtype == BGP_PATH_SHOW_MULTIPATH
&& (CHECK_FLAG(pi->flags, BGP_PATH_MULTIPATH)
|| CHECK_FLAG(pi->flags, BGP_PATH_SELECTED))))
route_vty_out_detail(vty, bgp, bgp_node, pi, AFI_IP,
safi, rpki_curr_state, json_paths);
}
if (json && json_paths) {
json_object_object_add(json_header, "paths", json_paths);
if (pfx_rd)
json_object_object_add(json, rdbuf, json_header);
}
}
/* Display specified route of BGP table. */
static int bgp_show_route_in_table(struct vty *vty, struct bgp *bgp,
struct bgp_table *rib, const char *ip_str,
afi_t afi, safi_t safi,
enum rpki_states rpki_target_state,
struct prefix_rd *prd, int prefix_check,
enum bgp_path_type pathtype, bool use_json)
{
int ret;
int display = 0;
struct prefix match;
struct bgp_dest *dest;
struct bgp_dest *rm;
struct bgp_table *table;
json_object *json = NULL;
json_object *json_paths = NULL;
/* Check IP address argument. */
ret = str2prefix(ip_str, &match);
if (!ret) {
vty_out(vty, "address is malformed\n");
return CMD_WARNING;
}
match.family = afi2family(afi);
if (use_json)
json = json_object_new_object();
if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP) {
for (dest = bgp_table_top(rib); dest;
dest = bgp_route_next(dest)) {
const struct prefix *dest_p = bgp_dest_get_prefix(dest);
if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
continue;
table = bgp_dest_get_bgp_table_info(dest);
if (!table)
continue;
rm = bgp_node_match(table, &match);
if (rm == NULL)
continue;
const struct prefix *rm_p = bgp_dest_get_prefix(rm);
if (prefix_check
&& rm_p->prefixlen != match.prefixlen) {
bgp_dest_unlock_node(rm);
continue;
}
bgp_show_path_info((struct prefix_rd *)dest_p, rm, vty,
bgp, afi, safi, json, pathtype,
&display, rpki_target_state);
bgp_dest_unlock_node(rm);
}
} else if (safi == SAFI_EVPN) {
struct bgp_dest *longest_pfx;
bool is_exact_pfxlen_match = false;
for (dest = bgp_table_top(rib); dest;
dest = bgp_route_next(dest)) {
const struct prefix *dest_p = bgp_dest_get_prefix(dest);
if (prd && memcmp(&dest_p->u.val, prd->val, 8) != 0)
continue;
table = bgp_dest_get_bgp_table_info(dest);
if (!table)
continue;
longest_pfx = NULL;
is_exact_pfxlen_match = false;
/*
* Search through all the prefixes for a match. The
* pfx's are enumerated in ascending order of pfxlens.
* So, the last pfx match is the longest match. Set
* is_exact_pfxlen_match when we get exact pfxlen match
*/
for (rm = bgp_table_top(table); rm;
rm = bgp_route_next(rm)) {
const struct prefix *rm_p =
bgp_dest_get_prefix(rm);
/*
* Get prefixlen of the ip-prefix within type5
* evpn route
*/
if (evpn_type5_prefix_match(rm_p, &match)
&& rm->info) {
longest_pfx = rm;
int type5_pfxlen =
bgp_evpn_get_type5_prefixlen(
rm_p);
if (type5_pfxlen == match.prefixlen) {
is_exact_pfxlen_match = true;
bgp_dest_unlock_node(rm);
break;
}
}
}
if (!longest_pfx)
continue;
if (prefix_check && !is_exact_pfxlen_match)
continue;
rm = longest_pfx;
bgp_dest_lock_node(rm);
bgp_show_path_info((struct prefix_rd *)dest_p, rm, vty,
bgp, afi, safi, json, pathtype,
&display, rpki_target_state);
bgp_dest_unlock_node(rm);
}
} else if (safi == SAFI_FLOWSPEC) {
if (use_json)
json_paths = json_object_new_array();
display = bgp_flowspec_display_match_per_ip(afi, rib,
&match, prefix_check,
vty,
use_json,
json_paths);
if (use_json) {
if (display)
json_object_object_add(json, "paths",
json_paths);
else
json_object_free(json_paths);
}
} else {
dest = bgp_node_match(rib, &match);
if (dest != NULL) {
const struct prefix *dest_p = bgp_dest_get_prefix(dest);
if (!prefix_check
|| dest_p->prefixlen == match.prefixlen) {
bgp_show_path_info(NULL, dest, vty, bgp, afi,
safi, json, pathtype,
&display, rpki_target_state);
}
bgp_dest_unlock_node(dest);
}
}
if (use_json) {
vty_out(vty, "%s\n", json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY |
JSON_C_TO_STRING_NOSLASHESCAPE));
json_object_free(json);
} else {
if (!display) {
vty_out(vty, "%% Network not in table\n");
return CMD_WARNING;
}
}
return CMD_SUCCESS;
}
/* Display specified route of Main RIB */
static int bgp_show_route(struct vty *vty, struct bgp *bgp, const char *ip_str,
afi_t afi, safi_t safi, struct prefix_rd *prd,
int prefix_check, enum bgp_path_type pathtype,
enum rpki_states rpki_target_state, bool use_json)
{
if (!bgp) {
bgp = bgp_get_default();
if (!bgp) {
if (!use_json)
vty_out(vty, "No BGP process is configured\n");
else
vty_out(vty, "{}\n");
return CMD_WARNING;
}
}
/* labeled-unicast routes live in the unicast table */
if (safi == SAFI_LABELED_UNICAST)
safi = SAFI_UNICAST;
return bgp_show_route_in_table(vty, bgp, bgp->rib[afi][safi], ip_str,
afi, safi, rpki_target_state, prd,
prefix_check, pathtype, use_json);
}
static int bgp_show_lcommunity(struct vty *vty, struct bgp *bgp, int argc,
struct cmd_token **argv, bool exact, afi_t afi,
safi_t safi, bool uj)
{
struct lcommunity *lcom;
struct buffer *b;
int i;
char *str;
int first = 0;
uint16_t show_flags = 0;
int ret;
if (uj)
SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
b = buffer_new(1024);
for (i = 0; i < argc; i++) {
if (first)
buffer_putc(b, ' ');
else {
if (strmatch(argv[i]->text, "AA:BB:CC")) {
first = 1;
buffer_putstr(b, argv[i]->arg);
}
}
}
buffer_putc(b, '\0');
str = buffer_getstr(b);
buffer_free(b);
lcom = lcommunity_str2com(str);
XFREE(MTYPE_TMP, str);
if (!lcom) {
vty_out(vty, "%% Large-community malformed\n");
return CMD_WARNING;
}
ret = bgp_show(vty, bgp, afi, safi,
(exact ? bgp_show_type_lcommunity_exact
: bgp_show_type_lcommunity),
lcom, show_flags, RPKI_NOT_BEING_USED);
lcommunity_free(&lcom);
return ret;
}
static int bgp_show_lcommunity_list(struct vty *vty, struct bgp *bgp,
const char *lcom, bool exact, afi_t afi,
safi_t safi, bool uj)
{
struct community_list *list;
uint16_t show_flags = 0;
if (uj)
SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
list = community_list_lookup(bgp_clist, lcom, 0,
LARGE_COMMUNITY_LIST_MASTER);
if (list == NULL) {
vty_out(vty, "%% %s is not a valid large-community-list name\n",
lcom);
return CMD_WARNING;
}
return bgp_show(vty, bgp, afi, safi,
(exact ? bgp_show_type_lcommunity_list_exact
: bgp_show_type_lcommunity_list),
list, show_flags, RPKI_NOT_BEING_USED);
}
DEFUN (show_ip_bgp_large_community_list,
show_ip_bgp_large_community_list_cmd,
"show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] large-community-list <(1-500)|LCOMMUNITY_LIST_NAME> [exact-match] [json]",
SHOW_STR
IP_STR
BGP_STR
BGP_INSTANCE_HELP_STR
BGP_AFI_HELP_STR
BGP_SAFI_WITH_LABEL_HELP_STR
"Display routes matching the large-community-list\n"
"large-community-list number\n"
"large-community-list name\n"
"Exact match of the large-communities\n"
JSON_STR)
{
afi_t afi = AFI_IP6;
safi_t safi = SAFI_UNICAST;
int idx = 0;
bool exact_match = 0;
struct bgp *bgp = NULL;
bool uj = use_json(argc, argv);
if (uj)
argc--;
bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi,
&bgp, uj);
if (!idx)
return CMD_WARNING;
argv_find(argv, argc, "large-community-list", &idx);
const char *clist_number_or_name = argv[++idx]->arg;
if (++idx < argc && strmatch(argv[idx]->text, "exact-match"))
exact_match = 1;
return bgp_show_lcommunity_list(vty, bgp, clist_number_or_name,
exact_match, afi, safi, uj);
}
DEFUN (show_ip_bgp_large_community,
show_ip_bgp_large_community_cmd,
"show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] large-community [<AA:BB:CC> [exact-match]] [json]",
SHOW_STR
IP_STR
BGP_STR
BGP_INSTANCE_HELP_STR
BGP_AFI_HELP_STR
BGP_SAFI_WITH_LABEL_HELP_STR
"Display routes matching the large-communities\n"
"List of large-community numbers\n"
"Exact match of the large-communities\n"
JSON_STR)
{
afi_t afi = AFI_IP6;
safi_t safi = SAFI_UNICAST;
int idx = 0;
bool exact_match = 0;
struct bgp *bgp = NULL;
bool uj = use_json(argc, argv);
uint16_t show_flags = 0;
if (uj) {
argc--;
SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
}
bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi,
&bgp, uj);
if (!idx)
return CMD_WARNING;
if (argv_find(argv, argc, "AA:BB:CC", &idx)) {
if (argv_find(argv, argc, "exact-match", &idx))
exact_match = 1;
return bgp_show_lcommunity(vty, bgp, argc, argv,
exact_match, afi, safi, uj);
} else
return bgp_show(vty, bgp, afi, safi,
bgp_show_type_lcommunity_all, NULL, show_flags,
RPKI_NOT_BEING_USED);
}
static int bgp_table_stats_single(struct vty *vty, struct bgp *bgp, afi_t afi,
safi_t safi, struct json_object *json_array);
static int bgp_table_stats(struct vty *vty, struct bgp *bgp, afi_t afi,
safi_t safi, struct json_object *json);
DEFUN(show_ip_bgp_statistics_all, show_ip_bgp_statistics_all_cmd,
"show [ip] bgp [<view|vrf> VIEWVRFNAME] statistics-all [json]",
SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR
"Display number of prefixes for all afi/safi\n" JSON_STR)
{
bool uj = use_json(argc, argv);
struct bgp *bgp = NULL;
safi_t safi = SAFI_UNICAST;
afi_t afi = AFI_IP6;
int idx = 0;
struct json_object *json_all = NULL;
struct json_object *json_afi_safi = NULL;
bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi,
&bgp, false);
if (!idx)
return CMD_WARNING;
if (uj)
json_all = json_object_new_object();
FOREACH_AFI_SAFI (afi, safi) {
/*
* So limit output to those afi/safi pairs that
* actually have something interesting in them
*/
if (strmatch(get_afi_safi_str(afi, safi, true),
"Unknown")) {
continue;
}
if (uj) {
json_afi_safi = json_object_new_array();
json_object_object_add(
json_all,
get_afi_safi_str(afi, safi, true),
json_afi_safi);
} else {
json_afi_safi = NULL;
}
bgp_table_stats(vty, bgp, afi, safi, json_afi_safi);
}
if (uj) {
vty_out(vty, "%s",
json_object_to_json_string_ext(
json_all, JSON_C_TO_STRING_PRETTY));
json_object_free(json_all);
}
return CMD_SUCCESS;
}
/* BGP route print out function without JSON */
DEFUN (show_ip_bgp_l2vpn_evpn_statistics,
show_ip_bgp_l2vpn_evpn_statistics_cmd,
"show [ip] bgp [<view|vrf> VIEWVRFNAME] l2vpn evpn statistics [json]",
SHOW_STR
IP_STR
BGP_STR
BGP_INSTANCE_HELP_STR
L2VPN_HELP_STR
EVPN_HELP_STR
"BGP RIB advertisement statistics\n"
JSON_STR)
{
afi_t afi = AFI_IP6;
safi_t safi = SAFI_UNICAST;
struct bgp *bgp = NULL;
int idx = 0, ret;
bool uj = use_json(argc, argv);
struct json_object *json_afi_safi = NULL, *json = NULL;
bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi,
&bgp, false);
if (!idx)
return CMD_WARNING;
if (uj)
json_afi_safi = json_object_new_array();
else
json_afi_safi = NULL;
ret = bgp_table_stats(vty, bgp, afi, safi, json_afi_safi);
if (uj) {
json = json_object_new_object();
json_object_object_add(json, get_afi_safi_str(afi, safi, true),
json_afi_safi);
vty_out(vty, "%s", json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
}
return ret;
}
/* BGP route print out function without JSON */
DEFUN(show_ip_bgp_afi_safi_statistics, show_ip_bgp_afi_safi_statistics_cmd,
"show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
" [" BGP_SAFI_WITH_LABEL_CMD_STR
"]]\
statistics [json]",
SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
BGP_SAFI_WITH_LABEL_HELP_STR
"BGP RIB advertisement statistics\n" JSON_STR)
{
afi_t afi = AFI_IP6;
safi_t safi = SAFI_UNICAST;
struct bgp *bgp = NULL;
int idx = 0, ret;
bool uj = use_json(argc, argv);
struct json_object *json_afi_safi = NULL, *json = NULL;
bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi,
&bgp, false);
if (!idx)
return CMD_WARNING;
if (uj)
json_afi_safi = json_object_new_array();
else
json_afi_safi = NULL;
ret = bgp_table_stats(vty, bgp, afi, safi, json_afi_safi);
if (uj) {
json = json_object_new_object();
json_object_object_add(json, get_afi_safi_str(afi, safi, true),
json_afi_safi);
vty_out(vty, "%s",
json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
}
return ret;
}
/* BGP route print out function without JSON */
DEFPY(show_ip_bgp, show_ip_bgp_cmd,
"show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
" [" BGP_SAFI_WITH_LABEL_CMD_STR
"]]\
<[all$all] dampening <parameters>\
|route-map WORD\
|prefix-list WORD\
|filter-list WORD\
|community-list <(1-500)|COMMUNITY_LIST_NAME> [exact-match]\
|A.B.C.D/M longer-prefixes\
|X:X::X:X/M longer-prefixes\
>",
SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
BGP_SAFI_WITH_LABEL_HELP_STR
"Display the entries for all address families\n"
"Display detailed information about dampening\n"
"Display detail of configured dampening parameters\n"
"Display routes matching the route-map\n"
"A route-map to match on\n"
"Display routes conforming to the prefix-list\n"
"Prefix-list name\n"
"Display routes conforming to the filter-list\n"
"Regular expression access list name\n"
"Display routes matching the community-list\n"
"community-list number\n"
"community-list name\n"
"Exact match of the communities\n"
"IPv4 prefix\n"
"Display route and more specific routes\n"
"IPv6 prefix\n"
"Display route and more specific routes\n")
{
afi_t afi = AFI_IP6;
safi_t safi = SAFI_UNICAST;
int exact_match = 0;
struct bgp *bgp = NULL;
int idx = 0;
uint16_t show_flags = 0;
/* [<ipv4|ipv6> [all]] */
if (all) {
SET_FLAG(show_flags, BGP_SHOW_OPT_AFI_ALL);
if (argv_find(argv, argc, "ipv4", &idx))
SET_FLAG(show_flags, BGP_SHOW_OPT_AFI_IP);
if (argv_find(argv, argc, "ipv6", &idx))
SET_FLAG(show_flags, BGP_SHOW_OPT_AFI_IP6);
}
bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi,
&bgp, false);
if (!idx)
return CMD_WARNING;
if (argv_find(argv, argc, "dampening", &idx)) {
if (argv_find(argv, argc, "parameters", &idx))
return bgp_show_dampening_parameters(vty, afi, safi,
show_flags);
}
if (argv_find(argv, argc, "prefix-list", &idx))
return bgp_show_prefix_list(vty, bgp, argv[idx + 1]->arg, afi,
safi, bgp_show_type_prefix_list);
if (argv_find(argv, argc, "filter-list", &idx))
return bgp_show_filter_list(vty, bgp, argv[idx + 1]->arg, afi,
safi, bgp_show_type_filter_list);
if (argv_find(argv, argc, "route-map", &idx))
return bgp_show_route_map(vty, bgp, argv[idx + 1]->arg, afi,
safi, bgp_show_type_route_map);
if (argv_find(argv, argc, "community-list", &idx)) {
const char *clist_number_or_name = argv[++idx]->arg;
if (++idx < argc && strmatch(argv[idx]->text, "exact-match"))
exact_match = 1;
return bgp_show_community_list(vty, bgp, clist_number_or_name,
exact_match, afi, safi);
}
/* prefix-longer */
if (argv_find(argv, argc, "A.B.C.D/M", &idx)
|| argv_find(argv, argc, "X:X::X:X/M", &idx))
return bgp_show_prefix_longer(vty, bgp, argv[idx]->arg, afi,
safi,
bgp_show_type_prefix_longer);
return CMD_WARNING;
}
/* BGP route print out function with JSON */
DEFPY(show_ip_bgp_json, show_ip_bgp_json_cmd,
"show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
" [" BGP_SAFI_WITH_LABEL_CMD_STR
"]]\
[all$all]\
[cidr-only\
|dampening <flap-statistics|dampened-paths>\
|community [AA:NN|local-AS|no-advertise|no-export\
|graceful-shutdown|no-peer|blackhole|llgr-stale|no-llgr\
|accept-own|accept-own-nexthop|route-filter-v6\
|route-filter-v4|route-filter-translated-v6\
|route-filter-translated-v4] [exact-match]\
|rpki <invalid|valid|notfound>\
|version (1-4294967295)\
|alias ALIAS_NAME\
] [json$uj [detail$detail] | wide$wide]",
SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
BGP_SAFI_WITH_LABEL_HELP_STR
"Display the entries for all address families\n"
"Display only routes with non-natural netmasks\n"
"Display detailed information about dampening\n"
"Display flap statistics of routes\n"
"Display paths suppressed due to dampening\n"
"Display routes matching the communities\n" COMMUNITY_AANN_STR
"Do not send outside local AS (well-known community)\n"
"Do not advertise to any peer (well-known community)\n"
"Do not export to next AS (well-known community)\n"
"Graceful shutdown (well-known community)\n"
"Do not export to any peer (well-known community)\n"
"Inform EBGP peers to blackhole traffic to prefix (well-known community)\n"
"Staled Long-lived Graceful Restart VPN route (well-known community)\n"
"Removed because Long-lived Graceful Restart was not enabled for VPN route (well-known community)\n"
"Should accept local VPN route if exported and imported into different VRF (well-known community)\n"
"Should accept VPN route with local nexthop (well-known community)\n"
"RT VPNv6 route filtering (well-known community)\n"
"RT VPNv4 route filtering (well-known community)\n"
"RT translated VPNv6 route filtering (well-known community)\n"
"RT translated VPNv4 route filtering (well-known community)\n"
"Exact match of the communities\n"
"RPKI route types\n"
"A valid path as determined by rpki\n"
"A invalid path as determined by rpki\n"
"A path that has no rpki data\n"
"Display prefixes with matching version numbers\n"
"Version number and above\n"
"Display prefixes with matching BGP community alias\n"
"BGP community alias\n" JSON_STR
"Display detailed version of JSON output\n"
"Increase table width for longer prefixes\n")
{
afi_t afi = AFI_IP6;
safi_t safi = SAFI_UNICAST;
enum bgp_show_type sh_type = bgp_show_type_normal;
struct bgp *bgp = NULL;
int idx = 0;
int exact_match = 0;
char *community = NULL;
char *prefix_version = NULL;
char *bgp_community_alias = NULL;
bool first = true;
uint16_t show_flags = 0;
enum rpki_states rpki_target_state = RPKI_NOT_BEING_USED;
if (uj) {
argc--;
SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
}
if (detail)
SET_FLAG(show_flags, BGP_SHOW_OPT_DETAIL);
/* [<ipv4|ipv6> [all]] */
if (all) {
SET_FLAG(show_flags, BGP_SHOW_OPT_AFI_ALL);
if (argv_find(argv, argc, "ipv4", &idx))
SET_FLAG(show_flags, BGP_SHOW_OPT_AFI_IP);
if (argv_find(argv, argc, "ipv6", &idx))
SET_FLAG(show_flags, BGP_SHOW_OPT_AFI_IP6);
}
if (wide)
SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi,
&bgp, uj);
if (!idx)
return CMD_WARNING;
if (argv_find(argv, argc, "cidr-only", &idx))
sh_type = bgp_show_type_cidr_only;
if (argv_find(argv, argc, "dampening", &idx)) {
if (argv_find(argv, argc, "dampened-paths", &idx))
sh_type = bgp_show_type_dampend_paths;
else if (argv_find(argv, argc, "flap-statistics", &idx))
sh_type = bgp_show_type_flap_statistics;
}
if (argv_find(argv, argc, "community", &idx)) {
char *maybecomm = NULL;
if (idx + 1 < argc) {
if (argv[idx + 1]->type == VARIABLE_TKN)
maybecomm = argv[idx + 1]->arg;
else
maybecomm = argv[idx + 1]->text;
}
if (maybecomm && !strmatch(maybecomm, "json")
&& !strmatch(maybecomm, "exact-match"))
community = maybecomm;
if (argv_find(argv, argc, "exact-match", &idx))
exact_match = 1;
if (!community)
sh_type = bgp_show_type_community_all;
}
if (argv_find(argv, argc, "rpki", &idx)) {
sh_type = bgp_show_type_rpki;
if (argv_find(argv, argc, "valid", &idx))
rpki_target_state = RPKI_VALID;
else if (argv_find(argv, argc, "invalid", &idx))
rpki_target_state = RPKI_INVALID;
}
/* Display prefixes with matching version numbers */
if (argv_find(argv, argc, "version", &idx)) {
sh_type = bgp_show_type_prefix_version;
prefix_version = argv[idx + 1]->arg;
}
/* Display prefixes with matching BGP community alias */
if (argv_find(argv, argc, "alias", &idx)) {
sh_type = bgp_show_type_community_alias;
bgp_community_alias = argv[idx + 1]->arg;
}
if (!all) {
/* show bgp: AFI_IP6, show ip bgp: AFI_IP */
if (community)
return bgp_show_community(vty, bgp, community,
exact_match, afi, safi,
show_flags);
else if (prefix_version)
return bgp_show(vty, bgp, afi, safi, sh_type,
prefix_version, show_flags,
rpki_target_state);
else if (bgp_community_alias)
return bgp_show(vty, bgp, afi, safi, sh_type,
bgp_community_alias, show_flags,
rpki_target_state);
else
return bgp_show(vty, bgp, afi, safi, sh_type, NULL,
show_flags, rpki_target_state);
} else {
/* show <ip> bgp ipv4 all: AFI_IP, show <ip> bgp ipv6 all:
* AFI_IP6 */
if (uj)
vty_out(vty, "{\n");
if (CHECK_FLAG(show_flags, BGP_SHOW_OPT_AFI_IP)
|| CHECK_FLAG(show_flags, BGP_SHOW_OPT_AFI_IP6)) {
afi = CHECK_FLAG(show_flags, BGP_SHOW_OPT_AFI_IP)
? AFI_IP
: AFI_IP6;
FOREACH_SAFI (safi) {
if (!bgp_afi_safi_peer_exists(bgp, afi, safi))
continue;
if (uj) {
if (first)
first = false;
else
vty_out(vty, ",\n");
vty_out(vty, "\"%s\":{\n",
get_afi_safi_str(afi, safi,
true));
} else
vty_out(vty,
"\nFor address family: %s\n",
get_afi_safi_str(afi, safi,
false));
if (community)
bgp_show_community(vty, bgp, community,
exact_match, afi,
safi, show_flags);
else if (prefix_version)
return bgp_show(vty, bgp, afi, safi,
sh_type, prefix_version,
show_flags,
rpki_target_state);
else if (bgp_community_alias)
return bgp_show(
vty, bgp, afi, safi, sh_type,
bgp_community_alias, show_flags,
rpki_target_state);
else
bgp_show(vty, bgp, afi, safi, sh_type,
NULL, show_flags,
rpki_target_state);
if (uj)
vty_out(vty, "}\n");
}
} else {
/* show <ip> bgp all: for each AFI and SAFI*/
FOREACH_AFI_SAFI (afi, safi) {
if (!bgp_afi_safi_peer_exists(bgp, afi, safi))
continue;
if (uj) {
if (first)
first = false;
else
vty_out(vty, ",\n");
vty_out(vty, "\"%s\":{\n",
get_afi_safi_str(afi, safi,
true));
} else
vty_out(vty,
"\nFor address family: %s\n",
get_afi_safi_str(afi, safi,
false));
if (community)
bgp_show_community(vty, bgp, community,
exact_match, afi,
safi, show_flags);
else if (prefix_version)
return bgp_show(vty, bgp, afi, safi,
sh_type, prefix_version,
show_flags,
rpki_target_state);
else
bgp_show(vty, bgp, afi, safi, sh_type,
NULL, show_flags,
rpki_target_state);
if (uj)
vty_out(vty, "}\n");
}
}
if (uj)
vty_out(vty, "}\n");
}
return CMD_SUCCESS;
}
DEFUN (show_ip_bgp_route,
show_ip_bgp_route_cmd,
"show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]]<A.B.C.D|A.B.C.D/M|X:X::X:X|X:X::X:X/M> [<bestpath|multipath>] [rpki <valid|invalid|notfound>] [json]",
SHOW_STR
IP_STR
BGP_STR
BGP_INSTANCE_HELP_STR
BGP_AFI_HELP_STR
BGP_SAFI_WITH_LABEL_HELP_STR
"Network in the BGP routing table to display\n"
"IPv4 prefix\n"
"Network in the BGP routing table to display\n"
"IPv6 prefix\n"
"Display only the bestpath\n"
"Display only multipaths\n"
"Display only paths that match the specified rpki state\n"
"A valid path as determined by rpki\n"
"A invalid path as determined by rpki\n"
"A path that has no rpki data\n"
JSON_STR)
{
int prefix_check = 0;
afi_t afi = AFI_IP6;
safi_t safi = SAFI_UNICAST;
char *prefix = NULL;
struct bgp *bgp = NULL;
enum bgp_path_type path_type;
bool uj = use_json(argc, argv);
int idx = 0;
bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi,
&bgp, uj);
if (!idx)
return CMD_WARNING;
if (!bgp) {
vty_out(vty,
"Specified 'all' vrf's but this command currently only works per view/vrf\n");
return CMD_WARNING;
}
/* <A.B.C.D|A.B.C.D/M|X:X::X:X|X:X::X:X/M> */
if (argv_find(argv, argc, "A.B.C.D", &idx)
|| argv_find(argv, argc, "X:X::X:X", &idx))
prefix_check = 0;
else if (argv_find(argv, argc, "A.B.C.D/M", &idx)
|| argv_find(argv, argc, "X:X::X:X/M", &idx))
prefix_check = 1;
if ((argv[idx]->type == IPV6_TKN || argv[idx]->type == IPV6_PREFIX_TKN)
&& afi != AFI_IP6) {
vty_out(vty,
"%% Cannot specify IPv6 address or prefix with IPv4 AFI\n");
return CMD_WARNING;
}
if ((argv[idx]->type == IPV4_TKN || argv[idx]->type == IPV4_PREFIX_TKN)
&& afi != AFI_IP) {
vty_out(vty,
"%% Cannot specify IPv4 address or prefix with IPv6 AFI\n");
return CMD_WARNING;
}
prefix = argv[idx]->arg;
/* [<bestpath|multipath>] */
if (argv_find(argv, argc, "bestpath", &idx))
path_type = BGP_PATH_SHOW_BESTPATH;
else if (argv_find(argv, argc, "multipath", &idx))
path_type = BGP_PATH_SHOW_MULTIPATH;
else
path_type = BGP_PATH_SHOW_ALL;
return bgp_show_route(vty, bgp, prefix, afi, safi, NULL, prefix_check,
path_type, RPKI_NOT_BEING_USED, uj);
}
DEFUN (show_ip_bgp_regexp,
show_ip_bgp_regexp_cmd,
"show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] regexp REGEX [json]",
SHOW_STR
IP_STR
BGP_STR
BGP_INSTANCE_HELP_STR
BGP_AFI_HELP_STR
BGP_SAFI_WITH_LABEL_HELP_STR
"Display routes matching the AS path regular expression\n"
"A regular-expression (1234567890_^|[,{}() ]$*+.?-\\) to match the BGP AS paths\n"
JSON_STR)
{
afi_t afi = AFI_IP6;
safi_t safi = SAFI_UNICAST;
struct bgp *bgp = NULL;
bool uj = use_json(argc, argv);
char *regstr = NULL;
int idx = 0;
bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi,
&bgp, false);
if (!idx)
return CMD_WARNING;
// get index of regex
if (argv_find(argv, argc, "REGEX", &idx))
regstr = argv[idx]->arg;
assert(regstr);
return bgp_show_regexp(vty, bgp, (const char *)regstr, afi, safi,
bgp_show_type_regexp, uj);
}
DEFPY (show_ip_bgp_instance_all,
show_ip_bgp_instance_all_cmd,
"show [ip] bgp <view|vrf> all ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] [json$uj | wide$wide]",
SHOW_STR
IP_STR
BGP_STR
BGP_INSTANCE_ALL_HELP_STR
BGP_AFI_HELP_STR
BGP_SAFI_WITH_LABEL_HELP_STR
JSON_STR
"Increase table width for longer prefixes\n")
{
afi_t afi = AFI_IP;
safi_t safi = SAFI_UNICAST;
struct bgp *bgp = NULL;
int idx = 0;
uint16_t show_flags = 0;
if (uj) {
argc--;
SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
}
if (wide)
SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi,
&bgp, uj);
if (!idx)
return CMD_WARNING;
bgp_show_all_instances_routes_vty(vty, afi, safi, show_flags);
return CMD_SUCCESS;
}
static int bgp_show_regexp(struct vty *vty, struct bgp *bgp, const char *regstr,
afi_t afi, safi_t safi, enum bgp_show_type type,
bool use_json)
{
regex_t *regex;
int rc;
uint16_t show_flags = 0;
if (use_json)
SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
if (!config_bgp_aspath_validate(regstr)) {
vty_out(vty, "Invalid character in REGEX %s\n",
regstr);
return CMD_WARNING_CONFIG_FAILED;
}
regex = bgp_regcomp(regstr);
if (!regex) {
vty_out(vty, "Can't compile regexp %s\n", regstr);
return CMD_WARNING;
}
rc = bgp_show(vty, bgp, afi, safi, type, regex, show_flags,
RPKI_NOT_BEING_USED);
bgp_regex_free(regex);
return rc;
}
static int bgp_show_prefix_list(struct vty *vty, struct bgp *bgp,
const char *prefix_list_str, afi_t afi,
safi_t safi, enum bgp_show_type type)
{
struct prefix_list *plist;
uint16_t show_flags = 0;
plist = prefix_list_lookup(afi, prefix_list_str);
if (plist == NULL) {
vty_out(vty, "%% %s is not a valid prefix-list name\n",
prefix_list_str);
return CMD_WARNING;
}
return bgp_show(vty, bgp, afi, safi, type, plist, show_flags,
RPKI_NOT_BEING_USED);
}
static int bgp_show_filter_list(struct vty *vty, struct bgp *bgp,
const char *filter, afi_t afi, safi_t safi,
enum bgp_show_type type)
{
struct as_list *as_list;
uint16_t show_flags = 0;
as_list = as_list_lookup(filter);
if (as_list == NULL) {
vty_out(vty, "%% %s is not a valid AS-path access-list name\n",
filter);
return CMD_WARNING;
}
return bgp_show(vty, bgp, afi, safi, type, as_list, show_flags,
RPKI_NOT_BEING_USED);
}
static int bgp_show_route_map(struct vty *vty, struct bgp *bgp,
const char *rmap_str, afi_t afi, safi_t safi,
enum bgp_show_type type)
{
struct route_map *rmap;
uint16_t show_flags = 0;
rmap = route_map_lookup_by_name(rmap_str);
if (!rmap) {
vty_out(vty, "%% %s is not a valid route-map name\n", rmap_str);
return CMD_WARNING;
}
return bgp_show(vty, bgp, afi, safi, type, rmap, show_flags,
RPKI_NOT_BEING_USED);
}
static int bgp_show_community(struct vty *vty, struct bgp *bgp,
const char *comstr, int exact, afi_t afi,
safi_t safi, uint16_t show_flags)
{
struct community *com;
int ret = 0;
com = community_str2com(comstr);
if (!com) {
vty_out(vty, "%% Community malformed: %s\n", comstr);
return CMD_WARNING;
}
ret = bgp_show(vty, bgp, afi, safi,
(exact ? bgp_show_type_community_exact
: bgp_show_type_community),
com, show_flags, RPKI_NOT_BEING_USED);
community_free(&com);
return ret;
}
static int bgp_show_community_list(struct vty *vty, struct bgp *bgp,
const char *com, int exact, afi_t afi,
safi_t safi)
{
struct community_list *list;
uint16_t show_flags = 0;
list = community_list_lookup(bgp_clist, com, 0, COMMUNITY_LIST_MASTER);
if (list == NULL) {
vty_out(vty, "%% %s is not a valid community-list name\n", com);
return CMD_WARNING;
}
return bgp_show(vty, bgp, afi, safi,
(exact ? bgp_show_type_community_list_exact
: bgp_show_type_community_list),
list, show_flags, RPKI_NOT_BEING_USED);
}
static int bgp_show_prefix_longer(struct vty *vty, struct bgp *bgp,
const char *prefix, afi_t afi, safi_t safi,
enum bgp_show_type type)
{
int ret;
struct prefix *p;
uint16_t show_flags = 0;
p = prefix_new();
ret = str2prefix(prefix, p);
if (!ret) {
vty_out(vty, "%% Malformed Prefix\n");
return CMD_WARNING;
}
ret = bgp_show(vty, bgp, afi, safi, type, p, show_flags,
RPKI_NOT_BEING_USED);
prefix_free(&p);
return ret;
}
enum bgp_stats {
BGP_STATS_MAXBITLEN = 0,
BGP_STATS_RIB,
BGP_STATS_PREFIXES,
BGP_STATS_TOTPLEN,
BGP_STATS_UNAGGREGATEABLE,
BGP_STATS_MAX_AGGREGATEABLE,
BGP_STATS_AGGREGATES,
BGP_STATS_SPACE,
BGP_STATS_ASPATH_COUNT,
BGP_STATS_ASPATH_MAXHOPS,
BGP_STATS_ASPATH_TOTHOPS,
BGP_STATS_ASPATH_MAXSIZE,
BGP_STATS_ASPATH_TOTSIZE,
BGP_STATS_ASN_HIGHEST,
BGP_STATS_MAX,
};
#define TABLE_STATS_IDX_VTY 0
#define TABLE_STATS_IDX_JSON 1
static const char *table_stats_strs[][2] = {
[BGP_STATS_PREFIXES] = {"Total Prefixes", "totalPrefixes"},
[BGP_STATS_TOTPLEN] = {"Average prefix length", "averagePrefixLength"},
[BGP_STATS_RIB] = {"Total Advertisements", "totalAdvertisements"},
[BGP_STATS_UNAGGREGATEABLE] = {"Unaggregateable prefixes",
"unaggregateablePrefixes"},
[BGP_STATS_MAX_AGGREGATEABLE] = {"Maximum aggregateable prefixes",
"maximumAggregateablePrefixes"},
[BGP_STATS_AGGREGATES] = {"BGP Aggregate advertisements",
"bgpAggregateAdvertisements"},
[BGP_STATS_SPACE] = {"Address space advertised",
"addressSpaceAdvertised"},
[BGP_STATS_ASPATH_COUNT] = {"Advertisements with paths",
"advertisementsWithPaths"},
[BGP_STATS_ASPATH_MAXHOPS] = {"Longest AS-Path (hops)",
"longestAsPath"},
[BGP_STATS_ASPATH_MAXSIZE] = {"Largest AS-Path (bytes)",
"largestAsPath"},
[BGP_STATS_ASPATH_TOTHOPS] = {"Average AS-Path length (hops)",
"averageAsPathLengthHops"},
[BGP_STATS_ASPATH_TOTSIZE] = {"Average AS-Path size (bytes)",
"averageAsPathSizeBytes"},
[BGP_STATS_ASN_HIGHEST] = {"Highest public ASN", "highestPublicAsn"},
[BGP_STATS_MAX] = {NULL, NULL}
};
struct bgp_table_stats {
struct bgp_table *table;
unsigned long long counts[BGP_STATS_MAX];
double total_space;
};
static void bgp_table_stats_rn(struct bgp_dest *dest, struct bgp_dest *top,
struct bgp_table_stats *ts, unsigned int space)
{
struct bgp_dest *pdest = bgp_dest_parent_nolock(dest);
struct bgp_path_info *pi;
const struct prefix *rn_p;
if (!bgp_dest_has_bgp_path_info_data(dest))
return;
rn_p = bgp_dest_get_prefix(dest);
ts->counts[BGP_STATS_PREFIXES]++;
ts->counts[BGP_STATS_TOTPLEN] += rn_p->prefixlen;
/* check if the prefix is included by any other announcements */
while (pdest && !bgp_dest_has_bgp_path_info_data(pdest))
pdest = bgp_dest_parent_nolock(pdest);
if (pdest == NULL || pdest == top) {
ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
/* announced address space */
if (space)
ts->total_space += pow(2.0, space - rn_p->prefixlen);
} else if (bgp_dest_has_bgp_path_info_data(pdest))
ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) {
ts->counts[BGP_STATS_RIB]++;
if (CHECK_FLAG(pi->attr->flag,
ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE)))
ts->counts[BGP_STATS_AGGREGATES]++;
/* as-path stats */
if (pi->attr->aspath) {
unsigned int hops = aspath_count_hops(pi->attr->aspath);
unsigned int size = aspath_size(pi->attr->aspath);
as_t highest = aspath_highest(pi->attr->aspath);
ts->counts[BGP_STATS_ASPATH_COUNT]++;
if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
}
}
}
static int bgp_table_stats_walker(struct thread *t)
{
struct bgp_dest *dest, *ndest;
struct bgp_dest *top;
struct bgp_table_stats *ts = THREAD_ARG(t);
unsigned int space = 0;
if (!(top = bgp_table_top(ts->table)))
return 0;
switch (ts->table->afi) {
case AFI_IP:
space = IPV4_MAX_BITLEN;
break;
case AFI_IP6:
space = IPV6_MAX_BITLEN;
break;
case AFI_L2VPN:
space = EVPN_ROUTE_PREFIXLEN;
break;
default:
return 0;
}
ts->counts[BGP_STATS_MAXBITLEN] = space;
for (dest = top; dest; dest = bgp_route_next(dest)) {
if (ts->table->safi == SAFI_MPLS_VPN
|| ts->table->safi == SAFI_ENCAP
|| ts->table->safi == SAFI_EVPN) {
struct bgp_table *table;
table = bgp_dest_get_bgp_table_info(dest);
if (!table)
continue;
top = bgp_table_top(table);
for (ndest = bgp_table_top(table); ndest;
ndest = bgp_route_next(ndest))
bgp_table_stats_rn(ndest, top, ts, space);
} else {
bgp_table_stats_rn(dest, top, ts, space);
}
}
return 0;
}
static void bgp_table_stats_all(struct vty *vty, afi_t afi, safi_t safi,
struct json_object *json_array)
{
struct listnode *node, *nnode;
struct bgp *bgp;
for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp))
bgp_table_stats_single(vty, bgp, afi, safi, json_array);
}
static int bgp_table_stats_single(struct vty *vty, struct bgp *bgp, afi_t afi,
safi_t safi, struct json_object *json_array)
{
struct bgp_table_stats ts;
unsigned int i;
int ret = CMD_SUCCESS;
char temp_buf[20];
struct json_object *json = NULL;
if (json_array)
json = json_object_new_object();
if (!bgp->rib[afi][safi]) {
char warning_msg[50];
snprintf(warning_msg, sizeof(warning_msg),
"%% No RIB exist's for the AFI(%d)/SAFI(%d)", afi,
safi);
if (!json)
vty_out(vty, "%s\n", warning_msg);
else
json_object_string_add(json, "warning", warning_msg);
ret = CMD_WARNING;
goto end_table_stats;
}
if (!json)
vty_out(vty, "BGP %s RIB statistics (%s)\n",
get_afi_safi_str(afi, safi, false), bgp->name_pretty);
else
json_object_string_add(json, "instance", bgp->name_pretty);
/* labeled-unicast routes live in the unicast table */
if (safi == SAFI_LABELED_UNICAST)
safi = SAFI_UNICAST;
memset(&ts, 0, sizeof(ts));
ts.table = bgp->rib[afi][safi];
thread_execute(bm->master, bgp_table_stats_walker, &ts, 0);
for (i = 0; i < BGP_STATS_MAX; i++) {
if ((!json && !table_stats_strs[i][TABLE_STATS_IDX_VTY])
|| (json && !table_stats_strs[i][TABLE_STATS_IDX_JSON]))
continue;
switch (i) {
case BGP_STATS_ASPATH_TOTHOPS:
case BGP_STATS_ASPATH_TOTSIZE:
if (!json) {
snprintf(
temp_buf, sizeof(temp_buf), "%12.2f",
ts.counts[i]
? (float)ts.counts[i]
/ (float)ts.counts
[BGP_STATS_ASPATH_COUNT]
: 0);
vty_out(vty, "%-30s: %s",
table_stats_strs[i]
[TABLE_STATS_IDX_VTY],
temp_buf);
} else {
json_object_double_add(
json,
table_stats_strs[i]
[TABLE_STATS_IDX_JSON],
ts.counts[i]
? (double)ts.counts[i]
/ (double)ts.counts
[BGP_STATS_ASPATH_COUNT]
: 0);
}
break;
case BGP_STATS_TOTPLEN:
if (!json) {
snprintf(
temp_buf, sizeof(temp_buf), "%12.2f",
ts.counts[i]
? (float)ts.counts[i]
/ (float)ts.counts
[BGP_STATS_PREFIXES]
: 0);
vty_out(vty, "%-30s: %s",
table_stats_strs[i]
[TABLE_STATS_IDX_VTY],
temp_buf);
} else {
json_object_double_add(
json,
table_stats_strs[i]
[TABLE_STATS_IDX_JSON],
ts.counts[i]
? (double)ts.counts[i]
/ (double)ts.counts
[BGP_STATS_PREFIXES]
: 0);
}
break;
case BGP_STATS_SPACE:
if (!json) {
snprintf(temp_buf, sizeof(temp_buf), "%12g",
ts.total_space);
vty_out(vty, "%-30s: %s\n",
table_stats_strs[i]
[TABLE_STATS_IDX_VTY],
temp_buf);
} else {
json_object_double_add(
json,
table_stats_strs[i]
[TABLE_STATS_IDX_JSON],
(double)ts.total_space);
}
if (afi == AFI_IP6) {
if (!json) {
snprintf(temp_buf, sizeof(temp_buf),
"%12g",
ts.total_space
* pow(2.0, -128 + 32));
vty_out(vty, "%30s: %s\n",
"/32 equivalent %s\n",
temp_buf);
} else {
json_object_double_add(
json, "/32equivalent",
(double)(ts.total_space
* pow(2.0,
-128 + 32)));
}
if (!json) {
snprintf(temp_buf, sizeof(temp_buf),
"%12g",
ts.total_space
* pow(2.0, -128 + 48));
vty_out(vty, "%30s: %s\n",
"/48 equivalent %s\n",
temp_buf);
} else {
json_object_double_add(
json, "/48equivalent",
(double)(ts.total_space
* pow(2.0,
-128 + 48)));
}
} else {
if (!json) {
snprintf(temp_buf, sizeof(temp_buf),
"%12.2f",
ts.total_space * 100.
* pow(2.0, -32));
vty_out(vty, "%30s: %s\n",
"% announced ", temp_buf);
} else {
json_object_double_add(
json, "%announced",
(double)(ts.total_space * 100.
* pow(2.0, -32)));
}
if (!json) {
snprintf(temp_buf, sizeof(temp_buf),
"%12.2f",
ts.total_space
* pow(2.0, -32 + 8));
vty_out(vty, "%30s: %s\n",
"/8 equivalent ", temp_buf);
} else {
json_object_double_add(
json, "/8equivalent",
(double)(ts.total_space
* pow(2.0, -32 + 8)));
}
if (!json) {
snprintf(temp_buf, sizeof(temp_buf),
"%12.2f",
ts.total_space
* pow(2.0, -32 + 24));
vty_out(vty, "%30s: %s\n",
"/24 equivalent ", temp_buf);
} else {
json_object_double_add(
json, "/24equivalent",
(double)(ts.total_space
* pow(2.0, -32 + 24)));
}
}
break;
default:
if (!json) {
snprintf(temp_buf, sizeof(temp_buf), "%12llu",
ts.counts[i]);
vty_out(vty, "%-30s: %s",
table_stats_strs[i]
[TABLE_STATS_IDX_VTY],
temp_buf);
} else {
json_object_int_add(
json,
table_stats_strs[i]
[TABLE_STATS_IDX_JSON],
ts.counts[i]);
}
}
if (!json)
vty_out(vty, "\n");
}
end_table_stats:
if (json)
json_object_array_add(json_array, json);
return ret;
}
static int bgp_table_stats(struct vty *vty, struct bgp *bgp, afi_t afi,
safi_t safi, struct json_object *json_array)
{
if (!bgp) {
bgp_table_stats_all(vty, afi, safi, json_array);
return CMD_SUCCESS;
}
return bgp_table_stats_single(vty, bgp, afi, safi, json_array);
}
enum bgp_pcounts {
PCOUNT_ADJ_IN = 0,
PCOUNT_DAMPED,
PCOUNT_REMOVED,
PCOUNT_HISTORY,
PCOUNT_STALE,
PCOUNT_VALID,
PCOUNT_ALL,
PCOUNT_COUNTED,
PCOUNT_BPATH_SELECTED,
PCOUNT_PFCNT, /* the figure we display to users */
PCOUNT_MAX,
};
static const char *const pcount_strs[] = {
[PCOUNT_ADJ_IN] = "Adj-in",
[PCOUNT_DAMPED] = "Damped",
[PCOUNT_REMOVED] = "Removed",
[PCOUNT_HISTORY] = "History",
[PCOUNT_STALE] = "Stale",
[PCOUNT_VALID] = "Valid",
[PCOUNT_ALL] = "All RIB",
[PCOUNT_COUNTED] = "PfxCt counted",
[PCOUNT_BPATH_SELECTED] = "PfxCt Best Selected",
[PCOUNT_PFCNT] = "Useable",
[PCOUNT_MAX] = NULL,
};
struct peer_pcounts {
unsigned int count[PCOUNT_MAX];
const struct peer *peer;
const struct bgp_table *table;
safi_t safi;
};
static void bgp_peer_count_proc(struct bgp_dest *rn, struct peer_pcounts *pc)
{
const struct bgp_adj_in *ain;
const struct bgp_path_info *pi;
const struct peer *peer = pc->peer;
for (ain = rn->adj_in; ain; ain = ain->next)
if (ain->peer == peer)
pc->count[PCOUNT_ADJ_IN]++;
for (pi = bgp_dest_get_bgp_path_info(rn); pi; pi = pi->next) {
if (pi->peer != peer)
continue;
pc->count[PCOUNT_ALL]++;
if (CHECK_FLAG(pi->flags, BGP_PATH_DAMPED))
pc->count[PCOUNT_DAMPED]++;
if (CHECK_FLAG(pi->flags, BGP_PATH_HISTORY))
pc->count[PCOUNT_HISTORY]++;
if (CHECK_FLAG(pi->flags, BGP_PATH_REMOVED))
pc->count[PCOUNT_REMOVED]++;
if (CHECK_FLAG(pi->flags, BGP_PATH_STALE))
pc->count[PCOUNT_STALE]++;
if (CHECK_FLAG(pi->flags, BGP_PATH_VALID))
pc->count[PCOUNT_VALID]++;
if (!CHECK_FLAG(pi->flags, BGP_PATH_UNUSEABLE))
pc->count[PCOUNT_PFCNT]++;
if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED))
pc->count[PCOUNT_BPATH_SELECTED]++;
if (CHECK_FLAG(pi->flags, BGP_PATH_COUNTED)) {
pc->count[PCOUNT_COUNTED]++;
if (CHECK_FLAG(pi->flags, BGP_PATH_UNUSEABLE))
flog_err(
EC_LIB_DEVELOPMENT,
"Attempting to count but flags say it is unusable");
} else {
if (!CHECK_FLAG(pi->flags, BGP_PATH_UNUSEABLE))
flog_err(
EC_LIB_DEVELOPMENT,
"Not counted but flags say we should");
}
}
}
static int bgp_peer_count_walker(struct thread *t)
{
struct bgp_dest *rn, *rm;
const struct bgp_table *table;
struct peer_pcounts *pc = THREAD_ARG(t);
if (pc->safi == SAFI_MPLS_VPN || pc->safi == SAFI_ENCAP
|| pc->safi == SAFI_EVPN) {
/* Special handling for 2-level routing tables. */
for (rn = bgp_table_top(pc->table); rn;
rn = bgp_route_next(rn)) {
table = bgp_dest_get_bgp_table_info(rn);
if (table != NULL)
for (rm = bgp_table_top(table); rm;
rm = bgp_route_next(rm))
bgp_peer_count_proc(rm, pc);
}
} else
for (rn = bgp_table_top(pc->table); rn; rn = bgp_route_next(rn))
bgp_peer_count_proc(rn, pc);
return 0;
}
static int bgp_peer_counts(struct vty *vty, struct peer *peer, afi_t afi,
safi_t safi, bool use_json)
{
struct peer_pcounts pcounts = {.peer = peer};
unsigned int i;
json_object *json = NULL;
json_object *json_loop = NULL;
if (use_json) {
json = json_object_new_object();
json_loop = json_object_new_object();
}
if (!peer || !peer->bgp || !peer->afc[afi][safi]
|| !peer->bgp->rib[afi][safi]) {
if (use_json) {
json_object_string_add(
json, "warning",
"No such neighbor or address family");
vty_out(vty, "%s\n", json_object_to_json_string(json));
json_object_free(json);
json_object_free(json_loop);
} else
vty_out(vty, "%% No such neighbor or address family\n");
return CMD_WARNING;
}
memset(&pcounts, 0, sizeof(pcounts));
pcounts.peer = peer;
pcounts.table = peer->bgp->rib[afi][safi];
pcounts.safi = safi;
/* in-place call via thread subsystem so as to record execution time
* stats for the thread-walk (i.e. ensure this can't be blamed on
* on just vty_read()).
*/
thread_execute(bm->master, bgp_peer_count_walker, &pcounts, 0);
if (use_json) {
json_object_string_add(json, "prefixCountsFor", peer->host);
json_object_string_add(json, "multiProtocol",
get_afi_safi_str(afi, safi, true));
json_object_int_add(json, "pfxCounter",
peer->pcount[afi][safi]);
for (i = 0; i < PCOUNT_MAX; i++)
json_object_int_add(json_loop, pcount_strs[i],
pcounts.count[i]);
json_object_object_add(json, "ribTableWalkCounters", json_loop);
if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi]) {
json_object_string_add(json, "pfxctDriftFor",
peer->host);
json_object_string_add(
json, "recommended",
"Please report this bug, with the above command output");
}
vty_out(vty, "%s\n", json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
} else {
if (peer->hostname
&& CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHOW_HOSTNAME)) {
vty_out(vty, "Prefix counts for %s/%s, %s\n",
peer->hostname, peer->host,
get_afi_safi_str(afi, safi, false));
} else {
vty_out(vty, "Prefix counts for %s, %s\n", peer->host,
get_afi_safi_str(afi, safi, false));
}
vty_out(vty, "PfxCt: %u\n", peer->pcount[afi][safi]);
vty_out(vty, "\nCounts from RIB table walk:\n\n");
for (i = 0; i < PCOUNT_MAX; i++)
vty_out(vty, "%20s: %-10d\n", pcount_strs[i],
pcounts.count[i]);
if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi]) {
vty_out(vty, "%s [pcount] PfxCt drift!\n", peer->host);
vty_out(vty,
"Please report this bug, with the above command output\n");
}
}
return CMD_SUCCESS;
}
DEFUN (show_ip_bgp_instance_neighbor_prefix_counts,
show_ip_bgp_instance_neighbor_prefix_counts_cmd,
"show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] neighbors <A.B.C.D|X:X::X:X|WORD> prefix-counts [json]",
SHOW_STR
IP_STR
BGP_STR
BGP_INSTANCE_HELP_STR
BGP_AFI_HELP_STR
BGP_SAFI_HELP_STR
"Detailed information on TCP and BGP neighbor connections\n"
"Neighbor to display information about\n"
"Neighbor to display information about\n"
"Neighbor on BGP configured interface\n"
"Display detailed prefix count information\n"
JSON_STR)
{
afi_t afi = AFI_IP6;
safi_t safi = SAFI_UNICAST;
struct peer *peer;
int idx = 0;
struct bgp *bgp = NULL;
bool uj = use_json(argc, argv);
if (uj)
argc--;
bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi,
&bgp, uj);
if (!idx)
return CMD_WARNING;
argv_find(argv, argc, "neighbors", &idx);
peer = peer_lookup_in_view(vty, bgp, argv[idx + 1]->arg, uj);
if (!peer)
return CMD_WARNING;
return bgp_peer_counts(vty, peer, afi, safi, uj);
}
#ifdef KEEP_OLD_VPN_COMMANDS
DEFUN (show_ip_bgp_vpn_neighbor_prefix_counts,
show_ip_bgp_vpn_neighbor_prefix_counts_cmd,
"show [ip] bgp <vpnv4|vpnv6> all neighbors <A.B.C.D|X:X::X:X|WORD> prefix-counts [json]",
SHOW_STR
IP_STR
BGP_STR
BGP_VPNVX_HELP_STR
"Display information about all VPNv4 NLRIs\n"
"Detailed information on TCP and BGP neighbor connections\n"
"Neighbor to display information about\n"
"Neighbor to display information about\n"
"Neighbor on BGP configured interface\n"
"Display detailed prefix count information\n"
JSON_STR)
{
int idx_peer = 6;
struct peer *peer;
bool uj = use_json(argc, argv);
peer = peer_lookup_in_view(vty, NULL, argv[idx_peer]->arg, uj);
if (!peer)
return CMD_WARNING;
return bgp_peer_counts(vty, peer, AFI_IP, SAFI_MPLS_VPN, uj);
}
DEFUN (show_ip_bgp_vpn_all_route_prefix,
show_ip_bgp_vpn_all_route_prefix_cmd,
"show [ip] bgp <vpnv4|vpnv6> all <A.B.C.D|A.B.C.D/M> [json]",
SHOW_STR
IP_STR
BGP_STR
BGP_VPNVX_HELP_STR
"Display information about all VPNv4 NLRIs\n"
"Network in the BGP routing table to display\n"
"Network in the BGP routing table to display\n"
JSON_STR)
{
int idx = 0;
char *network = NULL;
struct bgp *bgp = bgp_get_default();
if (!bgp) {
vty_out(vty, "Can't find default instance\n");
return CMD_WARNING;
}
if (argv_find(argv, argc, "A.B.C.D", &idx))
network = argv[idx]->arg;
else if (argv_find(argv, argc, "A.B.C.D/M", &idx))
network = argv[idx]->arg;
else {
vty_out(vty, "Unable to figure out Network\n");
return CMD_WARNING;
}
return bgp_show_route(vty, bgp, network, AFI_IP, SAFI_MPLS_VPN, NULL, 0,
BGP_PATH_SHOW_ALL, RPKI_NOT_BEING_USED,
use_json(argc, argv));
}
#endif /* KEEP_OLD_VPN_COMMANDS */
DEFUN (show_bgp_l2vpn_evpn_route_prefix,
show_bgp_l2vpn_evpn_route_prefix_cmd,
"show bgp l2vpn evpn <A.B.C.D|A.B.C.D/M|X:X::X:X|X:X::X:X/M> [json]",
SHOW_STR
BGP_STR
L2VPN_HELP_STR
EVPN_HELP_STR
"Network in the BGP routing table to display\n"
"Network in the BGP routing table to display\n"
"Network in the BGP routing table to display\n"
"Network in the BGP routing table to display\n"
JSON_STR)
{
int idx = 0;
char *network = NULL;
int prefix_check = 0;
if (argv_find(argv, argc, "A.B.C.D", &idx) ||
argv_find(argv, argc, "X:X::X:X", &idx))
network = argv[idx]->arg;
else if (argv_find(argv, argc, "A.B.C.D/M", &idx) ||
argv_find(argv, argc, "X:X::X:X/M", &idx)) {
network = argv[idx]->arg;
prefix_check = 1;
} else {
vty_out(vty, "Unable to figure out Network\n");
return CMD_WARNING;
}
return bgp_show_route(vty, NULL, network, AFI_L2VPN, SAFI_EVPN, NULL,
prefix_check, BGP_PATH_SHOW_ALL,
RPKI_NOT_BEING_USED, use_json(argc, argv));
}
static void show_adj_route_header(struct vty *vty, struct bgp *bgp,
struct bgp_table *table, int *header1,
int *header2, json_object *json,
json_object *json_scode,
json_object *json_ocode, bool wide)
{
uint64_t version = table ? table->version : 0;
char buf[BUFSIZ] = {0};
if (*header1) {
if (json) {
json_object_int_add(json, "bgpTableVersion", version);
json_object_string_add(json, "bgpLocalRouterId",
inet_ntop(AF_INET,
&bgp->router_id, buf,
sizeof(buf)));
json_object_int_add(json, "defaultLocPrf",
bgp->default_local_pref);
json_object_int_add(json, "localAS", bgp->as);
json_object_object_add(json, "bgpStatusCodes",
json_scode);
json_object_object_add(json, "bgpOriginCodes",
json_ocode);
} else {
vty_out(vty,
"BGP table version is %" PRIu64
", local router ID is %pI4, vrf id ",
version, &bgp->router_id);
if (bgp->vrf_id == VRF_UNKNOWN)
vty_out(vty, "%s", VRFID_NONE_STR);
else
vty_out(vty, "%u", bgp->vrf_id);
vty_out(vty, "\n");
vty_out(vty, "Default local pref %u, ",
bgp->default_local_pref);
vty_out(vty, "local AS %u\n", bgp->as);
vty_out(vty, BGP_SHOW_SCODE_HEADER);
vty_out(vty, BGP_SHOW_NCODE_HEADER);
vty_out(vty, BGP_SHOW_OCODE_HEADER);
vty_out(vty, BGP_SHOW_RPKI_HEADER);
}
*header1 = 0;
}
if (*header2) {
if (!json)
vty_out(vty, (wide ? BGP_SHOW_HEADER_WIDE
: BGP_SHOW_HEADER));
*header2 = 0;
}
}
static void
show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table,
afi_t afi, safi_t safi, enum bgp_show_adj_route_type type,
const char *rmap_name, json_object *json, json_object *json_ar,
json_object *json_scode, json_object *json_ocode,
uint16_t show_flags, int *header1, int *header2, char *rd_str,
unsigned long *output_count, unsigned long *filtered_count)
{
struct bgp_adj_in *ain;
struct bgp_adj_out *adj;
struct bgp_dest *dest;
struct bgp *bgp;
struct attr attr;
int ret;
struct update_subgroup *subgrp;
struct peer_af *paf;
bool route_filtered;
bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
bool wide = CHECK_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
bool show_rd = ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)
|| (safi == SAFI_EVPN))
? true
: false;
bgp = peer->bgp;
subgrp = peer_subgroup(peer, afi, safi);
if (type == bgp_show_adj_route_advertised && subgrp
&& CHECK_FLAG(subgrp->sflags, SUBGRP_STATUS_DEFAULT_ORIGINATE)) {
char buf[BUFSIZ] = {0};
if (use_json) {
json_object_int_add(json, "bgpTableVersion",
table->version);
json_object_string_add(json, "bgpLocalRouterId",
inet_ntop(AF_INET,
&bgp->router_id, buf,
sizeof(buf)));
json_object_int_add(json, "defaultLocPrf",
bgp->default_local_pref);
json_object_int_add(json, "localAS", bgp->as);
json_object_object_add(json, "bgpStatusCodes",
json_scode);
json_object_object_add(json, "bgpOriginCodes",
json_ocode);
json_object_string_add(
json, "bgpOriginatingDefaultNetwork",
(afi == AFI_IP) ? "0.0.0.0/0" : "::/0");
} else {
vty_out(vty,
"BGP table version is %" PRIu64
", local router ID is %pI4, vrf id ",
table->version, &bgp->router_id);
if (bgp->vrf_id == VRF_UNKNOWN)
vty_out(vty, "%s", VRFID_NONE_STR);
else
vty_out(vty, "%u", bgp->vrf_id);
vty_out(vty, "\n");
vty_out(vty, "Default local pref %u, ",
bgp->default_local_pref);
vty_out(vty, "local AS %u\n", bgp->as);
vty_out(vty, BGP_SHOW_SCODE_HEADER);
vty_out(vty, BGP_SHOW_NCODE_HEADER);
vty_out(vty, BGP_SHOW_OCODE_HEADER);
vty_out(vty, BGP_SHOW_RPKI_HEADER);
vty_out(vty, "Originating default network %s\n\n",
(afi == AFI_IP) ? "0.0.0.0/0" : "::/0");
}
*header1 = 0;
}
for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) {
if (type == bgp_show_adj_route_received
|| type == bgp_show_adj_route_filtered) {
for (ain = dest->adj_in; ain; ain = ain->next) {
if (ain->peer != peer)
continue;
show_adj_route_header(vty, bgp, table, header1,
header2, json, json_scode,
json_ocode, wide);
if ((safi == SAFI_MPLS_VPN)
|| (safi == SAFI_ENCAP)
|| (safi == SAFI_EVPN)) {
if (use_json)
json_object_string_add(
json_ar, "rd", rd_str);
else if (show_rd && rd_str) {
vty_out(vty,
"Route Distinguisher: %s\n",
rd_str);
show_rd = false;
}
}
attr = *ain->attr;
route_filtered = false;
/* Filter prefix using distribute list,
* filter list or prefix list
*/
const struct prefix *rn_p =
bgp_dest_get_prefix(dest);
if ((bgp_input_filter(peer, rn_p, &attr, afi,
safi))
== FILTER_DENY)
route_filtered = true;
/* Filter prefix using route-map */
ret = bgp_input_modifier(peer, rn_p, &attr, afi,
safi, rmap_name, NULL,
0, NULL);
if (type == bgp_show_adj_route_filtered &&
!route_filtered && ret != RMAP_DENY) {
bgp_attr_undup(&attr, ain->attr);
continue;
}
if (type == bgp_show_adj_route_received
&& (route_filtered || ret == RMAP_DENY))
(*filtered_count)++;
route_vty_out_tmp(vty, dest, rn_p, &attr, safi,
use_json, json_ar, wide);
bgp_attr_undup(&attr, ain->attr);
(*output_count)++;
}
} else if (type == bgp_show_adj_route_advertised) {
RB_FOREACH (adj, bgp_adj_out_rb, &dest->adj_out)
SUBGRP_FOREACH_PEER (adj->subgroup, paf) {
if (paf->peer != peer || !adj->attr)
continue;
show_adj_route_header(vty, bgp, table,
header1, header2,
json, json_scode,
json_ocode, wide);
const struct prefix *rn_p =
bgp_dest_get_prefix(dest);
attr = *adj->attr;
ret = bgp_output_modifier(
peer, rn_p, &attr, afi, safi,
rmap_name);
if (ret != RMAP_DENY) {
if ((safi == SAFI_MPLS_VPN)
|| (safi == SAFI_ENCAP)
|| (safi == SAFI_EVPN)) {
if (use_json)
json_object_string_add(
json_ar,
"rd",
rd_str);
else if (show_rd
&& rd_str) {
vty_out(vty,
"Route Distinguisher: %s\n",
rd_str);
show_rd = false;
}
}
route_vty_out_tmp(
vty, dest, rn_p, &attr,
safi, use_json, json_ar,
wide);
(*output_count)++;
} else {
(*filtered_count)++;
}
bgp_attr_undup(&attr, adj->attr);
}
} else if (type == bgp_show_adj_route_bestpath) {
struct bgp_path_info *pi;
show_adj_route_header(vty, bgp, table, header1, header2,
json, json_scode, json_ocode,
wide);
for (pi = bgp_dest_get_bgp_path_info(dest); pi;
pi = pi->next) {
if (pi->peer != peer)
continue;
if (!CHECK_FLAG(pi->flags, BGP_PATH_SELECTED))
continue;
route_vty_out_tmp(vty, dest,
bgp_dest_get_prefix(dest),
pi->attr, safi, use_json,
json_ar, wide);
(*output_count)++;
}
}
}
}
static int peer_adj_routes(struct vty *vty, struct peer *peer, afi_t afi,
safi_t safi, enum bgp_show_adj_route_type type,
const char *rmap_name, uint16_t show_flags)
{
struct bgp *bgp;
struct bgp_table *table;
json_object *json = NULL;
json_object *json_scode = NULL;
json_object *json_ocode = NULL;
json_object *json_ar = NULL;
bool use_json = CHECK_FLAG(show_flags, BGP_SHOW_OPT_JSON);
/* Init BGP headers here so they're only displayed once
* even if 'table' is 2-tier (MPLS_VPN, ENCAP, EVPN).
*/
int header1 = 1;
int header2 = 1;
/*
* Initialize variables for each RD
* All prefixes under an RD is aggregated within "json_routes"
*/
char rd_str[BUFSIZ] = {0};
json_object *json_routes = NULL;
/* For 2-tier tables, prefix counts need to be
* maintained across multiple runs of show_adj_route()
*/
unsigned long output_count_per_rd;
unsigned long filtered_count_per_rd;
unsigned long output_count = 0;
unsigned long filtered_count = 0;
if (use_json) {
json = json_object_new_object();
json_ar = json_object_new_object();
json_scode = json_object_new_object();
json_ocode = json_object_new_object();
json_object_string_add(json_scode, "suppressed", "s");
json_object_string_add(json_scode, "damped", "d");
json_object_string_add(json_scode, "history", "h");
json_object_string_add(json_scode, "valid", "*");
json_object_string_add(json_scode, "best", ">");
json_object_string_add(json_scode, "multipath", "=");
json_object_string_add(json_scode, "internal", "i");
json_object_string_add(json_scode, "ribFailure", "r");
json_object_string_add(json_scode, "stale", "S");
json_object_string_add(json_scode, "removed", "R");
json_object_string_add(json_ocode, "igp", "i");
json_object_string_add(json_ocode, "egp", "e");
json_object_string_add(json_ocode, "incomplete", "?");
}
if (!peer || !peer->afc[afi][safi]) {
if (use_json) {
json_object_string_add(
json, "warning",
"No such neighbor or address family");
vty_out(vty, "%s\n", json_object_to_json_string(json));
json_object_free(json);
json_object_free(json_ar);
json_object_free(json_scode);
json_object_free(json_ocode);
} else
vty_out(vty, "%% No such neighbor or address family\n");
return CMD_WARNING;
}
if ((type == bgp_show_adj_route_received
|| type == bgp_show_adj_route_filtered)
&& !CHECK_FLAG(peer->af_flags[afi][safi],
PEER_FLAG_SOFT_RECONFIG)) {
if (use_json) {
json_object_string_add(
json, "warning",
"Inbound soft reconfiguration not enabled");
vty_out(vty, "%s\n", json_object_to_json_string(json));
json_object_free(json);
json_object_free(json_ar);
json_object_free(json_scode);
json_object_free(json_ocode);
} else
vty_out(vty,
"%% Inbound soft reconfiguration not enabled\n");
return CMD_WARNING;
}
bgp = peer->bgp;
/* labeled-unicast routes live in the unicast table */
if (safi == SAFI_LABELED_UNICAST)
table = bgp->rib[afi][SAFI_UNICAST];
else
table = bgp->rib[afi][safi];
if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)
|| (safi == SAFI_EVPN)) {
struct bgp_dest *dest;
for (dest = bgp_table_top(table); dest;
dest = bgp_route_next(dest)) {
table = bgp_dest_get_bgp_table_info(dest);
if (!table)
continue;
output_count_per_rd = 0;
filtered_count_per_rd = 0;
if (use_json)
json_routes = json_object_new_object();
const struct prefix_rd *prd;
prd = (const struct prefix_rd *)bgp_dest_get_prefix(
dest);
prefix_rd2str(prd, rd_str, sizeof(rd_str));
show_adj_route(vty, peer, table, afi, safi, type,
rmap_name, json, json_routes, json_scode,
json_ocode, show_flags, &header1,
&header2, rd_str, &output_count_per_rd,
&filtered_count_per_rd);
/* Don't include an empty RD in the output! */
if (json_routes && (output_count_per_rd > 0))
json_object_object_add(json_ar, rd_str,
json_routes);
output_count += output_count_per_rd;
filtered_count += filtered_count_per_rd;
}
} else
show_adj_route(vty, peer, table, afi, safi, type, rmap_name,
json, json_ar, json_scode, json_ocode,
show_flags, &header1, &header2, rd_str,
&output_count, &filtered_count);
if (use_json) {
json_object_object_add(json, "advertisedRoutes", json_ar);
json_object_int_add(json, "totalPrefixCounter", output_count);
json_object_int_add(json, "filteredPrefixCounter",
filtered_count);
vty_out(vty, "%s\n",
json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
/*
* These fields only give up ownership to `json` when `header1`
* is used (set to zero). See code in `show_adj_route` and
* `show_adj_route_header`.
*/
if (header1 == 1) {
json_object_free(json_scode);
json_object_free(json_ocode);
}
json_object_free(json);
} else if (output_count > 0) {
if (filtered_count > 0)
vty_out(vty,
"\nTotal number of prefixes %ld (%ld filtered)\n",
output_count, filtered_count);
else
vty_out(vty, "\nTotal number of prefixes %ld\n",
output_count);
}
return CMD_SUCCESS;
}
DEFPY (show_ip_bgp_instance_neighbor_bestpath_route,
show_ip_bgp_instance_neighbor_bestpath_route_cmd,
"show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] neighbors <A.B.C.D|X:X::X:X|WORD> bestpath-routes [json$uj | wide$wide]",
SHOW_STR
IP_STR
BGP_STR
BGP_INSTANCE_HELP_STR
BGP_AFI_HELP_STR
BGP_SAFI_WITH_LABEL_HELP_STR
"Detailed information on TCP and BGP neighbor connections\n"
"Neighbor to display information about\n"
"Neighbor to display information about\n"
"Neighbor on BGP configured interface\n"
"Display the routes selected by best path\n"
JSON_STR
"Increase table width for longer prefixes\n")
{
afi_t afi = AFI_IP6;
safi_t safi = SAFI_UNICAST;
char *rmap_name = NULL;
char *peerstr = NULL;
struct bgp *bgp = NULL;
struct peer *peer;
enum bgp_show_adj_route_type type = bgp_show_adj_route_bestpath;
int idx = 0;
uint16_t show_flags = 0;
if (uj)
SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
if (wide)
SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi,
&bgp, uj);
if (!idx)
return CMD_WARNING;
argv_find(argv, argc, "neighbors", &idx);
peerstr = argv[++idx]->arg;
peer = peer_lookup_in_view(vty, bgp, peerstr, uj);
if (!peer)
return CMD_WARNING;
return peer_adj_routes(vty, peer, afi, safi, type, rmap_name,
show_flags);
}
DEFPY (show_ip_bgp_instance_neighbor_advertised_route,
show_ip_bgp_instance_neighbor_advertised_route_cmd,
"show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] [all$all] neighbors <A.B.C.D|X:X::X:X|WORD> <advertised-routes|received-routes|filtered-routes> [route-map WORD] [json$uj | wide$wide]",
SHOW_STR
IP_STR
BGP_STR
BGP_INSTANCE_HELP_STR
BGP_AFI_HELP_STR
BGP_SAFI_WITH_LABEL_HELP_STR
"Display the entries for all address families\n"
"Detailed information on TCP and BGP neighbor connections\n"
"Neighbor to display information about\n"
"Neighbor to display information about\n"
"Neighbor on BGP configured interface\n"
"Display the routes advertised to a BGP neighbor\n"
"Display the received routes from neighbor\n"
"Display the filtered routes received from neighbor\n"
"Route-map to modify the attributes\n"
"Name of the route map\n"
JSON_STR
"Increase table width for longer prefixes\n")
{
afi_t afi = AFI_IP6;
safi_t safi = SAFI_UNICAST;
char *rmap_name = NULL;
char *peerstr = NULL;
struct bgp *bgp = NULL;
struct peer *peer;
enum bgp_show_adj_route_type type = bgp_show_adj_route_advertised;
int idx = 0;
bool first = true;
uint16_t show_flags = 0;
if (uj) {
argc--;
SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
}
if (all) {
SET_FLAG(show_flags, BGP_SHOW_OPT_AFI_ALL);
if (argv_find(argv, argc, "ipv4", &idx))
SET_FLAG(show_flags, BGP_SHOW_OPT_AFI_IP);
if (argv_find(argv, argc, "ipv6", &idx))
SET_FLAG(show_flags, BGP_SHOW_OPT_AFI_IP6);
}
if (wide)
SET_FLAG(show_flags, BGP_SHOW_OPT_WIDE);
bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi,
&bgp, uj);
if (!idx)
return CMD_WARNING;
/* neighbors <A.B.C.D|X:X::X:X|WORD> */
argv_find(argv, argc, "neighbors", &idx);
peerstr = argv[++idx]->arg;
peer = peer_lookup_in_view(vty, bgp, peerstr, uj);
if (!peer)
return CMD_WARNING;
if (argv_find(argv, argc, "advertised-routes", &idx))
type = bgp_show_adj_route_advertised;
else if (argv_find(argv, argc, "received-routes", &idx))
type = bgp_show_adj_route_received;
else if (argv_find(argv, argc, "filtered-routes", &idx))
type = bgp_show_adj_route_filtered;
if (argv_find(argv, argc, "route-map", &idx))
rmap_name = argv[++idx]->arg;
if (!all)
return peer_adj_routes(vty, peer, afi, safi, type, rmap_name,
show_flags);
if (uj)
vty_out(vty, "{\n");
if (CHECK_FLAG(show_flags, BGP_SHOW_OPT_AFI_IP)
|| CHECK_FLAG(show_flags, BGP_SHOW_OPT_AFI_IP6)) {
afi = CHECK_FLAG(show_flags, BGP_SHOW_OPT_AFI_IP) ? AFI_IP
: AFI_IP6;
FOREACH_SAFI (safi) {
if (!bgp_afi_safi_peer_exists(bgp, afi, safi))
continue;
if (uj) {
if (first)
first = false;
else
vty_out(vty, ",\n");
vty_out(vty, "\"%s\":",
get_afi_safi_str(afi, safi, true));
} else
vty_out(vty, "\nFor address family: %s\n",
get_afi_safi_str(afi, safi, false));
peer_adj_routes(vty, peer, afi, safi, type, rmap_name,
show_flags);
}
} else {
FOREACH_AFI_SAFI (afi, safi) {
if (!bgp_afi_safi_peer_exists(bgp, afi, safi))
continue;
if (uj) {
if (first)
first = false;
else
vty_out(vty, ",\n");
vty_out(vty, "\"%s\":",
get_afi_safi_str(afi, safi, true));
} else
vty_out(vty, "\nFor address family: %s\n",
get_afi_safi_str(afi, safi, false));
peer_adj_routes(vty, peer, afi, safi, type, rmap_name,
show_flags);
}
}
if (uj)
vty_out(vty, "}\n");
return CMD_SUCCESS;
}
DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
show_ip_bgp_neighbor_received_prefix_filter_cmd,
"show [ip] bgp [<ipv4|ipv6> [unicast]] neighbors <A.B.C.D|X:X::X:X|WORD> received prefix-filter [json]",
SHOW_STR
IP_STR
BGP_STR
"Address Family\n"
"Address Family\n"
"Address Family modifier\n"
"Detailed information on TCP and BGP neighbor connections\n"
"Neighbor to display information about\n"
"Neighbor to display information about\n"
"Neighbor on BGP configured interface\n"
"Display information received from a BGP neighbor\n"
"Display the prefixlist filter\n"
JSON_STR)
{
afi_t afi = AFI_IP6;
safi_t safi = SAFI_UNICAST;
char *peerstr = NULL;
char name[BUFSIZ];
union sockunion su;
struct peer *peer;
int count, ret;
int idx = 0;
/* show [ip] bgp */
if (argv_find(argv, argc, "ip", &idx))
afi = AFI_IP;
/* [<ipv4|ipv6> [unicast]] */
if (argv_find(argv, argc, "ipv4", &idx))
afi = AFI_IP;
if (argv_find(argv, argc, "ipv6", &idx))
afi = AFI_IP6;
/* neighbors <A.B.C.D|X:X::X:X|WORD> */
argv_find(argv, argc, "neighbors", &idx);
peerstr = argv[++idx]->arg;
bool uj = use_json(argc, argv);
ret = str2sockunion(peerstr, &su);
if (ret < 0) {
peer = peer_lookup_by_conf_if(NULL, peerstr);
if (!peer) {
if (uj)
vty_out(vty, "{}\n");
else
vty_out(vty,
"%% Malformed address or name: %s\n",
peerstr);
return CMD_WARNING;
}
} else {
peer = peer_lookup(NULL, &su);
if (!peer) {
if (uj)
vty_out(vty, "{}\n");
else
vty_out(vty, "No peer\n");
return CMD_WARNING;
}
}
snprintf(name, sizeof(name), "%s.%d.%d", peer->host, afi, safi);
count = prefix_bgp_show_prefix_list(NULL, afi, name, uj);
if (count) {
if (!uj)
vty_out(vty, "Address Family: %s\n",
get_afi_safi_str(afi, safi, false));
prefix_bgp_show_prefix_list(vty, afi, name, uj);
} else {
if (uj)
vty_out(vty, "{}\n");
else
vty_out(vty, "No functional output\n");
}
return CMD_SUCCESS;
}
static int bgp_show_neighbor_route(struct vty *vty, struct peer *peer,
afi_t afi, safi_t safi,
enum bgp_show_type type, bool use_json)
{
uint16_t show_flags = 0;
if (use_json)
SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
if (!peer || !peer->afc[afi][safi]) {
if (use_json) {
json_object *json_no = NULL;
json_no = json_object_new_object();
json_object_string_add(
json_no, "warning",
"No such neighbor or address family");
vty_out(vty, "%s\n",
json_object_to_json_string(json_no));
json_object_free(json_no);
} else
vty_out(vty, "%% No such neighbor or address family\n");
return CMD_WARNING;
}
/* labeled-unicast routes live in the unicast table */
if (safi == SAFI_LABELED_UNICAST)
safi = SAFI_UNICAST;
return bgp_show(vty, peer->bgp, afi, safi, type, &peer->su, show_flags,
RPKI_NOT_BEING_USED);
}
DEFUN (show_ip_bgp_flowspec_routes_detailed,
show_ip_bgp_flowspec_routes_detailed_cmd,
"show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" flowspec] detail [json]",
SHOW_STR
IP_STR
BGP_STR
BGP_INSTANCE_HELP_STR
BGP_AFI_HELP_STR
"SAFI Flowspec\n"
"Detailed information on flowspec entries\n"
JSON_STR)
{
afi_t afi = AFI_IP;
safi_t safi = SAFI_UNICAST;
struct bgp *bgp = NULL;
int idx = 0;
bool uj = use_json(argc, argv);
uint16_t show_flags = 0;
if (uj) {
argc--;
SET_FLAG(show_flags, BGP_SHOW_OPT_JSON);
}
bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi,
&bgp, uj);
if (!idx)
return CMD_WARNING;
return bgp_show(vty, bgp, afi, safi, bgp_show_type_detail, NULL,
show_flags, RPKI_NOT_BEING_USED);
}
DEFUN (show_ip_bgp_neighbor_routes,
show_ip_bgp_neighbor_routes_cmd,
"show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] neighbors <A.B.C.D|X:X::X:X|WORD> <flap-statistics|dampened-routes|routes> [json]",
SHOW_STR
IP_STR
BGP_STR
BGP_INSTANCE_HELP_STR
BGP_AFI_HELP_STR
BGP_SAFI_WITH_LABEL_HELP_STR
"Detailed information on TCP and BGP neighbor connections\n"
"Neighbor to display information about\n"
"Neighbor to display information about\n"
"Neighbor on BGP configured interface\n"
"Display flap statistics of the routes learned from neighbor\n"
"Display the dampened routes received from neighbor\n"
"Display routes learned from neighbor\n"
JSON_STR)
{
char *peerstr = NULL;
struct bgp *bgp = NULL;
afi_t afi = AFI_IP6;
safi_t safi = SAFI_UNICAST;
struct peer *peer;
enum bgp_show_type sh_type = bgp_show_type_neighbor;
int idx = 0;
bool uj = use_json(argc, argv);
if (uj)
argc--;
bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi,
&bgp, uj);
if (!idx)
return CMD_WARNING;
/* neighbors <A.B.C.D|X:X::X:X|WORD> */
argv_find(argv, argc, "neighbors", &idx);
peerstr = argv[++idx]->arg;
peer = peer_lookup_in_view(vty, bgp, peerstr, uj);
if (!peer)
return CMD_WARNING;
if (argv_find(argv, argc, "flap-statistics", &idx))
sh_type = bgp_show_type_flap_neighbor;
else if (argv_find(argv, argc, "dampened-routes", &idx))
sh_type = bgp_show_type_damp_neighbor;
else if (argv_find(argv, argc, "routes", &idx))
sh_type = bgp_show_type_neighbor;
return bgp_show_neighbor_route(vty, peer, afi, safi, sh_type, uj);
}
struct bgp_table *bgp_distance_table[AFI_MAX][SAFI_MAX];
struct bgp_distance {
/* Distance value for the IP source prefix. */
uint8_t distance;
/* Name of the access-list to be matched. */
char *access_list;
};
DEFUN (show_bgp_afi_vpn_rd_route,
show_bgp_afi_vpn_rd_route_cmd,
"show bgp "BGP_AFI_CMD_STR" vpn rd <ASN:NN_OR_IP-ADDRESS:NN|all> <A.B.C.D/M|X:X::X:X/M> [json]",
SHOW_STR
BGP_STR
BGP_AFI_HELP_STR
"Address Family modifier\n"
"Display information for a route distinguisher\n"
"Route Distinguisher\n"
"All Route Distinguishers\n"
"Network in the BGP routing table to display\n"
"Network in the BGP routing table to display\n"
JSON_STR)
{
int ret;
struct prefix_rd prd;
afi_t afi = AFI_MAX;
int idx = 0;
if (!argv_find_and_parse_afi(argv, argc, &idx, &afi)) {
vty_out(vty, "%% Malformed Address Family\n");
return CMD_WARNING;
}
if (!strcmp(argv[5]->arg, "all"))
return bgp_show_route(vty, NULL, argv[6]->arg, afi,
SAFI_MPLS_VPN, NULL, 0, BGP_PATH_SHOW_ALL,
RPKI_NOT_BEING_USED,
use_json(argc, argv));
ret = str2prefix_rd(argv[5]->arg, &prd);
if (!ret) {
vty_out(vty, "%% Malformed Route Distinguisher\n");
return CMD_WARNING;
}
return bgp_show_route(vty, NULL, argv[6]->arg, afi, SAFI_MPLS_VPN, &prd,
0, BGP_PATH_SHOW_ALL, RPKI_NOT_BEING_USED,
use_json(argc, argv));
}
static struct bgp_distance *bgp_distance_new(void)
{
return XCALLOC(MTYPE_BGP_DISTANCE, sizeof(struct bgp_distance));
}
static void bgp_distance_free(struct bgp_distance *bdistance)
{
XFREE(MTYPE_BGP_DISTANCE, bdistance);
}
static int bgp_distance_set(struct vty *vty, const char *distance_str,
const char *ip_str, const char *access_list_str)
{
int ret;
afi_t afi;
safi_t safi;
struct prefix p;
uint8_t distance;
struct bgp_dest *dest;
struct bgp_distance *bdistance;
afi = bgp_node_afi(vty);
safi = bgp_node_safi(vty);
ret = str2prefix(ip_str, &p);
if (ret == 0) {
vty_out(vty, "Malformed prefix\n");
return CMD_WARNING_CONFIG_FAILED;
}
distance = atoi(distance_str);
/* Get BGP distance node. */
dest = bgp_node_get(bgp_distance_table[afi][safi], &p);
bdistance = bgp_dest_get_bgp_distance_info(dest);
if (bdistance)
bgp_dest_unlock_node(dest);
else {
bdistance = bgp_distance_new();
bgp_dest_set_bgp_distance_info(dest, bdistance);
}
/* Set distance value. */
bdistance->distance = distance;
/* Reset access-list configuration. */
XFREE(MTYPE_AS_LIST, bdistance->access_list);
if (access_list_str)
bdistance->access_list =
XSTRDUP(MTYPE_AS_LIST, access_list_str);
return CMD_SUCCESS;
}
static int bgp_distance_unset(struct vty *vty, const char *distance_str,
const char *ip_str, const char *access_list_str)
{
int ret;
afi_t afi;
safi_t safi;
struct prefix p;
int distance;
struct bgp_dest *dest;
struct bgp_distance *bdistance;
afi = bgp_node_afi(vty);
safi = bgp_node_safi(vty);
ret = str2prefix(ip_str, &p);
if (ret == 0) {
vty_out(vty, "Malformed prefix\n");
return CMD_WARNING_CONFIG_FAILED;
}
dest = bgp_node_lookup(bgp_distance_table[afi][safi], &p);
if (!dest) {
vty_out(vty, "Can't find specified prefix\n");
return CMD_WARNING_CONFIG_FAILED;
}
bdistance = bgp_dest_get_bgp_distance_info(dest);
distance = atoi(distance_str);
if (bdistance->distance != distance) {
vty_out(vty, "Distance does not match configured\n");
bgp_dest_unlock_node(dest);
return CMD_WARNING_CONFIG_FAILED;
}
XFREE(MTYPE_AS_LIST, bdistance->access_list);
bgp_distance_free(bdistance);
bgp_dest_set_bgp_path_info(dest, NULL);
bgp_dest_unlock_node(dest);
bgp_dest_unlock_node(dest);
return CMD_SUCCESS;
}
/* Apply BGP information to distance method. */
uint8_t bgp_distance_apply(const struct prefix *p, struct bgp_path_info *pinfo,
afi_t afi, safi_t safi, struct bgp *bgp)
{
struct bgp_dest *dest;
struct prefix q = {0};
struct peer *peer;
struct bgp_distance *bdistance;
struct access_list *alist;
struct bgp_static *bgp_static;
if (!bgp)
return 0;
peer = pinfo->peer;
if (pinfo->attr->distance)
return pinfo->attr->distance;
/* Check source address.
* Note: for aggregate route, peer can have unspec af type.
*/
if (pinfo->sub_type != BGP_ROUTE_AGGREGATE
&& !sockunion2hostprefix(&peer->su, &q))
return 0;
dest = bgp_node_match(bgp_distance_table[afi][safi], &q);
if (dest) {
bdistance = bgp_dest_get_bgp_distance_info(dest);
bgp_dest_unlock_node(dest);
if (bdistance->access_list) {
alist = access_list_lookup(afi, bdistance->access_list);
if (alist
&& access_list_apply(alist, p) == FILTER_PERMIT)
return bdistance->distance;
} else
return bdistance->distance;
}
/* Backdoor check. */
dest = bgp_node_lookup(bgp->route[afi][safi], p);
if (dest) {
bgp_static = bgp_dest_get_bgp_static_info(dest);
bgp_dest_unlock_node(dest);
if (bgp_static->backdoor) {
if (bgp->distance_local[afi][safi])
return bgp->distance_local[afi][safi];
else
return ZEBRA_IBGP_DISTANCE_DEFAULT;
}
}
if (peer->sort == BGP_PEER_EBGP) {
if (bgp->distance_ebgp[afi][safi])
return bgp->distance_ebgp[afi][safi];
return ZEBRA_EBGP_DISTANCE_DEFAULT;
} else if (peer->sort == BGP_PEER_IBGP) {
if (bgp->distance_ibgp[afi][safi])
return bgp->distance_ibgp[afi][safi];
return ZEBRA_IBGP_DISTANCE_DEFAULT;
} else {
if (bgp->distance_local[afi][safi])
return bgp->distance_local[afi][safi];
return ZEBRA_IBGP_DISTANCE_DEFAULT;
}
}
/* If we enter `distance bgp (1-255) (1-255) (1-255)`,
* we should tell ZEBRA update the routes for a specific
* AFI/SAFI to reflect changes in RIB.
*/
static void bgp_announce_routes_distance_update(struct bgp *bgp,
afi_t update_afi,
safi_t update_safi)
{
afi_t afi;
safi_t safi;
FOREACH_AFI_SAFI (afi, safi) {
if (!bgp_fibupd_safi(safi))
continue;
if (afi != update_afi && safi != update_safi)
continue;
if (BGP_DEBUG(zebra, ZEBRA))
zlog_debug(
"%s: Announcing routes due to distance change afi/safi (%d/%d)",
__func__, afi, safi);
bgp_zebra_announce_table(bgp, afi, safi);
}
}
DEFUN (bgp_distance,
bgp_distance_cmd,
"distance bgp (1-255) (1-255) (1-255)",
"Define an administrative distance\n"
"BGP distance\n"
"Distance for routes external to the AS\n"
"Distance for routes internal to the AS\n"
"Distance for local routes\n")
{
VTY_DECLVAR_CONTEXT(bgp, bgp);
int idx_number = 2;
int idx_number_2 = 3;
int idx_number_3 = 4;
int distance_ebgp = atoi(argv[idx_number]->arg);
int distance_ibgp = atoi(argv[idx_number_2]->arg);
int distance_local = atoi(argv[idx_number_3]->arg);
afi_t afi;
safi_t safi;
afi = bgp_node_afi(vty);
safi = bgp_node_safi(vty);
if (bgp->distance_ebgp[afi][safi] != distance_ebgp
|| bgp->distance_ibgp[afi][safi] != distance_ibgp
|| bgp->distance_local[afi][safi] != distance_local) {
bgp->distance_ebgp[afi][safi] = distance_ebgp;
bgp->distance_ibgp[afi][safi] = distance_ibgp;
bgp->distance_local[afi][safi] = distance_local;
bgp_announce_routes_distance_update(bgp, afi, safi);
}
return CMD_SUCCESS;
}
DEFUN (no_bgp_distance,
no_bgp_distance_cmd,
"no distance bgp [(1-255) (1-255) (1-255)]",
NO_STR
"Define an administrative distance\n"
"BGP distance\n"
"Distance for routes external to the AS\n"
"Distance for routes internal to the AS\n"
"Distance for local routes\n")
{
VTY_DECLVAR_CONTEXT(bgp, bgp);
afi_t afi;
safi_t safi;
afi = bgp_node_afi(vty);
safi = bgp_node_safi(vty);
if (bgp->distance_ebgp[afi][safi] != 0
|| bgp->distance_ibgp[afi][safi] != 0
|| bgp->distance_local[afi][safi] != 0) {
bgp->distance_ebgp[afi][safi] = 0;
bgp->distance_ibgp[afi][safi] = 0;
bgp->distance_local[afi][safi] = 0;
bgp_announce_routes_distance_update(bgp, afi, safi);
}
return CMD_SUCCESS;
}
DEFUN (bgp_distance_source,
bgp_distance_source_cmd,
"distance (1-255) A.B.C.D/M",
"Define an administrative distance\n"
"Administrative distance\n"
"IP source prefix\n")
{
int idx_number = 1;
int idx_ipv4_prefixlen = 2;
bgp_distance_set(vty, argv[idx_number]->arg,
argv[idx_ipv4_prefixlen]->arg, NULL);
return CMD_SUCCESS;
}
DEFUN (no_bgp_distance_source,
no_bgp_distance_source_cmd,
"no distance (1-255) A.B.C.D/M",
NO_STR
"Define an administrative distance\n"
"Administrative distance\n"
"IP source prefix\n")
{
int idx_number = 2;
int idx_ipv4_prefixlen = 3;
bgp_distance_unset(vty, argv[idx_number]->arg,
argv[idx_ipv4_prefixlen]->arg, NULL);
return CMD_SUCCESS;
}
DEFUN (bgp_distance_source_access_list,
bgp_distance_source_access_list_cmd,
"distance (1-255) A.B.C.D/M WORD",
"Define an administrative distance\n"
"Administrative distance\n"
"IP source prefix\n"
"Access list name\n")
{
int idx_number = 1;
int idx_ipv4_prefixlen = 2;
int idx_word = 3;
bgp_distance_set(vty, argv[idx_number]->arg,
argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg);
return CMD_SUCCESS;
}
DEFUN (no_bgp_distance_source_access_list,
no_bgp_distance_source_access_list_cmd,
"no distance (1-255) A.B.C.D/M WORD",
NO_STR
"Define an administrative distance\n"
"Administrative distance\n"
"IP source prefix\n"
"Access list name\n")
{
int idx_number = 2;
int idx_ipv4_prefixlen = 3;
int idx_word = 4;
bgp_distance_unset(vty, argv[idx_number]->arg,
argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg);
return CMD_SUCCESS;
}
DEFUN (ipv6_bgp_distance_source,
ipv6_bgp_distance_source_cmd,
"distance (1-255) X:X::X:X/M",
"Define an administrative distance\n"
"Administrative distance\n"
"IP source prefix\n")
{
bgp_distance_set(vty, argv[1]->arg, argv[2]->arg, NULL);
return CMD_SUCCESS;
}
DEFUN (no_ipv6_bgp_distance_source,
no_ipv6_bgp_distance_source_cmd,
"no distance (1-255) X:X::X:X/M",
NO_STR
"Define an administrative distance\n"
"Administrative distance\n"
"IP source prefix\n")
{
bgp_distance_unset(vty, argv[2]->arg, argv[3]->arg, NULL);
return CMD_SUCCESS;
}
DEFUN (ipv6_bgp_distance_source_access_list,
ipv6_bgp_distance_source_access_list_cmd,
"distance (1-255) X:X::X:X/M WORD",
"Define an administrative distance\n"
"Administrative distance\n"
"IP source prefix\n"
"Access list name\n")
{
bgp_distance_set(vty, argv[1]->arg, argv[2]->arg, argv[3]->arg);
return CMD_SUCCESS;
}
DEFUN (no_ipv6_bgp_distance_source_access_list,
no_ipv6_bgp_distance_source_access_list_cmd,
"no distance (1-255) X:X::X:X/M WORD",
NO_STR
"Define an administrative distance\n"
"Administrative distance\n"
"IP source prefix\n"
"Access list name\n")
{
bgp_distance_unset(vty, argv[2]->arg, argv[3]->arg, argv[4]->arg);
return CMD_SUCCESS;
}
DEFUN (bgp_damp_set,
bgp_damp_set_cmd,
"bgp dampening [(1-45) [(1-20000) (1-20000) (1-255)]]",
"BGP Specific commands\n"
"Enable route-flap dampening\n"
"Half-life time for the penalty\n"
"Value to start reusing a route\n"
"Value to start suppressing a route\n"
"Maximum duration to suppress a stable route\n")
{
VTY_DECLVAR_CONTEXT(bgp, bgp);
int idx_half_life = 2;
int idx_reuse = 3;
int idx_suppress = 4;
int idx_max_suppress = 5;
int half = DEFAULT_HALF_LIFE * 60;
int reuse = DEFAULT_REUSE;
int suppress = DEFAULT_SUPPRESS;
int max = 4 * half;
if (argc == 6) {
half = atoi(argv[idx_half_life]->arg) * 60;
reuse = atoi(argv[idx_reuse]->arg);
suppress = atoi(argv[idx_suppress]->arg);
max = atoi(argv[idx_max_suppress]->arg) * 60;
} else if (argc == 3) {
half = atoi(argv[idx_half_life]->arg) * 60;
max = 4 * half;
}
/*
* These can't be 0 but our SA doesn't understand the
* way our cli is constructed
*/
assert(reuse);
assert(half);
if (suppress < reuse) {
vty_out(vty,
"Suppress value cannot be less than reuse value \n");
return 0;
}
return bgp_damp_enable(bgp, bgp_node_afi(vty), bgp_node_safi(vty), half,
reuse, suppress, max);
}
DEFUN (bgp_damp_unset,
bgp_damp_unset_cmd,
"no bgp dampening [(1-45) [(1-20000) (1-20000) (1-255)]]",
NO_STR
"BGP Specific commands\n"
"Enable route-flap dampening\n"
"Half-life time for the penalty\n"
"Value to start reusing a route\n"
"Value to start suppressing a route\n"
"Maximum duration to suppress a stable route\n")
{
VTY_DECLVAR_CONTEXT(bgp, bgp);
return bgp_damp_disable(bgp, bgp_node_afi(vty), bgp_node_safi(vty));
}
/* Display specified route of BGP table. */
static int bgp_clear_damp_route(struct vty *vty, const char *view_name,
const char *ip_str, afi_t afi, safi_t safi,
struct prefix_rd *prd, int prefix_check)
{
int ret;
struct prefix match;
struct bgp_dest *dest;
struct bgp_dest *rm;
struct bgp_path_info *pi;
struct bgp_path_info *pi_temp;
struct bgp *bgp;
struct bgp_table *table;
/* BGP structure lookup. */
if (view_name) {
bgp = bgp_lookup_by_name(view_name);
if (bgp == NULL) {
vty_out(vty, "%% Can't find BGP instance %s\n",
view_name);
return CMD_WARNING;
}
} else {
bgp = bgp_get_default();
if (bgp == NULL) {
vty_out(vty, "%% No BGP process is configured\n");
return CMD_WARNING;
}
}
/* Check IP address argument. */
ret = str2prefix(ip_str, &match);
if (!ret) {
vty_out(vty, "%% address is malformed\n");
return CMD_WARNING;
}
match.family = afi2family(afi);
if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)
|| (safi == SAFI_EVPN)) {
for (dest = bgp_table_top(bgp->rib[AFI_IP][safi]); dest;
dest = bgp_route_next(dest)) {
const struct prefix *dest_p = bgp_dest_get_prefix(dest);
if (prd && memcmp(dest_p->u.val, prd->val, 8) != 0)
continue;
table = bgp_dest_get_bgp_table_info(dest);
if (!table)
continue;
rm = bgp_node_match(table, &match);
if (rm == NULL)
continue;
const struct prefix *rm_p = bgp_dest_get_prefix(dest);
if (!prefix_check
|| rm_p->prefixlen == match.prefixlen) {
pi = bgp_dest_get_bgp_path_info(rm);
while (pi) {
if (pi->extra && pi->extra->damp_info) {
pi_temp = pi->next;
bgp_damp_info_free(
pi->extra->damp_info,
1, afi, safi);
pi = pi_temp;
} else
pi = pi->next;
}
}
bgp_dest_unlock_node(rm);
}
} else {
dest = bgp_node_match(bgp->rib[afi][safi], &match);
if (dest != NULL) {
const struct prefix *dest_p = bgp_dest_get_prefix(dest);
if (!prefix_check
|| dest_p->prefixlen == match.prefixlen) {
pi = bgp_dest_get_bgp_path_info(dest);
while (pi) {
if (pi->extra && pi->extra->damp_info) {
pi_temp = pi->next;
bgp_damp_info_free(
pi->extra->damp_info,
1, afi, safi);
pi = pi_temp;
} else
pi = pi->next;
}
}
bgp_dest_unlock_node(dest);
}
}
return CMD_SUCCESS;
}
DEFUN (clear_ip_bgp_dampening,
clear_ip_bgp_dampening_cmd,
"clear ip bgp dampening",
CLEAR_STR
IP_STR
BGP_STR
"Clear route flap dampening information\n")
{
bgp_damp_info_clean(AFI_IP, SAFI_UNICAST);
return CMD_SUCCESS;
}
DEFUN (clear_ip_bgp_dampening_prefix,
clear_ip_bgp_dampening_prefix_cmd,
"clear ip bgp dampening A.B.C.D/M",
CLEAR_STR
IP_STR
BGP_STR
"Clear route flap dampening information\n"
"IPv4 prefix\n")
{
int idx_ipv4_prefixlen = 4;
return bgp_clear_damp_route(vty, NULL, argv[idx_ipv4_prefixlen]->arg,
AFI_IP, SAFI_UNICAST, NULL, 1);
}
DEFUN (clear_ip_bgp_dampening_address,
clear_ip_bgp_dampening_address_cmd,
"clear ip bgp dampening A.B.C.D",
CLEAR_STR
IP_STR
BGP_STR
"Clear route flap dampening information\n"
"Network to clear damping information\n")
{
int idx_ipv4 = 4;
return bgp_clear_damp_route(vty, NULL, argv[idx_ipv4]->arg, AFI_IP,
SAFI_UNICAST, NULL, 0);
}
DEFUN (clear_ip_bgp_dampening_address_mask,
clear_ip_bgp_dampening_address_mask_cmd,
"clear ip bgp dampening A.B.C.D A.B.C.D",
CLEAR_STR
IP_STR
BGP_STR
"Clear route flap dampening information\n"
"Network to clear damping information\n"
"Network mask\n")
{
int idx_ipv4 = 4;
int idx_ipv4_2 = 5;
int ret;
char prefix_str[BUFSIZ];
ret = netmask_str2prefix_str(argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg,
prefix_str, sizeof(prefix_str));
if (!ret) {
vty_out(vty, "%% Inconsistent address and mask\n");
return CMD_WARNING;
}
return bgp_clear_damp_route(vty, NULL, prefix_str, AFI_IP, SAFI_UNICAST,
NULL, 0);
}
static void show_bgp_peerhash_entry(struct hash_bucket *bucket, void *arg)
{
struct vty *vty = arg;
struct peer *peer = bucket->data;
char buf[SU_ADDRSTRLEN];
vty_out(vty, "\tPeer: %s %s\n", peer->host,
sockunion2str(&peer->su, buf, sizeof(buf)));
}
DEFUN (show_bgp_listeners,
show_bgp_listeners_cmd,
"show bgp listeners",
SHOW_STR
BGP_STR
"Display Listen Sockets and who created them\n")
{
bgp_dump_listener_info(vty);
return CMD_SUCCESS;
}
DEFUN (show_bgp_peerhash,
show_bgp_peerhash_cmd,
"show bgp peerhash",
SHOW_STR
BGP_STR
"Display information about the BGP peerhash\n")
{
struct list *instances = bm->bgp;
struct listnode *node;
struct bgp *bgp;
for (ALL_LIST_ELEMENTS_RO(instances, node, bgp)) {
vty_out(vty, "BGP: %s\n", bgp->name);
hash_iterate(bgp->peerhash, show_bgp_peerhash_entry,
vty);
}
return CMD_SUCCESS;
}
/* also used for encap safi */
static void bgp_config_write_network_vpn(struct vty *vty, struct bgp *bgp,
afi_t afi, safi_t safi)
{
struct bgp_dest *pdest;
struct bgp_dest *dest;
struct bgp_table *table;
const struct prefix *p;
const struct prefix_rd *prd;
struct bgp_static *bgp_static;
mpls_label_t label;
char rdbuf[RD_ADDRSTRLEN];
/* Network configuration. */
for (pdest = bgp_table_top(bgp->route[afi][safi]); pdest;
pdest = bgp_route_next(pdest)) {
table = bgp_dest_get_bgp_table_info(pdest);
if (!table)
continue;
for (dest = bgp_table_top(table); dest;
dest = bgp_route_next(dest)) {
bgp_static = bgp_dest_get_bgp_static_info(dest);
if (bgp_static == NULL)
continue;
p = bgp_dest_get_prefix(dest);
prd = (const struct prefix_rd *)bgp_dest_get_prefix(
pdest);
/* "network" configuration display. */
prefix_rd2str(prd, rdbuf, sizeof(rdbuf));
label = decode_label(&bgp_static->label);
vty_out(vty, " network %pFX rd %s", p, rdbuf);
if (safi == SAFI_MPLS_VPN)
vty_out(vty, " label %u", label);
if (bgp_static->rmap.name)
vty_out(vty, " route-map %s",
bgp_static->rmap.name);
if (bgp_static->backdoor)
vty_out(vty, " backdoor");
vty_out(vty, "\n");
}
}
}
static void bgp_config_write_network_evpn(struct vty *vty, struct bgp *bgp,
afi_t afi, safi_t safi)
{
struct bgp_dest *pdest;
struct bgp_dest *dest;
struct bgp_table *table;
const struct prefix *p;
const struct prefix_rd *prd;
struct bgp_static *bgp_static;
char buf[PREFIX_STRLEN * 2];
char buf2[SU_ADDRSTRLEN];
char rdbuf[RD_ADDRSTRLEN];
char esi_buf[ESI_BYTES];
/* Network configuration. */
for (pdest = bgp_table_top(bgp->route[afi][safi]); pdest;
pdest = bgp_route_next(pdest)) {
table = bgp_dest_get_bgp_table_info(pdest);
if (!table)
continue;
for (dest = bgp_table_top(table); dest;
dest = bgp_route_next(dest)) {
bgp_static = bgp_dest_get_bgp_static_info(dest);
if (bgp_static == NULL)
continue;
char *macrouter = NULL;
if (bgp_static->router_mac)
macrouter = prefix_mac2str(
bgp_static->router_mac, NULL, 0);
if (bgp_static->eth_s_id)
esi_to_str(bgp_static->eth_s_id,
esi_buf, sizeof(esi_buf));
p = bgp_dest_get_prefix(dest);
prd = (struct prefix_rd *)bgp_dest_get_prefix(pdest);
/* "network" configuration display. */
prefix_rd2str(prd, rdbuf, sizeof(rdbuf));
if (p->u.prefix_evpn.route_type == 5) {
char local_buf[PREFIX_STRLEN];
uint8_t family = is_evpn_prefix_ipaddr_v4((
struct prefix_evpn *)p)
? AF_INET
: AF_INET6;
inet_ntop(family,
&p->u.prefix_evpn.prefix_addr.ip.ip.addr,
local_buf, PREFIX_STRLEN);
snprintf(buf, sizeof(buf), "%s/%u", local_buf,
p->u.prefix_evpn.prefix_addr
.ip_prefix_length);
} else {
prefix2str(p, buf, sizeof(buf));
}
if (bgp_static->gatewayIp.family == AF_INET
|| bgp_static->gatewayIp.family == AF_INET6)
inet_ntop(bgp_static->gatewayIp.family,
&bgp_static->gatewayIp.u.prefix, buf2,
sizeof(buf2));
vty_out(vty,
" network %s rd %s ethtag %u label %u esi %s gwip %s routermac %s\n",
buf, rdbuf,
p->u.prefix_evpn.prefix_addr.eth_tag,
decode_label(&bgp_static->label), esi_buf, buf2,
macrouter);
XFREE(MTYPE_TMP, macrouter);
}
}
}
/* Configuration of static route announcement and aggregate
information. */
void bgp_config_write_network(struct vty *vty, struct bgp *bgp, afi_t afi,
safi_t safi)
{
struct bgp_dest *dest;
const struct prefix *p;
struct bgp_static *bgp_static;
struct bgp_aggregate *bgp_aggregate;
if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)) {
bgp_config_write_network_vpn(vty, bgp, afi, safi);
return;
}
if (afi == AFI_L2VPN && safi == SAFI_EVPN) {
bgp_config_write_network_evpn(vty, bgp, afi, safi);
return;
}
/* Network configuration. */
for (dest = bgp_table_top(bgp->route[afi][safi]); dest;
dest = bgp_route_next(dest)) {
bgp_static = bgp_dest_get_bgp_static_info(dest);
if (bgp_static == NULL)
continue;
p = bgp_dest_get_prefix(dest);
vty_out(vty, " network %pFX", p);
if (bgp_static->label_index != BGP_INVALID_LABEL_INDEX)
vty_out(vty, " label-index %u",
bgp_static->label_index);
if (bgp_static->rmap.name)
vty_out(vty, " route-map %s", bgp_static->rmap.name);
if (bgp_static->backdoor)
vty_out(vty, " backdoor");
vty_out(vty, "\n");
}
/* Aggregate-address configuration. */
for (dest = bgp_table_top(bgp->aggregate[afi][safi]); dest;
dest = bgp_route_next(dest)) {
bgp_aggregate = bgp_dest_get_bgp_aggregate_info(dest);
if (bgp_aggregate == NULL)
continue;
p = bgp_dest_get_prefix(dest);
vty_out(vty, " aggregate-address %pFX", p);
if (bgp_aggregate->as_set)
vty_out(vty, " as-set");
if (bgp_aggregate->summary_only)
vty_out(vty, " summary-only");
if (bgp_aggregate->rmap.name)
vty_out(vty, " route-map %s", bgp_aggregate->rmap.name);
if (bgp_aggregate->origin != BGP_ORIGIN_UNSPECIFIED)
vty_out(vty, " origin %s",
bgp_origin2str(bgp_aggregate->origin));
if (bgp_aggregate->match_med)
vty_out(vty, " matching-MED-only");
if (bgp_aggregate->suppress_map_name)
vty_out(vty, " suppress-map %s",
bgp_aggregate->suppress_map_name);
vty_out(vty, "\n");
}
}
void bgp_config_write_distance(struct vty *vty, struct bgp *bgp, afi_t afi,
safi_t safi)
{
struct bgp_dest *dest;
struct bgp_distance *bdistance;
/* Distance configuration. */
if (bgp->distance_ebgp[afi][safi] && bgp->distance_ibgp[afi][safi]
&& bgp->distance_local[afi][safi]
&& (bgp->distance_ebgp[afi][safi] != ZEBRA_EBGP_DISTANCE_DEFAULT
|| bgp->distance_ibgp[afi][safi] != ZEBRA_IBGP_DISTANCE_DEFAULT
|| bgp->distance_local[afi][safi]
!= ZEBRA_IBGP_DISTANCE_DEFAULT)) {
vty_out(vty, " distance bgp %d %d %d\n",
bgp->distance_ebgp[afi][safi],
bgp->distance_ibgp[afi][safi],
bgp->distance_local[afi][safi]);
}
for (dest = bgp_table_top(bgp_distance_table[afi][safi]); dest;
dest = bgp_route_next(dest)) {
bdistance = bgp_dest_get_bgp_distance_info(dest);
if (bdistance != NULL)
vty_out(vty, " distance %d %pBD %s\n",
bdistance->distance, dest,
bdistance->access_list ? bdistance->access_list
: "");
}
}
/* Allocate routing table structure and install commands. */
void bgp_route_init(void)
{
afi_t afi;
safi_t safi;
/* Init BGP distance table. */
FOREACH_AFI_SAFI (afi, safi)
bgp_distance_table[afi][safi] = bgp_table_init(NULL, afi, safi);
/* IPv4 BGP commands. */
install_element(BGP_NODE, &bgp_table_map_cmd);
install_element(BGP_NODE, &bgp_network_cmd);
install_element(BGP_NODE, &no_bgp_table_map_cmd);
install_element(BGP_NODE, &aggregate_addressv4_cmd);
/* IPv4 unicast configuration. */
install_element(BGP_IPV4_NODE, &bgp_table_map_cmd);
install_element(BGP_IPV4_NODE, &bgp_network_cmd);
install_element(BGP_IPV4_NODE, &no_bgp_table_map_cmd);
install_element(BGP_IPV4_NODE, &aggregate_addressv4_cmd);
/* IPv4 multicast configuration. */
install_element(BGP_IPV4M_NODE, &bgp_table_map_cmd);
install_element(BGP_IPV4M_NODE, &bgp_network_cmd);
install_element(BGP_IPV4M_NODE, &no_bgp_table_map_cmd);
install_element(BGP_IPV4M_NODE, &aggregate_addressv4_cmd);
/* IPv4 labeled-unicast configuration. */
install_element(BGP_IPV4L_NODE, &bgp_network_cmd);
install_element(BGP_IPV4L_NODE, &aggregate_addressv4_cmd);
install_element(VIEW_NODE, &show_ip_bgp_instance_all_cmd);
install_element(VIEW_NODE, &show_ip_bgp_cmd);
install_element(VIEW_NODE, &show_ip_bgp_afi_safi_statistics_cmd);
install_element(VIEW_NODE, &show_ip_bgp_l2vpn_evpn_statistics_cmd);
install_element(VIEW_NODE, &show_ip_bgp_json_cmd);
install_element(VIEW_NODE, &show_ip_bgp_route_cmd);
install_element(VIEW_NODE, &show_ip_bgp_regexp_cmd);
install_element(VIEW_NODE, &show_ip_bgp_statistics_all_cmd);
install_element(VIEW_NODE,
&show_ip_bgp_instance_neighbor_advertised_route_cmd);
install_element(VIEW_NODE,
&show_ip_bgp_instance_neighbor_bestpath_route_cmd);
install_element(VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
install_element(VIEW_NODE,
&show_ip_bgp_neighbor_received_prefix_filter_cmd);
#ifdef KEEP_OLD_VPN_COMMANDS
install_element(VIEW_NODE, &show_ip_bgp_vpn_all_route_prefix_cmd);
#endif /* KEEP_OLD_VPN_COMMANDS */
install_element(VIEW_NODE, &show_bgp_afi_vpn_rd_route_cmd);
install_element(VIEW_NODE,
&show_bgp_l2vpn_evpn_route_prefix_cmd);
/* BGP dampening clear commands */
install_element(ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
install_element(ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
install_element(ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
install_element(ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
/* prefix count */
install_element(ENABLE_NODE,
&show_ip_bgp_instance_neighbor_prefix_counts_cmd);
#ifdef KEEP_OLD_VPN_COMMANDS
install_element(ENABLE_NODE,
&show_ip_bgp_vpn_neighbor_prefix_counts_cmd);
#endif /* KEEP_OLD_VPN_COMMANDS */
/* New config IPv6 BGP commands. */
install_element(BGP_IPV6_NODE, &bgp_table_map_cmd);
install_element(BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
install_element(BGP_IPV6_NODE, &no_bgp_table_map_cmd);
install_element(BGP_IPV6_NODE, &aggregate_addressv6_cmd);
install_element(BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
/* IPv6 labeled unicast address family. */
install_element(BGP_IPV6L_NODE, &ipv6_bgp_network_cmd);
install_element(BGP_IPV6L_NODE, &aggregate_addressv6_cmd);
install_element(BGP_NODE, &bgp_distance_cmd);
install_element(BGP_NODE, &no_bgp_distance_cmd);
install_element(BGP_NODE, &bgp_distance_source_cmd);
install_element(BGP_NODE, &no_bgp_distance_source_cmd);
install_element(BGP_NODE, &bgp_distance_source_access_list_cmd);
install_element(BGP_NODE, &no_bgp_distance_source_access_list_cmd);
install_element(BGP_IPV4_NODE, &bgp_distance_cmd);
install_element(BGP_IPV4_NODE, &no_bgp_distance_cmd);
install_element(BGP_IPV4_NODE, &bgp_distance_source_cmd);
install_element(BGP_IPV4_NODE, &no_bgp_distance_source_cmd);
install_element(BGP_IPV4_NODE, &bgp_distance_source_access_list_cmd);
install_element(BGP_IPV4_NODE, &no_bgp_distance_source_access_list_cmd);
install_element(BGP_IPV4M_NODE, &bgp_distance_cmd);
install_element(BGP_IPV4M_NODE, &no_bgp_distance_cmd);
install_element(BGP_IPV4M_NODE, &bgp_distance_source_cmd);
install_element(BGP_IPV4M_NODE, &no_bgp_distance_source_cmd);
install_element(BGP_IPV4M_NODE, &bgp_distance_source_access_list_cmd);
install_element(BGP_IPV4M_NODE,
&no_bgp_distance_source_access_list_cmd);
install_element(BGP_IPV6_NODE, &bgp_distance_cmd);
install_element(BGP_IPV6_NODE, &no_bgp_distance_cmd);
install_element(BGP_IPV6_NODE, &ipv6_bgp_distance_source_cmd);
install_element(BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_cmd);
install_element(BGP_IPV6_NODE,
&ipv6_bgp_distance_source_access_list_cmd);
install_element(BGP_IPV6_NODE,
&no_ipv6_bgp_distance_source_access_list_cmd);
install_element(BGP_IPV6M_NODE, &bgp_distance_cmd);
install_element(BGP_IPV6M_NODE, &no_bgp_distance_cmd);
install_element(BGP_IPV6M_NODE, &ipv6_bgp_distance_source_cmd);
install_element(BGP_IPV6M_NODE, &no_ipv6_bgp_distance_source_cmd);
install_element(BGP_IPV6M_NODE,
&ipv6_bgp_distance_source_access_list_cmd);
install_element(BGP_IPV6M_NODE,
&no_ipv6_bgp_distance_source_access_list_cmd);
/* BGP dampening */
install_element(BGP_NODE, &bgp_damp_set_cmd);
install_element(BGP_NODE, &bgp_damp_unset_cmd);
install_element(BGP_IPV4_NODE, &bgp_damp_set_cmd);
install_element(BGP_IPV4_NODE, &bgp_damp_unset_cmd);
install_element(BGP_IPV4M_NODE, &bgp_damp_set_cmd);
install_element(BGP_IPV4M_NODE, &bgp_damp_unset_cmd);
install_element(BGP_IPV4L_NODE, &bgp_damp_set_cmd);
install_element(BGP_IPV4L_NODE, &bgp_damp_unset_cmd);
install_element(BGP_IPV6_NODE, &bgp_damp_set_cmd);
install_element(BGP_IPV6_NODE, &bgp_damp_unset_cmd);
install_element(BGP_IPV6M_NODE, &bgp_damp_set_cmd);
install_element(BGP_IPV6M_NODE, &bgp_damp_unset_cmd);
install_element(BGP_IPV6L_NODE, &bgp_damp_set_cmd);
install_element(BGP_IPV6L_NODE, &bgp_damp_unset_cmd);
/* Large Communities */
install_element(VIEW_NODE, &show_ip_bgp_large_community_list_cmd);
install_element(VIEW_NODE, &show_ip_bgp_large_community_cmd);
/* show bgp ipv4 flowspec detailed */
install_element(VIEW_NODE, &show_ip_bgp_flowspec_routes_detailed_cmd);
install_element(VIEW_NODE, &show_bgp_listeners_cmd);
install_element(VIEW_NODE, &show_bgp_peerhash_cmd);
}
void bgp_route_finish(void)
{
afi_t afi;
safi_t safi;
FOREACH_AFI_SAFI (afi, safi) {
bgp_table_unlock(bgp_distance_table[afi][safi]);
bgp_distance_table[afi][safi] = NULL;
}
}
| 27.82339 | 235 | 0.673024 |
ae3405c84be8620e654a309425831cd2537f3fcd | 38 | c | C | src/cpp/qpsolver/cvxopt/src/C/SuiteSparse_cvxopt_extra/umfpack/amd_l_order.c | Hap-Hugh/quicksel | 10eee90b759638d5c54ba19994ae8e36e90e12b8 | [
"Apache-2.0"
] | 15 | 2020-07-07T16:32:53.000Z | 2022-03-16T14:23:23.000Z | src/cpp/qpsolver/cvxopt/src/C/SuiteSparse_cvxopt_extra/umfpack/amd_l_order.c | Hap-Hugh/quicksel | 10eee90b759638d5c54ba19994ae8e36e90e12b8 | [
"Apache-2.0"
] | 2 | 2020-09-02T15:25:39.000Z | 2020-09-24T08:37:18.000Z | src/cpp/qpsolver/cvxopt/src/C/SuiteSparse_cvxopt_extra/umfpack/amd_l_order.c | Hap-Hugh/quicksel | 10eee90b759638d5c54ba19994ae8e36e90e12b8 | [
"Apache-2.0"
] | 6 | 2020-08-14T22:02:07.000Z | 2021-03-31T07:08:29.000Z | #define DLONG
#include "amd_order.c"
| 9.5 | 22 | 0.736842 |
85f504e5ac27f88c8fdb8ceb8cb38c0de1f5f57c | 599 | h | C | Sources/Emulator/Util/LargeBuffer.h | drunkfly/retrotoolkit | 38fc08ce931339948d697a4dcf6f2441bccef7d6 | [
"MIT",
"Unlicense"
] | 3 | 2021-04-17T11:32:36.000Z | 2022-01-03T17:51:27.000Z | Sources/Emulator/Util/LargeBuffer.h | drunkfly/retrotoolkit | 38fc08ce931339948d697a4dcf6f2441bccef7d6 | [
"MIT",
"Unlicense"
] | null | null | null | Sources/Emulator/Util/LargeBuffer.h | drunkfly/retrotoolkit | 38fc08ce931339948d697a4dcf6f2441bccef7d6 | [
"MIT",
"Unlicense"
] | null | null | null | #ifndef EMULATOR_UTIL_LARGEBUFFER_H
#define EMULATOR_UTIL_LARGEBUFFER_H
#include "Emulator/Common.h"
class LargeBuffer
{
public:
explicit LargeBuffer(size_t size);
~LargeBuffer();
size_t size() const { return mSize; }
uint8_t operator[](size_t offset) const;
uint8_t& operator[](size_t offset);
void readAt(size_t offset, void* dst, size_t count) const;
void readFile(const char* path);
private:
std::unique_ptr<uint8_t[]> mBuffer;
size_t mSize;
size_t mReserved;
void ensureLength(size_t needed) const;
DISABLE_COPY(LargeBuffer);
};
#endif
| 18.71875 | 62 | 0.711185 |
6aa13db824d932ddef18142414b1a921f56bac99 | 9,732 | h | C | xdk-asf-3.51.0/sam/utils/cmsis/sam3x/include/instance/instance_tc2.h | j3270/SAMD_Experiments | 5c242aff44fc8d7092322d7baf2dda450a78a9b7 | [
"MIT"
] | 13 | 2019-06-14T11:48:49.000Z | 2022-03-04T21:28:29.000Z | xdk-asf-3.51.0/sam/utils/cmsis/sam3x/include/instance/instance_tc2.h | j3270/SAMD_Experiments | 5c242aff44fc8d7092322d7baf2dda450a78a9b7 | [
"MIT"
] | 1 | 2021-04-13T10:02:05.000Z | 2021-04-13T10:55:29.000Z | xdk-asf-3.51.0/sam/utils/cmsis/sam3x/include/instance/instance_tc2.h | j3270/SAMD_Experiments | 5c242aff44fc8d7092322d7baf2dda450a78a9b7 | [
"MIT"
] | 2 | 2020-10-12T15:06:25.000Z | 2021-05-13T01:47:18.000Z | /**
* \file
*
* Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/
#ifndef _SAM3XA_TC2_INSTANCE_
#define _SAM3XA_TC2_INSTANCE_
/* ========== Register definition for TC2 peripheral ========== */
#if (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__))
#define REG_TC2_CCR0 (0x40088000U) /**< \brief (TC2) Channel Control Register (channel = 0) */
#define REG_TC2_CMR0 (0x40088004U) /**< \brief (TC2) Channel Mode Register (channel = 0) */
#define REG_TC2_SMMR0 (0x40088008U) /**< \brief (TC2) Stepper Motor Mode Register (channel = 0) */
#define REG_TC2_CV0 (0x40088010U) /**< \brief (TC2) Counter Value (channel = 0) */
#define REG_TC2_RA0 (0x40088014U) /**< \brief (TC2) Register A (channel = 0) */
#define REG_TC2_RB0 (0x40088018U) /**< \brief (TC2) Register B (channel = 0) */
#define REG_TC2_RC0 (0x4008801CU) /**< \brief (TC2) Register C (channel = 0) */
#define REG_TC2_SR0 (0x40088020U) /**< \brief (TC2) Status Register (channel = 0) */
#define REG_TC2_IER0 (0x40088024U) /**< \brief (TC2) Interrupt Enable Register (channel = 0) */
#define REG_TC2_IDR0 (0x40088028U) /**< \brief (TC2) Interrupt Disable Register (channel = 0) */
#define REG_TC2_IMR0 (0x4008802CU) /**< \brief (TC2) Interrupt Mask Register (channel = 0) */
#define REG_TC2_CCR1 (0x40088040U) /**< \brief (TC2) Channel Control Register (channel = 1) */
#define REG_TC2_CMR1 (0x40088044U) /**< \brief (TC2) Channel Mode Register (channel = 1) */
#define REG_TC2_SMMR1 (0x40088048U) /**< \brief (TC2) Stepper Motor Mode Register (channel = 1) */
#define REG_TC2_CV1 (0x40088050U) /**< \brief (TC2) Counter Value (channel = 1) */
#define REG_TC2_RA1 (0x40088054U) /**< \brief (TC2) Register A (channel = 1) */
#define REG_TC2_RB1 (0x40088058U) /**< \brief (TC2) Register B (channel = 1) */
#define REG_TC2_RC1 (0x4008805CU) /**< \brief (TC2) Register C (channel = 1) */
#define REG_TC2_SR1 (0x40088060U) /**< \brief (TC2) Status Register (channel = 1) */
#define REG_TC2_IER1 (0x40088064U) /**< \brief (TC2) Interrupt Enable Register (channel = 1) */
#define REG_TC2_IDR1 (0x40088068U) /**< \brief (TC2) Interrupt Disable Register (channel = 1) */
#define REG_TC2_IMR1 (0x4008806CU) /**< \brief (TC2) Interrupt Mask Register (channel = 1) */
#define REG_TC2_CCR2 (0x40088080U) /**< \brief (TC2) Channel Control Register (channel = 2) */
#define REG_TC2_CMR2 (0x40088084U) /**< \brief (TC2) Channel Mode Register (channel = 2) */
#define REG_TC2_SMMR2 (0x40088088U) /**< \brief (TC2) Stepper Motor Mode Register (channel = 2) */
#define REG_TC2_CV2 (0x40088090U) /**< \brief (TC2) Counter Value (channel = 2) */
#define REG_TC2_RA2 (0x40088094U) /**< \brief (TC2) Register A (channel = 2) */
#define REG_TC2_RB2 (0x40088098U) /**< \brief (TC2) Register B (channel = 2) */
#define REG_TC2_RC2 (0x4008809CU) /**< \brief (TC2) Register C (channel = 2) */
#define REG_TC2_SR2 (0x400880A0U) /**< \brief (TC2) Status Register (channel = 2) */
#define REG_TC2_IER2 (0x400880A4U) /**< \brief (TC2) Interrupt Enable Register (channel = 2) */
#define REG_TC2_IDR2 (0x400880A8U) /**< \brief (TC2) Interrupt Disable Register (channel = 2) */
#define REG_TC2_IMR2 (0x400880ACU) /**< \brief (TC2) Interrupt Mask Register (channel = 2) */
#define REG_TC2_BCR (0x400880C0U) /**< \brief (TC2) Block Control Register */
#define REG_TC2_BMR (0x400880C4U) /**< \brief (TC2) Block Mode Register */
#define REG_TC2_QIER (0x400880C8U) /**< \brief (TC2) QDEC Interrupt Enable Register */
#define REG_TC2_QIDR (0x400880CCU) /**< \brief (TC2) QDEC Interrupt Disable Register */
#define REG_TC2_QIMR (0x400880D0U) /**< \brief (TC2) QDEC Interrupt Mask Register */
#define REG_TC2_QISR (0x400880D4U) /**< \brief (TC2) QDEC Interrupt Status Register */
#define REG_TC2_FMR (0x400880D8U) /**< \brief (TC2) Fault Mode Register */
#define REG_TC2_WPMR (0x400880E4U) /**< \brief (TC2) Write Protect Mode Register */
#else
#define REG_TC2_CCR0 (*(WoReg*)0x40088000U) /**< \brief (TC2) Channel Control Register (channel = 0) */
#define REG_TC2_CMR0 (*(RwReg*)0x40088004U) /**< \brief (TC2) Channel Mode Register (channel = 0) */
#define REG_TC2_SMMR0 (*(RwReg*)0x40088008U) /**< \brief (TC2) Stepper Motor Mode Register (channel = 0) */
#define REG_TC2_CV0 (*(RoReg*)0x40088010U) /**< \brief (TC2) Counter Value (channel = 0) */
#define REG_TC2_RA0 (*(RwReg*)0x40088014U) /**< \brief (TC2) Register A (channel = 0) */
#define REG_TC2_RB0 (*(RwReg*)0x40088018U) /**< \brief (TC2) Register B (channel = 0) */
#define REG_TC2_RC0 (*(RwReg*)0x4008801CU) /**< \brief (TC2) Register C (channel = 0) */
#define REG_TC2_SR0 (*(RoReg*)0x40088020U) /**< \brief (TC2) Status Register (channel = 0) */
#define REG_TC2_IER0 (*(WoReg*)0x40088024U) /**< \brief (TC2) Interrupt Enable Register (channel = 0) */
#define REG_TC2_IDR0 (*(WoReg*)0x40088028U) /**< \brief (TC2) Interrupt Disable Register (channel = 0) */
#define REG_TC2_IMR0 (*(RoReg*)0x4008802CU) /**< \brief (TC2) Interrupt Mask Register (channel = 0) */
#define REG_TC2_CCR1 (*(WoReg*)0x40088040U) /**< \brief (TC2) Channel Control Register (channel = 1) */
#define REG_TC2_CMR1 (*(RwReg*)0x40088044U) /**< \brief (TC2) Channel Mode Register (channel = 1) */
#define REG_TC2_SMMR1 (*(RwReg*)0x40088048U) /**< \brief (TC2) Stepper Motor Mode Register (channel = 1) */
#define REG_TC2_CV1 (*(RoReg*)0x40088050U) /**< \brief (TC2) Counter Value (channel = 1) */
#define REG_TC2_RA1 (*(RwReg*)0x40088054U) /**< \brief (TC2) Register A (channel = 1) */
#define REG_TC2_RB1 (*(RwReg*)0x40088058U) /**< \brief (TC2) Register B (channel = 1) */
#define REG_TC2_RC1 (*(RwReg*)0x4008805CU) /**< \brief (TC2) Register C (channel = 1) */
#define REG_TC2_SR1 (*(RoReg*)0x40088060U) /**< \brief (TC2) Status Register (channel = 1) */
#define REG_TC2_IER1 (*(WoReg*)0x40088064U) /**< \brief (TC2) Interrupt Enable Register (channel = 1) */
#define REG_TC2_IDR1 (*(WoReg*)0x40088068U) /**< \brief (TC2) Interrupt Disable Register (channel = 1) */
#define REG_TC2_IMR1 (*(RoReg*)0x4008806CU) /**< \brief (TC2) Interrupt Mask Register (channel = 1) */
#define REG_TC2_CCR2 (*(WoReg*)0x40088080U) /**< \brief (TC2) Channel Control Register (channel = 2) */
#define REG_TC2_CMR2 (*(RwReg*)0x40088084U) /**< \brief (TC2) Channel Mode Register (channel = 2) */
#define REG_TC2_SMMR2 (*(RwReg*)0x40088088U) /**< \brief (TC2) Stepper Motor Mode Register (channel = 2) */
#define REG_TC2_CV2 (*(RoReg*)0x40088090U) /**< \brief (TC2) Counter Value (channel = 2) */
#define REG_TC2_RA2 (*(RwReg*)0x40088094U) /**< \brief (TC2) Register A (channel = 2) */
#define REG_TC2_RB2 (*(RwReg*)0x40088098U) /**< \brief (TC2) Register B (channel = 2) */
#define REG_TC2_RC2 (*(RwReg*)0x4008809CU) /**< \brief (TC2) Register C (channel = 2) */
#define REG_TC2_SR2 (*(RoReg*)0x400880A0U) /**< \brief (TC2) Status Register (channel = 2) */
#define REG_TC2_IER2 (*(WoReg*)0x400880A4U) /**< \brief (TC2) Interrupt Enable Register (channel = 2) */
#define REG_TC2_IDR2 (*(WoReg*)0x400880A8U) /**< \brief (TC2) Interrupt Disable Register (channel = 2) */
#define REG_TC2_IMR2 (*(RoReg*)0x400880ACU) /**< \brief (TC2) Interrupt Mask Register (channel = 2) */
#define REG_TC2_BCR (*(WoReg*)0x400880C0U) /**< \brief (TC2) Block Control Register */
#define REG_TC2_BMR (*(RwReg*)0x400880C4U) /**< \brief (TC2) Block Mode Register */
#define REG_TC2_QIER (*(WoReg*)0x400880C8U) /**< \brief (TC2) QDEC Interrupt Enable Register */
#define REG_TC2_QIDR (*(WoReg*)0x400880CCU) /**< \brief (TC2) QDEC Interrupt Disable Register */
#define REG_TC2_QIMR (*(RoReg*)0x400880D0U) /**< \brief (TC2) QDEC Interrupt Mask Register */
#define REG_TC2_QISR (*(RoReg*)0x400880D4U) /**< \brief (TC2) QDEC Interrupt Status Register */
#define REG_TC2_FMR (*(RwReg*)0x400880D8U) /**< \brief (TC2) Fault Mode Register */
#define REG_TC2_WPMR (*(RwReg*)0x400880E4U) /**< \brief (TC2) Write Protect Mode Register */
#endif /* (defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */
#endif /* _SAM3XA_TC2_INSTANCE_ */
| 77.238095 | 107 | 0.665434 |
6a638f6d236f6b22a956c7b4706e1e53d75a6600 | 6,194 | h | C | src/plugins/cpp/templates/lr.template.h | gs-akhan/syntax | b9bb5c1d30f7762bbf4aeb93056960d3ceb4eae1 | [
"MIT"
] | 409 | 2015-11-27T07:57:06.000Z | 2022-03-27T15:56:23.000Z | src/plugins/cpp/templates/lr.template.h | gs-akhan/syntax | b9bb5c1d30f7762bbf4aeb93056960d3ceb4eae1 | [
"MIT"
] | 88 | 2016-10-22T16:59:25.000Z | 2022-03-26T19:10:47.000Z | src/plugins/cpp/templates/lr.template.h | gs-akhan/syntax | b9bb5c1d30f7762bbf4aeb93056960d3ceb4eae1 | [
"MIT"
] | 61 | 2016-10-08T12:31:16.000Z | 2022-03-31T12:35:25.000Z | /**
* LR parser for C++ generated by the Syntax tool.
*
* https://www.npmjs.com/package/syntax-cli
*
* npm install -g syntax-cli
*
* syntax-cli --help
*
* To regenerate run:
*
* syntax-cli \
* --grammar ~/path-to-grammar-file \
* --mode <parsing-mode> \
* --output ~/ParserClassName.h
*/
#ifndef __Syntax_LR_Parser_h
#define __Syntax_LR_Parser_h
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-private-field"
#include <assert.h>
#include <array>
#include <iostream>
#include <map>
#include <memory>
#include <regex>
#include <sstream>
#include <string>
#include <vector>
// ------------------------------------
// Module include prologue.
//
// Should include at least value/result type:
//
// type Value = <...>;
//
// Or struct Value { ... };
//
// Can also include parsing hooks:
//
// void onParseBegin(const Parser& parser, const std::string& str) {
// ...
// }
//
// void onParseBegin(const Parser& parser, const Value& result) {
// ...
// }
//
// clang-format off
{{{MODULE_INCLUDE}}} // clang-format on
namespace syntax {
/**
* Tokenizer class.
*/
// clang-format off
{{{TOKENIZER}}}
// clang-format on
#define POP_V() \
parser.valuesStack.back(); \
parser.valuesStack.pop_back()
#define POP_T() \
parser.tokensStack.back(); \
parser.tokensStack.pop_back()
#define PUSH_VR() parser.valuesStack.push_back(__)
#define PUSH_TR() parser.tokensStack.push_back(__)
/**
* Parsing table type.
*/
enum class TE {
Accept,
Shift,
Reduce,
Transit,
};
/**
* Parsing table entry.
*/
struct TableEntry {
TE type;
int value;
};
// clang-format off
class {{{PARSER_CLASS_NAME}}};
// clang-format on
using yyparse = {{{PARSER_CLASS_NAME}}};
typedef void (*ProductionHandler)(yyparse&);
/**
* Encoded production.
*
* opcode - encoded index
* rhsLength - length of the RHS to pop.
*/
struct Production {
int opcode;
int rhsLength;
ProductionHandler handler;
};
// Key: Encoded symbol (terminal or non-terminal) index
// Value: TableEntry
using Row = std::map<int, TableEntry>;
/**
* Parser class.
*/
// clang-format off
class {{{PARSER_CLASS_NAME}}} {
// clang-format on
public:
/**
* Parsing values stack.
*/
std::vector<Value> valuesStack;
/**
* Token values stack.
*/
std::vector<std::string> tokensStack;
/**
* Parsing states stack.
*/
std::vector<int> statesStack;
/**
* Tokenizer.
*/
Tokenizer tokenizer;
/**
* Previous state to calculate the next one.
*/
int previousState;
/**
* Parses a string.
*/
Value parse(const std::string& str) {
// clang-format off
{{{ON_PARSE_BEGIN_CALL}}}
// clang-format on
// Initialize the tokenizer and the string.
tokenizer.initString(str);
// Initialize the stacks.
valuesStack.clear();
tokensStack.clear();
statesStack.clear();
// Initial 0 state.
statesStack.push_back(0);
auto token = tokenizer.getNextToken();
auto shiftedToken = token;
// Main parsing loop.
for (;;) {
auto state = statesStack.back();
auto column = (int)token->type;
if (table_[state].count(column) == 0) {
throwUnexpectedToken(token);
}
auto entry = table_[state].at(column);
// Shift a token, go to state.
if (entry.type == TE::Shift) {
// Push token.
tokensStack.push_back(token->value);
// Push next state number: "s5" -> 5
statesStack.push_back(entry.value);
shiftedToken = token;
token = tokenizer.getNextToken();
}
// Reduce by production.
else if (entry.type == TE::Reduce) {
auto productionNumber = entry.value;
auto production = productions_[productionNumber];
tokenizer.yytext = shiftedToken->value;
auto rhsLength = production.rhsLength;
while (rhsLength > 0) {
statesStack.pop_back();
rhsLength--;
}
// Call the handler.
production.handler(*this);
auto previousState = statesStack.back();
auto symbolToReduceWith = production.opcode;
auto nextStateEntry = table_[previousState].at(symbolToReduceWith);
assert(nextStateEntry.type == TE::Transit);
statesStack.push_back(nextStateEntry.value);
}
// Accept the string.
else if (entry.type == TE::Accept) {
// Pop state number.
statesStack.pop_back();
// Pop the parsed value.
// clang-format off
{{{PARSED_RESULT}}}
// clang-format on
if (statesStack.size() != 1 || statesStack.back() != 0 ||
tokenizer.hasMoreTokens()) {
throwUnexpectedToken(token);
}
statesStack.pop_back();
// clang-format off
{{{ON_PARSE_END_CALL}}}
// clang-format on
return result;
}
}
}
private:
/**
* Throws parser error on unexpected token.
*/
[[noreturn]] void throwUnexpectedToken(SharedToken token) {
if (token->type == TokenType::__EOF && !tokenizer.hasMoreTokens()) {
std::string errMsg = "Unexpected end of input.\n";
std::cerr << errMsg;
throw std::runtime_error(errMsg.c_str());
}
tokenizer.throwUnexpectedToken(token->value, token->startLine,
token->startColumn);
}
// clang-format off
static constexpr size_t PRODUCTIONS_COUNT = {{{PRODUCTIONS_COUNT}}};
static std::array<Production, PRODUCTIONS_COUNT> productions_;
static constexpr size_t ROWS_COUNT = {{{ROWS_COUNT}}};
static std::array<Row, ROWS_COUNT> table_;
// clang-format on
};
// ------------------------------------------------------------------
// Productions.
// clang-format off
{{{PRODUCTION_HANDLERS}}}
// clang-format on
// clang-format off
std::array<Production, yyparse::PRODUCTIONS_COUNT> yyparse::productions_ = {{{PRODUCTIONS}}};
// clang-format on
// ------------------------------------------------------------------
// Parsing table.
// clang-format off
std::array<Row, yyparse::ROWS_COUNT> yyparse::table_ = {{{TABLE}}};
// clang-format on
} // namespace syntax
#endif | 21.506944 | 93 | 0.601227 |
27110bce482a77b4ffd47048d9ae94171c3e4e1b | 63 | h | C | trunk/win/Source/Includes/QtIncludes/include/QtXmlPatterns/private/qdatetimefn_p.h | dyzmapl/BumpTop | 1329ea41411c7368516b942d19add694af3d602f | [
"Apache-2.0"
] | 460 | 2016-01-13T12:49:34.000Z | 2022-02-20T04:10:40.000Z | trunk/win/Source/Includes/QtIncludes/include/QtXmlPatterns/private/qdatetimefn_p.h | dyzmapl/BumpTop | 1329ea41411c7368516b942d19add694af3d602f | [
"Apache-2.0"
] | 24 | 2016-11-07T04:59:49.000Z | 2022-03-14T06:34:12.000Z | trunk/win/Source/Includes/QtIncludes/include/QtXmlPatterns/private/qdatetimefn_p.h | dyzmapl/BumpTop | 1329ea41411c7368516b942d19add694af3d602f | [
"Apache-2.0"
] | 148 | 2016-01-17T03:16:43.000Z | 2022-03-17T12:20:36.000Z | #include "../../../src/xmlpatterns/functions/qdatetimefn_p.h"
| 31.5 | 62 | 0.698413 |
167c657c3210f94bb54be9abff393966c63b65d4 | 620 | h | C | graf.h | Deadlykittenn/Tema1_Poo_Stoicescu_Adrian | cf1a34fb2326b1c57759bcea3aaf80799490506b | [
"MIT"
] | null | null | null | graf.h | Deadlykittenn/Tema1_Poo_Stoicescu_Adrian | cf1a34fb2326b1c57759bcea3aaf80799490506b | [
"MIT"
] | null | null | null | graf.h | Deadlykittenn/Tema1_Poo_Stoicescu_Adrian | cf1a34fb2326b1c57759bcea3aaf80799490506b | [
"MIT"
] | null | null | null | #ifndef GRAF_H
#define GRAF_H
#include<iostream>
class graf
{
int size_;
int** mat_;
public:
graf(int nr_noduri);
graf(const graf& other);
void add_muchie(int x, int y);
void BFS(int nod);
void DFS(int nod);
int distanta(int x,int y);
void afis_lista_adiacenta_nod(const int nod);
virtual ~graf();
graf operator+(const graf& other);
graf operator-(const int nod);
bool arbore();
bool conex();
int nr_noduri();
int nr_muchii();
graf& operator=(const graf& other);
friend std::ostream& operator<<(std::ostream&, const graf&);
};
#endif // GRAF_H
| 20 | 64 | 0.632258 |
0e924e11ac05eeae908f3ce4a2720e95b897a51f | 420 | h | C | net4cpp21/utils/int64.h | MariusStrugaru/rmtsvc | abe3807d8bd98131b5a935a75746708b2abba3b9 | [
"MIT"
] | 63 | 2016-09-30T06:34:01.000Z | 2022-03-12T14:47:28.000Z | attac/INT64.H | zbeckerman/attac | ca07aeb7fbb14e2aea8d19aeb0b044bbc27721e7 | [
"Apache-2.0"
] | 2 | 2017-11-13T20:53:07.000Z | 2020-11-04T08:06:15.000Z | attac/INT64.H | zbeckerman/attac | ca07aeb7fbb14e2aea8d19aeb0b044bbc27721e7 | [
"Apache-2.0"
] | 43 | 2015-12-19T07:16:25.000Z | 2021-12-23T02:40:56.000Z | /*
* Header for int64.c.
*/
#ifndef PUTTY_INT64_H
#define PUTTY_INT64_H
typedef struct {
unsigned long hi, lo;
} uint64, int64;
uint64 uint64_div10(uint64 x, int *remainder);
void uint64_decimal(uint64 x, char *buffer);
uint64 uint64_make(unsigned long hi, unsigned long lo);
uint64 uint64_add(uint64 x, uint64 y);
uint64 uint64_add32(uint64 x, unsigned long y);
int uint64_compare(uint64 x, uint64 y);
#endif
| 21 | 55 | 0.747619 |
8dfb6cfe0c4f3ef22835aee517d4c1c60d4ef9c3 | 3,401 | h | C | ext/lib/crypto/mbedtls/include/mbedtls/asn1.h | dmgerman/zephyrd3 | b6a23cc9c5d534c352e33fd18fff7799ac3c2886 | [
"Apache-2.0"
] | null | null | null | ext/lib/crypto/mbedtls/include/mbedtls/asn1.h | dmgerman/zephyrd3 | b6a23cc9c5d534c352e33fd18fff7799ac3c2886 | [
"Apache-2.0"
] | null | null | null | ext/lib/crypto/mbedtls/include/mbedtls/asn1.h | dmgerman/zephyrd3 | b6a23cc9c5d534c352e33fd18fff7799ac3c2886 | [
"Apache-2.0"
] | null | null | null | DECL|MBEDTLS_ASN1_BIT_STRING|macro|MBEDTLS_ASN1_BIT_STRING
DECL|MBEDTLS_ASN1_BMP_STRING|macro|MBEDTLS_ASN1_BMP_STRING
DECL|MBEDTLS_ASN1_BOOLEAN|macro|MBEDTLS_ASN1_BOOLEAN
DECL|MBEDTLS_ASN1_CONSTRUCTED|macro|MBEDTLS_ASN1_CONSTRUCTED
DECL|MBEDTLS_ASN1_CONTEXT_SPECIFIC|macro|MBEDTLS_ASN1_CONTEXT_SPECIFIC
DECL|MBEDTLS_ASN1_GENERALIZED_TIME|macro|MBEDTLS_ASN1_GENERALIZED_TIME
DECL|MBEDTLS_ASN1_H|macro|MBEDTLS_ASN1_H
DECL|MBEDTLS_ASN1_IA5_STRING|macro|MBEDTLS_ASN1_IA5_STRING
DECL|MBEDTLS_ASN1_INTEGER|macro|MBEDTLS_ASN1_INTEGER
DECL|MBEDTLS_ASN1_NULL|macro|MBEDTLS_ASN1_NULL
DECL|MBEDTLS_ASN1_OCTET_STRING|macro|MBEDTLS_ASN1_OCTET_STRING
DECL|MBEDTLS_ASN1_OID|macro|MBEDTLS_ASN1_OID
DECL|MBEDTLS_ASN1_PRIMITIVE|macro|MBEDTLS_ASN1_PRIMITIVE
DECL|MBEDTLS_ASN1_PRINTABLE_STRING|macro|MBEDTLS_ASN1_PRINTABLE_STRING
DECL|MBEDTLS_ASN1_SEQUENCE|macro|MBEDTLS_ASN1_SEQUENCE
DECL|MBEDTLS_ASN1_SET|macro|MBEDTLS_ASN1_SET
DECL|MBEDTLS_ASN1_T61_STRING|macro|MBEDTLS_ASN1_T61_STRING
DECL|MBEDTLS_ASN1_TAG_CLASS_MASK|macro|MBEDTLS_ASN1_TAG_CLASS_MASK
DECL|MBEDTLS_ASN1_TAG_PC_MASK|macro|MBEDTLS_ASN1_TAG_PC_MASK
DECL|MBEDTLS_ASN1_TAG_VALUE_MASK|macro|MBEDTLS_ASN1_TAG_VALUE_MASK
DECL|MBEDTLS_ASN1_UNIVERSAL_STRING|macro|MBEDTLS_ASN1_UNIVERSAL_STRING
DECL|MBEDTLS_ASN1_UTC_TIME|macro|MBEDTLS_ASN1_UTC_TIME
DECL|MBEDTLS_ASN1_UTF8_STRING|macro|MBEDTLS_ASN1_UTF8_STRING
DECL|MBEDTLS_ERR_ASN1_ALLOC_FAILED|macro|MBEDTLS_ERR_ASN1_ALLOC_FAILED
DECL|MBEDTLS_ERR_ASN1_BUF_TOO_SMALL|macro|MBEDTLS_ERR_ASN1_BUF_TOO_SMALL
DECL|MBEDTLS_ERR_ASN1_INVALID_DATA|macro|MBEDTLS_ERR_ASN1_INVALID_DATA
DECL|MBEDTLS_ERR_ASN1_INVALID_LENGTH|macro|MBEDTLS_ERR_ASN1_INVALID_LENGTH
DECL|MBEDTLS_ERR_ASN1_LENGTH_MISMATCH|macro|MBEDTLS_ERR_ASN1_LENGTH_MISMATCH
DECL|MBEDTLS_ERR_ASN1_OUT_OF_DATA|macro|MBEDTLS_ERR_ASN1_OUT_OF_DATA
DECL|MBEDTLS_ERR_ASN1_UNEXPECTED_TAG|macro|MBEDTLS_ERR_ASN1_UNEXPECTED_TAG
DECL|MBEDTLS_OID_CMP|macro|MBEDTLS_OID_CMP
DECL|MBEDTLS_OID_SIZE|macro|MBEDTLS_OID_SIZE
DECL|buf|member|mbedtls_asn1_buf buf; /**< Buffer containing the given ASN.1 item. */
DECL|len|member|size_t len; /**< ASN1 length, in octets. */
DECL|len|member|size_t len; /**< ASN1 length, in octets. */
DECL|mbedtls_asn1_bitstring|struct|typedef struct mbedtls_asn1_bitstring
DECL|mbedtls_asn1_bitstring|typedef|mbedtls_asn1_bitstring;
DECL|mbedtls_asn1_buf|struct|typedef struct mbedtls_asn1_buf
DECL|mbedtls_asn1_buf|typedef|mbedtls_asn1_buf;
DECL|mbedtls_asn1_named_data|struct|typedef struct mbedtls_asn1_named_data
DECL|mbedtls_asn1_named_data|typedef|mbedtls_asn1_named_data;
DECL|mbedtls_asn1_sequence|struct|typedef struct mbedtls_asn1_sequence
DECL|mbedtls_asn1_sequence|typedef|mbedtls_asn1_sequence;
DECL|next_merged|member|unsigned char next_merged; /**< Merge next item into the current one? */
DECL|next|member|struct mbedtls_asn1_named_data *next; /**< The next entry in the sequence. */
DECL|next|member|struct mbedtls_asn1_sequence *next; /**< The next entry in the sequence. */
DECL|oid|member|mbedtls_asn1_buf oid; /**< The object identifier. */
DECL|p|member|unsigned char *p; /**< ASN1 data, e.g. in ASCII. */
DECL|p|member|unsigned char *p; /**< Raw ASN1 data for the bit string */
DECL|tag|member|int tag; /**< ASN1 type, e.g. MBEDTLS_ASN1_UTF8_STRING. */
DECL|unused_bits|member|unsigned char unused_bits; /**< Number of unused bits at the end of the string */
DECL|val|member|mbedtls_asn1_buf val; /**< The named value. */
| 64.169811 | 105 | 0.87239 |
e1c0e846c904b62881874566c49159deac3aa9fa | 1,061 | h | C | Pod/Classes/RSAnalytics.h | ricsantos/RSAnalytics | c278dbf98f5fb3b9af4076a5ca66eefc81855815 | [
"Apache-2.0"
] | 1 | 2018-08-15T18:14:10.000Z | 2018-08-15T18:14:10.000Z | Pod/Classes/RSAnalytics.h | ricsantos/RSAnalytics | c278dbf98f5fb3b9af4076a5ca66eefc81855815 | [
"Apache-2.0"
] | null | null | null | Pod/Classes/RSAnalytics.h | ricsantos/RSAnalytics | c278dbf98f5fb3b9af4076a5ca66eefc81855815 | [
"Apache-2.0"
] | null | null | null | //
// RSAnalytics.h
//
// Created by Ric Santos on 24/05/14.
//
#import <Foundation/Foundation.h>
#define RSAnalyticsCategoryOneshot @"CategoryOneshot"
#define RSAnalyticsCategorySystem @"CategorySystem"
#define RSAnalyticsCategorySharing @"CategorySharing"
#define RSAnalyticsCategoryIAP @"CategoryIAP"
extern NSString *const RSAnalyticsProviderFabric;
extern NSString *const RSAnalyticsProviderFacebook;
extern NSString *const RSAnalyticsProviderGoogle;
@interface RSAnalytics : NSObject
+ (RSAnalytics *)sharedInstance;
- (void)addProvider:(NSString *)provider withKey:(NSString *)key;
+ (NSMutableDictionary *)deviceAttributes;
+ (void)logEventWithCategory:(NSString *)category action:(NSString *)action;
+ (void)logEventWithCategory:(NSString *)category action:(NSString *)action label:(NSString *)label value:(NSNumber *)value;
+ (void)logEventWithAction:(NSString *)action attributes:(NSDictionary *)attributes;
+ (void)logAppLaunched;
+ (void)logOneshotEventWithAction:(NSString *)action andUserDefaultsKey:(NSString *)userDefaultsKey;
@end
| 31.205882 | 124 | 0.794533 |
e8fadb75cdba9c32808eaefffa82f7367ccfe5bf | 217 | h | C | src/predict.h | mikldk/libdisclapmix2 | fd5097096094345fa83ac34ba98b14aa233cc00b | [
"Apache-2.0"
] | null | null | null | src/predict.h | mikldk/libdisclapmix2 | fd5097096094345fa83ac34ba98b14aa233cc00b | [
"Apache-2.0"
] | null | null | null | src/predict.h | mikldk/libdisclapmix2 | fd5097096094345fa83ac34ba98b14aa233cc00b | [
"Apache-2.0"
] | null | null | null | #ifndef PREDICT_H
#define PREDICT_H
#include "common.h"
#include "input_validation.h"
VectorXd predict(const MatrixXi& new_data, const MatrixXi& y, const MatrixXd& disclap_parameters, const VectorXd& tau);
#endif
| 19.727273 | 119 | 0.78341 |
77443176041c968b4f2573ea7abd76e45f0b53ed | 592 | c | C | c/learn_c_the_hard_way/ex10.c | ssavinash1/Algorithm_stanford | f2588b6bcac2b0858e78b819e6e8402109e80ee2 | [
"MIT"
] | 24 | 2016-03-21T07:53:54.000Z | 2020-06-29T12:16:36.000Z | c/learn_c_the_hard_way/ex10.c | ssavinash1/Algorithm_stanford | f2588b6bcac2b0858e78b819e6e8402109e80ee2 | [
"MIT"
] | 5 | 2015-09-29T17:12:36.000Z | 2020-03-26T20:51:56.000Z | c/learn_c_the_hard_way/ex10.c | ssavinash1/Algorithm_stanford | f2588b6bcac2b0858e78b819e6e8402109e80ee2 | [
"MIT"
] | 12 | 2016-05-24T16:48:32.000Z | 2020-10-02T12:22:09.000Z | #include <stdio.h>
int main(int argc, char *argv[]) {
int i = 0;
// Our own array of strings.
char *states[] = {"California", "Oregon", "Washington", "Texas"};
int num_states = 4;
// extra: interchange a state with an argument.
char *tmp = states[0];
states[0] = argv[0];
argv[0] = tmp;
// Go through all params of the script and print them.
// First item in argv is the name of the script!
for (i = 0; i < argc; i++) {
printf("arg %d: %s\n", i, argv[i]);
}
for (i = 0; i < num_states; i++) {
printf("state %d: %s.\n", i, states[i]);
}
return 0;
}
| 21.925926 | 67 | 0.567568 |
9899ab518e5ee6149a3328a2bc261b606e1c828c | 4,159 | c | C | xdk-asf-3.51.0/common/components/wifi/winc3400/host_app/provisioning/base64decode.c | j3270/SAMD_Experiments | 5c242aff44fc8d7092322d7baf2dda450a78a9b7 | [
"MIT"
] | null | null | null | xdk-asf-3.51.0/common/components/wifi/winc3400/host_app/provisioning/base64decode.c | j3270/SAMD_Experiments | 5c242aff44fc8d7092322d7baf2dda450a78a9b7 | [
"MIT"
] | null | null | null | xdk-asf-3.51.0/common/components/wifi/winc3400/host_app/provisioning/base64decode.c | j3270/SAMD_Experiments | 5c242aff44fc8d7092322d7baf2dda450a78a9b7 | [
"MIT"
] | null | null | null | /**
*
* \file
*
* \brief This module contains WINC3400 Host MCU Provisioning implementation.
*
* Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.
*
* \asf_license_start
*
* \page License
*
* Subject to your compliance with these terms, you may use Microchip
* software and any derivatives exclusively with Microchip products.
* It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that
* may accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
#include "http_content.h"
#include <string.h>
#include <ctype.h>
static const char b64_table[] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '+', '/'
};
uint32 base64decode(char* src, uint32 len)
{
uint32 i = 0;
uint32 j = 0;
uint32 size = 0;
uint8 buf[3];
uint8 tmp[4];
char* dst = src;
// Skip line which contains '-' (-----BEGIN ...)
for(;j<len;j++)
{
if(src[j] == '-')
break;
}
for(;j<len;j++)
{
if(src[j] == '\r' || src[j] == '\n')
{
len -= j;
src = &src[j];
break;
}
}
for(uint32 k=0;j<len;k++)
{
char c = src[k];
if(c == '\r' || c == '\n') // Ignore new line characters
continue;
else if (c == '=' || (!isalnum(c) && c != '+' && c != '/')) // Stop if character is padding (=) or invalid
break;
tmp[i++] = c;
if (i == 4)
{
// Translate values in 'tmp' from table
for (i=0;i<4;i++)
{
// Find translation char in 'b64_table'
for (uint8 x=0;x<64;x++)
{
if (tmp[i] == b64_table[x])
{
tmp[i] = x;
break;
}
}
}
// Decode
buf[0] = (tmp[0] << 2) + ((tmp[1] & 0x30) >> 4);
buf[1] = ((tmp[1] & 0xf) << 4) + ((tmp[2] & 0x3c) >> 2);
buf[2] = ((tmp[2] & 0x3) << 6) + tmp[3];
memcpy(&dst[size], buf, sizeof(buf));
size += sizeof(buf);
i = 0;
}
}
// Remainder
if (i > 0)
{
// Fill remaining chars with '\0'
for (uint8 l=i;l<4;l++)
tmp[l] = '\0';
// Translate remainder
for (uint8 m=0;m<4;m++)
{
// Find translation char in 'b64_table'
for (uint8 x=0;x<64;x++)
{
if(tmp[m] == b64_table[x])
{
tmp[m] = x;
break;
}
}
}
// Decode remainder
buf[0] = (tmp[0] << 2) + ((tmp[1] & 0x30) >> 4);
buf[1] = ((tmp[1] & 0xf) << 4) + ((tmp[2] & 0x3c) >> 2);
buf[2] = ((tmp[2] & 0x3) << 6) + tmp[3];
memcpy(&dst[size], buf, i - 1);
size += i - 1;
}
return size;
}
uint32 decodeLength(uint8* buff, uint8* lenBytes)
{
// The length byte can be in 2 forms:
// Short form: 8th bit is 0, remaining bits is the length of the section, up to 127 bytes.
// Long form: 8th bit is 1, remaining bits are how many subsequent bytes make up the length.
// See ISO/IEC 8825-1 section 8.1.3
// https://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf
uint32 length = buff[0];
*lenBytes = 0;
if(length & 0x80) // Long form
{
*lenBytes = length & 0x7F; // Get how many bytes make up the length value
length = 0;
for(uint8 i=0;i<*lenBytes;i++)
length += (uint32)(buff[i + 1] << ((*lenBytes - i - 1) * 8));
}
return length;
}
| 24.609467 | 108 | 0.57081 |
60ee1c4431326c6c52303999275012ea3bdd3d14 | 576 | h | C | data/train/cpp/1d4d19cc43a2d8d6e592841e7cd4cb6c1cc24526Chunk.h | harshp8l/deep-learning-lang-detection | 2a54293181c1c2b1a2b840ddee4d4d80177efb33 | [
"MIT"
] | 84 | 2017-10-25T15:49:21.000Z | 2021-11-28T21:25:54.000Z | data/train/cpp/1d4d19cc43a2d8d6e592841e7cd4cb6c1cc24526Chunk.h | vassalos/deep-learning-lang-detection | cbb00b3e81bed3a64553f9c6aa6138b2511e544e | [
"MIT"
] | 5 | 2018-03-29T11:50:46.000Z | 2021-04-26T13:33:18.000Z | data/train/cpp/1d4d19cc43a2d8d6e592841e7cd4cb6c1cc24526Chunk.h | vassalos/deep-learning-lang-detection | cbb00b3e81bed3a64553f9c6aa6138b2511e544e | [
"MIT"
] | 24 | 2017-11-22T08:31:00.000Z | 2022-03-27T01:22:31.000Z | #ifndef __msg_chunk_h__
#define __msg_chunk_h__
#include "MsgCommon.h"
namespace Msg
{
class Chunk
{
public:
Chunk() : m_unChunkSize(0) , m_pBuf(NULL){}
Chunk(void * pBuf , UINT32 unChunkSize) : m_unChunkSize(unChunkSize) , m_pBuf((char *)pBuf){}
~Chunk(){}
public:
char * GetBuf(){ return m_pBuf; }
void SetBuf(void * pBuf){ m_pBuf = (char *)pBuf; }
UINT32 GetSize(){ return m_unChunkSize; }
void SetSize(UINT32 unChunkSize){ m_unChunkSize = unChunkSize; }
private:
char * m_pBuf;
UINT32 m_unChunkSize;
};
}
#endif | 22.153846 | 95 | 0.649306 |
7c03f2757f0ec5348fdc2a066321954bf0d0a5ae | 3,204 | c | C | c/amo.c | openshmem-org/openshmem-examples | 729ab1e4836fd553a4569d273a2d4ee602f1506b | [
"Unlicense"
] | 19 | 2015-08-08T14:29:30.000Z | 2021-05-12T03:23:33.000Z | c/amo.c | openshmem-org/openshmem-examples | 729ab1e4836fd553a4569d273a2d4ee602f1506b | [
"Unlicense"
] | 3 | 2016-02-12T18:23:33.000Z | 2021-02-05T16:43:17.000Z | c/amo.c | openshmem-org/openshmem-examples | 729ab1e4836fd553a4569d273a2d4ee602f1506b | [
"Unlicense"
] | 13 | 2015-01-25T21:47:28.000Z | 2021-05-31T22:51:32.000Z | /*****************************************************************************
* Copyright (C) 2015 Silicon Graphics International Corp.
* All rights reserved.
****************************************************************************/
/* Program contributed by SGI on the OpenSHMEM mailing list*/
#include <shmem.h>
#include <stdio.h>
#include <stdlib.h>
const int tries = 10000;
#ifdef TEST64BIT
typedef long locktype;
#else /* */
typedef int locktype;
#endif /* */
int
main()
{
int tpe, other;
long i;
struct
{
locktype a;
locktype b;
} *twovars;
int numfail = 0;
shmem_init();
tpe = 0;
other = shmem_n_pes() - 1;
twovars = shmem_malloc(sizeof(*twovars));
if (shmem_my_pe() == 0) {
printf("Element size: %ld bytes\n", sizeof(locktype));
printf("Addresses: 1st element %p\n", (void *) &twovars->a);
printf(" 2nd element %p\n", (void *) &twovars->b);
printf("Iterations: %d target PE: %d other active PE: %d\n",
tries, tpe, other);
}
twovars->a = 0;
twovars->b = 0;
shmem_barrier_all();
if (shmem_my_pe() == 0) {
// put two values alternately to the 1st 32 bit word
long expect, check;
for (i = 0; i < tries; i++) {
expect = 2 + i % 2;
if (sizeof(locktype) == sizeof(int)) {
shmem_int_p((void *) &twovars->a, expect, tpe);
check = shmem_int_g((void *) &twovars->a, tpe);
}
else if (sizeof(locktype) == sizeof(long)) {
shmem_long_p((void *) &twovars->a, expect, tpe);
check = shmem_long_g((void *) &twovars->a, tpe);
}
if (check != expect) {
printf("error: iter %ld get returned %ld expected %ld\n", i,
check, expect);
numfail++;
if (numfail > 10) {
printf("FAIL\n");
abort();
}
}
}
printf("PE %d done doing puts and gets\n", shmem_my_pe());
}
else if (shmem_my_pe() == other) {
// keep on atomically incrementing the 2nd 32 bit word
long oldval;
for (i = 0; i < tries; i++) {
if (sizeof(locktype) == sizeof(int)) {
oldval =
shmem_int_atomic_fetch_inc((void *) &twovars->b, tpe);
}
else if (sizeof(locktype) == sizeof(long)) {
oldval =
shmem_long_atomic_fetch_inc((void *) &twovars->b, tpe);
}
if (oldval != i) {
printf("error: iter %ld finc got %ld expect %ld\n", i,
oldval, i);
numfail++;
if (numfail > 10) {
printf("FAIL\n");
abort();
}
}
}
printf("PE %d done doing fincs\n", shmem_my_pe());
}
shmem_barrier_all();
if (numfail) {
printf("FAIL\n");
}
shmem_barrier_all();
if (shmem_my_pe() == 0) {
printf("test complete\n");
}
shmem_finalize();
return 0;
}
| 29.394495 | 78 | 0.451935 |
5031670551620272a92fe310af2f5363c633ae75 | 327 | h | C | src/entity/systementity.h | Christophedlr/EDSystem | c9d158278ce1c2326ec5fd238a806e5052bdb8f3 | [
"MIT"
] | null | null | null | src/entity/systementity.h | Christophedlr/EDSystem | c9d158278ce1c2326ec5fd238a806e5052bdb8f3 | [
"MIT"
] | null | null | null | src/entity/systementity.h | Christophedlr/EDSystem | c9d158278ce1c2326ec5fd238a806e5052bdb8f3 | [
"MIT"
] | null | null | null | #ifndef SYSTEMENTITY_H
#define SYSTEMENTITY_H
#include <QString>
#include "../model/entity.h"
class SystemEntity : public Entity
{
public:
SystemEntity();
QString getName() const;
void setName(const QString name);
private:
QString m_name;
};
#endif // SYSTEMENTITY_H
| 16.35 | 42 | 0.626911 |
da9acd14dce840d66acf93df99e702705d24802b | 54,923 | h | C | Source/ExtSupport/Module.h | jadu/Phalanger | 41c3fc0da98f9120bcb92ca310f4abeac4e4b993 | [
"Apache-2.0"
] | null | null | null | Source/ExtSupport/Module.h | jadu/Phalanger | 41c3fc0da98f9120bcb92ca310f4abeac4e4b993 | [
"Apache-2.0"
] | null | null | null | Source/ExtSupport/Module.h | jadu/Phalanger | 41c3fc0da98f9120bcb92ca310f4abeac4e4b993 | [
"Apache-2.0"
] | null | null | null | //
// ExtSupport - substitute for php4ts.dll/php5ts.dll
//
// Module.h
// - contains declaration of Constant class
// - contains declaration of Function class
// - contains declaration of Method class
// - contains declaration of CallerMethod class
// - contains declaration of ConstructorMethod class
// - contains declaration of GetterMethod class
// - contains declaration of SetterMethod class
// - contains declaration of Class class
// - contains declaration of IniEntry class
// - contains declaration of Module class
//
#pragma once
#include "stdafx.h"
#include "Objects.h"
#include "PhpMarshaler.h"
#include "VirtualWorkingDir.h"
#include "Memory.h"
#include "TsrmLs.h"
#undef GetClassName
using namespace System;
using namespace System::Collections;
using namespace System::Runtime::InteropServices;
/*
Designed and implemented by Ladislav Prosek.
*/
extern MUTEX_T mx_module_entries;
/// <summary>
/// Holds information about one class registered by an extension.
/// </summary>
struct unmng_class_entry
{
zend_class_entry *original_entry; // as given by the extension
zend_class_entry *entry; // copied
zend_class_entry *parent; // should point to the appropriate _copy_
};
/// <summary>
/// Holds information about classes and contants registered by one extension.
/// </summary>
struct unmng_class_and_constant_info
{
HashTable *class_entries;
HashTable *constant_entries;
};
// Performs unmanaged class registration (necessary for reregistration in another AppDomain).
void unmng_register_class(int module_number, zend_class_entry *ce, zend_class_entry *parent_ce);
// Performs unmanaged constant registration (necessary for reregistration in another AppDomain).
void unmng_register_constant(zend_constant *c);
namespace PHP
{
namespace ExtManager
{
ref class Class;
ref class Module;
ref class Request;
/// <summary>
/// Represents a constant defined by an extension.
/// </summary>
/// <remarks>
/// Instances of this class are stored in hash tables keyed by constant name. The reason why
/// the constant's value is not stored in hash tables directly is that the Case-Sensitive
/// flag also needs to be remembered.
/// </remarks>
private ref class Constant
{
public:
/// <summary>
/// Creates a new <see cref="Constant"/>.
/// </summary>
/// <param name="mod">Reference to the module (extension) that has defined this constant.</param>
/// <param name="_value">The value of this constant.</param>
/// <param name="_name">The name of this constant.</param>
/// <param name="_caseInsensitive">Specifies whether this constant is case insensitive.</param>
Constant(Module ^mod, String ^_name, Object ^_value, bool _caseInsensitive)
{
containingModule = mod;
name = _name;
value = _value;
caseInsensitive = _caseInsensitive;
}
/// <summary>
/// Adds this constant to a <see cref="IDictionary"/>.
/// </summary>
/// <param name="dictionary">The <see cref="IDictionary"/> to add this constant to.</param>
/// <param name="name">The name of this constant.</param>
/// <returns><B>true</B> if successfully added, <B>false</B> otherwise.</returns>
bool AddToDictionary(IDictionary ^dictionary, String ^name);
/// <summary>
/// Retrievs a constant from a <see cref="IDictionary"/>.
/// </summary>
/// <param name="dictionary">The <see cref="IDictionary"/> to retrieve a constant from.</param>
/// <param name="name">The name of the constant to retrieve.</param>
/// <returns>The <see cref="Constant"/> or <B>null</B> if not found.</returns>
static Constant ^RetrieveFromDictionary(IDictionary ^dictionary, String ^name);
/// <summary>
/// Returns the name of this constant.
/// </summary>
/// <returns>The name of this constant.</returns>
String ^GetName()
{
return name;
}
/// <summary>
/// Returns the value of this constant.
/// </summary>
/// <returns>The value of this constant.</returns>
Object ^GetValue()
{
return value;
}
/// <summary>
/// Returns <B>true</B> if this <see cref="Constant"/> is case insensitive, <B>false</B> otherwise.
/// </summary>
/// <returns>
/// <B>true</B> if this <see cref="Constant"/> is case insensitive, <B>false</B> otherwise.
/// </returns>
bool IsCaseInsensitive()
{
return caseInsensitive;
}
/// <summary>
/// Returns the containing <see cref="Module"/> of this <see cref="Constant"/>.
/// </summary>
/// <returns>The containing <see cref="Module"/>.</returns>
Module ^GetContainingModule()
{
return containingModule;
}
/// <summary>
/// Registers this constant in the appropriate context (module or request).
/// </summary>
/// <param name="persistent"><B>true</B> if the constant should be registered as persistent,
/// <B>false</B> otherwise.</param>
/// <returns><B>true</B> if the constant was successfully registered, <B>false</B> otherwise.
/// </returns>
bool Register(bool persistent);
/// <summary>
/// Looks up a constant based on its name.
/// </summary>
/// <param name="name">The name of the constant.</param>
/// <returns>The constant or <B>null</B> if not found.</returns>
static Constant ^Lookup(String ^name);
private:
/// <summary>
/// Specifies whether this <see cref="Constant"/> is case insensitive.
/// </summary>
/// <remarks>
/// Case insensitive constants are converted to lower case before adding to a dictionary
/// and loookups.
/// <remarks>
bool caseInsensitive;
///<summary>The name of this constant.</summary>
String ^name;
///<summary>The value of this constant.</summary>
Object ^value;
/// <summary>The <see cref="Module"/> that has defined this constant.</summary>
Module ^containingModule;
};
/// <summary>
/// Represents a function defined by an extension.
/// </summary>
/// <remarks>
/// Instances of this class are stored in hash tables keyed by function name.
/// </remarks>
private ref class Function : public MarshalByRefObject, public PHP::Core::IExternalFunction
{
public:
virtual Object^ Invoke(PhpObject^ self, array<Object ^> ^%args, array<int> ^refInfo, String ^workingDir);
// ignored here, implemented in Externasl.CLR.cs
virtual property IExternals^ ExtManager{IExternals^ get(){throw gcnew NotImplementedException();}}
internal:
/// <summary>
/// Creates a new <see cref="Function"/>.
/// </summary>
/// <param name="mod">Reference to the module (extension) this function is defined in.</param>
/// <param name="func">Unmanaged pointer to the corresponding <c>zend_function_entry</c> block.</param>
Function(Module ^mod, zend_function_entry *func)
{
functionEntry = func;
containingModule = mod;
}
/// <summary>
/// Returns unmanaged pointer to the function itself (the handler).
/// </summary>
/// <returns>Unmanaged pointer to the function entry point.</returns>
virtual void (*GetFunctionPtr())(INTERNAL_FUNCTION_PARAMETERS)
{
return functionEntry->handler;
}
/// <summary>
/// Returns the name of this function.
/// </summary>
/// <returns>The name of this function.</returns>
virtual String ^GetFunctionName()
{
return gcnew String(functionEntry->fname);
}
/// <summary>
/// Returns the containing <see cref="Module"/> of this <see cref="Function"/>.
/// </summary>
/// <returns>The containing <see cref="Module"/>.</returns>
Module ^GetContainingModule()
{
return containingModule;
}
/// <summary>
/// Determines whether a parameter must always be passed by reference.
/// </summary>
/// <param name="paramNumber">Zero-based parameter index.</param>
/// <returns><B>true</B> if the parameter with index <paramref name="paramNumber"/> must be
/// passed by reference, <B>false</B> otherwise.
virtual bool ParameterForcedByRef(int paramNumber)
{
#if defined(PHP4TS)
unsigned char *arg_types = functionEntry->func_arg_types;
return (arg_types != NULL &&
((paramNumber < arg_types[0] && arg_types[paramNumber + 1] == BYREF_FORCE) ||
arg_types[arg_types[0]] == BYREF_FORCE_REST));
#elif defined(PHP5TS)
_zend_arg_info *info = functionEntry->arg_info;
return (info != NULL &&
((paramNumber < (int)functionEntry->num_args && info[paramNumber + 1].pass_by_reference) ||
info[0].pass_by_reference));
#else
Debug::Assert(false);
return false;
#endif
}
/// <summary>
/// Invokes this function with given parameters.
/// </summary>
/// <param name="retValueUsed">Specifies whether the caller is interested in return value.</param>
/// <param name="self">The instance on which the function should be invoked (if it is a method).</param>
/// <param name="args">Function parameters.</param>
/// <param name="refInfo">Indexes into the <paramref name="args"/> marking parameters that should
/// be passed by reference, and optionally terminated with <c>-1</c> which means that from
/// the last marked parameter on, everything should be passed by reference.</param>
/// <param name="propertyReference">Additional parameter to be passed to the function handler,
/// used by the <c>handle_function_call</c> handler.</param>
/// <returns>The return value (only valid if <paramref name="retValueUsed"/> is <B>true</B>.</returns>
virtual Object ^Invoke(Request ^request, bool retValueUsed, PHP::Core::PhpObject ^self, array<Object ^> ^args,
array<int> ^refInfo, zend_property_reference *propertyReference);
protected:
/// <summary>
/// Construct a bool array marking parameters to be passed by reference and check whether all
/// parameters that are forced to be passed by reference actually are.
/// </summary>
/// <param name="request">Current <see cref="Request"/>.</param>
/// <param name="numArgs">Number of actual paramaters.</param>
/// <param name="refInfo">Parameter indexes marking parameters that should be passed by reference,
/// and optionally terminated with <c>-1</c> which means that from the last marked parameter on,
/// everything should be passed by reference.</param>
/// <returns><B>true</B> if successfully validated, <B>false</B> otherwise.</returns>
bool ValidateParameters(Request ^request, int numArgs, array<int> ^refInfo);
/// <summary>
/// Unmanaged pointer to the corresponding <c>zend_function_entry</c> block.
/// </summary>
zend_function_entry *functionEntry;
/// <summary>
/// Reference to the module (extension) this function is defined in.
/// </summary>
Module ^containingModule;
};
/// <summary>
/// Represents a method defined by an extension.
/// </summary>
/// <remarks>
/// Instances of this class are stored in hash tables keyed by method name.
/// </remarks>
private ref class Method : public Function
{
public:
internal:
/// <summary>
/// Creates a new <see cref="Method"/>.
/// </summary>
/// <param name="cls">Reference to the class this method is defined in.</param>
/// <param name="func">Unmanaged pointer to the corresponding <c>zend_function_entry</c> block.</param>
Method(Class ^cls, zend_function_entry *func);
#if defined(PHP5TS)
/// <summary>
/// Allocates a <c>zend_function</c> describing this instance.
/// </summary>
/// <returns>Pointer to the <c>zend_function</c>.</returns>
zend_function *CreateZendFunction();
#endif
/// <summary>
/// Returns the declaring <see cref="Class"/> of this <see cref="Method"/>.
/// </summary>
/// <returns>The declaring <see cref="Class"/>.</returns>
Class ^GetDeclaringClass()
{
return declaringClass;
}
/// <summary>
/// Invokes this method with given parameters.
/// </summary>
/// <param name="retValueUsed">Specifies whether the caller is interested in return value.</param>
/// <param name="self">The instance on which the function should be invoked.</param>
/// <param name="args">Method parameters.</param>
/// <param name="refInfo">Indexes into the <paramref name="args"/> marking parameters that should
/// be passed by reference, and optionally terminated with <c>-1</c> which means that from
/// the last marked parameter on, everything should be passed by reference.</param>
/// <param name="propertyReference">Additional parameter to be passed to the function handler,
/// used by the <c>handle_function_call</c> handler.</param>
/// <returns>The return value (only valid if <paramref name="retValueUsed"/> is <B>true</B>.</returns>
/// <remarks>Checks are made to ensure that <paramref name="self"/> is valid.</remarks>
virtual Object ^Invoke(Request ^request, bool retValueUsed, PHP::Core::PhpObject ^self, array<Object ^> ^args,
array<int> ^refInfo, zend_property_reference *propertyReference) override;
protected:
/// <summary>
/// Reference to the class this method is defined in.
/// </summary>
Class ^declaringClass;
};
#if defined(PHP4TS) || defined (PHP5TS)
/// <summary>
/// Represents a <c>handle_function_call</c> handler defined by an extension.
/// </summary>
/// <remarks>
/// The handler is wrapped by this class in order to be callable like a <c>__call</c> method.
/// </remarks>
private ref class CallerMethod : public Method
{
public:
#ifdef PHP4TS
/// <summary>
/// Creates a new <see cref="CallerMethod"/>.
/// </summary>
/// <param name="cls">Reference to the class this method is defined in.</param>
/// <param name="handler">Unmanaged pointer to the corresponding <c>handle_function_call</c> function.</param>
CallerMethod(Class ^cls,
void (*handler)(INTERNAL_FUNCTION_PARAMETERS, zend_property_reference *property_reference))
: Method(cls, NULL)
{
this->handler = (void (*)(INTERNAL_FUNCTION_PARAMETERS))handler;
}
#elif defined(PHP5TS)
/// <summary>
/// Creates a new <see cref="CallerMethod"/>.
/// </summary>
/// <param name="cls">Reference to the class this method is defined in.</param>
/// <param name="handler">Unmanaged pointer to the corresponding <c>handle_function_call</c> function.</param>
CallerMethod(Class ^cls,
void (*handler)(INTERNAL_FUNCTION_PARAMETERS))
: Method(cls, NULL)
{
this->handler = handler;
}
#endif
/// <summary>
/// Returns unmanaged pointer to the function itself (the handler).
/// </summary>
/// <returns>Unmanaged pointer to the function entry point.</returns>
virtual void (*GetFunctionPtr())(INTERNAL_FUNCTION_PARAMETERS) override
{
return handler;
}
/// <summary>
/// Invokes the handler.
/// </summary>
/// <param name="retValueUsed">Specifies whether the caller is interested in return value.</param>
/// <param name="self">The instance on which the handler should be invoked.</param>
/// <param name="args">Method parameters.</param>
/// <param name="refInfo">Indexes into the <paramref name="args"/> marking parameters that should
/// be passed by reference, and optionally terminated with <c>-1</c> which means that from
/// the last marked parameter on, everything should be passed by reference.</param>
/// <param name="methodName">The name of the method to invoke.</param>
/// <returns>The return value (only valid if <paramref name="retValueUsed"/> is <B>true</B>.</returns>
Object ^InvokeHandler(Request ^request, bool retValueUsed, PHP::Core::PhpObject ^self, array<Object ^> ^args,
array<int> ^refInfo, String ^methodName);
/// <summary>
/// Determines whether a parameter must always be passed by reference.
/// </summary>
/// <param name="paramNumber">Zero-based parameter index.</param>
/// <returns><B>true</B> if the parameter with index <paramref name="paramNumber"/> must be
/// passed by reference, <B>false</B> otherwise.
virtual bool ParameterForcedByRef(int paramNumber) override
{
// handle_function_call has no info block with such information
return false;
}
/// <summary>
/// Returns the name of this "function".
/// </summary>
/// <returns>The name of this function.</returns>
virtual String ^GetFunctionName() override
{
#pragma warning (push)
#pragma warning (disable: 4395)
return PHP::Core::PhpObject::SpecialMethodNames::Call.ToString();
#pragma warning (pop)
}
/// <summary>
/// Invokes the handler as a <c>__call</c> method - name of the method to invoke is expected in argument 0.
/// </summary>
/// <param name="retValueUsed">Specifies whether the caller is interested in return value.</param>
/// <param name="self">The instance on which the handler should be invoked.</param>
/// <param name="args">Method name followed by method parameters.</param>
/// <param name="refInfo">Indexes into the <paramref name="args"/> marking parameters that should
/// be passed by reference, and optionally terminated with <c>-1</c> which means that from
/// the last marked parameter on, everything should be passed by reference.</param>
/// <param name="propertyReference">Additional parameter to be passed to the function handler,
/// used by the <c>handle_function_call</c> handler.</param>
/// <returns>The return value (only valid if <paramref name="retValueUsed"/> is <B>true</B>.</returns>
virtual Object ^Invoke(Request ^request, bool retValueUsed, PHP::Core::PhpObject ^self, array<Object ^> ^args,
array<int> ^refInfo, zend_property_reference *propertyReference) override;
protected:
/// <summary>Unmanaged pointer to the corresponding <c>handle_function_call</c> function.</summary>
void (*handler)(INTERNAL_FUNCTION_PARAMETERS);
};
#endif
#ifdef PHP4TS
/// <summary>
/// Represents an artificial PHP constructor.
/// </summary>
/// <remarks>
/// <para>
/// When a user-defined PHP class has no constructor, the <c>__call</c> method - if defined - is not called
/// during instantiation. However, if an extension defines a class with a non-null <c>handle_function_call</c>
/// handler (for example <c>Java</c> class in <c>php_java</c> extension), this handler is called during
/// instantiation. That's why this artificial constructor is added to such classes.
/// </para>
/// <para>
/// This method is added to the declaring class's method table under the <c>$(class_name)</c> name, so that
/// it is recognized as a PHP contructor by managed wrapper generator as well as by certain object support
/// routines at run-time.
/// </para>
/// </remarks>
private ref class ConstructorMethod : public Method
{
public:
/// <summary>
/// Creates a new <see cref="ConstructorMethod"/>.
/// </summary>
/// <param name="callerMethod">The <see cref="CallerMethod"/> that invocations of this method
/// should be delegated to.</param>
ConstructorMethod(CallerMethod ^callerMethod) : Method(callerMethod->GetDeclaringClass(), NULL)
{
this->callerMethod = callerMethod;
}
/// <summary>
/// Returns the name of this function.
/// </summary>
/// <returns>The name of this function.</returns>
virtual String ^GetFunctionName() override;
/// <summary>
/// Invokes the associated <see cref="CallerMethod"/> with given parameters.
/// </summary>
/// <param name="retValueUsed">Specifies whether the caller is interested in return value.</param>
/// <param name="self">The instance on which the handler should be invoked.</param>
/// <param name="args">Constructor parameters.</param>
/// <param name="refInfo">Indexes into the <paramref name="args"/> marking parameters that should
/// be passed by reference, and optionally terminated with <c>-1</c> which means that from
/// the last marked parameter on, everything should be passed by reference.</param>
/// <param name="propertyReference">Additional parameter to be passed to the function handler,
/// used by the <c>handle_function_call</c> handler.</param>
/// <returns>The return value (only valid if <paramref name="retValueUsed"/> is <B>true</B>.</returns>
virtual Object ^Invoke(Request ^request, bool retValueUsed, PHP::Core::PhpObject ^self, array<Object ^> ^args,
array<int> ^refInfo, zend_property_reference *propertyReference) override;
protected:
/// <summary>The associated <see cref="CallerMethod"/>.</summary>
CallerMethod ^callerMethod;
};
/// <summary>
/// Represents a <c>handle_propery_get</c> handler defined by an extension.
/// </summary>
/// <remarks>
/// The handler is wrapped by this class in order to be callable like a <c>__get</c> method.
/// </remarks>
private ref class GetterMethod : public Method
{
public:
/// <summary>
/// Creates a new <see cref="GetterMethod"/>.
/// </summary>
/// <param name="cls">Reference to the class this method is defined in.</param>
/// <param name="handler">Unmanaged pointer to the corresponding <c>handle_property_get</c> function.</param>
GetterMethod(Class ^cls, zval (*handler)(zend_property_reference *property_reference))
: Method(cls, NULL)
{
this->handler = handler;
}
/// <summary>
/// Returns the name of this function.
/// </summary>
/// <returns>The name of this function.</returns>
virtual String ^GetFunctionName() override
{
#pragma warning (push)
#pragma warning (disable: 4395)
return PHP::Core::PhpObject::SpecialMethodNames::Get.ToString();
#pragma warning (pop)
}
/// <summary>
/// Invokes the handler as a <c>__get</c> method - name of the field to retrieve is expected in argument 0.
/// </summary>
/// <param name="retValueUsed">Specifies whether the caller is interested in return value.</param>
/// <param name="self">The instance on which the handler should be invoked.</param>
/// <param name="args">Field name.</param>
/// <param name="refInfo">Indexes into the <paramref name="args"/> marking parameters that should
/// be passed by reference, and optionally terminated with <c>-1</c> which means that from
/// the last marked parameter on, everything should be passed by reference.</param>
/// <param name="propertyReference">Additional parameter to be passed to the function handler,
/// used by the <c>handle_function_call</c> handler.</param>
/// <returns>The return value (only valid if <paramref name="retValueUsed"/> is <B>true</B>.</returns>
virtual Object ^Invoke(Request ^request, bool retValueUsed, PHP::Core::PhpObject ^self, array<Object ^> ^args,
array<int> ^refInfo, zend_property_reference *propertyReference) override;
protected:
/// <summary>Unmanaged pointer to the corresponding <c>handle_property_get</c> function.</summary>
zval (*handler)(zend_property_reference *property_reference);
};
/// <summary>
/// Represents a <c>handle_propery_set</c> handler defined by an extension.
/// </summary>
/// <remarks>
/// The handler is wrapped by this class in order to be callable like a <c>__set</c> method.
/// </remarks>
private ref class SetterMethod : public Method
{
public:
/// <summary>
/// Creates a new <see cref="SetterMethod"/>.
/// </summary>
/// <param name="cls">Reference to the class this method is defined in.</param>
/// <param name="handler">Unmanaged pointer to the corresponding <c>handle_property_set</c> function.</param>
SetterMethod(Class ^cls, int (*handler)(zend_property_reference *property_reference, zval *value))
: Method(cls, NULL)
{
this->handler = handler;
}
/// <summary>
/// Returns the name of this function.
/// </summary>
/// <returns>The name of this function.</returns>
virtual String ^GetFunctionName() override
{
#pragma warning (push)
#pragma warning (disable: 4395)
return PHP::Core::PhpObject::SpecialMethodNames::Set.ToString();
#pragma warning (pop)
}
/// <summary>
/// Invokes the handler as a <c>__set</c> method - name of the field to set or an array of
/// <see cref="RuntimeChainElement"/>s is expected in argument 0, the new field value is expected
/// in argument 1.
/// </summary>
/// <param name="retValueUsed">Specifies whether the caller is interested in return value.</param>
/// <param name="self">The instance on which the handler should be invoked.</param>
/// <param name="args">Field name followed by field value.</param>
/// <param name="refInfo">Indexes into the <paramref name="args"/> marking parameters that should
/// be passed by reference, and optionally terminated with <c>-1</c> which means that from
/// the last marked parameter on, everything should be passed by reference.</param>
/// <param name="propertyReference">Additional parameter to be passed to the function handler,
/// used by the <c>handle_function_call</c> handler.</param>
/// <returns>The return value (only valid if <paramref name="retValueUsed"/> is <B>true</B>.</returns>
virtual Object ^Invoke(Request ^request, bool retValueUsed, PHP::Core::PhpObject ^self, array<Object ^> ^args,
array<int> ^refInfo, zend_property_reference *propertyReference) override;
protected:
/// <summary>Unmanaged pointer to the corresponding <c>handle_property_set</c> function.</summary>
int (*handler)(zend_property_reference *property_reference, zval *value);
};
#elif defined (PHP5TS)
private ref class SpecialMethod : public Method
{
public:
/// <summary>
/// Creates a new <see cref="SpecialMethod"/>, such as _get, _set, etc.
/// </summary>
/// <param name="cls">Reference to the class this method is defined in.</param>
/// <param name="handler">Unmanaged pointer to the corresponding <c>zend_function</c> function.</param>
SpecialMethod(String^ name, Class ^cls,
void (*handler)(INTERNAL_FUNCTION_PARAMETERS))
: Method(cls, NULL)
{
this->handler = handler;
this->name = name;
}
/// <summary>
/// Returns the name of this "function".
/// </summary>
/// <returns>The name of this function.</returns>
virtual String ^GetFunctionName() override
{
return name;
}
/// <summary>
/// Returns unmanaged pointer to the function itself (the handler).
/// </summary>
/// <returns>Unmanaged pointer to the function entry point.</returns>
virtual void (*GetFunctionPtr())(INTERNAL_FUNCTION_PARAMETERS) override
{
return handler;
}
protected:
/// <summary>Unmanaged pointer to the corresponding <c>handle_function_call</c> function.</summary>
void (*handler)(INTERNAL_FUNCTION_PARAMETERS);
/// <summary>Name of the special function.</summary>
String^ name;
};
#endif
/// <summary>
/// Represents a class defined by an extension.
/// </summary>
/// <remarks>
/// Instances of <see cref="Class"/> are stored in hash tables keyed by class name.
/// </remarks>
private ref class Class : public IDisposable
{
public:
/// <summary>
/// Creates a new <see cref="Class"/>.
/// </summary>
/// <param name="mod">Reference to the module (extension) this class is defined in.</param>
/// <param name="entry">Unmanaged pointer to the corresponding <c>zend_class_entry</c> block.</param>
/// <param name="parentEntry">Unmanaged pointer to the parent <c>zend_class_entry</c> block.</param>
Class(Module ^mod, zend_class_entry *entry, zend_class_entry *parentEntry);
/// <summary>
/// Returns the name of this class.
/// </summary>
/// <returns>The name of this class.</returns>
String ^GetClassName()
{
if (classEntry->name == NULL) return String::Empty;
return gcnew String(classEntry->name, 0, classEntry->name_length);
}
/// <summary>
/// Returns the name of the base class.
/// </summary>
/// <returns>The name of this class's base class or <B>null</B> if this class has no base class.</returns>
String ^GetParentClassName()
{
if (classEntry == NULL || classEntry->parent == NULL) return nullptr;
if (classEntry->parent->name == NULL) return String::Empty;
return gcnew String(classEntry->parent->name, 0, classEntry->parent->name_length);
}
/// <summary>
/// Returns pointer to the corresponding <c>zend_class_entry</c>.
/// </summary>
/// <returns>Unmanaged pointer to the corresponding <c>zend_class_entry</c> block.</returns>
zend_class_entry *GetClassEntry()
{
return isOriginalClassEntryValid ? originalClassEntry : classEntry;
}
/// <summary>
/// Returns the containing <see cref="Module"/> of this <see cref="Class"/>.
/// </summary>
/// <returns>The containing <see cref="Module"/>.</returns>
Module ^GetContainingModule()
{
return containingModule;
}
/// <summary>
/// Returns <B>true</B> if this class represents <c>stdClass</c>.
/// </summary>
/// <returns><B>true</B> if this class represents <c>stdClass</c>, <B>false</B> otherwise.</returns>
bool IsStdClass()
{
return originalClassEntry == zend_stdClass_ptr;
}
/// <summary>
/// Returns a <see cref="Type"/> defined in the corresponding managed wrapper that wraps this Zend class.
/// </summary>
/// <returns>The wrapping type.</returns>
/// <remarks>
/// The wrapping type plays a key role in native-to-managed marshaling, see <see cref="PhpMarshaler"/>.
/// </remarks>
Type ^GetWrappingType()
{
return wrappingType;
}
/// <summary>
/// Returns a <see cref="Method"/> with a given name that was defined in this class.
/// </summary>
/// <param name="name">The name of the method.</param>
/// <returns>The <see cref="Method"/> or <B>null</B> if not found.
Method ^GetMethodByName(String ^name)
{
return static_cast<Method ^>(methods[name]);
}
/// <summary>
/// Returns a <see cref="Constants"/> with a given name that was defined in this class.
/// </summary>
/// <param name="name">The name of the constant.</param>
/// <returns>The <see cref="Constant"/> or <B>null</B> if not found.
Constant ^GetConstantByName(String ^name);
/// <summary>
/// Returns an <see cref="IDictionaryEnumerator"/> to be used for method enumeration.
/// </summary>
/// <returns>The enumerator.</returns>
IDictionaryEnumerator ^GetMethodEnumerator()
{
return methods->GetEnumerator();
}
/// <summary>
/// Returns an <see cref="IDictionaryEnumerator"/> to be used for constant enumeration.
/// </summary>
/// <returns>The enumerator.</returns>
IDictionaryEnumerator ^GetConstantEnumerator();
/// <summary>
/// Called when an instance of this class is being marshal from native to managed representation.
/// <summary>
/// <param name="entry">The <c>zend_class_entry</c> pointed to by the native representation.</param>
void OnMarshalNativeToManaged(zend_class_entry *entry)
{
if (entry == originalClassEntry) isOriginalClassEntryValid = true;
}
/// <summary>
/// Releases the unmanaged <c>zend_class_entry</c>.
/// </summary>
~Class()
{
GC::SuppressFinalize(this);
#if defined(PHP4TS)
destroy_zend_class(classEntry);
free(classEntry);
#elif defined(PHP5TS)
zend_class_entry *_tmp = classEntry;
destroy_zend_class(&_tmp);
classEntry = _tmp;
#else
Debug::Assert();
#endif
}
private:
/// <summary>
/// Unmanaged pointer to the corresponding <c>zend_function_entry</c> block.
/// </summary>
zend_class_entry *classEntry;
/// <summary>
/// Unmanaged pointer to the original <c>zend_function_entry</c> block (as supplied to
/// <c>register_internal_class</c>.
/// </summary>
zend_class_entry *originalClassEntry;
/// <summary>
/// Determines whether <see cref="originalClassEntry"/> is assumed valid.
/// </summary>
/// <remarks>
/// When creating new objects, some extensions use the original <c>zend_class_entry</c> pointer
/// that they had passed to <c>register_internal_class</c>, some use the pointer returned by
/// the call (pointer to a copy). The purpose of this field is to signal which of these two patterns
/// is followed by the <see cref="containingModule"/>.
/// </remarks>
bool isOriginalClassEntryValid;
/// <summary>
/// Reference to the module (extension) this class is defined in.
/// </summary>
Module ^containingModule;
/// <summary>
/// Collection of <see cref="Method"/>s declared by this class.
/// </summary>
Hashtable ^methods;
/// <summary>
/// The <see cref="Type"/> defined in the corresponding managed wrapper that wraps this Zend class.
/// </summary>
/// <remarks>
/// The wrapping type plays a key role in native-to-managed marshaling, see <see cref="PhpMarshaler"/>.
/// </remarks>
Type ^wrappingType;
// Static members
public:
/// <summary>
/// Returns the name of a Zend class.
/// </summary>
/// <returns>The name of the class.</returns>
static String ^GetZendClassName(zend_class_entry *entry)
{
if (entry == NULL) return String::Empty;
return gcnew String(entry->name, 0, entry->name_length);
}
/// <summary>A singleton representing the <c>stdClass</c> standard class.</summary>
static Class ^StdClass = gcnew Class(nullptr, zend_stdClass_ptr, NULL);
};
/// <summary>
/// Represents one configuration entry - one <c><set/> node in <c>ExtManager.exe.config</c>.
/// </summary>
/// <remarks>
/// The value is kept in both managed and unmanaged form, because some configuration related
/// Zend API functions return pointer to <c>zval</c>, pointer to <c>char</c> etc.
/// </remarks>
private ref class IniEntry
{
public:
/// <summary>
/// Creates a new <see cref="IniEntry"/>.
/// </summary>
/// <param name="value">The entry value.</param>
IniEntry(String ^value)
{
MngValue = value;
ntvValue = NULL;
}
/// <summary>
/// Cleans up unmanaged resources.
/// </summary>
~IniEntry()
{
if (ntvValue != NULL)
{
free(ntvValue->value.str.val);
free(ntvValue);
ntvValue = NULL;
}
}
/// <summary>
/// Returns the value in unmanaged form (pointer to <c>zval</c> structure).
/// </summary>
/// <returns>The value in unmanaged form.</returns>
zval *GetNativeValue()
{
Threading::Monitor::Enter(MngValue);
try
{
if (ntvValue == NULL)
{
ntvValue = (zval *)malloc(sizeof(zval));
INIT_PZVAL(ntvValue);
char *s = PhpMarshaler::GetInstance(nullptr)->MarshalManagedStringToNativeStringPersistent(MngValue);
ZVAL_STRING(ntvValue, s, false);
}
return ntvValue;
}
finally
{
Threading::Monitor::Exit(MngValue);
}
}
/// <summary>
/// The entry value.
/// </summary>
String ^MngValue;
private:
/// <summary>
/// Unmanaged form of the entry value.
/// </summary>
zval *ntvValue;
};
/// <summary>
/// Represents an abstract extension module.
/// </summary>
private ref class Module abstract
{
public:
/// <summary>
/// Calls extension's <c>info_func</c> handler.
/// </summary>
/// <returns><B>true</B> if the module has non-null <c>info_func</c> handler, <B>false</B> otherwise.
/// <remarks>
/// The result (extension information) is appended to <see cref="Request.phpInfoBuilder"/> of the current
/// <see cref="Request"/>.
/// </remarks>
virtual bool PhpInfo() = 0;
/// <summary>
/// Unloads this <see cref="Module"/>.
/// </summary>
virtual void ModuleShutdown() = 0;
/// <summary>
/// Calls extension's <c>request_startup_func</c> handler.
/// </summary>
virtual void RequestStartup(Request ^request) = 0;
/// <summary>
/// Calls extensions's <c>request_shutdown_func</c> handler.
/// </summary>
virtual void RequestShutdown(Request ^request) = 0;
/// <summary>
/// Generates managed wrapper for this extension.
/// </summary>
virtual String ^GenerateManagedWrapper() = 0;
/// <summary>
/// Returns the internal name of this extension. For example "sockets".
/// </summary>
/// <returns>The module name.</returns>
virtual String ^GetModuleName() = 0;
/// <summary>
/// Returns file name of this extension (without trailing <c>.DLL</c>). For example "php_sockets".
/// </summary>
/// <returns>The file name.</returns>
virtual String ^GetFileName() = 0;
/// <summary>
/// Returns module number (a unique integer ID).
/// </summary>
/// <returns>The module number.</returns>
virtual int GetModuleNumber() = 0;
/// <summary>
/// Returns module version.
/// </summary>
/// <returns>The module version or <B>null</B> if it's not specified.</returns>
virtual String ^GetVersion() = 0;
/// <summary>
/// Returns reference to the corresponding managed wrapper assembly.
/// </summary>
/// <returns>The <see cref="Reflection.Assembly"/> or <B>null</B> if the wrapper could not be found.</returns>
virtual System::Reflection::Assembly ^GetWrappingAssembly() = 0;
/// <summary>
/// Supports "one request" extensions that do their initialization in request startup handler
/// and are meant to server only one request (e.g. GTK).
/// </summary>
/// <return><B>true</B> if this is a one request extension, <B>false</B> otherwise.</return>
virtual bool IsEarlyInit()
{
return false;
}
/// <summary>
/// Returns a <see cref="Constant"/> with given name that was defined by this extension.
/// </summary>
/// <param name="name">The name of the constant.</param>
/// <returns>The <see cref="Constant"/> or <B>null</B> if not found.
Constant ^GetConstantByName(String ^name);
/// <summary>
/// Returns a <see cref="Function"/> with given name that was defined by this extension.
/// </summary>
/// <param name="name">The name of the function.</param>
/// <returns>The <see cref="Function"/> or <B>null</B> if not found.
Function ^GetFunctionByName(String ^name);
/// <summary>
/// Returns a <see cref="Class"/> with given name that was defined by this extension.
/// </summary>
/// <param name="name">The name of the class.</param>
/// <returns>The <see cref="Class"/> or <B>null</B> if not found.
Class ^GetClassByName(String ^name);
/// <summary>
/// Adds a persistent constant to the table of constants defined by this extension.
/// </summary>
/// <param name="name">Name of the constant.</param>
/// <param name="constant">The <see cref="Constant"/> representing the constant.</param>
/// <returns><B>true</B> if successfully added, <B>false</B> otherwise.</returns>
bool AddConstant(String ^name, Constant ^constant);
/// <summary>
/// Adds a class to the table of classes defined by this extension.
/// </summary>
/// <param name="name">Name of the class.</param>
/// <param name="entry">The <see cref="Class"/> representing the class.</param>
/// <param name="transient"><B>true</B> to register this constant as transient (as part of this request),
/// <B>false</B> to register it in module context.</param>
/// <returns><B>true</B> if successfully added, <B>false</B> otherwise.</returns>
void AddClass(String ^name, Class ^entry, bool transient);
/// <summary>
/// Determines whether the parameter represents a method table of a Zend class registered by this extension.
/// </summary>
/// <param name="ht">A Zend <c>HashTable</c> pointer.</ht>
/// <return><B>true</B> if <paramref name="ht"/> is a method table.</return>
bool IsNativeMethodTable(HashTable *ht);
/// <summary>
/// Returns an <see cref="ICollection"/> of names of functions defined by this extension.
/// </summary>
/// <returns>The collection.</returns>
ICollection ^GetFunctionNames();
/// <summary>
/// Returns an <see cref="ICollection"/> of names of classes defined by this extension.
/// </summary>
/// <returns>The collection.</returns>
ICollection ^GetClassNames();
/// <summary>
/// Returns an <see cref="IniEntry"/> given the key (INI entry name).
/// </summary>
/// <param name="key">The INI entry name.</param>
/// <returns>The <see cref="IniEntry"/> or <B>null</B> if not found.</returns>
IniEntry ^GetConfigEntry(String ^key);
protected:
/// <summary>Collection of <see cref="Function"/>s defined in this extension.</summary>
Hashtable ^functions;
/// <summary>Collection of <see cref="Constant"/>s that were registered by this extension.</summary>
Hashtable ^constants;
/// <summary>
/// Collection of classes that were registered by this extension.<summary>
/// </summary>
/// <remarks>
/// The reason that <see cref="OrderedHashtable"/> is used is that it is also necessary to maintain order.
/// When generating wrappers base class (registered earlier) has to be wrapped before derived
/// classes (registered later).
/// </remarks>
PHP::Core::OrderedHashtable<String ^> ^classes;
/// <summary>
/// Collection of INI settings for this extension that were found in the <c>ExtManager.exe.config</c>
/// file.
/// </summary>
Hashtable ^iniSettings;
// static members
public:
/// <summary>
/// Returns a module with given file name.
/// </summary>
/// <param name="name">The file name of the extension (without trailing <c>.DLL</c>). For example
/// "php_sockets".</param>
/// <returns>The <see cref="Module"/> or <B>null</B> if not found.</returns>
static Module ^GetModule(String ^name)
{
return static_cast<Module ^>(modules[name]);
}
/// <summary>
/// Returns a module with given zero-based index.
/// </summary>
/// <param name="index">The zero-based index.</param>
/// <returns>The <see cref="Module"/>.</returns>
/// <exception cref="ArgumentOutOfRangeException">Index out of range.</exception>
static Module ^GetModule(int index)
{
return static_cast<Module ^>(modules->GetByIndex(index));
}
/// <summary>
/// Returns a module with a given module number.
/// </summary>
/// <param name="number">The one-based module number.</param>
/// <returns>The <see cref="Module"/> or <B>null</B> if not found.</returns>
static Module ^GetModuleByModuleNumber(int number)
{
for (int i = 0; i < modules->Count; i++)
{
Module ^mod = static_cast<Module ^>(modules->GetByIndex(i));
if (mod != nullptr && mod->GetModuleNumber() == number) return mod;
}
return nullptr;
}
/// <summary>
/// Returns an early init module with given zero-based index.
/// </summary>
/// <param name="index">The zero-based index.</param>
/// <returns>The <see cref="Module"/>.</returns>
/// <exception cref="ArgumentOutOfRangeException">Index out of range.</exception>
static Module ^GetEarlyInitModule(int index)
{
return static_cast<Module ^>(earlyInitModules[index]);
}
/// <summary>
/// Returns a module with given module name (NOT file name).
/// </summary>
/// <param name="name">The module name of the extension. For example "sockets".</param>
/// <returns>The <see cref="Module"/> or <B>null</B> if not found.</returns>
static Module ^GetModuleByInternalName(String ^name)
{
return static_cast<Module ^>(modulesByInternalName[name]);
}
/// <summary>
/// Returns the number of loaded extensions.
/// </summary>
/// <returns>The number of loaded extensions.</returns>
static int GetModuleCount()
{
return modules->Count;
}
/// <summary>
/// Returns the number of loaded early init extensions.
/// </summary>
/// <returns>The number of loaded early init extensions.</returns>
static int GetEarlyInitModuleCount()
{
return earlyInitModules->Count;
}
/// <summary>
/// Returns an <see cref="ICollection"/> of file names (without trailing <c>.DLL</c>) of loaded
/// extensions.
/// </summary>
/// <returns>The collection.</returns>
static ICollection ^GetModuleNames()
{
return modules->Keys;
}
/// <summary>
/// Returns an <see cref="ICollection"/> of internal names of loaded extensions.
/// </summary>
/// <returns>The collection.</returns>
static ICollection ^GetInternalModuleNames()
{
return modulesByInternalName->Keys;
}
/// <summary>
/// Returns reference to the <see cref="Module/> that contains currently executing function.
/// </summary>
/// <returns>The <see cref="Module/> that contains currently executing function or <B>null</B>
/// if no external function is currently executing.</returns>
/// <remarks>
/// Understands <see cref="ModuleBoundContext"/> as well as <see cref="Request"/> context notion.
/// </remarks>
static Module ^GetCurrentModule();
/// <summary>
/// Contains reference to current <see cref="Module"/> for calling thread.
/// </summary>
/// <remarks>
/// This thread-static member is not <B>null</B> when a function in the extension is called
/// with no <see cref="Request"/> context (typically <c>module_startup</c>, <c>module_shutdown</c>).
[ThreadStatic]
static Module ^ModuleBoundContext = nullptr;
protected:
/// <summary>
/// Collection of all loaded extensions, keyed by file name without trailing <c>.DLL</c>.
/// </summary>
static SortedList ^modules = SortedList::Synchronized(gcnew SortedList());
/// <summary>
/// Collection of all loaded extensions, keyed by <c>moduleEntry->name</c> (internal name).
/// </summary>
static Hashtable ^modulesByInternalName = Hashtable::Synchronized(gcnew Hashtable());
/// <summary>
/// Collection of early init extensions.
/// </summary>
static ArrayList ^earlyInitModules = ArrayList::Synchronized(gcnew ArrayList());
};
/// <summary>
/// Represents a module (PHP extension DLL).
/// </summary>
private ref class DynamicModule : public Module
{
public:
/// <summary>
/// Creates and loads a new <see cref="DynamicModule"/>.
/// </summary>
/// <remarks>
/// Note that dynamic loading of extensions at runtime using the <c>dl()</c> PHP function is
/// not supported (as it is in PHP with multithreaded web servers). All extensions are loaded
/// and corresponding <see cref="Module"/> instances are constructed during start up.
/// </remarks>
DynamicModule(String ^_path, String ^_fileName, bool _earlyInit);
/// <summary>
/// Calls extension's <c>info_func</c> handler.
/// </summary>
/// <returns><B>true</B> if the module has non-null <c>info_func</c> handler, <B>false</B> otherwise.
/// <remarks>
/// The result (extension information) is appended to <see cref="Request.phpInfoBuilder"/> of the current
/// <see cref="Request"/>.
/// </remarks>
virtual bool PhpInfo() override;
/// <summary>
/// Unloads this <see cref="Module"/>.
/// </summary>
virtual void ModuleShutdown() override;
/// <summary>
/// Calls extension's <c>request_startup_func</c> handler.
/// </summary>
virtual void RequestStartup(Request ^request) override;
/// <summary>
/// Calls extensions's <c>request_shutdown_func</c> handler.
/// </summary>
virtual void RequestShutdown(Request ^request) override;
/// <summary>
/// Generates managed wrapper for this extension.
/// </summary>
virtual String ^GenerateManagedWrapper() override;
//
//
/// <summary>
/// Returns file name of this extension (without trailing <c>.DLL</c>). For example "php_sockets".
/// </summary>
/// <returns>The file name.</returns>
virtual String ^GetFileName() override
{
return fileName;
}
/// <summary>
/// Returns the internal name of this extension. For example "sockets".
/// </summary>
/// <returns>The module name.</returns>
virtual String ^GetModuleName() override
{
return gcnew String(moduleEntry->name);
}
/// <summary>
/// Returns reference to the corresponding managed wrapper assembly.
/// </summary>
/// <returns>The <see cref="Reflection.Assembly"/> or <B>null</B> if the wrapper could not be found.</returns>
virtual System::Reflection::Assembly ^GetWrappingAssembly() override;
/// <summary>
/// Returns module number (a unique integer ID).
/// </summary>
/// <returns>The module number.</returns>
virtual int GetModuleNumber() override
{
return moduleEntry->module_number;
}
/// <summary>
/// Returns module version.
/// </summary>
/// <returns>The module version or <B>null</B> if it's not specified.</returns>
virtual String ^GetVersion() override
{
if (moduleEntry->version == NULL) return nullptr;
return gcnew String(moduleEntry->version);
}
/// <summary>
/// Supports "one request" extensions that do their initialization in request startup handler
/// and are meant to serve only one request (e.g. GTK).
/// </summary>
/// <return><B>true</B> if this is a one request extension, <B>false</B> otherwise.</return>
virtual bool IsEarlyInit() override
{
return earlyInit;
}
private:
/// <summary>
/// P/Invoke declaration of <c>LoadLibraryEx</c>.
/// </summary>
/// <remarks>
/// This declaration merely saves us from doing manual <see cref="String"/> marshaling.
/// </remarks>
[DllImport("kernel32.dll", CharSet = CharSet::Unicode, SetLastError = true)]
static HMODULE LoadLibraryEx(String ^fileName,IntPtr reserved,int flags);
/// <summary><B>true</B> if this instance is fully initialized, <B>false</B> otherwise (tested in finalizer).</summary>
bool initialized;
/// <summary><B>true</B> if this is a one request extension (e.g. GTK)</summary>
bool earlyInit;
/// <summary>Handle of the loaded DLL.</summary>
HMODULE hLib;
/// <summary>
/// The file name of this extension (without trailing <c>.DLL</c>). For example "php_sockets".
/// </summary>
String ^fileName;
/// <summary>
/// Reference to the corresponding managed wrapper assembly (loaded lazily only when necessary).
/// </summary>
/// <remarks><seealso cref="GetWrappingAssembly"/></remarks>
System::Reflection::Assembly ^wrappingAssembly;
/// <summary>Unmanaged pointer to this extension's <c>zend_module_entry block</c>.</summary>
zend_module_entry *moduleEntry;
/// <summary>
/// Signature of the <c>get_module</c> function, which is the only symbol exported by
/// PHP extension DLLs.
/// </summary>
typedef zend_module_entry *(*GetModuleProto)();
// static members
public:
/// <summary>
/// Loads specified extension implemented in a DLL.
/// </summary>
/// <remarks>
/// A new <see cref="Module"/> is instantiated to represent the loaded extension. Reference to
/// the newly created instance is added to <see cref="modules"/>, <see cref="modulesByName"/> and
/// the Zend <c>module_registry</c>.
/// </remarks>
static DynamicModule ^LoadDynamicModule(ExtensionLibraryDescriptor ^descriptor);
};
/// <summary>
/// Represents built-in stream wrappers "extension" (currently ftp, http).
/// </summary>
private ref class InternalStreamWrappers : public Module
{
public:
/// <summary>
/// Registers built-in stream wrappers.
/// </summary>
InternalStreamWrappers();
/// <summary>
/// Returns <B>false</B>.
/// </summary>
virtual bool PhpInfo() override
{
return false;
}
/// <summary>
/// Unloads this <see cref="Module"/>.
/// </summary>
virtual void ModuleShutdown() override;
/// <summary>
/// Does nothing.
/// </summary>
virtual void RequestStartup(Request ^request) override
{ }
/// <summary>
/// Does nothing.
/// </summary>
virtual void RequestShutdown(Request ^request) override
{ }
/// <summary>
/// Returns <B>null</B>.
/// </summary>
virtual String ^GenerateManagedWrapper() override
{
return nullptr;
}
/// <summary>
/// Returns the internal name of this "extension".
/// </summary>
/// <returns>The module name.</returns>
virtual String ^GetModuleName() override
{
return "#stream_wrappers";
}
/// <summary>
/// Returns <B>null</B>.
/// </summary>
/// <returns><B>null</B></returns>
virtual String ^GetFileName() override
{
return "#stream_wrappers";
}
/// <summary>
/// Returns <c>-1</c>.
/// </summary>
/// <returns><c>-1</c></returns>
virtual int GetModuleNumber() override
{
return -1;
}
/// <summary>
/// Returns module version.
/// </summary>
/// <returns><B>null</B></returns>
virtual String ^GetVersion() override
{
return nullptr;
}
/// <summary>
/// Returns <B>null</B>.,
/// </summary>
/// <returns><B>null</B></returns>
virtual System::Reflection::Assembly ^GetWrappingAssembly() override
{
return nullptr;
}
// static members
public:
/// <summary>
/// Loads this extension.
/// </summary>
/// <remarks>
/// A new <see cref="Module"/> is instantiated to represent the loaded extension. Reference to
/// the newly created instance is added to <see cref="modules"/> and <see cref="modulesByName"/>.
/// </remarks>
static void LoadModule();
};
}
}
| 36.737793 | 123 | 0.643501 |
fb9a8b709ff4dfe3e08e6a1e28f3bfe729770f14 | 671 | h | C | EPTwittererChainFinderController.h | simX/degrees-of-tweetdom | 1cad3724dad46f28aa8aff8fdc854f41d17d3088 | [
"MIT"
] | 1 | 2016-05-09T06:51:24.000Z | 2016-05-09T06:51:24.000Z | EPTwittererChainFinderController.h | simX/degrees-of-tweetdom | 1cad3724dad46f28aa8aff8fdc854f41d17d3088 | [
"MIT"
] | null | null | null | EPTwittererChainFinderController.h | simX/degrees-of-tweetdom | 1cad3724dad46f28aa8aff8fdc854f41d17d3088 | [
"MIT"
] | null | null | null | //
// EPTwittererChainFinderController.h
// Degrees of Tweetdom
//
// Created by Simone Manganelli on 2008-08-24.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@class EPTwittererChainFinder;
@interface EPTwittererChainFinderController : NSWindowController {
IBOutlet NSTextView *errorConsoleView;
IBOutlet NSTextField *statusTextField;
IBOutlet NSTextField *firstTwittererTextField;
IBOutlet NSTextField *secondTwittererTextField;
EPTwittererChainFinder *twittererChainFinderInstance;
}
- (void)addStatusLine:(NSString *)statusLine;
- (void)scrollErrorConsoleToBottom;
- (IBAction)startChainSearch:(id)sender;
@end
| 23.964286 | 66 | 0.801788 |
f730e854f7abc9e1666ee95b73ab5bcd71014f34 | 15,536 | h | C | include/cutlass/epilogue/threadblock/predicated_tile_iterator_strided_dgrad.h | kroburg/cutlass | 21c1fa38495bf66ec72023dbb3cb70e1eb52fdf1 | [
"BSD-3-Clause"
] | null | null | null | include/cutlass/epilogue/threadblock/predicated_tile_iterator_strided_dgrad.h | kroburg/cutlass | 21c1fa38495bf66ec72023dbb3cb70e1eb52fdf1 | [
"BSD-3-Clause"
] | null | null | null | include/cutlass/epilogue/threadblock/predicated_tile_iterator_strided_dgrad.h | kroburg/cutlass | 21c1fa38495bf66ec72023dbb3cb70e1eb52fdf1 | [
"BSD-3-Clause"
] | null | null | null | /***************************************************************************************************
* Copyright (c) 2017 - 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
*
* 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.
*
**************************************************************************************************/
/*! \file
\brief Epilogue for threadblock scoped GEMMs using Tensor Ops.
The epilogue rearranges the result of a matrix product through shared memory to match canonical
tensor layouts in global memory. Epilogues support conversion and reduction operations.
*/
#pragma once
#include "cutlass/cutlass.h"
#include "cutlass/numeric_types.h"
#include "cutlass/array.h"
#include "cutlass/layout/matrix.h"
#include "cutlass/layout/tensor.h"
#include "cutlass/matrix_shape.h"
#include "cutlass/tensor_ref.h"
#include "cutlass/transform/pitch_linear_thread_map.h"
#include "cutlass/epilogue/threadblock/output_tile_thread_map.h"
#include "cutlass/arch/arch.h"
#include "cutlass/arch/memory.h"
#include "cutlass/conv/conv2d_problem_size.h"
#include "cutlass/epilogue/threadblock/predicated_tile_iterator_params.h"
////////////////////////////////////////////////////////////////////////////////
namespace cutlass {
////////////////////////////////////////////////////////////////////////////////
namespace epilogue {
namespace threadblock {
////////////////////////////////////////////////////////////////////////////////
/// Tile iterator used to load and store output tile from global memory in epilogue.
///
/// Satisfies: ReadableTileIterator | PredicatedTileIterator | ForwardTileIterator
///
template <
typename ThreadMap_, ///< Thread map (conept: OutputTileThreadMap)
typename Element_ ///< Element data type
>
class PredicatedTileIteratorStridedDgrad {
public:
using ThreadMap = ThreadMap_;
using Shape = typename ThreadMap::Shape;
using Element = Element_;
using Layout = layout::RowMajor;
using TensorRef = TensorRef<Element, Layout>;
using ConstTensorRef = typename TensorRef::ConstTensorRef;
using Index = typename Layout::Index;
using LongIndex = typename Layout::LongIndex;
using TensorCoord = MatrixCoord;
static int const kElementsPerAccess = ThreadMap::kElementsPerAccess;
static int const kThreads = ThreadMap::kThreads;
static int const kIterations = ThreadMap::Count::kTile;
static_assert( ThreadMap::Iterations::kRow > 0,"ThreadMap::Iterations::kRow must be > 0");
static_assert( ThreadMap::Iterations::kGroup > 0,"ThreadMap::Iterations::kGroup must be > 0");
static_assert( ThreadMap::Iterations::kCluster > 0,"ThreadMap::Iterations::kCluster must be > 0");
static_assert( ThreadMap::Iterations::kColumn > 0,"ThreadMap::Iterations::kColumn must be > 0");
/// Fragment object
using Fragment = Array<
Element,
ThreadMap::Iterations::kColumn *
ThreadMap::Iterations::kRow *
ThreadMap::Iterations::kGroup *
ThreadMap::Iterations::kCluster * ThreadMap::kElementsPerAccess>;
/// Memory access size
using AccessType = AlignedArray<Element, ThreadMap::kElementsPerAccess>;
//
// Parameters struct
//
/// Uses a non-template class
struct Params : PredicatedTileIteratorParams {
/// Convolution problem size
cutlass::conv::Conv2dProblemSize problem_size;
int tiled_rows_per_filter;
CUTLASS_HOST_DEVICE
Params() { }
CUTLASS_HOST_DEVICE
Params(Layout const &layout, cutlass::conv::Conv2dProblemSize problem_size_, int threadblock_row):
problem_size(problem_size_),
PredicatedTileIteratorParams(
layout.stride(0) * int(sizeof(AccessType)) / kElementsPerAccess,
make_OutputTileThreadMapDesc<ThreadMap>()
)
{
int tile_m_per_filter = strided_dgrad_tile_m_per_filter(problem_size, threadblock_row);
tiled_rows_per_filter = tile_m_per_filter * threadblock_row;
}
};
/// Mask object
struct Mask {
static int const kCount = ThreadMap::Iterations::kColumn;
/// Predicate state
bool predicates[kCount];
//
// Mask
//
CUTLASS_HOST_DEVICE
Mask() {
enable();
}
///< Efficiently disables all accesses guarded by mask
CUTLASS_HOST_DEVICE void clear() {
CUTLASS_PRAGMA_UNROLL
for (int i = 0; i < kCount; ++i) {
predicates[i] = false;
}
}
///< CUTLASS_HOST_DEVICE enables all accesses guarded by mask
CUTLASS_DEVICE void enable() {
CUTLASS_PRAGMA_UNROLL
for (int i = 0; i < kCount; ++i) {
predicates[i] = true;
}
}
};
private:
//
// Data members
//
/// Parameters structure containing reference and precomputed state.
Params params_;
/// Byte-level pointer
uint8_t *byte_pointer_;
/// Array of boolean values to contain steady-state predicates
Mask mask_;
/// Extent of the matrix tile in rows
Index extent_row_;
/// Starting Dx h and w dimenstion for strided dgrad mapping
int start_h_, start_w_;
/// Effective Dy P and Q dimenstions for strided dgrad mapping
int p_, q_;
/// A thread's starting row position (assuming steady-state predicates have been computed)
Index thread_start_row_;
/// A thread's starting column position (assuming steady-state predicates have been computed)
Index thread_start_column_;
/// Internal state counter
int state_[3];
//
// Static asserts about internal strides
//
static_assert(sizeof(extent_row_) == 4, "Expected 32b extents");
static_assert(sizeof(thread_start_row_) == 4, "Expected 32b extents");
static_assert(sizeof(PredicatedTileIteratorParams::stride) == 8, "Expected 64b strides");
private:
//
// Methods
//
public:
//
// Methods
//
/// Constructor
CUTLASS_DEVICE
PredicatedTileIteratorStridedDgrad(
Params const & params,
Element *pointer,
TensorCoord extent,
int thread_idx,
FastDivmod const &stride_h_divmod, FastDivmod const &stride_w_divmod,
int start_r, int start_s,
TensorCoord threadblock_offset = TensorCoord()
):
params_(params)
{
TensorCoord thread_offset = ThreadMap::initial_offset(thread_idx) + threadblock_offset;
int r = start_r;
int s = start_s;
if (params_.problem_size.mode == cutlass::conv::Mode::kConvolution) {
r = (params_.problem_size.R - 1 - r);
s = (params_.problem_size.S - 1 - s);
}
// compute starting coordinates in Dx start_h_ and start_w_
strided_dgrad_starting_coords(
params_.problem_size,
stride_h_divmod, stride_w_divmod,
r, s,
start_h_, start_w_);
p_ = (params_.problem_size.H - start_h_ + params_.problem_size.stride_h - 1) / params_.problem_size.stride_h;
q_ = (params_.problem_size.W - start_w_ + params_.problem_size.stride_w - 1) / params_.problem_size.stride_w;
extent_row_ = extent.row();
thread_start_row_ = thread_offset.row();
thread_start_column_ = thread_offset.column();
// Initialize predicates
CUTLASS_PRAGMA_UNROLL
for (int c = 0; c < ThreadMap::Iterations::kColumn; ++c) {
mask_.predicates[c] = ((thread_offset.column()
+ ThreadMap::Delta::kColumn * c) < extent.column());
}
// Null pointer performs no accesses
if (!pointer) {
mask_.clear();
}
// Initialize pointer
byte_pointer_ = reinterpret_cast<uint8_t *>(pointer);
// Initialize internal state counter
state_[0] = state_[1] = state_[2] = 0;
}
/// Adds a pointer offset in units of Element
CUTLASS_HOST_DEVICE
void add_pointer_offset(LongIndex pointer_offset) {
byte_pointer_ += pointer_offset * sizeof_bits<Element>::value / 8;
}
/// Loads a fragment from memory
CUTLASS_DEVICE
void load_with_byte_offset(Fragment &frag, int64_t byte_offset) {
uint8_t *byte_pointer = byte_pointer_;
AccessType *frag_ptr = reinterpret_cast<AccessType *>(&frag);
CUTLASS_PRAGMA_UNROLL
for (int cluster = 0; cluster < ThreadMap::Iterations::kCluster; ++cluster) {
CUTLASS_PRAGMA_UNROLL
for (int group = 0; group < ThreadMap::Iterations::kGroup; ++group) {
CUTLASS_PRAGMA_UNROLL
for (int row = 0; row < ThreadMap::Iterations::kRow; ++row) {
int frag_row_idx =
(row + ThreadMap::Iterations::kRow * (group + ThreadMap::Iterations::kGroup * cluster));
int row_offset = row * ThreadMap::Delta::kRow
+ group * ThreadMap::Delta::kGroup
+ cluster * ThreadMap::Delta::kCluster;
// remapping rows to find the mapped_row_offset
int npq_offset = (row_offset + thread_start_row_) % params_.tiled_rows_per_filter;
// (STEP 4.a) [order NHW rows to be loaded and stored in output Dx NHWxC layout]
int n = npq_offset / (p_ * q_);
int residual = npq_offset % (p_ * q_);
int p = residual / q_;
int q = residual % q_;
int mapped_row_offset = n * (params_.problem_size.H * params_.problem_size.W) +
(start_h_ + p * params_.problem_size.stride_h) * params_.problem_size.W +
(start_w_ + q * params_.problem_size.stride_w);
bool row_guard = mapped_row_offset < extent_row_;
int64_t row_byte_offset = mapped_row_offset * params_.stride;
CUTLASS_PRAGMA_UNROLL
for (int column = 0; column < ThreadMap::Iterations::kColumn; ++column) {
int64_t column_byte_offset = (thread_start_column_ + column * ThreadMap::Delta::kColumn) * (sizeof_bits<Element>::value / 8);
bool guard = row_guard && mask_.predicates[column];
cutlass::arch::global_load<
AccessType,
sizeof(AccessType)
>(
frag_ptr[frag_row_idx * ThreadMap::Iterations::kColumn +
column],
(void *)(byte_pointer + row_byte_offset + column_byte_offset + byte_offset),
guard);
}
}
}
}
}
/// Loads a fragment from memory
CUTLASS_DEVICE
void load(Fragment &frag) {
load_with_byte_offset(frag, 0);
}
/// Stores a fragment to memory
CUTLASS_DEVICE
void store_with_byte_offset(Fragment const &frag, int64_t byte_offset) {
uint8_t *byte_pointer = byte_pointer_;
AccessType const *frag_ptr = reinterpret_cast<AccessType const *>(&frag);
CUTLASS_PRAGMA_UNROLL
for (int cluster = 0; cluster < ThreadMap::Iterations::kCluster; ++cluster) {
CUTLASS_PRAGMA_UNROLL
for (int group = 0; group < ThreadMap::Iterations::kGroup; ++group) {
CUTLASS_PRAGMA_UNROLL
for (int row = 0; row < ThreadMap::Iterations::kRow; ++row) {
int frag_row_idx =
(row + ThreadMap::Iterations::kRow * (group + ThreadMap::Iterations::kGroup * cluster));
int row_offset = row * ThreadMap::Delta::kRow
+ group * ThreadMap::Delta::kGroup
+ cluster * ThreadMap::Delta::kCluster;
// remapping rows to find the mapped_row_offset
int npq_offset = (row_offset + thread_start_row_) % params_.tiled_rows_per_filter;
// (STEP 4.a) [order NHW rows to be loaded and stored in output Dx NHWxC layout]
int n = npq_offset / (p_ * q_);
int residual = npq_offset % (p_ * q_);
int p = residual / q_;
int q = residual % q_;
int mapped_row_offset = n * (params_.problem_size.H * params_.problem_size.W) +
(start_h_ + p * params_.problem_size.stride_h) * params_.problem_size.W +
(start_w_ + q * params_.problem_size.stride_w);
bool row_guard = mapped_row_offset < extent_row_;
int64_t row_byte_offset = mapped_row_offset * params_.stride;
CUTLASS_PRAGMA_UNROLL
for (int column = 0; column < ThreadMap::Iterations::kColumn; ++column) {
int64_t column_byte_offset = (thread_start_column_ + column * ThreadMap::Delta::kColumn) * (sizeof_bits<Element>::value / 8);
bool guard = row_guard && mask_.predicates[column];
cutlass::arch::global_store<AccessType, sizeof(AccessType) >(
frag_ptr[frag_row_idx * ThreadMap::Iterations::kColumn + column],
(void *)(byte_pointer + row_byte_offset + column_byte_offset + byte_offset),
guard);
}
}
}
}
}
/// Stores a fragment to memory
CUTLASS_DEVICE
void store(Fragment const &frag) {
store_with_byte_offset(frag, 0);
}
/// Advances to the next position to load or store
CUTLASS_HOST_DEVICE
PredicatedTileIteratorStridedDgrad &operator++() {
++state_[0];
thread_start_row_ += ThreadMap::Shape::kRow;
if (state_[0] == ThreadMap::Count::kRow) {
state_[0] = 0;
++state_[1];
thread_start_row_ += (ThreadMap::Shape::kGroup - 1) *
ThreadMap::Shape::kRow * ThreadMap::Count::kRow;
if (state_[1] == ThreadMap::Count::kGroup) {
state_[1] = 0;
++state_[2];
thread_start_row_ += ThreadMap::Count::kGroup *
ThreadMap::Shape::kGroup * ThreadMap::Count::kRow * ThreadMap::Shape::kRow;
if (state_[2] == ThreadMap::Count::kCluster) {
state_[2] = 0;
}
}
}
return *this;
}
///< Efficiently disables all accesses guarded by mask
CUTLASS_DEVICE void clear_mask() {
mask_.clear();
}
///< Efficiently enables all accesses guarded by mask
CUTLASS_DEVICE void enable_mask() {
mask_.enable();
}
///< Sets the mask
CUTLASS_DEVICE void get_mask(Mask &mask) {
mask = mask_;
}
///< Sets the mask
CUTLASS_DEVICE void set_mask(Mask const &mask) {
mask_ = mask;
}
};
///////////////////////////////////////////////////////////////////////////////
} // namespace threadblock
} // namespace epilogue
} // namespace cutlass
////////////////////////////////////////////////////////////////////////////////
| 32.366667 | 137 | 0.644246 |
a16ebe92f896f77d6030e5286fff4146376f6bf8 | 5,401 | c | C | snapgear_linux/linux-2.6.21.1/drivers/ambapp/gaisler/gpio/gpio.c | impedimentToProgress/UCI-BlueChip | 53e5d48b79079eaf60d42f7cb65bb795743d19fc | [
"MIT"
] | null | null | null | snapgear_linux/linux-2.6.21.1/drivers/ambapp/gaisler/gpio/gpio.c | impedimentToProgress/UCI-BlueChip | 53e5d48b79079eaf60d42f7cb65bb795743d19fc | [
"MIT"
] | null | null | null | snapgear_linux/linux-2.6.21.1/drivers/ambapp/gaisler/gpio/gpio.c | impedimentToProgress/UCI-BlueChip | 53e5d48b79079eaf60d42f7cb65bb795743d19fc | [
"MIT"
] | 3 | 2016-06-13T13:20:56.000Z | 2019-12-05T02:31:23.000Z | #include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <asm/uaccess.h>
#ifdef CONFIG_LEON
#include <asm/leon.h>
#endif
#include "gpio.h"
MODULE_LICENSE ("GPL");
//#define GPIO_DEBUG_ON 1
//#define GPIO_DEBUG_WRITE_ON 1
//#define GPIO_DEBUG_GPIO_READ 1
//#define GPIO_DEBUG_JTAG 1
//#define GPIO_DEBUG_TAP 1
#define GPIO_MAX_DEVICES 4
#define GPIO_OFFSET 0
int gpio_major = 212;
int gpio_minor = 0;
int cdev_count = 0;
#ifdef CONFIG_LEON
amba_apb_device adev[GPIO_MAX_DEVICES];
#endif
struct cdev cdev[GPIO_MAX_DEVICES];
int gpio_busy[GPIO_MAX_DEVICES];
static int gpio_open (struct inode *inode, struct file *file);
static int gpio_release (struct inode *inode, struct file *file);
static int gpio_ioctl (struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg);
struct file_operations gpio_fops = {
.owner = THIS_MODULE,
.open = gpio_open,
.release = gpio_release,
.ioctl = gpio_ioctl
};
static int gpio_open (struct inode *inode, struct file *file) {
int idx = iminor (inode);
if (idx >= cdev_count) {
printk (KERN_WARNING "GRGPIO: device %d doesnt exist (%d)\n", idx, cdev_count);
return -ENODEV;
}
if (gpio_busy[idx]) {
printk (KERN_WARNING "GRGPIO: device %d already opened\n", idx);
return -EBUSY;
}
printk (KERN_INFO "GRGPIO: device %d opened\n",idx);
gpio_busy[idx] = 1;
return 0;
}
static int gpio_release (struct inode *inode, struct file *file) {
int idx = iminor (inode);
gpio_busy[idx] = 0;
printk (KERN_INFO "GRGPIO: device %d released\n",idx);
return 0;
}
int gpio_ioctl (struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
{
int err = 0; int retval = 0, data = 0;
#ifdef CONFIG_LEON
LEON3_GPIO_IOPORT_Regs_Map *regs;
#endif
int idx = iminor (inode);
if (idx >= cdev_count) {
printk (KERN_WARNING "GRGPIO: device %d doesnt exist (%d)\n", idx, cdev_count);
return -ENODEV;
}
#ifdef CONFIG_LEON
regs = (LEON3_GPIO_IOPORT_Regs_Map *)adev[idx].start;
#endif
if (_IOC_DIR(cmd) & _IOC_WRITE)
err = !access_ok(VERIFY_WRITE, (void __user *)arg, _IOC_SIZE(cmd));
if ((!err) && (_IOC_DIR(cmd) & _IOC_READ))
err = !access_ok(VERIFY_READ, (void __user *)arg, _IOC_SIZE(cmd));
if (err) return -EFAULT;
switch (cmd) {
case GR_GPIO_SET_OUT:
if ((retval = __get_user(data, (int __user *)arg)) == 0) {
#ifdef GPIO_DEBUG_ON
printk (KERN_INFO "GRGPIO: GR_GPIO_SET_OUT(0x%x)\n",data);
#endif
#ifdef CONFIG_LEON
LEON3_BYPASS_STORE_PA(&(regs->ioout),data);
#endif
}
return retval;
case GR_GPIO_GET_IN:
#ifdef CONFIG_LEON
data = LEON3_BYPASS_LOAD_PA(&(regs->iodata));
#else
data = 1;
#endif
if ((retval = __put_user(data, (int __user *)arg)) == 0) {
#ifdef GPIO_DEBUG_ON
printk (KERN_INFO "GRGPIO: GR_GPIO_GET_IN=>(0x%x)\n",data);
#endif
}
return retval;
case GR_GPIO_SET_DIR:
if ((retval = __get_user(data, (int __user *)arg)) == 0) {
#ifdef GPIO_DEBUG_ON
printk (KERN_INFO "GRGPIO: GR_GPIO_SET_DIR(0x%x)\n",data);
#endif
#ifdef CONFIG_LEON
LEON3_BYPASS_STORE_PA(&(regs->iodir),data);
#endif
}
return retval;
case GR_GPIO_GET_DIR:
#ifdef CONFIG_LEON
data = LEON3_BYPASS_LOAD_PA(&(regs->iodir));
#else
data = 2;
#endif
if ((retval = __put_user(data, (int __user *)arg)) == 0) {
#ifdef GPIO_DEBUG_ON
printk (KERN_INFO "GRGPIO: GR_GPIO_GET_DIR=>(0x%x)\n",data);
#endif
}
return retval;
}
return -EINVAL;
}
#ifndef CONFIG_LEON
static void char_reg_setup_cdev (int minor) {
int error, devno = MKDEV (gpio_major, minor);
cdev_init (&cdev[minor], &gpio_fops);
cdev[minor].owner = THIS_MODULE;
cdev[minor].ops = &gpio_fops;
error = cdev_add (&cdev[minor], devno , 1);
if (error) {
printk (KERN_NOTICE "GRGPIO: Error %d adding char_reg_setup_cdev for device %d", error, minor);
}
}
#endif
static int __init gpio_init (void) {
int result, devno;
memset(gpio_busy,0,sizeof(gpio_busy));
memset(cdev,0,sizeof(cdev));
devno = MKDEV (gpio_major, gpio_minor);
result = register_chrdev_region (devno, GPIO_MAX_DEVICES, "gpio");
if (result<0) {
printk (KERN_WARNING "GRGPIO: can't get major number %d\n", gpio_major);
return result;
}
#ifdef CONFIG_LEON
if (GPIO_OFFSET) {
if ((cdev_count = amba_get_free_apbslv_devices (VENDOR_GAISLER, GAISLER_GRGPIO, adev, GPIO_OFFSET)) != GPIO_OFFSET) {
printk (KERN_WARNING "GRGPIO: can't skip over first %d gpio ports\n", GPIO_OFFSET);
return -EINVAL;
}
}
cdev_count = amba_get_free_apbslv_devices (VENDOR_GAISLER, GAISLER_GRGPIO, adev, GPIO_MAX_DEVICES);
if ( cdev_count < 1 ){
printk ("GRGPIO: no cores available\n");
return 0;
}
#else
cdev_count = 2;
for (i = 0; i < cdev_count; i++) {
char_reg_setup_cdev(i);
printk (KERN_INFO "GRGPIO: host dummy registered \n" );
}
#endif
return 0;
}
static void __exit gpio_exit (void) {
int i;
dev_t devno = MKDEV (gpio_major, gpio_minor);
for (i = 0; i < cdev_count; i++) {
cdev_del (&cdev[i]);
}
unregister_chrdev_region (devno, GPIO_MAX_DEVICES);
printk (KERN_INFO "gpio: char driver cleaned up\n");
}
module_init (gpio_init);
module_exit (gpio_exit);
| 26.605911 | 118 | 0.668024 |
1f2ae63027a7c59f0ce01efa5c70f039a646d268 | 257 | c | C | lab01/fib/fibptr.c | gddmatos/iaed21 | 8bfe153d27b4bc579c4fce94f330ba1b87046f0b | [
"MIT"
] | 10 | 2021-03-01T12:37:47.000Z | 2022-03-06T14:08:18.000Z | lab01/fib/fibptr.c | edsonCVN/iaed | c52e2252086b482be06659dc5bfe7dfd0c75825d | [
"MIT"
] | null | null | null | lab01/fib/fibptr.c | edsonCVN/iaed | c52e2252086b482be06659dc5bfe7dfd0c75825d | [
"MIT"
] | 16 | 2021-03-19T18:29:29.000Z | 2021-09-17T17:13:19.000Z | #include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int n = 42, i = 0, j = 1, *seg = &i;
if (argc > 1)
n = atoi(argv[1]);
while (n-- > 0) {
seg[0] = i + j;
seg = (seg == &i) ? &j : &i;
}
printf("%d\n", seg[0]);
return 0;
}
| 18.357143 | 37 | 0.470817 |
f7ec81e741da5d89f921b754ccd11b79f02b2ba3 | 2,352 | h | C | src/pb/FDkernels.h | jeanlucf22/mgmol | 4e79bc32c14c8a47ae18ad0659ea740719c8b77f | [
"BSD-3-Clause-LBNL",
"FSFAP"
] | 25 | 2018-12-29T03:33:01.000Z | 2021-05-08T12:52:27.000Z | src/pb/FDkernels.h | jeanlucf22/mgmol | 4e79bc32c14c8a47ae18ad0659ea740719c8b77f | [
"BSD-3-Clause-LBNL",
"FSFAP"
] | 121 | 2018-12-19T02:38:21.000Z | 2021-12-20T16:29:24.000Z | src/pb/FDkernels.h | jeanlucf22/mgmol | 4e79bc32c14c8a47ae18ad0659ea740719c8b77f | [
"BSD-3-Clause-LBNL",
"FSFAP"
] | 15 | 2019-02-17T05:28:43.000Z | 2022-02-28T05:24:11.000Z | #ifndef FDkernels_H
#define FDkernels_H
#include "Grid.h"
#include "memory_space.h"
#include <iostream>
namespace pb
{
void printFDkernelTimers(std::ostream& os);
template <typename ScalarType>
void FDkernelDel2_2nd(const Grid& grid, ScalarType* v, ScalarType* b,
const size_t nfunc, MemorySpace::Host);
template <typename ScalarType>
void FDkernelDel2_4th(const Grid& grid, ScalarType* v, ScalarType* b,
const size_t nfunc, MemorySpace::Host);
template <typename ScalarType>
void FDkernelDel2_4th_Mehr(const Grid& grid, ScalarType* v, ScalarType* b,
const size_t nfunc, MemorySpace::Host);
template <typename ScalarType>
void FDkernelDel2_6th(const Grid& grid, ScalarType* v, ScalarType* b,
const size_t nfunc, MemorySpace::Host);
template <typename ScalarType>
void FDkernelDel2_8th(const Grid& grid, ScalarType* v, ScalarType* b,
const size_t nfunc, MemorySpace::Host);
template <typename ScalarType>
void FDkernelRHS_4th_Mehr1(const Grid& grid, ScalarType* v, ScalarType* b,
const short rhs_ghosts, const size_t nfunc, MemorySpace::Host);
#ifdef HAVE_MAGMA
template <typename ScalarType>
void FDkernelDel2_2nd(const Grid& grid, ScalarType* v, ScalarType* b,
const size_t nfunc, MemorySpace::Device)
{ /*to be implemented*/
std::cerr << "Function FDkernelDel2_2nd() not implemented!!!" << std::endl;
abort();
};
template <typename ScalarType>
void FDkernelDel2_4th(const Grid& grid, ScalarType* v, ScalarType* b,
const size_t nfunc, MemorySpace::Device);
template <typename ScalarType>
void FDkernelDel2_4th_Mehr(const Grid& grid, ScalarType* v, ScalarType* b,
const size_t nfunc, MemorySpace::Device)
{ /*to be implemented*/
std::cerr << "Function FDkernelDel2_4th_Mehr() not implemented!!!"
<< std::endl;
abort();
};
template <typename ScalarType>
void FDkernelDel2_6th(const Grid& grid, ScalarType* v, ScalarType* b,
const size_t nfunc, MemorySpace::Device)
{ /*to be implemented*/
std::cerr << "Function FDkernelDel2_6th() not implemented!!!" << std::endl;
abort();
};
template <typename ScalarType>
void FDkernelDel2_8th(const Grid& grid, ScalarType* v, ScalarType* b,
const size_t nfunc, MemorySpace::Device)
{ /*to be implemented*/
std::cerr << "Function FDkernelDel2_8th() not implemented!!!" << std::endl;
abort();
};
#endif
}
#endif
| 29.772152 | 79 | 0.732143 |
f7f0565e44dc7a252505efa3ca394a668fd19974 | 229 | h | C | dSwift/SwiftDemoKit/SwiftDemoKit/CCLogSystem/CCLogViewController.h | MartinOSix/DemoKit | 3d8c6267ef1782a2688fcf25dd2223595074c4ff | [
"Apache-2.0"
] | null | null | null | dSwift/SwiftDemoKit/SwiftDemoKit/CCLogSystem/CCLogViewController.h | MartinOSix/DemoKit | 3d8c6267ef1782a2688fcf25dd2223595074c4ff | [
"Apache-2.0"
] | null | null | null | dSwift/SwiftDemoKit/SwiftDemoKit/CCLogSystem/CCLogViewController.h | MartinOSix/DemoKit | 3d8c6267ef1782a2688fcf25dd2223595074c4ff | [
"Apache-2.0"
] | null | null | null | //
// CCLogViewController.h
// CCLogSystem
//
// Created by Chun Ye on 10/30/14.
// Copyright (c) 2014 Chun Tips. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface CCLogViewController : UITableViewController
@end
| 16.357143 | 54 | 0.707424 |
ea5a54879659d69e1a9dbb04c0b7ad0b31925a40 | 955 | h | C | LibSource/mpir/mpir.net/mpir.net/Stdafx.h | ekzyis/CrypTool-2 | 1af234b4f74486fbfeb3b3c49228cc36533a8c89 | [
"Apache-2.0"
] | 12 | 2021-09-29T14:50:06.000Z | 2022-03-31T15:01:21.000Z | LibSource/mpir/mpir.net/mpir.net/Stdafx.h | ekzyis/CrypTool-2 | 1af234b4f74486fbfeb3b3c49228cc36533a8c89 | [
"Apache-2.0"
] | 15 | 2021-12-24T22:53:49.000Z | 2021-12-25T10:03:13.000Z | LibSource/mpir/mpir.net/mpir.net/Stdafx.h | ekzyis/CrypTool-2 | 1af234b4f74486fbfeb3b3c49228cc36533a8c89 | [
"Apache-2.0"
] | 10 | 2021-10-17T19:46:51.000Z | 2022-03-18T02:57:57.000Z | /*
Copyright 2014 Alex Dyachenko
This file is part of the MPIR Library.
The MPIR 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 3 of the License, or (at
your option) any later version.
The MPIR 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 the MPIR Library. If not, see http://www.gnu.org/licenses/.
*/
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently
#pragma once
#include "mpir.h"
#include "gmp-impl.h"
#include "Common.h"
| 32.931034 | 74 | 0.776963 |
6ebe0ead385e1f8a477081a065880d580f348b36 | 934 | c | C | examples/movies/movies.c | rohanrhu/libhash | cc4941b1389737dba955395116db3ff4c943efb1 | [
"MIT"
] | 4 | 2021-11-30T19:57:22.000Z | 2022-01-18T10:02:58.000Z | examples/movies/movies.c | rohanrhu/libhash | cc4941b1389737dba955395116db3ff4c943efb1 | [
"MIT"
] | null | null | null | examples/movies/movies.c | rohanrhu/libhash | cc4941b1389737dba955395116db3ff4c943efb1 | [
"MIT"
] | 1 | 2021-12-01T04:35:26.000Z | 2021-12-01T04:35:26.000Z | /*
* libhash is a fast and efficient non-iterating hashmap library
*
* https://github.com/rohanrhu/libhash
*
* Licensed under MIT
* Copyright (C) 2021, Oğuzhan Eroğlu (https://oguzhaneroglu.com/) <rohanrhu2@gmail.com>
*
*/
#define _GNU_SOURCE
#include <stdio.h>
#include "../../include/libhash.h"
int main() {
libhash_t* movies = libhash_init();
libhash_set(movies, "Alien", "The best movie ever!");
libhash_set(movies, "Prometheus", "The worst movie ever!");
libhash_set(movies, "こんにちは世界", "Hello World!");
libhash_node_t* alien = libhash_get(movies, "Alien");
libhash_node_t* prometheus = libhash_get(movies, "Prometheus");
libhash_node_t* hello = libhash_get(movies, "こんにちは世界");
hello && printf("こんにちは世界: %s\n", hello->value);
alien && printf("Alien: %s\n", alien->value);
prometheus && printf("Prometheus: %s\n", prometheus->value);
libhash_free(movies);
return 0;
} | 27.470588 | 88 | 0.669165 |
542230d2ecbc4a344d250ca57545bbdf6a9f2af3 | 2,994 | h | C | bsp/imx6sx/iMX6_Platform_SDK/sdk/drivers/gpio/src/gpio_map.h | Davidfind/rt-thread | 56f1a8af4f9e8bad0a0fdc5cea7112767267b243 | [
"Apache-2.0"
] | 7,482 | 2015-01-01T09:23:08.000Z | 2022-03-31T19:34:05.000Z | platform/mcu/imx6/imx6_platform_sdk/sdk/drivers/gpio/src/gpio_map.h | IamBaoMouMou/AliOS-Things | 195a9160b871b3d78de6f8cf6c2ab09a71977527 | [
"Apache-2.0"
] | 2,543 | 2015-01-09T02:01:34.000Z | 2022-03-31T23:10:14.000Z | platform/mcu/imx6/imx6_platform_sdk/sdk/drivers/gpio/src/gpio_map.h | IamBaoMouMou/AliOS-Things | 195a9160b871b3d78de6f8cf6c2ab09a71977527 | [
"Apache-2.0"
] | 4,645 | 2015-01-06T07:05:31.000Z | 2022-03-31T18:21:50.000Z | /*
* Copyright (c) 2011-2012, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, 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 COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*!
* @file gpio_map.h
* @brief
* @ingroup diag_gpio
*/
#ifndef __GPIO_MAP_H__
#define __GPIO_MAP_H__
#include <stdint.h>
#include "registers/regsgpio.h"
//! @addtogroup diag_gpio
//! @{
////////////////////////////////////////////////////////////////////////////////
// Definitions
////////////////////////////////////////////////////////////////////////////////
//! @brief Number of pins per GPIO bank.
#define GPIO_PIN_COUNT (32)
//! @brief Table to map GPIO pins to their mux control register addresses.
//!
//! First subscript is bank, second is pin within the bank. There are always 32 pin
//! entries per bank. If a pin does not have an assigned GPIO, its address is 0.
//!
//! Example code to set GPIO 3,12 to GPIO mode:
//! @code
//! uint32_t addr = k_gpio_mux_registers[3][12];
//! volatile uint32_t * reg = (volatile uint32_t *)addr;
//! *reg = (*reg & ~BM_IOMUXC_SW_MUX_CTL_PAD_GPIO00_MUX_MODE)
//! | BF_IOMUXC_SW_MUX_CTL_PAD_GPIO00_MUX_MODE_V(ALT5);
//! @endcode
//!
//! The code above uses the bit field macros from an arbitrary mux register definition.
extern const uint32_t k_gpio_mux_registers[HW_GPIO_INSTANCE_COUNT][GPIO_PIN_COUNT];
//! @}
#endif //__GPIO_MAP_H__
////////////////////////////////////////////////////////////////////////////////
// EOF
////////////////////////////////////////////////////////////////////////////////
| 39.92 | 87 | 0.662659 |
5a3e59b42727a614229ed5fafd8114840bbb2db9 | 7,607 | h | C | cpp/hanser_c_und_linux/svgalib-1.9.25/demos/spintables.h | maximilianharr/code_snippets | 8b271e6fa9174e24200e88be59e417abd5f2f59a | [
"BSD-3-Clause"
] | null | null | null | cpp/hanser_c_und_linux/svgalib-1.9.25/demos/spintables.h | maximilianharr/code_snippets | 8b271e6fa9174e24200e88be59e417abd5f2f59a | [
"BSD-3-Clause"
] | null | null | null | cpp/hanser_c_und_linux/svgalib-1.9.25/demos/spintables.h | maximilianharr/code_snippets | 8b271e6fa9174e24200e88be59e417abd5f2f59a | [
"BSD-3-Clause"
] | null | null | null | float sine[360] = {
0.000000,
0.017449,
0.034893,
0.052326,
0.069743,
0.087139,
0.104509,
0.121846,
0.139147,
0.156405,
0.173616,
0.190773,
0.207873,
0.224909,
0.241877,
0.258771,
0.275587,
0.292318,
0.308961,
0.325509,
0.341958,
0.358303,
0.374539,
0.390661,
0.406664,
0.422544,
0.438294,
0.453911,
0.469390,
0.484726,
0.499914,
0.514951,
0.529830,
0.544548,
0.559100,
0.573482,
0.587689,
0.601718,
0.615563,
0.629221,
0.642687,
0.655957,
0.669028,
0.681895,
0.694554,
0.707002,
0.719235,
0.731248,
0.743039,
0.754604,
0.765939,
0.777040,
0.787905,
0.798530,
0.808912,
0.819048,
0.828934,
0.838568,
0.847947,
0.857067,
0.865927,
0.874522,
0.882852,
0.890912,
0.898702,
0.906217,
0.913457,
0.920419,
0.927100,
0.933499,
0.939614,
0.945442,
0.950983,
0.956234,
0.961195,
0.965862,
0.970235,
0.974313,
0.978094,
0.981578,
0.984762,
0.987647,
0.990230,
0.992513,
0.994493,
0.996170,
0.997544,
0.998614,
0.999381,
0.999843,
1.000000,
0.999853,
0.999401,
0.998645,
0.997586,
0.996222,
0.994555,
0.992585,
0.990313,
0.987739,
0.984865,
0.981691,
0.978217,
0.974446,
0.970379,
0.966015,
0.961358,
0.956408,
0.951166,
0.945635,
0.939816,
0.933711,
0.927322,
0.920650,
0.913698,
0.906468,
0.898961,
0.891181,
0.883130,
0.874810,
0.866223,
0.857372,
0.848261,
0.838891,
0.829266,
0.819388,
0.809261,
0.798887,
0.788270,
0.777413,
0.766320,
0.754992,
0.743436,
0.731652,
0.719646,
0.707421,
0.694980,
0.682328,
0.669468,
0.656404,
0.643141,
0.629681,
0.616030,
0.602191,
0.588169,
0.573967,
0.559591,
0.545045,
0.530332,
0.515459,
0.500428,
0.485244,
0.469913,
0.454439,
0.438827,
0.423081,
0.407206,
0.391207,
0.375089,
0.358857,
0.342515,
0.326069,
0.309524,
0.292885,
0.276156,
0.259344,
0.242452,
0.225487,
0.208453,
0.191355,
0.174199,
0.156991,
0.139734,
0.122435,
0.105098,
0.087730,
0.070335,
0.052918,
0.035485,
0.018042,
0.000593,
-0.016857,
-0.034301,
-0.051734,
-0.069152,
-0.086549,
-0.103919,
-0.121258,
-0.138560,
-0.155820,
-0.173032,
-0.190192,
-0.207293,
-0.224332,
-0.241302,
-0.258199,
-0.275017,
-0.291751,
-0.308397,
-0.324949,
-0.341401,
-0.357750,
-0.373990,
-0.390116,
-0.406123,
-0.422006,
-0.437761,
-0.453383,
-0.468867,
-0.484208,
-0.499401,
-0.514442,
-0.529327,
-0.544051,
-0.558609,
-0.572996,
-0.587210,
-0.601244,
-0.615096,
-0.628760,
-0.642233,
-0.655510,
-0.668587,
-0.681461,
-0.694128,
-0.706583,
-0.718823,
-0.730844,
-0.742642,
-0.754215,
-0.765557,
-0.776667,
-0.787540,
-0.798174,
-0.808564,
-0.818708,
-0.828603,
-0.838245,
-0.847633,
-0.856762,
-0.865630,
-0.874235,
-0.882573,
-0.890643,
-0.898442,
-0.905967,
-0.913216,
-0.920187,
-0.926878,
-0.933286,
-0.939411,
-0.945249,
-0.950800,
-0.956061,
-0.961031,
-0.965708,
-0.970091,
-0.974179,
-0.977971,
-0.981464,
-0.984659,
-0.987554,
-0.990148,
-0.992440,
-0.994431,
-0.996118,
-0.997503,
-0.998583,
-0.999360,
-0.999832,
-1.000000,
-0.999863,
-0.999422,
-0.998676,
-0.997627,
-0.996273,
-0.994616,
-0.992657,
-0.990395,
-0.987832,
-0.984967,
-0.981803,
-0.978340,
-0.974579,
-0.970522,
-0.966168,
-0.961521,
-0.956581,
-0.951349,
-0.945828,
-0.940019,
-0.933923,
-0.927544,
-0.920881,
-0.913939,
-0.906718,
-0.899221,
-0.891450,
-0.883408,
-0.875097,
-0.866519,
-0.857677,
-0.848575,
-0.839213,
-0.829597,
-0.819728,
-0.809609,
-0.799243,
-0.788635,
-0.777786,
-0.766700,
-0.755381,
-0.743832,
-0.732056,
-0.720058,
-0.707840,
-0.695406,
-0.682761,
-0.669908,
-0.656851,
-0.643594,
-0.630141,
-0.616497,
-0.602664,
-0.588648,
-0.574453,
-0.560082,
-0.545542,
-0.530835,
-0.515966,
-0.500941,
-0.485763,
-0.470436,
-0.454967,
-0.439359,
-0.423618,
-0.407747,
-0.391752,
-0.375638,
-0.359410,
-0.343072,
-0.326630,
-0.310088,
-0.293452,
-0.276726,
-0.259916,
-0.243027,
-0.226064,
-0.209032,
-0.191937,
-0.174783,
-0.157576,
-0.140321,
-0.123023,
-0.105688,
-0.088320,
-0.070926,
-0.053510,
-0.036077,
-0.018634,
};
float cosine[360] = {
1.000000,
0.999848,
0.999391,
0.998630,
0.997565,
0.996196,
0.994524,
0.992549,
0.990272,
0.987693,
0.984813,
0.981634,
0.978156,
0.974380,
0.970307,
0.965939,
0.961276,
0.956321,
0.951075,
0.945539,
0.939715,
0.933605,
0.927211,
0.920534,
0.913578,
0.906343,
0.898832,
0.891047,
0.882991,
0.874666,
0.866075,
0.857220,
0.848104,
0.838730,
0.829100,
0.819218,
0.809087,
0.798709,
0.788088,
0.777227,
0.766129,
0.754798,
0.743237,
0.731450,
0.719440,
0.707212,
0.694767,
0.682112,
0.669248,
0.656181,
0.642914,
0.629451,
0.615796,
0.601954,
0.587929,
0.573725,
0.559346,
0.544796,
0.530081,
0.515205,
0.500171,
0.484985,
0.469652,
0.454175,
0.438561,
0.422812,
0.406935,
0.390934,
0.374814,
0.358580,
0.342237,
0.325789,
0.309242,
0.292602,
0.275872,
0.259058,
0.242165,
0.225198,
0.208163,
0.191064,
0.173908,
0.156698,
0.139440,
0.122141,
0.104804,
0.087435,
0.070039,
0.052622,
0.035189,
0.017745,
0.000296,
-0.017153,
-0.034597,
-0.052030,
-0.069448,
-0.086844,
-0.104214,
-0.121552,
-0.138854,
-0.156113,
-0.173324,
-0.190483,
-0.207583,
-0.224621,
-0.241590,
-0.258485,
-0.275302,
-0.292035,
-0.308679,
-0.325229,
-0.341680,
-0.358027,
-0.374265,
-0.390389,
-0.406394,
-0.422275,
-0.438028,
-0.453647,
-0.469128,
-0.484467,
-0.499658,
-0.514697,
-0.529579,
-0.544299,
-0.558854,
-0.573239,
-0.587450,
-0.601481,
-0.615329,
-0.628990,
-0.642460,
-0.655733,
-0.668808,
-0.681678,
-0.694341,
-0.706792,
-0.719029,
-0.731046,
-0.742841,
-0.754409,
-0.765748,
-0.776854,
-0.787723,
-0.798352,
-0.808738,
-0.818878,
-0.828769,
-0.838407,
-0.847790,
-0.856915,
-0.865778,
-0.874379,
-0.882713,
-0.890778,
-0.898572,
-0.906092,
-0.913336,
-0.920303,
-0.926989,
-0.933393,
-0.939512,
-0.945346,
-0.950892,
-0.956148,
-0.961113,
-0.965785,
-0.970163,
-0.974246,
-0.978032,
-0.981521,
-0.984710,
-0.987600,
-0.990189,
-0.992477,
-0.994462,
-0.996144,
-0.997523,
-0.998599,
-0.999370,
-0.999837,
-1.000000,
-0.999858,
-0.999412,
-0.998661,
-0.997606,
-0.996248,
-0.994586,
-0.992621,
-0.990354,
-0.987786,
-0.984916,
-0.981747,
-0.978279,
-0.974513,
-0.970450,
-0.966092,
-0.961439,
-0.956494,
-0.951258,
-0.945732,
-0.939918,
-0.933817,
-0.927433,
-0.920766,
-0.913818,
-0.906593,
-0.899091,
-0.891316,
-0.883269,
-0.874953,
-0.866371,
-0.857525,
-0.848418,
-0.839052,
-0.829431,
-0.819558,
-0.809435,
-0.799065,
-0.788452,
-0.777600,
-0.766510,
-0.755187,
-0.743634,
-0.731854,
-0.719852,
-0.707630,
-0.695193,
-0.682545,
-0.669688,
-0.656628,
-0.643368,
-0.629911,
-0.616263,
-0.602428,
-0.588408,
-0.574210,
-0.559837,
-0.545293,
-0.530584,
-0.515712,
-0.500684,
-0.485503,
-0.470175,
-0.454703,
-0.439093,
-0.423349,
-0.407476,
-0.391480,
-0.375364,
-0.359133,
-0.342794,
-0.326349,
-0.309806,
-0.293168,
-0.276441,
-0.259630,
-0.242740,
-0.225775,
-0.208743,
-0.191646,
-0.174491,
-0.157283,
-0.140027,
-0.122729,
-0.105393,
-0.088025,
-0.070630,
-0.053214,
-0.035781,
-0.018338,
-0.000889,
0.016560,
0.034004,
0.051438,
0.068856,
0.086254,
0.103625,
0.120964,
0.138267,
0.155527,
0.172740,
0.189901,
0.207003,
0.224043,
0.241014,
0.257913,
0.274732,
0.291468,
0.308115,
0.324668,
0.341123,
0.357473,
0.373715,
0.389843,
0.405852,
0.421738,
0.437495,
0.453119,
0.468605,
0.483948,
0.499144,
0.514188,
0.529076,
0.543802,
0.558363,
0.572754,
0.586970,
0.601007,
0.614862,
0.628529,
0.642005,
0.655286,
0.668367,
0.681244,
0.693914,
0.706373,
0.718617,
0.730641,
0.742444,
0.754020,
0.765367,
0.776480,
0.787358,
0.797995,
0.808389,
0.818538,
0.828437,
0.838084,
0.847475,
0.856609,
0.865482,
0.874091,
0.882434,
0.890508,
0.898311,
0.905841,
0.913095,
0.920071,
0.926766,
0.933180,
0.939309,
0.945152,
0.950708,
0.955974,
0.960949,
0.965631,
0.970020,
0.974112,
0.977909,
0.981407,
0.984607,
0.987507,
0.990106,
0.992404,
0.994399,
0.996092,
0.997482,
0.998567,
0.999349,
0.999826,
};
| 10.492414 | 21 | 0.665966 |
874b0352dd6f50335428b242150231590924ad80 | 5,061 | h | C | Source/ChilliSource/Rendering/Sprite/DynamicSpriteBatcher.h | fjpavm/ChilliSource | 11c38bada3fff8f4701dee5ad7718c8bc150c3b6 | [
"MIT"
] | 1 | 2015-05-08T14:29:03.000Z | 2015-05-08T14:29:03.000Z | Source/ChilliSource/Rendering/Sprite/DynamicSpriteBatcher.h | mclaughlinhugh4/ChilliSource | bfd86242b28125371804ef35ee512a3908763795 | [
"MIT"
] | null | null | null | Source/ChilliSource/Rendering/Sprite/DynamicSpriteBatcher.h | mclaughlinhugh4/ChilliSource | bfd86242b28125371804ef35ee512a3908763795 | [
"MIT"
] | null | null | null | //
// DynamicSpriteBatcher.h
// Chilli Source
// Created by Scott Downie on 06/10/2010.
//
// The MIT License (MIT)
//
// Copyright (c) 2010 Tag Games Limited
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#ifndef _CHILLISOURCE_RENDERING_DYNAMICSPRITEBATCH_H_
#define _CHILLISOURCE_RENDERING_DYNAMICSPRITEBATCH_H_
#include <ChilliSource/ChilliSource.h>
#include <ChilliSource/Rendering/Sprite/SpriteBatch.h>
namespace ChilliSource
{
namespace Rendering
{
const u32 kudwNumBuffers = 2;
enum class CommandType
{
k_draw,
k_scissorOn,
k_scissorOff
};
struct RenderCommand
{
MaterialCSPtr m_material;
Core::Vector2 m_scissorPos;
Core::Vector2 m_scissorSize;
u32 m_offset;
u32 m_stride;
CommandType m_type;
};
class DynamicSpriteBatch
{
public:
DynamicSpriteBatch(RenderSystem* inpRenderSystem);
~DynamicSpriteBatch();
//-------------------------------------------------------
/// Render
///
/// Batch the sprite to be rendered later. Track the
/// render commands so that the correct subset of the
/// mesh buffer can be flushed and the correct material
/// applied
///
/// @param Sprite data to batch
//-------------------------------------------------------
void Render(const SpriteBatch::SpriteData& inpSprite, const Core::Matrix4 * inpTransform = nullptr);
//-------------------------------------------------------
/// Enable scissoring with the given region. Any
/// subsequent renders to the batcher will be clipped
/// based on the region
///
/// @author S Downie
///
/// @param Bottom left pos of the scissor rect
/// @param Size of the scissor rect
//-------------------------------------------------------
void EnableScissoring(const Core::Vector2& in_pos, const Core::Vector2& in_size);
//-------------------------------------------------------
/// Disable scissoring. Any
/// subsequent renders to the batcher will not be clipped/
///
/// @author S Downie
//-------------------------------------------------------
void DisableScissoring();
//-------------------------------------------------------
/// Force Render
///
/// Force the currently batched sprites to be rendered
/// regardless of whether the batch is full
//-------------------------------------------------------
void ForceRender();
private:
//-------------------------------------------------------
/// Take the contents of the sprite cache as it stands
/// and generate a draw call commmand
///
/// @author S Downie
//-------------------------------------------------------
void InsertDrawCommand();
//----------------------------------------------------------
/// Build and Flush Batch
///
/// Map the batch into the mesh buffer and present the
/// contents. This will then swap the active buffer
/// so that it can be filled while the other one is
/// rendering
//----------------------------------------------------------
void BuildAndFlushBatch();
private:
SpriteBatch* mpBatch[kudwNumBuffers];
std::vector<SpriteBatch::SpriteData> maSpriteCache;
std::vector<RenderCommand> maRenderCommands;
MaterialCSPtr mpLastMaterial;
u32 mudwCurrentRenderSpriteBatch;
u32 mudwSpriteCommandCounter;
RenderSystem* m_renderSystem;
};
}
}
#endif
| 36.15 | 103 | 0.519265 |
e19ecd4f635c2730671368eb73e3fc9b25927551 | 35,789 | c | C | source/kernel/elf.c | aejsmith/kiwi | 756d5b85d7dff631ad54c942a9da137ea298794e | [
"0BSD"
] | 15 | 2015-08-02T18:20:40.000Z | 2022-03-22T13:36:44.000Z | source/kernel/elf.c | aejsmith/kiwi | 756d5b85d7dff631ad54c942a9da137ea298794e | [
"0BSD"
] | null | null | null | source/kernel/elf.c | aejsmith/kiwi | 756d5b85d7dff631ad54c942a9da137ea298794e | [
"0BSD"
] | 3 | 2016-03-04T06:15:34.000Z | 2020-12-12T03:01:42.000Z | /*
* Copyright (C) 2009-2021 Alex Smith
*
* 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.
*/
/**
* @file
* @brief ELF loader.
*/
#include <io/fs.h>
#include <kernel/private/image.h>
#include <lib/string.h>
#include <lib/utility.h>
#include <mm/aspace.h>
#include <mm/malloc.h>
#include <mm/phys.h>
#include <mm/safe.h>
#include <mm/vm.h>
#include <proc/process.h>
#include <elf.h>
#include <kboot.h>
#include <kdb.h>
#include <kernel.h>
#include <module.h>
#include <status.h>
/** Define to enable debug output from the ELF loader. */
//#define DEBUG_ELF
#ifdef DEBUG_ELF
# define dprintf(fmt...) kprintf(LOG_DEBUG, fmt)
#else
# define dprintf(fmt...)
#endif
/** Next kernel image ID (protected by kernel_proc lock). */
static image_id_t next_kernel_image_id = 2;
/** Check whether an ELF header is valid for the current system. */
static bool check_ehdr(elf_ehdr_t *ehdr) {
if (strncmp((const char *)ehdr->e_ident, ELF_MAGIC, strlen(ELF_MAGIC)) != 0) {
return false;
} else if (ehdr->e_ident[ELF_EI_VERSION] != 1 || ehdr->e_version != 1) {
return false;
} else if (ehdr->e_ident[ELF_EI_CLASS] != ELF_CLASS) {
return false;
} else if (ehdr->e_ident[ELF_EI_DATA] != ELF_ENDIAN) {
return false;
} else if (ehdr->e_machine != ELF_MACHINE) {
return false;
}
return true;
}
static elf_shdr_t *get_image_section(elf_image_t *image, size_t idx) {
return (elf_shdr_t *)((ptr_t)image->shdrs + (image->ehdr->e_shentsize * idx));
}
/**
* Executable loader.
*/
/** Reserve space for an ELF binary in an address space.
* @param handle Handle to binary.
* @param as Address space to reserve in.
* @return Status code describing result of the operation. */
status_t elf_binary_reserve(object_handle_t *handle, vm_aspace_t *as) {
status_t ret;
size_t bytes;
/* Read the ELF header in from the file. */
elf_ehdr_t ehdr;
ret = file_read(handle, &ehdr, sizeof(ehdr), 0, &bytes);
if (ret != STATUS_SUCCESS) {
return ret;
} else if (bytes != sizeof(ehdr)) {
return STATUS_UNKNOWN_IMAGE;
} else if (!check_ehdr(&ehdr)) {
return STATUS_UNKNOWN_IMAGE;
}
/* If the binary's type is ET_DYN, we don't need to reserve space, as it can
* be loaded to anywhere. */
if (ehdr.e_type == ELF_ET_DYN) {
return STATUS_SUCCESS;
} else if (ehdr.e_type != ELF_ET_EXEC) {
return STATUS_UNKNOWN_IMAGE;
}
/* Check that program headers are the right size. */
if (ehdr.e_phentsize != sizeof(elf_phdr_t))
return STATUS_MALFORMED_IMAGE;
/* Allocate some memory for the program headers and load them too. */
size_t phdr_size = ehdr.e_phnum * ehdr.e_phentsize;
elf_phdr_t *phdrs = kmalloc(phdr_size, MM_USER);
if (!phdrs)
return STATUS_NO_MEMORY;
ret = file_read(handle, phdrs, phdr_size, ehdr.e_phoff, &bytes);
if (ret != STATUS_SUCCESS) {
kfree(phdrs);
return ret;
} else if (bytes != phdr_size) {
kfree(phdrs);
return STATUS_MALFORMED_IMAGE;
}
/* Reserve space for each LOAD header. */
for (size_t i = 0; i < ehdr.e_phnum; i++) {
if (phdrs[i].p_type != ELF_PT_LOAD)
continue;
ptr_t load_start = round_down(phdrs[i].p_vaddr, PAGE_SIZE);
ptr_t load_end = round_up(phdrs[i].p_vaddr + phdrs[i].p_memsz, PAGE_SIZE);
size_t load_size = load_end - load_start;
ret = vm_reserve(as, load_start, load_size);
if (ret != STATUS_SUCCESS) {
kfree(phdrs);
return ret;
}
}
kfree(phdrs);
return STATUS_SUCCESS;
}
static status_t do_load_phdr(elf_image_t *image, size_t i, object_handle_t *handle, vm_aspace_t *as) {
elf_phdr_t *phdr = &image->phdrs[i];
/* Work out the access flags to use. */
uint32_t access = 0;
if (phdr->p_flags & ELF_PF_R)
access |= VM_ACCESS_READ;
if (phdr->p_flags & ELF_PF_W)
access |= VM_ACCESS_WRITE;
if (phdr->p_flags & ELF_PF_X)
access |= VM_ACCESS_EXECUTE;
if (!access) {
dprintf("elf: %s: program header %zu has no protection flags set\n", image->name, i);
return STATUS_MALFORMED_IMAGE;
}
/* Map an anonymous region if memory size is greater than file size. */
if (phdr->p_memsz > phdr->p_filesz) {
ptr_t bss_start = image->load_base + round_down(phdr->p_vaddr + phdr->p_filesz, PAGE_SIZE);
ptr_t bss_end = image->load_base + round_up(phdr->p_vaddr + phdr->p_memsz, PAGE_SIZE);
size_t bss_size = bss_end - bss_start;
dprintf("elf: %s: loading BSS for %zu to %p (size: %zu)\n", image->name, i, start, size);
/* We have to have it writeable for us to be able to clear it later on. */
if (!(access & VM_ACCESS_WRITE)) {
dprintf("elf: %s: program header %zu should be writeable\n", image->name, i);
return STATUS_MALFORMED_IMAGE;
}
/* Create an anonymous memory region for it. */
status_t ret = vm_map(as, &bss_start, bss_size, 0, VM_ADDRESS_EXACT, access, VM_MAP_PRIVATE, NULL, 0, NULL);
if (ret != STATUS_SUCCESS)
return ret;
}
/* If file size is zero then this header is just uninitialized data. */
if (phdr->p_filesz == 0)
return STATUS_SUCCESS;
/* Work out the address to map to and the offset in the file. */
ptr_t start = image->load_base + round_down(phdr->p_vaddr, PAGE_SIZE);
ptr_t end = image->load_base + round_up(phdr->p_vaddr + phdr->p_filesz, PAGE_SIZE);
ptr_t size = end - start;
offset_t offset = round_down(phdr->p_offset, PAGE_SIZE);
dprintf("elf: %s: loading program header %zu to %p (size: %zu)\n", image->name, i, start, size);
/* Map the data in. Set the private flag if mapping as writeable. We do not
* need to check whether the supplied addresses are valid - vm_map() will
* reject them if they aren't. */
return vm_map(
as, &start, size, 0, VM_ADDRESS_EXACT, access,
(access & VM_ACCESS_WRITE) ? VM_MAP_PRIVATE : 0,
handle, offset, NULL);
}
/** Load an ELF binary into an address space.
* @param handle Handle to file being loaded.
* @param path Path to binary (used to name regions).
* @param as Address space to load into.
* @param _image Where to store image to pass to elf_binary_finish().
* @return Status code describing result of the operation. */
status_t elf_binary_load(
object_handle_t *handle, const char *path, vm_aspace_t *as,
elf_image_t **_image)
{
status_t ret;
size_t bytes;
elf_image_t *image = kmalloc(sizeof(*image), MM_KERNEL);
image->name = kbasename(path, MM_KERNEL);
image->ehdr = kmalloc(sizeof(*image->ehdr), MM_KERNEL);
image->phdrs = NULL;
ret = file_read(handle, image->ehdr, sizeof(*image->ehdr), 0, &bytes);
if (ret != STATUS_SUCCESS) {
goto err;
} else if (bytes != sizeof(*image->ehdr)) {
ret = STATUS_UNKNOWN_IMAGE;
goto err;
} else if (!check_ehdr(image->ehdr)) {
ret = STATUS_UNKNOWN_IMAGE;
goto err;
}
/* Ensure that it is a type that we can load. */
if (image->ehdr->e_type != ELF_ET_EXEC && image->ehdr->e_type != ELF_ET_DYN) {
ret = STATUS_UNKNOWN_IMAGE;
goto err;
}
/* Check that program headers are the right size. */
if (image->ehdr->e_phentsize != sizeof(elf_phdr_t)) {
ret = STATUS_MALFORMED_IMAGE;
goto err;
}
/* Allocate some memory for the program headers and load them too. */
size_t phdr_size = image->ehdr->e_phnum * image->ehdr->e_phentsize;
image->phdrs = kmalloc(phdr_size, MM_KERNEL);
ret = file_read(handle, image->phdrs, phdr_size, image->ehdr->e_phoff, &bytes);
if (ret != STATUS_SUCCESS) {
goto err;
} else if (bytes != phdr_size) {
ret = STATUS_MALFORMED_IMAGE;
goto err;
}
/* If loading an ET_DYN binary, work out how much space is required and map
* a chunk into the address space for it. */
image->load_size = 0;
if (image->ehdr->e_type == ELF_ET_DYN) {
for (size_t i = 0; i < image->ehdr->e_phnum; i++) {
if (image->phdrs[i].p_type != ELF_PT_LOAD)
continue;
if ((image->phdrs[i].p_vaddr + image->phdrs[i].p_memsz) > image->load_size) {
image->load_size = round_up(
image->phdrs[i].p_vaddr + image->phdrs[i].p_memsz,
PAGE_SIZE);
}
}
/* If a location is specified, force the binary to be there. */
ret = vm_map(
as, &image->load_base, image->load_size, 0, VM_ADDRESS_ANY,
VM_ACCESS_READ, VM_MAP_PRIVATE, NULL, 0, NULL);
if (ret != STATUS_SUCCESS)
goto err;
} else {
image->load_base = 0;
}
/* Handle all the program headers. */
size_t load_count = 0;
for (size_t i = 0; i < image->ehdr->e_phnum; i++) {
switch (image->phdrs[i].p_type) {
case ELF_PT_LOAD:
ret = do_load_phdr(image, i, handle, as);
if (ret != STATUS_SUCCESS)
goto err;
load_count++;
break;
case ELF_PT_TLS:
/* This is handled internally by libkernel, so allow it. */
break;
case ELF_PT_DYNAMIC:
case ELF_PT_PHDR:
case ELF_PT_NOTE:
/* These can be ignored without warning. */
break;
case ELF_PT_INTERP:
/* This code is used to load the kernel library, which must not
* have an interpreter. */
kprintf(LOG_WARN, "elf: %s: unexpected PT_INTERP header\n", image->name);
ret = STATUS_NOT_SUPPORTED;
goto err;
case ELF_PT_GNU_EH_FRAME:
case ELF_PT_GNU_STACK:
// FIXME: Handle stack. Need to take into account binary flags
// as well, and library ones, so RTLD should do something.
break;
default:
kprintf(
LOG_WARN, "elf: %s: unhandled program header type %u\n",
image->name, image->phdrs[i].p_type);
ret = STATUS_NOT_SUPPORTED;
goto err;
}
}
/* Check if we actually loaded anything. */
if (!load_count) {
kprintf(LOG_WARN, "elf: %s: no loadable program headers\n", image->name);
ret = STATUS_MALFORMED_IMAGE;
goto err;
}
*_image = image;
return STATUS_SUCCESS;
err:
kfree(image->phdrs);
kfree(image->ehdr);
kfree(image->name);
kfree(image);
return ret;
}
/** Finish binary loading, after address space is switched.
* @param image ELF image structure from elf_binary_load().
* @return Address of entry point. */
ptr_t elf_binary_finish(elf_image_t *image) {
/* Clear the BSS sections. */
for (size_t i = 0; i < image->ehdr->e_phnum; i++) {
if (image->phdrs[i].p_type == ELF_PT_LOAD) {
if (image->phdrs[i].p_filesz < image->phdrs[i].p_memsz) {
ptr_t base = image->load_base + image->phdrs[i].p_vaddr + image->phdrs[i].p_filesz;
dprintf("elf: clearing BSS for program header %zu at %p\n", i, base);
memset((void *)base, 0, image->phdrs[i].p_memsz - image->phdrs[i].p_filesz);
}
}
}
return image->load_base + image->ehdr->e_entry;
}
/** Free memory for an ELF image.
* @param image ELF image structure from elf_binary_load(). */
void elf_binary_destroy(elf_image_t *image) {
kfree(image->phdrs);
kfree(image->ehdr);
kfree(image->name);
kfree(image);
}
/**
* Kernel module loader.
*/
/** Resolve a symbol in a module.
* @param image Image to get value from.
* @param num Number of the symbol.
* @param _val Where to store symbol value.
* @return Status code describing result of the operation. */
status_t elf_module_resolve(elf_image_t *image, size_t num, elf_addr_t *_val) {
if (num >= (image->sym_size / image->sym_entsize))
return STATUS_MALFORMED_IMAGE;
elf_sym_t *sym = (elf_sym_t *)(image->symtab + (image->sym_entsize * num));
if (sym->st_shndx == ELF_SHN_UNDEF) {
/* External symbol, look up in the kernel and other modules. */
const char *name = (const char *)image->strtab + sym->st_name;
symbol_t ksym;
if (!symbol_lookup(name, true, true, &ksym)) {
kprintf(LOG_WARN, "elf: %s: reference to undefined symbol `%s'\n", image->name, name);
return STATUS_MISSING_SYMBOL;
}
*_val = ksym.addr;
} else {
/* Internal symbol. */
*_val = sym->st_value + image->load_base;
}
return STATUS_SUCCESS;
}
static status_t load_module_sections(elf_image_t *image, object_handle_t *handle) {
status_t ret;
/* Calculate the total size. */
image->load_size = 0;
for (size_t i = 0; i < image->ehdr->e_shnum; i++) {
elf_shdr_t *shdr = get_image_section(image, i);
switch (shdr->sh_type) {
case ELF_SHT_PROGBITS:
case ELF_SHT_NOBITS:
case ELF_SHT_STRTAB:
case ELF_SHT_SYMTAB:
if (shdr->sh_addralign)
image->load_size = round_up(image->load_size, shdr->sh_addralign);
image->load_size += shdr->sh_size;
break;
}
}
if (!image->load_size) {
kprintf(LOG_WARN, "elf: %s: no loadable sections\n", image->name);
return STATUS_MALFORMED_IMAGE;
}
/* Allocate space to load the module into. */
ptr_t dest = image->load_base = module_mem_alloc(image->load_size);
if (!dest)
return STATUS_NO_MEMORY;
/* For each section, read its data into the allocated area. */
for (size_t i = 0; i < image->ehdr->e_shnum; i++) {
elf_shdr_t *shdr = get_image_section(image, i);
size_t bytes;
switch (shdr->sh_type) {
case ELF_SHT_NOBITS:
if (shdr->sh_addralign)
dest = round_up(dest, shdr->sh_addralign);
shdr->sh_addr = dest;
dprintf(
"elf: %s: clearing SHT_NOBITS section %u at %p (size: %u)\n",
image->name, i, dest, shdr->sh_size);
memset((void *)dest, 0, shdr->sh_size);
dest += shdr->sh_size;
break;
case ELF_SHT_PROGBITS:
case ELF_SHT_STRTAB:
case ELF_SHT_SYMTAB:
if (shdr->sh_addralign)
dest = round_up(dest, shdr->sh_addralign);
shdr->sh_addr = (elf_addr_t)dest;
dprintf(
"elf: %s: loading data for section %u to %p (size: %u, type: %u)\n",
image->name, i, dest, shdr->sh_size, shdr->sh_type);
/* Read the section data in. */
ret = file_read(handle, (void *)dest, shdr->sh_size, shdr->sh_offset, &bytes);
if (ret != STATUS_SUCCESS) {
return ret;
} else if (bytes != shdr->sh_size) {
return STATUS_MALFORMED_IMAGE;
}
dest += shdr->sh_size;
break;
case ELF_SHT_REL:
case ELF_SHT_RELA:
/* Read in the relocations to a temporary location. They will be
* freed later on. */
shdr->sh_addr = (ptr_t)kmalloc(shdr->sh_size, MM_KERNEL);
ret = file_read(handle, (void *)shdr->sh_addr, shdr->sh_size, shdr->sh_offset, &bytes);
if (ret != STATUS_SUCCESS) {
return ret;
} else if (bytes != shdr->sh_size) {
return STATUS_MALFORMED_IMAGE;
}
break;
}
}
return STATUS_SUCCESS;
}
static status_t fix_module_symbols(elf_image_t *image) {
/* Look for the symbol and string tables. */
image->symtab = NULL;
for (size_t i = 0; i < image->ehdr->e_shnum; i++) {
elf_shdr_t *shdr = get_image_section(image, i);
if (shdr->sh_type == ELF_SHT_SYMTAB) {
image->symtab = (void *)shdr->sh_addr;
image->sym_size = shdr->sh_size;
image->sym_entsize = shdr->sh_entsize;
shdr = get_image_section(image, shdr->sh_link);
image->strtab = (void *)shdr->sh_addr;
break;
}
}
if (!image->symtab) {
dprintf("elf: %s: could not find symbol table\n", image->name);
return STATUS_MALFORMED_IMAGE;
}
for (size_t i = 0; i < image->sym_size / image->sym_entsize; i++) {
elf_sym_t *sym = (elf_sym_t *)(image->symtab + (image->sym_entsize * i));
if (sym->st_shndx == ELF_SHN_UNDEF || sym->st_shndx > image->ehdr->e_shnum)
continue;
/* Get the section that the symbol corresponds to. */
elf_shdr_t *shdr = get_image_section(image, sym->st_shndx);
if ((shdr->sh_flags & ELF_SHF_ALLOC) == 0)
continue;
/* Fix up the symbol value. Symbol value should be the symbol's offset
* from the module's load base. */
sym->st_value = sym->st_value + shdr->sh_addr - image->load_base;
}
return STATUS_SUCCESS;
}
static status_t apply_rel_relocs(elf_image_t *image, elf_shdr_t *shdr, elf_shdr_t *target) {
for (size_t i = 0; i < (shdr->sh_size / shdr->sh_entsize); i++) {
elf_rel_t *rel = (elf_rel_t *)(shdr->sh_addr + (i * shdr->sh_entsize));
status_t ret = arch_elf_module_relocate_rel(image, rel, target);
if (ret != STATUS_SUCCESS)
return ret;
}
return STATUS_SUCCESS;
}
static status_t apply_rela_relocs(elf_image_t *image, elf_shdr_t *shdr, elf_shdr_t *target) {
for (size_t i = 0; i < (shdr->sh_size / shdr->sh_entsize); i++) {
elf_rela_t *rel = (elf_rela_t *)(shdr->sh_addr + (i * shdr->sh_entsize));
status_t ret = arch_elf_module_relocate_rela(image, rel, target);
if (ret != STATUS_SUCCESS)
return ret;
}
return STATUS_SUCCESS;
}
static status_t relocate_module(elf_image_t *image, bool info) {
/* Need the string table for section names. */
elf_shdr_t *strtab = get_image_section(image, image->ehdr->e_shstrndx);
/* Look for relocation sections in the module. */
for (size_t i = 0; i < image->ehdr->e_shnum; i++) {
elf_shdr_t *shdr = get_image_section(image, i);
if (shdr->sh_type != ELF_SHT_REL && shdr->sh_type != ELF_SHT_RELA)
continue;
/* Check whether the target is a section we want to relocate. */
elf_shdr_t *target = get_image_section(image, shdr->sh_info);
const char *name = (const char *)strtab->sh_addr + target->sh_name;
if (info) {
if (strcmp(name, MODULE_INFO_SECTION) != 0)
continue;
} else {
if (strcmp(name, MODULE_INFO_SECTION) == 0)
continue;
}
dprintf(
"elf: %s: performing REL%s relocations in section %zu\n",
image->name, (shdr->sh_type == ELF_SHT_RELA) ? "A" : "", i);
/* Perform the relocation. */
status_t ret =
(shdr->sh_type == ELF_SHT_RELA)
? apply_rela_relocs(image, shdr, target)
: apply_rel_relocs(image, shdr, target);
if (ret != STATUS_SUCCESS)
return ret;
/* Free up the relocations, they're in a temporary allocation. */
kfree((void *)shdr->sh_addr);
shdr->sh_addr = 0;
}
return STATUS_SUCCESS;
}
/** Load an ELF kernel module.
* @param handle Handle to the module to load.
* @param path Path to the module file.
* @param image ELF image structure for the module.
* @return Status code describing result of the operation. */
status_t elf_module_load(object_handle_t *handle, const char *path, elf_image_t *image) {
status_t ret;
size_t bytes;
memset(image, 0, sizeof(*image));
list_init(&image->header);
image->name = kbasename(path, MM_KERNEL);
image->ehdr = kmalloc(sizeof(*image->ehdr), MM_KERNEL);
/* Read the ELF header in from the file. */
ret = file_read(handle, image->ehdr, sizeof(*image->ehdr), 0, &bytes);
if (ret != STATUS_SUCCESS) {
goto fail;
} else if (bytes != sizeof(*image->ehdr)) {
ret = STATUS_UNKNOWN_IMAGE;
goto fail;
} else if (!check_ehdr(image->ehdr)) {
ret = STATUS_UNKNOWN_IMAGE;
goto fail;
} else if (image->ehdr->e_type != ELF_ET_REL) {
ret = STATUS_UNKNOWN_IMAGE;
goto fail;
}
/* Calculate the size of the section headers and allocate space. */
size_t shdr_size = image->ehdr->e_shnum * image->ehdr->e_shentsize;
image->shdrs = kmalloc(shdr_size, MM_KERNEL);
/* Read the headers in. */
ret = file_read(handle, image->shdrs, shdr_size, image->ehdr->e_shoff, &bytes);
if (ret != STATUS_SUCCESS) {
goto fail;
} else if (bytes != shdr_size) {
ret = STATUS_MALFORMED_IMAGE;
goto fail;
}
/* Load all loadable sections into memory. */
ret = load_module_sections(image, handle);
if (ret != STATUS_SUCCESS)
goto fail;
/* Fix up the symbol table. */
ret = fix_module_symbols(image);
if (ret != STATUS_SUCCESS)
goto fail;
/* Finally relocate the module information sections. We do not want to fully
* relocate the module at this time as the module loader needs to check its
* dependencies first. */
ret = relocate_module(image, true);
if (ret != STATUS_SUCCESS)
goto fail;
return STATUS_SUCCESS;
fail:
if (image->load_base) {
module_mem_free(image->load_base, image->load_size);
/* Free up allocations made for relocations. */
for (size_t i = 0; i < image->ehdr->e_shnum; i++) {
elf_shdr_t *shdr = get_image_section(image, i);
if (shdr->sh_type != ELF_SHT_REL && shdr->sh_type != ELF_SHT_RELA)
continue;
kfree((void *)shdr->sh_addr);
}
}
kfree(image->shdrs);
kfree(image->ehdr);
kfree(image->name);
return ret;
}
/** Finish loading an ELF module.
* @param image Module to finish.
* @return Status code describing result of the operation. */
status_t elf_module_finish(elf_image_t *image) {
/* Perform remaining relocations. */
status_t ret = relocate_module(image, false);
if (ret != STATUS_SUCCESS)
return ret;
/* Register the image in the kernel process. */
mutex_lock(&kernel_proc->lock);
image->id = next_kernel_image_id++;
list_append(&kernel_proc->images, &image->header);
mutex_unlock(&kernel_proc->lock);
return STATUS_SUCCESS;
}
/** Free up data for an ELF module.
* @param image Image to destroy. */
void elf_module_destroy(elf_image_t *image) {
mutex_lock(&kernel_proc->lock);
list_remove(&image->header);
mutex_unlock(&kernel_proc->lock);
module_mem_free(image->load_base, image->load_size);
/* Free up allocations made for relocations. */
for (size_t i = 0; i < image->ehdr->e_shnum; i++) {
elf_shdr_t *shdr = get_image_section(image, i);
if (shdr->sh_type != ELF_SHT_REL && shdr->sh_type != ELF_SHT_RELA)
continue;
kfree((void *)shdr->sh_addr);
}
kfree(image->shdrs);
kfree(image->ehdr);
kfree(image->name);
}
/** Look up an image symbol by address.
* @param image Image to look up in.
* @param addr Address to lookup.
* @param symbol Symbol structure to fill in.
* @param _off Where to store symbol offset (can be NULL).
* @return Whether a symbol was found for the address. If a symbol
* is not found, but the address lies within the image's
* load region, then the image pointer in the symbol will
* be set to the image, otherwise it will be set to NULL. */
bool elf_symbol_from_addr(elf_image_t *image, ptr_t addr, symbol_t *symbol, size_t *_off) {
for (size_t i = 0; i < image->sym_size / image->sym_entsize; i++) {
elf_sym_t *sym = (elf_sym_t *)(image->symtab + (image->sym_entsize * i));
if (sym->st_shndx == ELF_SHN_UNDEF)
continue;
/* Ignore certain symbol types. */
uint8_t type = ELF_ST_TYPE(sym->st_info);
if (type == ELF_STT_NOTYPE || type == ELF_STT_SECTION || type == ELF_STT_FILE)
continue;
ptr_t value = sym->st_value + image->load_base;
if (addr >= value && addr < (value + sym->st_size)) {
if (_off)
*_off = addr - value;
symbol->addr = value;
symbol->size = sym->st_size;
symbol->name = (const char *)image->strtab + sym->st_name;
symbol->global = (ELF_ST_BIND(sym->st_info)) ? true : false;
symbol->exported = ELF_ST_VISIBILITY(sym->st_other) == ELF_STV_DEFAULT;
symbol->image = image;
return true;
}
}
if (addr >= image->load_base && addr < image->load_base + image->load_size) {
symbol->image = image;
} else {
symbol->image = NULL;
}
return false;
}
/** Look up an image symbol by name.
* @param image Image to look up in.
* @param name Name to lookup.
* @param global Whether to only look up global symbols.
* @param exported Whether to only look up exported symbols.
* @param symbol Symbol structure to fill in.
* @return Whether a symbol by this name was found. */
bool elf_symbol_lookup(
elf_image_t *image, const char *name, bool global, bool exported,
symbol_t *symbol)
{
for (size_t i = 0; i < image->sym_size / image->sym_entsize; i++) {
elf_sym_t *sym = (elf_sym_t *)(image->symtab + (image->sym_entsize * i));
if (sym->st_shndx == ELF_SHN_UNDEF)
continue;
/* Ignore certain symbol types. */
uint8_t type = ELF_ST_TYPE(sym->st_info);
if (type == ELF_STT_NOTYPE || type == ELF_STT_SECTION || type == ELF_STT_FILE)
continue;
/* Ignore symbols in unallocated sections. */
elf_shdr_t *shdr = get_image_section(image, sym->st_shndx);
if (!(shdr->sh_flags & ELF_SHF_ALLOC))
continue;
if (strcmp((const char *)image->strtab + sym->st_name, name) == 0) {
if (global && !ELF_ST_BIND(sym->st_info)) {
continue;
} else if (exported && ELF_ST_VISIBILITY(sym->st_other) != ELF_STV_DEFAULT) {
continue;
}
symbol->addr = sym->st_value + image->load_base;
symbol->size = sym->st_size;
symbol->name = (const char *)image->strtab + sym->st_name;
symbol->global = (ELF_ST_BIND(sym->st_info)) ? true : false;
symbol->exported = ELF_ST_VISIBILITY(sym->st_other) == ELF_STV_DEFAULT;
symbol->image = image;
return true;
}
}
return false;
}
static kdb_status_t kdb_cmd_images(int argc, char **argv, kdb_filter_t *filter) {
uint64_t val;
process_t *process;
elf_image_t *image;
if (kdb_help(argc, argv)) {
kdb_printf("Usage: %s <process ID>\n\n", argv[0]);
kdb_printf("Prints a list of all loaded images in a process.\n");
return KDB_SUCCESS;
} else if (argc != 2) {
kdb_printf("Incorrect number of arguments. See 'help %s' for help.\n", argv[0]);
return KDB_FAILURE;
}
if (kdb_parse_expression(argv[1], &val, NULL) != KDB_SUCCESS)
return KDB_FAILURE;
process = process_lookup_unsafe(val);
if (!process) {
kdb_printf("Invalid process ID.\n");
return KDB_FAILURE;
}
kdb_printf("ID Base Size Name\n");
kdb_printf("== ==== ==== ====\n");
list_foreach(&process->images, iter) {
image = list_entry(iter, elf_image_t, header);
kdb_printf(
"%-6" PRIu16 " %-18p 0x%-8zx %s\n",
image->id, image->load_base, image->load_size, image->name);
}
return KDB_SUCCESS;
}
/** Initialize the kernel ELF information.
* @param image Kernel ELF image. */
__init_text void elf_init(elf_image_t *image) {
list_init(&image->header);
image->id = 1;
image->name = (char *)"kernel";
image->load_base = 0;
image->load_size = 0;
/* Find the loaded section information for the kernel. */
kboot_tag_sections_t *sections = kboot_tag_iterate(KBOOT_TAG_SECTIONS, NULL);
if (!sections || !sections->num)
fatal("No kernel section information provided");
kprintf(
LOG_DEBUG,
"elf: kernel has %" PRIu32 " section headers (shentsize: %" PRIu32 ", shstrndx: %" PRIu32 ")\n",
sections->num, sections->entsize, sections->shstrndx);
/* KBoot gives us physical addresses of the sections. Go through and map
* them into virtual memory. */
for (uint32_t i = 0; i < sections->num; i++) {
elf_shdr_t *shdr = (elf_shdr_t *)§ions->sections[i * sections->entsize];
if (shdr->sh_flags & ELF_SHF_ALLOC ||
!shdr->sh_size ||
(shdr->sh_type != ELF_SHT_PROGBITS &&
shdr->sh_type != ELF_SHT_NOBITS &&
shdr->sh_type != ELF_SHT_SYMTAB &&
shdr->sh_type != ELF_SHT_STRTAB))
{
continue;
}
void *mapping = phys_map(shdr->sh_addr, shdr->sh_size, MM_BOOT);
kprintf(LOG_DEBUG, "elf: mapped section %u: 0x%lx -> %p\n", i, shdr->sh_addr, mapping);
shdr->sh_addr = (ptr_t)mapping;
}
/* The executable header is at the start of the kernel image. */
image->ehdr = kmemdup((elf_ehdr_t *)KERNEL_VIRT_BASE, sizeof(*image->ehdr), MM_BOOT);
image->shdrs = kmemdup(sections->sections, sections->num * sections->entsize, MM_BOOT);
/* Look for the symbol and string tables. */
image->symtab = NULL;
for (uint32_t i = 0; i < image->ehdr->e_shnum; i++) {
elf_shdr_t *shdr = get_image_section(image, i);
if (shdr->sh_type == ELF_SHT_SYMTAB) {
image->symtab = (void *)shdr->sh_addr;
image->sym_size = shdr->sh_size;
image->sym_entsize = shdr->sh_entsize;
shdr = get_image_section(image, shdr->sh_link);
image->strtab = (void *)shdr->sh_addr;
break;
}
}
if (!image->symtab)
fatal("Could not find kernel symbol table");
/* Register the KDB command. */
kdb_register_command(
"images", "Display information about a process' loaded images.",
kdb_cmd_images);
}
/**
* User image management.
*/
/** Clone loaded image information.
* @param process New process.
* @param parent Parent process. */
void elf_process_clone(process_t *process, process_t *parent) {
list_foreach(&parent->images, iter) {
elf_image_t *image = list_entry(iter, elf_image_t, header);
elf_image_t *clone = kmemdup(image, sizeof(*image), MM_KERNEL);
clone->name = kstrdup(image->name, MM_KERNEL);
list_init(&clone->header);
list_append(&process->images, &clone->header);
}
}
/** Clean up ELF images attached to a process.
* @param process Process to clean up. */
void elf_process_cleanup(process_t *process) {
list_foreach_safe(&process->images, iter) {
elf_image_t *image = list_entry(iter, elf_image_t, header);
list_remove(&image->header);
kfree(image->name);
kfree(image);
}
}
/** Register an ELF image with the kernel.
* @param id Image ID.
* @param info Image information structure.
* @return Status code describing the result of the operation. */
status_t kern_image_register(image_id_t id, image_info_t *info) {
status_t ret;
if (!info)
return STATUS_INVALID_ARG;
image_info_t kinfo;
ret = memcpy_from_user(&kinfo, info, sizeof(kinfo));
if (ret != STATUS_SUCCESS)
return ret;
if (kinfo.load_base && !is_user_range(kinfo.load_base, kinfo.load_size)) {
return STATUS_INVALID_ADDR;
} else if (kinfo.symtab && !is_user_range(kinfo.symtab, kinfo.sym_size)) {
return STATUS_INVALID_ADDR;
} else if (kinfo.strtab && !is_user_address(kinfo.strtab)) {
return STATUS_INVALID_ADDR;
}
elf_image_t *image = kmalloc(sizeof(*image), MM_KERNEL);
list_init(&image->header);
image->id = id;
image->load_base = (ptr_t)kinfo.load_base;
image->load_size = kinfo.load_size;
image->symtab = kinfo.symtab;
image->sym_size = kinfo.sym_size;
image->sym_entsize = kinfo.sym_entsize;
image->strtab = kinfo.strtab;
char *name;
ret = strndup_from_user(kinfo.name, FS_PATH_MAX, &name);
if (ret != STATUS_SUCCESS) {
kfree(image);
return ret;
}
image->name = kbasename(name, MM_KERNEL);
kfree(name);
mutex_lock(&curr_proc->lock);
list_foreach(&curr_proc->images, iter) {
elf_image_t *exist = list_entry(iter, elf_image_t, header);
if (exist->id == id) {
mutex_unlock(&curr_proc->lock);
kfree(image->name);
kfree(image);
return STATUS_ALREADY_EXISTS;
}
}
list_append(&curr_proc->images, &image->header);
mutex_unlock(&curr_proc->lock);
dprintf(
"elf: registered image %" PRIu16 " (%s) in process %" PRIu32 " (load_base: %p, load_size: 0x%zx)\n",
image->id, image->name, curr_proc->id, image->load_base, image->load_size);
return STATUS_SUCCESS;
}
/** Unregister an ELF image.
* @param id ID of the image to unregister.
* @return Status code describing the result of the operation. */
status_t kern_image_unregister(image_id_t id) {
mutex_lock(&curr_proc->lock);
list_foreach(&curr_proc->images, iter) {
elf_image_t *image = list_entry(iter, elf_image_t, header);
if (image->id == id) {
list_remove(&image->header);
dprintf(
"elf: unregistered image %" PRIu16 " (%s) in process %" PRIu32 "\n",
image->id, image->name, curr_proc->id);
mutex_unlock(&curr_proc->lock);
kfree(image->name);
kfree(image);
return STATUS_SUCCESS;
}
}
mutex_unlock(&curr_proc->lock);
return STATUS_NOT_FOUND;
}
| 33.604695 | 116 | 0.592975 |
f691c802da877fe49a4c7114b467036705781f7a | 1,840 | h | C | include/SFGraphing/PieChartDataSet.h | MoriokaReimen/SFGraphing | b0655124e4b439bf822e11ba3be44b7480769ea1 | [
"MIT"
] | 8 | 2020-04-26T17:00:29.000Z | 2020-05-06T18:49:40.000Z | include/SFGraphing/PieChartDataSet.h | MoriokaReimen/SFGraphing | b0655124e4b439bf822e11ba3be44b7480769ea1 | [
"MIT"
] | 6 | 2020-05-10T15:24:03.000Z | 2021-07-03T18:02:23.000Z | include/SFGraphing/PieChartDataSet.h | MoriokaReimen/SFGraphing | b0655124e4b439bf822e11ba3be44b7480769ea1 | [
"MIT"
] | 5 | 2020-05-27T10:27:39.000Z | 2021-11-20T10:23:26.000Z | #pragma once
/**
* @file Piechart data file
*
* @author Jerrit Gläsker
* @date 22.05.202
*
* @license MIT-License
*/
#include "SFML/Graphics.hpp"
#include <iostream>
namespace csrc
{
enum class Representation
{
RELATIVE,
ABSOLUTE
};
class PieChartDataSet
{
private:
std::vector<float> _values;
std::vector<std::string> _labels;
Representation _representation;
std::vector<sf::Color> _colors;
public:
/**
* Create empty data
*/
PieChartDataSet();
/**
* Create specific data
* values, labels and colors have to be the same size
* @param values sizes of the pie segments
* @param labels labels of each segment
* @param representation relative/absolute
* @param colors colors of segments
*/
PieChartDataSet(const std::vector<float>& values, const std::vector<std::string>& labels, const Representation& representation,
const std::vector<sf::Color>& colors);
/**
* Get Segment Count
* @return segment count
*/
size_t GetLength() const;
/**
* Get size of specific segment
* @param i index
* @return segment i
*/
float GetValue(const size_t& i) const;
/**
* Get label of segment i
* @param i index
* @return label of segment i
*/
std::string GetLabel(const size_t& i) const;
/**
* Get color of segment i
* @param i index
* @return color of segment i
*/
sf::Color GetColor(const size_t& i) const;
/**
* Get piechart representation
* @return _representation
*/
Representation GetRepresentation() const;
/**
* Set a segments value
* @param i index
* @param value new value
*/
void SetValue(const size_t& i, const float& value);
};
}
| 21.149425 | 131 | 0.599457 |
11f1a60e4868b6b12c388ce1c0d78bb70635180c | 221 | h | C | XYRearrangeCell/XYRearrangeCell/XYRearrangeCellDemo/Classes/Controller/XYTabBarController.h | Ossey/XYRearrangeCell | 3285c47cea83391050c11a45926a80948a3463c8 | [
"Apache-2.0"
] | 13 | 2016-11-08T11:19:12.000Z | 2017-12-16T07:35:35.000Z | XYRearrangeCell/XYRearrangeCell/XYRearrangeCellDemo/Classes/Controller/XYTabBarController.h | Ossey/XYRearrangeCell | 3285c47cea83391050c11a45926a80948a3463c8 | [
"Apache-2.0"
] | 2 | 2018-03-10T01:29:31.000Z | 2018-03-19T04:30:20.000Z | XYRearrangeCell/XYRearrangeCell/XYRearrangeCellDemo/Classes/Controller/XYTabBarController.h | Ossey/XYRearrangeCell | 3285c47cea83391050c11a45926a80948a3463c8 | [
"Apache-2.0"
] | 3 | 2017-05-02T06:16:13.000Z | 2017-12-16T07:31:05.000Z | //
// XYTabBarController.h
// XYRrearrangeCell
//
// Created by Ossey on 16/11/8.
// Copyright © 2016年 Ossey. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface XYTabBarController : UITabBarController
@end
| 15.785714 | 50 | 0.710407 |
efb9c6a50ca62aa918f60ed968ea0ff60c969cb7 | 25,622 | h | C | hookflash-core/core/hookflash/services/RUDPProtocol.h | ilin-in/OP | bf3e87d90008e2a4106ee70360fbe15b0d694e77 | [
"Unlicense"
] | 1 | 2020-02-19T09:55:55.000Z | 2020-02-19T09:55:55.000Z | hookflash-core/core/hookflash/services/RUDPProtocol.h | ilin-in/OP | bf3e87d90008e2a4106ee70360fbe15b0d694e77 | [
"Unlicense"
] | null | null | null | hookflash-core/core/hookflash/services/RUDPProtocol.h | ilin-in/OP | bf3e87d90008e2a4106ee70360fbe15b0d694e77 | [
"Unlicense"
] | null | null | null | /*
Copyright (c) 2012, SMB Phone Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 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.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
#pragma once
/*
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Channel Number | Data Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Flags | Lower 24bits of Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved | Lower 24bits of GSNR |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ Options and Padding /
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
/ Application Data /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Channel Number - in the same range as allowed by TURN (0x4000 -> 0x7FFF)
Data Length - how much application data is included in this packet after the
header (0 is a valid length)
Flags - See definition below
Lower 24bits of Sequence Number - lower 24 bits of the 64bit sequence number
Reserved - must be set to "0" on send and ignored upon receipt
Lower 24bits of GSNR - Lower 24bits of the 64bit GSNR (Greatest Sequence
Number Received). If no packets have been received this
should be set to the NEXT-SEQUENCE-NUMBER as received
from the remote party.
Options and padding - If the EQ bit is set to zero in the flags then the
vector/GSNFR is included as part of the header.
Application data - Application data at the length of the data length
Flags are defined as follows
0
0 1 2 3 4 5 6 7
+-+-+-+-+-+-+-+-+
|P|P|X|D|E|E|A|R|
|S|G|P|P|C|Q|R| |
+-+-+-+-+-+-+-+-+
PS = Parity bit of sending packet (this packet)
PG = Parity of the Greatest Sequence Number Received (if no packets have been
received yet then this value is "0")
XP = XOR'd parity of all packets received up-to-and-including the GSNFR (if
no packets have been received then this value is "0")
DP = Duplicate packets have been received since the last ACK packet was sent.
EC = ECN (Explicit Congestions Notification) received on incoming packet
since last packet in sequence sent. If no packets have been received then
this value is set to "0".
EQ = GSNR == GSNFR (Greatest Sequence Number Received equals Greatest
Sequence Number Fully Received). If no packets have been received then
this value is set to "1".
AR = ACK required (must send a STUN "RELIABLE-CHANNEL-ACK"
indication/request or another packet with ACK information (i.e.
header only packet without data is okay).
R = RFFU (Reserved For Future Use). Must be set to "0" on sending and ignored
upon receipt
-------------------------------------------------------------------------------
This header is present in packet after the header if EQ flag is "0" (and
therefor cannot be present if no packets were received from the remote party
as the EQ value in this case must be "1").
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|P|Vector Length| Lower 24bits of GSNFR |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ [0...vector length] vector RLE information .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
. [padded RLE to next DWORD alignment (if required)] /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
P - XOR'ed parity of all packets marked as received in the vector
(starting at the calculated XORed to-date-up-to-and-including the GSNFR)
Vector Length - Total vector size included after header as expressed in
DWORDs (if the only packet missing is the GSNFR+1 then
vector can be zero)
Lower 24 bits of GSNFR - The lower 24 bits of the 64bit GSNFR (Greatest
Sequence Number Fully Received).
The entire packet including header cannot be over the PMTU or 512 bytes
if not known.
Sender will estimate the receiver's packet window. The sender will only
send packets that are in the sequence number range from the last reported
GSNFR up to the end of the receiver's
estimated packet window, i.e.:
((sequence_number > GSNFR) &&
(sequence_number < (GSNFR + estimated_receivers_window)).
The sender will use a fairness algorithm to estimate the receiver's packet
window and adjust the window up and down according to its own policy on how
much data can be outstanding in the path in at half the RTT. The sender
can verify that the receiver has in fact received packets by way of the XOR'd
bit validation in a way that the receiver can't cheat and lie that it has
received packets when it has not. This prevents the receiver from maliciously
pretending it has received packets where it has not and causing the sender
to over-estimate the capacity of the path or miscalculate RTT by the
receiver acknowledging packets faster than it has actually received them.
The sender will cryptographically randomly choose a parity bit for every
packet is sends over the wire.
The sender will include the parity bit of the packet representing the GSNR
packet. The sender will include the XORed parity-to-date up-to-and-including
the GSNFR packet.
If the GSNFR equals the GSNR then the sender will set the EQ bit on the
packet to 1 otherwise it will set it to 0 and include the vector/GSNFR
additional header.
If the network in which the sender receives packets is ECN aware and
marks packets with ECN, the sender will set the EC flag on a packet to
1 if the packet
The sender will mark the last packet in a series when no more data is
available for sending at the moment with an AR flag.
The sender will automatically resend unacknowledged packets that are beyond
haven't been acknowledged in the 2 times the total estimated
RTT (Round Trip Time). The estimated RTT must never be lower than the
negotiated MINIMUM-RTT.
A receiver can ACK packets received in two ways:
1) Any channel data packet sent in a series acts as an ACK for the channel
2) Send a STUN RELIABLE-CHANNEL-ACK indication or request
The receiver will ignore incoming packets with a sequence number that is
less than the receiver's start window (the last fully ACKed packet) plus
the receiver's window size. The receiver will ignore packets that have the
GSNR parity incorrect for their sent packet. The receiver will close the
connection if it receives any packets with the incorrect GP parity or the
XP parity wrong from the same source:port:connection bound to the connection as
this is an attempt either by a spoofer to inject data into the stream or by a
client attempting to fake acknowledgements on packets it never received.
An IP spoofer could attempt to inject data into a stream by randomly flooding
a receiver in attempt to hit within the sequence number window but they would
have to fake the source IP:port and channel number in order for the attack to
succeed. Thus it is recommended that the channel number is randomly chosen
to make a spoof flood attack less likely to succeed.
Be aware that an IP spoofer may use the XP flag as an attack to attempt to
close a connection to which they don't own by broadcasting packets but they
are unlikely to know the correct sequence number window and channel number
and thus would have to attempt to broadcast many packets in order to obtain
a packet within the window. Obviously if they were sniffing and interfering
with the network directly they could launch an attack but they already could
interfere on a much deeper level in such situations which no protocol can stop
but only detect. Adding security, such as TLS on top of RUDP is recommended to
prevent faked data from being injected into a stream.
The receiver will ignore packets that are outside it's own receiving window
(i.e. from the last fully ACKed packet to the last valid received packet
plus the receiver's window). The receiver will ignore packets beyond its
own receiving buffer capacity (i.e. total packets beyond a missing packet
is greater than the receiver is willing to buffer).
If the AR flag was set on an accepted incoming packet for a packet
with a sequence number greater than the last acknowledged, the sender
will send an ACK packet immediately. The receiver can use a data packet
for the ACK as long as it doesn't violate its own sending rules.
The receiver must send an ACK packet for packets that it didn't acknowledge
yet within the window of the oldest unacknowledged packet plus one
calculated RTT time frame. The calculated RTT must never be lower than the
negotiated MINIMUM-RTT.
The receiver will acknowledge all packets it can every single data packet it
sends out.
The receiver will calculate the latest RTT based on the acknowledgement
of its last packet flagged with the AR bit. The calculated RTT must never be
set lower than the negotiated MINIMUM-RTT.
With packets the receiver accepts, the receiver will look for
acknowledgements that it can verify as accurate with the parity bits.
Older packets containing acknowledgements where the data is still available
to validate the parities can be used to acknowledge packets but never be
used to mark already acknowledged packets as having not been received.
Vector format is as follows:
+--------+--------+--------+--------
|SSLLLLLL|SSLLLLLL|SSLLLLLL| ...
+--------+--------+--------+--------
0 1 2 3 4 5 6 7
+-+-+-+-+-+-+-+-+
|Sta| Run Length|
+-+-+-+-+-+-+-+-+
Sta[te] occupies the most significant two bits of each byte and can
have one of four values, as follows:
State Meaning
----- -------
0 Received
1 Received ECN Marked
2 Reserved
3 Not Yet Received
A "0" vector byte is used at the end of a RLE series for padding to the next
DWORD alignment (and if interpreted would be seen as "0" packets received).
NOTE: There is no guarantee that a "0" byte will be contained at the end
of any vector RLE series as it is only used for padding.
-----------------------------------------------------------------------------
STUN REQUEST: RELIABLE-CHANNEL-OPEN
This STUN request is used to open a channel to a remote party. In an ICE
environment, the requester is always the ICE controlling party.
Will contain following attributes:
If sent over non-ICE to open an anonymous channel:
First send request without any attributes with get 401 back with
NONCE/REALM back.
USERNAME - is set to userRandomFragRemote:userRandomFromLocal. The random frag
should be globally unique to not cause conflict and unguessable.
PASSWORD - is set to the userRandomFragRemote. The password is not included
directly but instead used in the MESSAGE-INTEGRITY calculation.
When the server issues a request it will reverse the fragments
and use the userRandomFromLocal as the password.
NONCE - as indicated by server
REALM - as indicated by server
If sent over an established ICE channel:
USERNAME - is set to the userFragRemote:userFragLocal of the nominated ICE
pairing (just like ICE BINDING requests).
PASSWORD - is set to the ICE password of the remote party of the nominated
ICE pairing (just like ICE BINDING request). The password is not
included directly but instead used in the MESSAGE-INTEGRITY
calculation. Short-term credential calculation is used.
NONCE/REALM - not used.
The request will always contain:
LIFETIME - set to how long the channel should remain open before it is
automatically closed (in seconds). Setting to zero will
cause the channel to close immediately and there is no need to
contain NEXT-SEQUENCE-NUMBER, MINUMIM-RTT or CONGESTION-CONTROL.
Any data received on the channel or RELIABLE-CHANNEL-ACK will
cause the LIFETIME attribute timeout countdown to be reset to the
default.
If not specified, a LIFETIME of 10 minutes is assumed.
CHANNEL-NUMBER - set to the channel number the local party wishes the remote
party to use in all packets the remote party will send to
itself.
NEXT-SEQUENCE-NUMBER - set to the first sequence number-1 that
will be sent from this location (the first sequence
number must be at least 1 but less than 2^48-1)
MINUMIM-RTT - set to the number of milliseconds for the minimum RTT (Round Trip
Time). The request may contain the MINUMIM-RTT attribute to
indicate a minimum RTT it wishes to negotiate with the remote
party.
CONGESTION-CONTROL - A list of congestion control algorithms available to use
by the sender with the preferred listed first. There
must be two of these attributes, one representing the
local (requester) congestion to use and one representing
the remote (responder) congestion algorithm.
CONNECTION-INFO - A string representing whatever additional information is
required to exchange upon connection.
Response will contain (signed with message integrity):
LIFETIME - The responder can always choose a value lower than the requested
LIFETIME of the requester but never can respond with "0" unless
the requester sent "0". This is a negotiated value between requester
and responder. The channel is kept alive by any channel data being
sent or by RELIABLE-CHANNEL-ACK requests/indications. If the
responder wishes to close the channel at a later date the responder
can chose to issue its own CHANNEL open in the reverse direction
with a LIFETIME of "0" with the CHANNEL-NUMBER being set to the
CHANNEL-NUMBER the responder is currently expecting to receive
from the remote party.
If not specified, a LIFETIME of what the requester asked is assumed.
NEXT-SEQUENCE-NUMBER - set to the first sequence number-1 that
will be sent from this responder (the first sequence
number must be at least 1 but less than 2^48-1).
CHANNEL-NUMBER - set to the channel number the responder party wishes the
requester to use in all packets it will send to the
responder.
MINUMIM-RTT - set to the number of milliseconds for the minimum RTT (Round Trip
Time) that the response party will accept. If the response
agrees with the minimum value by the requester it does not
need to include this attribute. The response may contain this
attribute value containing a larger than the requester if it
wishes to negotiate a larger minimum RTT between the two parties
but can never choose a shorter minimum RTT than the requester.
CONGESTION-CONTROL - A list of congestion control algorithms available to use
by the receiver with the selected algorithm listed first.
The selected algorithm must be within the list offered
by the requester. If the attribute is missing then the
responder is assumed to use the algorithm preferred by
the requester. Typically, two of these attributes are
present in the response, one for the local (i.e.
responder) and one for the remote (requester).
CONNECTION-INFO - A string representing whatever additional information is
required to exchange upon connection.
When a channel is open for the first time, the responder does not start
sending data until the requester first sends data or sends an ACK. This is
required to ensure the response actually arrived to the requester and thus
proving the negotiation completed.
If either party responds to a renegotiation attempt (i.e. a new
RELIABLE-CHANNEL-OPEN with changed attributes on the same channel, it must
cease sending channel data until a data packet or ACK is received with a
remote sequence number equal or than the sequence number in the request.
If both parties attempt a simutanious renegotiation attempt a
"487 Role Conflict" should result unless the negotiated request from the
remote party is completely compatible with the outstanding negotiated
request issued from the local party.
If either party was attempting to close the channel but an error was
received as a response, the channel should therefor be considered closed
(except in the case where the NONCE is reported as stale).
-----------------------------------------------------------------------------
STUN REQUEST/INDICATION: RELIABLE-CHANNEL-ACK
Either party can send this as a request or indication. The NONCE/REALM are
only needed on a non-ICE situations. All other attributes must be present in
request, except the ACK-VECTOR if it is not needed (i.e. when the only
packet sequence number missing is the GSNR-1). If not send as an indication
then a response is required and the response must contain the same
attributes as listed for the request except the USERNAME, NONCE and REALM.
USERNAME - same logic as RELIABLE-CHANNEL-OPEN
PASSWORD - same logic as RELIABLE-CHANNEL-OPEN
REALM/NONCE - same logic as RELIABLE-CHANNEL-OPEN
CHANNEL-NUMBER - set to the channel number the local party wished the remote
party to use in all packets the remote party sent to
itself.
NEXT-SEQUENCE-NUMBER - set to the next sequence number the requester will
send over the wire (but has not sent yet).
GSNR - set to the greatest sequence number seen from the remote party.
GSNFR - set to greatest sequence number up to which all packets have been
received.
RELIABLE-FLAGS - Flags indicating the parity or other useful information
ACK-VECTOR - Vector RLE in the same fashion as in the data packet.
A successful response (MESSAGE-INTEGRITY is not required) will indicate
closure is complete. A failure response indicates the request/channel was
not understood properly and the client should consider it closed, except
a 483 where a packet must be re-issued to satisfy the NONCE being stale.
-----------------------------------------------------------------------------
STUN ATTRIBUTE: NEXT-SEQUENCE-NUMBER
This is a 64bit unsigned integer attribute indicating the next sequence
number the requester or responder expects to send (but has not sent).
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Sequence Number .
. |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-----------------------------------------------------------------------------
STUN ATTRIBUTE: GSNR
This is a 64bit unsigned integer attribute indicating the Greatest Sequence
Number Received by the requester/responder encoded in the same method as
the NEXT-SEQUENCE-NUMBER attribute.
-----------------------------------------------------------------------------
STUN ATTRIBUTE: GSNFR
This is a 64bit unsigned integer attribute indicating the Greatest Sequence
Number Fully Received by the requester/responder encoded in the same method
as the NEXT-SEQUENCE-NUMBER attribute. In other words, all the packets
that have been received to date up to a certain sequence number. If the GSNR
is the same value as the GSNFR then this attribute is optional. If this
attribute was not received on a RELIABLE-ACK then the GSNFR is assumed to
be the same value as the GSNR.
-----------------------------------------------------------------------------
STUN ATTRIBUTE: MINIMUM-RTT
This is a 32bit unsigned integer representing the minimum RTT in milliseconds
negotiated by the two parties.
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Minimum-RTT |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-----------------------------------------------------------------------------
STUN ATTRIBUTE: CONNECTION-INFO
An encoded string used at channel open to add additional information about
the connection. The interpretation is entirely dependant on the context.
-----------------------------------------------------------------------------
STUN ATTRIBUTE: RELIABLE-FLAGS
The reliable flags are flags needed to indicate the parity bits and other
acknowledgement flags encoded in 4 bytes. The first byte is the only byte used
at this time.
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|V|P|X|D|E| R | RFFU (Reserved For Future Use) |
|P|G|P|P|C| | (must be set to "0" on send and ignored) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
VP - XOR'ed parity of all packets marked as received in the ACK-VECTOR
attribute (starting with the calculated XORed to-date-up-to-and
including the GSNFR) - Same meaning as the "P" flag on the vector/GSNFR
header in the data packet.
PG = Parity of the Greatest Sequence Number Received
XP = XOR'd parity of all packets received up-to-and-including the GSNFR
DP = Duplicate packets have been received since the last ACK packet was sent.
EC = ECN (Explicit Congestions Notification) received on incoming packet
since last packet in sequence sent
R = RFFU (Reserved For Future Use). Must be set to "0" on sending and ignored
upon receipt
-----------------------------------------------------------------------------
STUN ATTRIBUTE: ACK-VECTOR
Has the same meaning and encoding as the optional vector encoded after the
vector/GSNFR header. The "P" flag from the vector header is contained in the
VP flag of the RELIABLE-FLAGS attribute.
-----------------------------------------------------------------------------
STUN ATTRIBUTE: CONGESTION-CONTROL
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|D| RFFU | RFFU | Profile preferred or selected |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ Profile preferred or selected | Profile preferred or selected /
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
/ Profile preferred or selected | [Profile/padding as required] /
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
The first byte is reserved for flags with only one flag available at this time.
D = Direction. If "0" the congestion control list applies to the "local"
party. If "1" the congestion control list applies to the
"remote" party.
When receiving a request, the remote will apply to the responder
and the local will apply the requester. When receiving a reply
the remote will apply to the requester and the local will apply
to the responder.
RFFU - All bits should be set to "0" and ignored upon receipt.
The second byte is RFFU.
This is a list of unsigned 16bit integers representing the congestions
profile algorithms offered or accepted. The preferred or selected algorithm
must be listed first. The order of the algorithms is assumed to be the
preferred order of the requester or responder. The responder must select an
algorithm within the list offered by the remote party.
*/
| 50.437008 | 80 | 0.656272 |
3c6bfd0b5bd10e26f7c1db9daba2fad1edff33d3 | 398 | c | C | test/src/kw_auto.c | shijunjing/ccsm | 2ca1c88008b8ab0a0c86e05aa571660e24b96ac4 | [
"Apache-2.0"
] | 33 | 2015-07-04T19:53:08.000Z | 2022-02-02T10:06:05.000Z | test/src/kw_auto.c | shijunjing/ccsm | 2ca1c88008b8ab0a0c86e05aa571660e24b96ac4 | [
"Apache-2.0"
] | 83 | 2015-03-07T16:34:20.000Z | 2021-06-23T21:33:31.000Z | test/src/kw_auto.c | shijunjing/ccsm | 2ca1c88008b8ab0a0c86e05aa571660e24b96ac4 | [
"Apache-2.0"
] | 15 | 2016-02-23T08:36:42.000Z | 2021-08-31T10:30:14.000Z | /* File to support VAR_FN_LOC_AUTO_CNT testing
2 functions to check that count is correctly associated with each function
*/
int x;
int y;
#define STORAGE auto
int main(void) {
auto int t;
int z;
auto int v;
if (1 == 1) {
auto int j;
}
return 0;
}
int t;
void v(void) {
auto int p;
STORAGE int i;
STORAGE int q;
STORAGE int j;
int l;
}
| 12.83871 | 77 | 0.590452 |
4cd3effced9d1f0dde06d15866339a8de8405185 | 699 | h | C | expandprots.h | daveshields/AdaEd | 57daecfb7ccadfd9aaf13b4d54f51065affbe599 | [
"BSD-4-Clause",
"BSD-3-Clause"
] | 3 | 2019-05-11T04:11:33.000Z | 2021-04-18T14:55:43.000Z | expandprots.h | daveshields/AdaEd | 57daecfb7ccadfd9aaf13b4d54f51065affbe599 | [
"BSD-4-Clause",
"BSD-3-Clause"
] | null | null | null | expandprots.h | daveshields/AdaEd | 57daecfb7ccadfd9aaf13b4d54f51065affbe599 | [
"BSD-4-Clause",
"BSD-3-Clause"
] | 2 | 2016-10-29T22:52:56.000Z | 2021-04-18T14:55:45.000Z | /*
* Copyright (C) 1985-1992 New York University
*
* This file is part of the Ada/Ed-C system. See the Ada/Ed README file for
* warranty (none) and distribution info and also the GNU General Public
* License for more details.
*/
/* expand */
void expand(Node);
/* expand2 */
void expand_line();
int in_bin_ops(Symbol);
int in_un_ops(Symbol);
void expand_block(Node, Node, Node, Node);
Symbol op_kind(Node);
static void replace_name(Node, Symbol, Symbol);
void check_priv_instance(Tuple, Symbolmap);
void expand_decl(Node);
void expand_type(Node);
void expand_subtype(Node);
void expand_attr(Node);
void expand_string(Node);
void expand_op(Node);
void expand_for(Node);
void mint(Node);
| 24.103448 | 76 | 0.741059 |
7169bb6f0122a501de387cee5040746e5dfd076f | 8,766 | c | C | bridge/bridge.c | ZirakZaheer/ZeroTrust-Ebpf | b0f1968e5c9fa307a84b62a76f02847845a458db | [
"Apache-2.0"
] | 2 | 2018-11-17T08:16:47.000Z | 2022-01-21T16:45:46.000Z | bridge/bridge.c | ZirakZaheer/ZeroTrust-Ebpf | b0f1968e5c9fa307a84b62a76f02847845a458db | [
"Apache-2.0"
] | null | null | null | bridge/bridge.c | ZirakZaheer/ZeroTrust-Ebpf | b0f1968e5c9fa307a84b62a76f02847845a458db | [
"Apache-2.0"
] | null | null | null | #include <bcc/proto.h>
#include <bcc/helpers.h>
#include <linux/skbuff.h>
#include <net/sock.h>
#include <linux/ns_common.h>
#include <net/net_namespace.h>
#include <linux/bpf.h>
#include <linux/string.h>
//Total ports should be number of hosts attached + 1.
#define IP_TCP 6
#define IP_UDP 17
#define TOTAL_PORTS 3
#define TASK_COMM_LEN 16
#define TAG_MASK 0xFFF
struct mac_key {
u64 mac;
};
struct context_t {
char appName[TASK_COMM_LEN];
// context grows here
};
//contains integer alias too all the context attributes
struct context_not_t {
u32 appName;
u32 userName;
//add attributes as needed
};
struct policy_t {
char srcContext[TASK_COMM_LEN];
char dstContext[TASK_COMM_LEN];
u32 action;
};
struct host_info {
u32 ifindex;
u64 rx_pkts;
u64 tx_pkts;
};
struct config {
int ifindex;
};
BPF_TABLE("hash", struct mac_key, struct host_info, mac2host, 10240);
BPF_TABLE_PUBLIC("hash", u16, struct context_t, DEMO_MAP1, 1024);
BPF_TABLE_PUBLIC("hash", u64, struct policy_t, POLICY_MAP, 1024);
BPF_TABLE_PUBLIC("hash", u32, u64, if_inum, 1024);
BPF_TABLE("hash", int, struct config, conf, TOTAL_PORTS);
BPF_PERF_OUTPUT(skb_events);
BPF_ARRAY(policyKey, int, 32);
//BPF_TABLE("hash",int, int, policyKey, 1
// Handle packets from (namespace outside) interface and forward it to bridge
int handle_ingress(void *skb2) {
//Lets assume that the packet is at 0th location of the memory.
struct __sk_buff *skb = (struct __sk_buff *)skb2;
u8 *cursor = 0;
int tagPort = 1;
u32 magic = 0xfaceb00c; //
struct mac_key src_key = {};
struct host_info src_info = {};
//Extract ethernet header from the memory and point cursor to payload of ethernet header.
struct ethernet_t *ethernet = cursor_advance(cursor, sizeof(*ethernet));
//assuming packets are IP_TCP
struct ip_t *ip = cursor_advance(cursor, sizeof(*ip));
if (ip->nextp == IP_TCP) {
struct tcp_t *tcp = cursor_advance(cursor, sizeof(*tcp));
tagPort = tcp->src_port;
} else if (ip->nextp == IP_UDP) {
struct udp_t *udp = cursor_advance(cursor, sizeof(*udp));
tagPort = udp->sport;
}
//we need sport and ifindex to locate the context from the context table
u32 ifindex = skb->ifindex;
u64* inum = if_inum.lookup(&ifindex);
// generate pseudohash
u32 pseudoHash = 0;
u16 tag_16 = 0;
// bpf_trace_printk("ifindex is %u \n", ifindex);
if (inum) {
pseudoHash = *inum + tagPort;
tag_16 = pseudoHash & 0xFFF;
bpf_trace_printk("inum is %u tagport is %d tag is %u \n",*inum, tagPort, tag_16);
} else {
bpf_trace_printk("inum not found\n");
pseudoHash = tagPort;
}
//consult the identity table to fetch context
if (tag_16 > 0) {
bpf_trace_printk("tag is %d, %u \n", tag_16, ip->nextp);
}
// Extract bridge ifindex from the config file, that is populated by the python file while
int zero = 0;
struct config *cfg = conf.lookup(&zero);
if (!cfg) return 1;
src_key.mac = ethernet->src;
src_info.ifindex = skb->ifindex;
src_info.rx_pkts = 0;
src_info.tx_pkts = 0;
int cfg_index = 0;
int vlan_proto = 0;
u16 vlan_tci = tag_16; //tag information goes in here
bpf_skb_vlan_push(skb, vlan_proto, vlan_tci); //pass this information from user space
bpf_trace_printk("final tag inside packet is %u\n", vlan_tci);
bpf_trace_printk(" \n");
bpf_trace_printk(" \n");
struct host_info *src_host = mac2host.lookup_or_init(&src_key, &src_info);
lock_xadd(&src_host->rx_pkts, 1);
bpf_clone_redirect(skb, cfg->ifindex, 1/*ingress*/);
return 0;
}
/*
static inline void copyStr(char dst[], char src[]) {
for (int i = 0; i < sizeof(src) -1;i++) {
dst[i] = src[i];
}
*/
static inline int policyCheck(struct context_t* src, struct context_t* dst, int* finalKey) {
/* access to policy maps, looks up policy tables by combining the carried context */
int dstVal = 0;
int srcVal = 0;
/* return policy decision */
/* to lookup first from the tag */
/* this function will expand and functionality would need to adapt when PTM are introduced*/
/* if (src) {
for (int i = 0; i < sizeof(src->appName)-1; i++) {
srcVal += (int) src->appName[i];
}
}
if (dst) {
for (int i = 0; i < sizeof(dst->appName)-1; i++) {
dstVal += (int) dst->appName[i];
}
}
int key = 0;
int newKey = 123;
policyKey.update(&key, &newKey);
key = srcVal + dstVal;
if (key > 0) {
return key;
} else {
return 0;
}
*/
return 0;
}
// Handle packets inside the bridge and forward it to respective interface
int handle_egress(struct __sk_buff *skb) {
u8 *cursor = 0;
struct ethernet_t *ethernet = cursor_advance(cursor, sizeof(*ethernet));
struct mac_key dst_key = {ethernet->dst};
struct host_info *dst_host = mac2host.lookup(&dst_key);
struct config *cfg = 0;
u64 dstPort = 0;
struct ip_t *ip = cursor_advance(cursor, sizeof(*ip));
if (ip->nextp == IP_TCP) {
struct tcp_t *tcp = cursor_advance(cursor, sizeof(*tcp));
dstPort = tcp->dst_port;
} else if (ip->nextp == IP_UDP) {
struct udp_t *udp = cursor_advance(cursor, sizeof(*udp));
dstPort = udp->dport;
} else {
dstPort = 1;
}
/* tag for destination container */
u64* inum = 0;
if (dst_host) {
u32 ifindex = dst_host->ifindex;
inum = if_inum.lookup(&ifindex);
} else {
bpf_trace_printk("destination host entry missing inside map\n");
}
u32 pseudoHash = 0;
u16 receiver_tag_16 = 123;
u16 packetTag = skb->vlan_tci;
if (inum) {
pseudoHash = *inum + dstPort;
receiver_tag_16 = pseudoHash & 0xFFF;
} else {
// throw error
bpf_trace_printk("inum not found\n");
}
struct context_t* recv_context = DEMO_MAP1.lookup(&receiver_tag_16);
struct context_t recv = {};
int srcVal = 0;
int recvVal = 0;
if (recv_context) {
bpf_trace_printk("receiver context found\n");
recv.appName[0] = recv_context->appName[0];
for (int i = 0; i < sizeof(recv_context->appName) -1;i++) {
recv.appName[i] = recv_context->appName[i];
}
for (int i = 0; i < sizeof(recv_context->appName)-1; i++) {
recvVal += (int) recv_context->appName[i];
}
}
struct context_t* send_context = DEMO_MAP1.lookup(&packetTag);
struct context_t src = {};
if (send_context) {
bpf_trace_printk("sender context found\n");
src.appName[0] = send_context->appName[0];
for (int i = 0; i < sizeof(send_context->appName) -1;i++) {
src.appName[i] = send_context->appName[i];
}
for (int i = 0; i < sizeof(send_context->appName)-1; i++) {
srcVal += (int) send_context->appName[i];
}
}
int finalKey = srcVal + recvVal;
//int finalKey2 = 1;
/*todo: key formation for policy table lookup: will need to include set/subset of recv&send context */
// static inline function that forms a key by combining recv and sender context, also takes in Policy Templates for key formation currently I can ignore this sincle context is simple
/* key should be same as the policy key in userspace*/
/*remove vlan header from skb */
//int ret = policyCheck(&src, &recv, &finalKey);
//if (keyFormed)
//int finalKey2 = ret;
bpf_skb_vlan_pop(skb);
//bpf_probe_read(&finalKey2, sizeof(finalKey2), finalKey);
int key1 = 123 + 3434;
bpf_trace_printk("keyformation check %d \n", key1);
/*handle policy here*/
struct policy_t* dstPolicy = POLICY_MAP.lookup(&dstPort);
int policyFound = 0;
if (dstPolicy) {
} else {
// bpf_trace_printk("policy for process on port %u not found\n",dstPort);
}
int cfg_index = 0;
//If flow exists then just send the packet to dst host else flood it to all ports.
// enforce simple polixy based on pid carried in the packet
struct context_t* context = DEMO_MAP1.lookup(&packetTag);
if (!context) {
// skb_events.perf_submit_skb(skb, skb->len, &packetTag, sizeof(packetTag));
bpf_trace_printk("context not found, Tag inside packet is = %u\n", packetTag);
packetTag = 1;
// go to end
} else if (context) bpf_trace_printk("Tag inside packet is = %u, context is = \n", packetTag);
if ((policyFound == 1) || (((ip->nextp != IP_TCP && ip->nextp != IP_UDP) && packetTag == 1))) {
if (dst_host) {
bpf_clone_redirect(skb, dst_host->ifindex, 0/*ingress*/);
lock_xadd(&dst_host->tx_pkts, 1);
} else {
for ( int j=1;j<TOTAL_PORTS;j++ )
{
cfg_index = j;
cfg = conf.lookup(&cfg_index);
if (cfg) {
bpf_clone_redirect(skb, cfg->ifindex, 0);//egress);
}
}
}
} else {
// drop packets
}
return 0;
}
| 30.65035 | 184 | 0.646817 |
71aa3537e82f72d472d366c66be3492df503665b | 162 | h | C | src/core/transformationfactory.h | fossabot/datura | d8a09c4d5ae13a6984a5a8e89c69ecb8a6023037 | [
"BSD-3-Clause"
] | null | null | null | src/core/transformationfactory.h | fossabot/datura | d8a09c4d5ae13a6984a5a8e89c69ecb8a6023037 | [
"BSD-3-Clause"
] | 1 | 2019-02-12T13:12:00.000Z | 2019-02-12T13:12:00.000Z | src/core/transformationfactory.h | fossabot/datura | d8a09c4d5ae13a6984a5a8e89c69ecb8a6023037 | [
"BSD-3-Clause"
] | 1 | 2019-02-12T13:10:06.000Z | 2019-02-12T13:10:06.000Z | #pragma once
#include "mode.h"
#include "transformationimpl.h"
#include <memory>
std::unique_ptr<TransformationImpl> createTransformation( Mode const& mode );
| 18 | 77 | 0.771605 |
092fd42a43396f33af72b026f1ecb19f4f4910a9 | 2,143 | h | C | matlab_code/jjcao_code-head/toolbox/jjcao_mesh/geodesic/mex/gw/gw_geodesic/GW_GeometryAtlas.h | joycewangsy/normals_pointnet | fc74a8ed1a009b18785990b1b4c20eda0549721c | [
"MIT"
] | null | null | null | matlab_code/jjcao_code-head/toolbox/jjcao_mesh/geodesic/mex/gw/gw_geodesic/GW_GeometryAtlas.h | joycewangsy/normals_pointnet | fc74a8ed1a009b18785990b1b4c20eda0549721c | [
"MIT"
] | null | null | null | matlab_code/jjcao_code-head/toolbox/jjcao_mesh/geodesic/mex/gw/gw_geodesic/GW_GeometryAtlas.h | joycewangsy/normals_pointnet | fc74a8ed1a009b18785990b1b4c20eda0549721c | [
"MIT"
] | null | null | null |
/*------------------------------------------------------------------------------*/
/**
* \file GW_GeometryAtlas.h
* \brief Definition of class \c GW_GeometryAtlas
* \author Gabriel Peyr?
* \date 2-4-2004
*/
/*------------------------------------------------------------------------------*/
#ifndef _GW_GEOMETRYATLAS_H_
#define _GW_GEOMETRYATLAS_H_
#include "../gw_core/GW_Config.h"
#include "GW_GeometryCell.h"
namespace GW {
/*------------------------------------------------------------------------------*/
/**
* \class GW_GeometryAtlas
* \brief A collection of cells.
* \author Gabriel Peyr?
* \date 2-4-2004
*
* A collection of cell with interconnections
*/
/*------------------------------------------------------------------------------*/
class GW_GeometryAtlas
{
public:
/*------------------------------------------------------------------------------*/
/** \name Constructor and destructor */
/*------------------------------------------------------------------------------*/
//@{
GW_GeometryAtlas();
virtual ~GW_GeometryAtlas();
//@}
void InitSampling( std::vector<T_TrissectorInfoVector>& CyclicPositionCollection, GW_U32 n );
void PositionateVertex( T_MeshVector& ParamMeshVector, T_MeshVector& RealMeshVector );
void SmoothSampling( GW_U32 nNbrIter = 20 );
static void SmoothSampling( T_GeometryCellVector& CurCellGroup );
T_GeometryCellVector& GetCellVector()
{ return CellVector_; }
std::vector<T_GeometryCellVector>& GetCellGroupVector()
{ return CellGroupVector_; }
private:
T_GeometryCellVector CellVector_;
std::vector<T_GeometryCellVector> CellGroupVector_;
};
} // End namespace GW
#ifdef GW_USE_INLINE
#include "GW_GeometryAtlas.inl"
#endif
#endif // _GW_GEOMETRYATLAS_H_
///////////////////////////////////////////////////////////////////////////////
// Copyright (c) Gabriel Peyr?
///////////////////////////////////////////////////////////////////////////////
// END OF FILE //
///////////////////////////////////////////////////////////////////////////////
| 27.474359 | 94 | 0.448437 |
5dd00cd4cec17826337c5175a88fda1ebb3866f2 | 34,312 | c | C | source/blender/blenkernel/intern/writeffmpeg.c | wycivil08/blendocv | f6cce83e1f149fef39afa8043aade9c64378f33e | [
"Unlicense"
] | 30 | 2015-01-29T14:06:05.000Z | 2022-01-10T07:47:29.000Z | source/blender/blenkernel/intern/writeffmpeg.c | ttagu99/blendocv | f6cce83e1f149fef39afa8043aade9c64378f33e | [
"Unlicense"
] | 1 | 2017-02-20T20:57:48.000Z | 2018-12-19T23:44:38.000Z | source/blender/blenkernel/intern/writeffmpeg.c | ttagu99/blendocv | f6cce83e1f149fef39afa8043aade9c64378f33e | [
"Unlicense"
] | 15 | 2015-04-23T02:38:36.000Z | 2021-03-01T20:09:39.000Z | /*
* $Id: writeffmpeg.c 40903 2011-10-10 09:38:02Z campbellbarton $
*
* ffmpeg-write support
*
* Partial Copyright (c) 2006 Peter Schlaile
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
/** \file blender/blenkernel/intern/writeffmpeg.c
* \ingroup bke
*/
#ifdef WITH_FFMPEG
#include <string.h>
#include <stdio.h>
#if defined(_WIN32) && defined(DEBUG) && !defined(__MINGW32__) && !defined(__CYGWIN__)
/* This does not seem necessary or present on MSVC 8, but may be needed in earlier versions? */
#if _MSC_VER < 1400
#include <stdint.h>
#endif
#endif
#include <stdlib.h>
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libavutil/rational.h>
#include <libswscale/swscale.h>
#include <libavcodec/opt.h>
#include "MEM_guardedalloc.h"
#include "DNA_scene_types.h"
#include "BLI_blenlib.h"
#ifdef WITH_AUDASPACE
# include "AUD_C-API.h"
#endif
#include "BKE_global.h"
#include "BKE_idprop.h"
#include "BKE_main.h"
#include "BKE_report.h"
#include "BKE_sound.h"
#include "BKE_writeffmpeg.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
#include "ffmpeg_compat.h"
extern void do_init_ffmpeg(void);
static int ffmpeg_type = 0;
static int ffmpeg_codec = CODEC_ID_MPEG4;
static int ffmpeg_audio_codec = CODEC_ID_NONE;
static int ffmpeg_video_bitrate = 1150;
static int ffmpeg_audio_bitrate = 128;
static int ffmpeg_gop_size = 12;
static int ffmpeg_autosplit = 0;
static int ffmpeg_autosplit_count = 0;
static AVFormatContext* outfile = 0;
static AVStream* video_stream = 0;
static AVStream* audio_stream = 0;
static AVFrame* current_frame = 0;
static struct SwsContext *img_convert_ctx = 0;
static uint8_t* video_buffer = 0;
static int video_buffersize = 0;
static uint8_t* audio_input_buffer = 0;
static int audio_input_samples = 0;
static uint8_t* audio_output_buffer = 0;
static int audio_outbuf_size = 0;
static double audio_time = 0.0f;
#ifdef WITH_AUDASPACE
static AUD_Device* audio_mixdown_device = 0;
#endif
#define FFMPEG_AUTOSPLIT_SIZE 2000000000
/* Delete a picture buffer */
static void delete_picture(AVFrame* f)
{
if (f) {
if (f->data[0]) MEM_freeN(f->data[0]);
av_free(f);
}
}
#ifdef WITH_AUDASPACE
static int write_audio_frame(void)
{
AVCodecContext* c = NULL;
AVPacket pkt;
c = audio_stream->codec;
av_init_packet(&pkt);
pkt.size = 0;
AUD_readDevice(audio_mixdown_device, audio_input_buffer, audio_input_samples);
audio_time += (double) audio_input_samples / (double) c->sample_rate;
pkt.size = avcodec_encode_audio(c, audio_output_buffer,
audio_outbuf_size,
(short*) audio_input_buffer);
if(pkt.size < 0)
{
// XXX error("Error writing audio packet");
return -1;
}
pkt.data = audio_output_buffer;
if(c->coded_frame && c->coded_frame->pts != AV_NOPTS_VALUE)
{
pkt.pts = av_rescale_q(c->coded_frame->pts,
c->time_base, audio_stream->time_base);
fprintf(stderr, "Audio Frame PTS: %d\n", (int)pkt.pts);
}
pkt.stream_index = audio_stream->index;
pkt.flags |= AV_PKT_FLAG_KEY;
if (av_interleaved_write_frame(outfile, &pkt) != 0) {
fprintf(stderr, "Error writing audio packet!\n");
return -1;
}
return 0;
}
#endif // #ifdef WITH_AUDASPACE
/* Allocate a temporary frame */
static AVFrame* alloc_picture(int pix_fmt, int width, int height)
{
AVFrame* f;
uint8_t* buf;
int size;
/* allocate space for the struct */
f = avcodec_alloc_frame();
if (!f) return NULL;
size = avpicture_get_size(pix_fmt, width, height);
/* allocate the actual picture buffer */
buf = MEM_mallocN(size, "AVFrame buffer");
if (!buf) {
free(f);
return NULL;
}
avpicture_fill((AVPicture*)f, buf, pix_fmt, width, height);
return f;
}
/* Get the correct file extensions for the requested format,
first is always desired guess_format parameter */
static const char** get_file_extensions(int format)
{
switch(format) {
case FFMPEG_DV: {
static const char * rv[] = { ".dv", NULL };
return rv;
}
case FFMPEG_MPEG1: {
static const char * rv[] = { ".mpg", ".mpeg", NULL };
return rv;
}
case FFMPEG_MPEG2: {
static const char * rv[] = { ".dvd", ".vob", ".mpg", ".mpeg",
NULL };
return rv;
}
case FFMPEG_MPEG4: {
static const char * rv[] = { ".mp4", ".mpg", ".mpeg", NULL };
return rv;
}
case FFMPEG_AVI: {
static const char * rv[] = { ".avi", NULL };
return rv;
}
case FFMPEG_MOV: {
static const char * rv[] = { ".mov", NULL };
return rv;
}
case FFMPEG_H264: {
/* FIXME: avi for now... */
static const char * rv[] = { ".avi", NULL };
return rv;
}
case FFMPEG_XVID: {
/* FIXME: avi for now... */
static const char * rv[] = { ".avi", NULL };
return rv;
}
case FFMPEG_FLV: {
static const char * rv[] = { ".flv", NULL };
return rv;
}
case FFMPEG_MKV: {
static const char * rv[] = { ".mkv", NULL };
return rv;
}
case FFMPEG_OGG: {
static const char * rv[] = { ".ogg", ".ogv", NULL };
return rv;
}
case FFMPEG_MP3: {
static const char * rv[] = { ".mp3", NULL };
return rv;
}
case FFMPEG_WAV: {
static const char * rv[] = { ".wav", NULL };
return rv;
}
default:
return NULL;
}
}
/* Write a frame to the output file */
static int write_video_frame(RenderData *rd, AVFrame* frame, ReportList *reports)
{
int outsize = 0;
int ret, success= 1;
AVCodecContext* c = video_stream->codec;
frame->pts = rd->cfra - rd->sfra;
if (rd->mode & R_FIELDS) {
frame->top_field_first = ((rd->mode & R_ODDFIELD) != 0);
}
outsize = avcodec_encode_video(c, video_buffer, video_buffersize,
frame);
if (outsize != 0) {
AVPacket packet;
av_init_packet(&packet);
if (c->coded_frame->pts != AV_NOPTS_VALUE) {
packet.pts = av_rescale_q(c->coded_frame->pts,
c->time_base,
video_stream->time_base);
fprintf(stderr, "Video Frame PTS: %d\n", (int)packet.pts);
} else {
fprintf(stderr, "Video Frame PTS: not set\n");
}
if (c->coded_frame->key_frame)
packet.flags |= AV_PKT_FLAG_KEY;
packet.stream_index = video_stream->index;
packet.data = video_buffer;
packet.size = outsize;
ret = av_interleaved_write_frame(outfile, &packet);
} else {
ret = 0;
}
if (ret != 0) {
success= 0;
BKE_report(reports, RPT_ERROR, "Error writing frame.");
}
return success;
}
/* read and encode a frame of audio from the buffer */
static AVFrame* generate_video_frame(uint8_t* pixels, ReportList *reports)
{
uint8_t* rendered_frame;
AVCodecContext* c = video_stream->codec;
int width = c->width;
int height = c->height;
AVFrame* rgb_frame;
if (c->pix_fmt != PIX_FMT_BGR32) {
rgb_frame = alloc_picture(PIX_FMT_BGR32, width, height);
if (!rgb_frame) {
BKE_report(reports, RPT_ERROR, "Couldn't allocate temporary frame.");
return NULL;
}
} else {
rgb_frame = current_frame;
}
rendered_frame = pixels;
/* Do RGBA-conversion and flipping in one step depending
on CPU-Endianess */
if (ENDIAN_ORDER == L_ENDIAN) {
int y;
for (y = 0; y < height; y++) {
uint8_t* target = rgb_frame->data[0]
+ width * 4 * (height - y - 1);
uint8_t* src = rendered_frame + width * 4 * y;
uint8_t* end = src + width * 4;
while (src != end) {
target[3] = src[3];
target[2] = src[2];
target[1] = src[1];
target[0] = src[0];
target += 4;
src += 4;
}
}
} else {
int y;
for (y = 0; y < height; y++) {
uint8_t* target = rgb_frame->data[0]
+ width * 4 * (height - y - 1);
uint8_t* src = rendered_frame + width * 4 * y;
uint8_t* end = src + width * 4;
while (src != end) {
target[3] = src[0];
target[2] = src[1];
target[1] = src[2];
target[0] = src[3];
target += 4;
src += 4;
}
}
}
if (c->pix_fmt != PIX_FMT_BGR32) {
sws_scale(img_convert_ctx, (const uint8_t * const*) rgb_frame->data,
rgb_frame->linesize, 0, c->height,
current_frame->data, current_frame->linesize);
delete_picture(rgb_frame);
}
return current_frame;
}
static void set_ffmpeg_property_option(AVCodecContext* c, IDProperty * prop)
{
char name[128];
char * param;
const AVOption * rv = NULL;
fprintf(stderr, "FFMPEG expert option: %s: ", prop->name);
BLI_strncpy(name, prop->name, sizeof(name));
param = strchr(name, ':');
if (param) {
*param++ = 0;
}
switch(prop->type) {
case IDP_STRING:
fprintf(stderr, "%s.\n", IDP_String(prop));
av_set_string3(c, prop->name, IDP_String(prop), 1, &rv);
break;
case IDP_FLOAT:
fprintf(stderr, "%g.\n", IDP_Float(prop));
rv = av_set_double(c, prop->name, IDP_Float(prop));
break;
case IDP_INT:
fprintf(stderr, "%d.\n", IDP_Int(prop));
if (param) {
if (IDP_Int(prop)) {
av_set_string3(c, name, param, 1, &rv);
} else {
return;
}
} else {
rv = av_set_int(c, prop->name, IDP_Int(prop));
}
break;
}
if (!rv) {
fprintf(stderr, "ffmpeg-option not supported: %s! Skipping.\n",
prop->name);
}
}
static void set_ffmpeg_properties(RenderData *rd, AVCodecContext *c, const char * prop_name)
{
IDProperty * prop;
void * iter;
IDProperty * curr;
if (!rd->ffcodecdata.properties) {
return;
}
prop = IDP_GetPropertyFromGroup(
rd->ffcodecdata.properties, (char*) prop_name);
if (!prop) {
return;
}
iter = IDP_GetGroupIterator(prop);
while ((curr = IDP_GroupIterNext(iter)) != NULL) {
set_ffmpeg_property_option(c, curr);
}
}
/* prepare a video stream for the output file */
static AVStream* alloc_video_stream(RenderData *rd, int codec_id, AVFormatContext* of,
int rectx, int recty)
{
AVStream* st;
AVCodecContext* c;
AVCodec* codec;
st = av_new_stream(of, 0);
if (!st) return NULL;
/* Set up the codec context */
c = st->codec;
c->codec_id = codec_id;
c->codec_type = AVMEDIA_TYPE_VIDEO;
/* Get some values from the current render settings */
c->width = rectx;
c->height = recty;
/* FIXME: Really bad hack (tm) for NTSC support */
if (ffmpeg_type == FFMPEG_DV && rd->frs_sec != 25) {
c->time_base.den = 2997;
c->time_base.num = 100;
} else if ((double) ((int) rd->frs_sec_base) ==
rd->frs_sec_base) {
c->time_base.den = rd->frs_sec;
c->time_base.num = (int) rd->frs_sec_base;
} else {
c->time_base.den = rd->frs_sec * 100000;
c->time_base.num = ((double) rd->frs_sec_base) * 100000;
}
c->gop_size = ffmpeg_gop_size;
c->bit_rate = ffmpeg_video_bitrate*1000;
c->rc_max_rate = rd->ffcodecdata.rc_max_rate*1000;
c->rc_min_rate = rd->ffcodecdata.rc_min_rate*1000;
c->rc_buffer_size = rd->ffcodecdata.rc_buffer_size * 1024;
c->rc_initial_buffer_occupancy
= rd->ffcodecdata.rc_buffer_size*3/4;
c->rc_buffer_aggressivity = 1.0;
c->me_method = ME_EPZS;
codec = avcodec_find_encoder(c->codec_id);
if (!codec) return NULL;
/* Be sure to use the correct pixel format(e.g. RGB, YUV) */
if (codec->pix_fmts) {
c->pix_fmt = codec->pix_fmts[0];
} else {
/* makes HuffYUV happy ... */
c->pix_fmt = PIX_FMT_YUV422P;
}
if (ffmpeg_type == FFMPEG_XVID) {
/* arghhhh ... */
c->pix_fmt = PIX_FMT_YUV420P;
c->codec_tag = (('D'<<24) + ('I'<<16) + ('V'<<8) + 'X');
}
if (codec_id == CODEC_ID_H264) {
/* correct wrong default ffmpeg param which crash x264 */
c->qmin=10;
c->qmax=51;
}
// Keep lossless encodes in the RGB domain.
if (codec_id == CODEC_ID_HUFFYUV || codec_id == CODEC_ID_FFV1) {
/* HUFFYUV was PIX_FMT_YUV422P before */
c->pix_fmt = PIX_FMT_RGB32;
}
if ((of->oformat->flags & AVFMT_GLOBALHEADER)
// || !strcmp(of->oformat->name, "mp4")
// || !strcmp(of->oformat->name, "mov")
// || !strcmp(of->oformat->name, "3gp")
) {
fprintf(stderr, "Using global header\n");
c->flags |= CODEC_FLAG_GLOBAL_HEADER;
}
/* Determine whether we are encoding interlaced material or not */
if (rd->mode & R_FIELDS) {
fprintf(stderr, "Encoding interlaced video\n");
c->flags |= CODEC_FLAG_INTERLACED_DCT;
c->flags |= CODEC_FLAG_INTERLACED_ME;
}
/* xasp & yasp got float lately... */
st->sample_aspect_ratio = c->sample_aspect_ratio = av_d2q(
((double) rd->xasp / (double) rd->yasp), 255);
set_ffmpeg_properties(rd, c, "video");
if (avcodec_open(c, codec) < 0) {
//
//XXX error("Couldn't initialize codec");
return NULL;
}
video_buffersize = avpicture_get_size(c->pix_fmt, c->width, c->height);
video_buffer = (uint8_t*)MEM_mallocN(video_buffersize*sizeof(uint8_t),
"FFMPEG video buffer");
current_frame = alloc_picture(c->pix_fmt, c->width, c->height);
img_convert_ctx = sws_getContext(c->width, c->height,
PIX_FMT_BGR32,
c->width, c->height,
c->pix_fmt,
SWS_BICUBIC,
NULL, NULL, NULL);
return st;
}
/* Prepare an audio stream for the output file */
static AVStream* alloc_audio_stream(RenderData *rd, int codec_id, AVFormatContext* of)
{
AVStream* st;
AVCodecContext* c;
AVCodec* codec;
st = av_new_stream(of, 1);
if (!st) return NULL;
c = st->codec;
c->codec_id = codec_id;
c->codec_type = AVMEDIA_TYPE_AUDIO;
c->sample_rate = rd->ffcodecdata.audio_mixrate;
c->bit_rate = ffmpeg_audio_bitrate*1000;
c->sample_fmt = SAMPLE_FMT_S16;
c->channels = rd->ffcodecdata.audio_channels;
codec = avcodec_find_encoder(c->codec_id);
if (!codec) {
//XXX error("Couldn't find a valid audio codec");
return NULL;
}
set_ffmpeg_properties(rd, c, "audio");
if (avcodec_open(c, codec) < 0) {
//XXX error("Couldn't initialize audio codec");
return NULL;
}
/* need to prevent floating point exception when using vorbis audio codec,
initialize this value in the same way as it's done in FFmpeg iteslf (sergey) */
st->codec->time_base.num= 1;
st->codec->time_base.den= st->codec->sample_rate;
audio_outbuf_size = FF_MIN_BUFFER_SIZE;
if((c->codec_id >= CODEC_ID_PCM_S16LE) && (c->codec_id <= CODEC_ID_PCM_DVD))
audio_input_samples = audio_outbuf_size * 8 / c->bits_per_coded_sample / c->channels;
else
{
audio_input_samples = c->frame_size;
if(c->frame_size * c->channels * sizeof(int16_t) * 4 > audio_outbuf_size)
audio_outbuf_size = c->frame_size * c->channels * sizeof(int16_t) * 4;
}
audio_output_buffer = (uint8_t*)av_malloc(
audio_outbuf_size);
audio_input_buffer = (uint8_t*)av_malloc(
audio_input_samples * c->channels * sizeof(int16_t));
audio_time = 0.0f;
return st;
}
/* essential functions -- start, append, end */
static int start_ffmpeg_impl(struct RenderData *rd, int rectx, int recty, ReportList *reports)
{
/* Handle to the output file */
AVFormatContext* of;
AVOutputFormat* fmt;
char name[256];
const char ** exts;
ffmpeg_type = rd->ffcodecdata.type;
ffmpeg_codec = rd->ffcodecdata.codec;
ffmpeg_audio_codec = rd->ffcodecdata.audio_codec;
ffmpeg_video_bitrate = rd->ffcodecdata.video_bitrate;
ffmpeg_audio_bitrate = rd->ffcodecdata.audio_bitrate;
ffmpeg_gop_size = rd->ffcodecdata.gop_size;
ffmpeg_autosplit = rd->ffcodecdata.flags
& FFMPEG_AUTOSPLIT_OUTPUT;
do_init_ffmpeg();
/* Determine the correct filename */
filepath_ffmpeg(name, rd);
fprintf(stderr, "Starting output to %s(ffmpeg)...\n"
" Using type=%d, codec=%d, audio_codec=%d,\n"
" video_bitrate=%d, audio_bitrate=%d,\n"
" gop_size=%d, autosplit=%d\n"
" render width=%d, render height=%d\n",
name, ffmpeg_type, ffmpeg_codec, ffmpeg_audio_codec,
ffmpeg_video_bitrate, ffmpeg_audio_bitrate,
ffmpeg_gop_size, ffmpeg_autosplit, rectx, recty);
exts = get_file_extensions(ffmpeg_type);
if (!exts) {
BKE_report(reports, RPT_ERROR, "No valid formats found.");
return 0;
}
fmt = av_guess_format(NULL, exts[0], NULL);
if (!fmt) {
BKE_report(reports, RPT_ERROR, "No valid formats found.");
return 0;
}
of = avformat_alloc_context();
if (!of) {
BKE_report(reports, RPT_ERROR, "Error opening output file");
return 0;
}
of->oformat = fmt;
of->packet_size= rd->ffcodecdata.mux_packet_size;
if (ffmpeg_audio_codec != CODEC_ID_NONE) {
of->mux_rate = rd->ffcodecdata.mux_rate;
} else {
of->mux_rate = 0;
}
of->preload = (int)(0.5*AV_TIME_BASE);
of->max_delay = (int)(0.7*AV_TIME_BASE);
fmt->audio_codec = ffmpeg_audio_codec;
BLI_snprintf(of->filename, sizeof(of->filename), "%s", name);
/* set the codec to the user's selection */
switch(ffmpeg_type) {
case FFMPEG_AVI:
case FFMPEG_MOV:
case FFMPEG_MKV:
fmt->video_codec = ffmpeg_codec;
break;
case FFMPEG_OGG:
fmt->video_codec = CODEC_ID_THEORA;
break;
case FFMPEG_DV:
fmt->video_codec = CODEC_ID_DVVIDEO;
break;
case FFMPEG_MPEG1:
fmt->video_codec = CODEC_ID_MPEG1VIDEO;
break;
case FFMPEG_MPEG2:
fmt->video_codec = CODEC_ID_MPEG2VIDEO;
break;
case FFMPEG_H264:
fmt->video_codec = CODEC_ID_H264;
break;
case FFMPEG_XVID:
fmt->video_codec = CODEC_ID_MPEG4;
break;
case FFMPEG_FLV:
fmt->video_codec = CODEC_ID_FLV1;
break;
case FFMPEG_MP3:
fmt->audio_codec = CODEC_ID_MP3;
case FFMPEG_WAV:
fmt->video_codec = CODEC_ID_NONE;
break;
case FFMPEG_MPEG4:
default:
fmt->video_codec = CODEC_ID_MPEG4;
break;
}
if (fmt->video_codec == CODEC_ID_DVVIDEO) {
if (rectx != 720) {
BKE_report(reports, RPT_ERROR, "Render width has to be 720 pixels for DV!");
return 0;
}
if (rd->frs_sec != 25 && recty != 480) {
BKE_report(reports, RPT_ERROR, "Render height has to be 480 pixels for DV-NTSC!");
return 0;
}
if (rd->frs_sec == 25 && recty != 576) {
BKE_report(reports, RPT_ERROR, "Render height has to be 576 pixels for DV-PAL!");
return 0;
}
}
if (ffmpeg_type == FFMPEG_DV) {
fmt->audio_codec = CODEC_ID_PCM_S16LE;
if (ffmpeg_audio_codec != CODEC_ID_NONE && rd->ffcodecdata.audio_mixrate != 48000 && rd->ffcodecdata.audio_channels != 2) {
BKE_report(reports, RPT_ERROR, "FFMPEG only supports 48khz / stereo audio for DV!");
return 0;
}
}
if (fmt->video_codec != CODEC_ID_NONE) {
video_stream = alloc_video_stream(rd, fmt->video_codec, of, rectx, recty);
printf("alloc video stream %p\n", video_stream);
if (!video_stream) {
BKE_report(reports, RPT_ERROR, "Error initializing video stream.");
return 0;
}
}
if (ffmpeg_audio_codec != CODEC_ID_NONE) {
audio_stream = alloc_audio_stream(rd, fmt->audio_codec, of);
if (!audio_stream) {
BKE_report(reports, RPT_ERROR, "Error initializing audio stream.");
return 0;
}
}
if (av_set_parameters(of, NULL) < 0) {
BKE_report(reports, RPT_ERROR, "Error setting output parameters.");
return 0;
}
if (!(fmt->flags & AVFMT_NOFILE)) {
if (avio_open(&of->pb, name, AVIO_FLAG_WRITE) < 0) {
BKE_report(reports, RPT_ERROR, "Could not open file for writing.");
return 0;
}
}
if (av_write_header(of) < 0) {
BKE_report(reports, RPT_ERROR, "Could not initialize streams. Probably unsupported codec combination.");
return 0;
}
outfile = of;
av_dump_format(of, 0, name, 1);
return 1;
}
/**
* Writes any delayed frames in the encoder. This function is called before
* closing the encoder.
*
* <p>
* Since an encoder may use both past and future frames to predict
* inter-frames (H.264 B-frames, for example), it can output the frames
* in a different order from the one it was given.
* For example, when sending frames 1, 2, 3, 4 to the encoder, it may write
* them in the order 1, 4, 2, 3 - first the two frames used for predition,
* and then the bidirectionally-predicted frames. What this means in practice
* is that the encoder may not immediately produce one output frame for each
* input frame. These delayed frames must be flushed before we close the
* stream. We do this by calling avcodec_encode_video with NULL for the last
* parameter.
* </p>
*/
void flush_ffmpeg(void)
{
int outsize = 0;
int ret = 0;
AVCodecContext* c = video_stream->codec;
/* get the delayed frames */
while (1) {
AVPacket packet;
av_init_packet(&packet);
outsize = avcodec_encode_video(c, video_buffer, video_buffersize, NULL);
if (outsize < 0) {
fprintf(stderr, "Error encoding delayed frame %d\n", outsize);
break;
}
if (outsize == 0) {
break;
}
if (c->coded_frame->pts != AV_NOPTS_VALUE) {
packet.pts = av_rescale_q(c->coded_frame->pts,
c->time_base,
video_stream->time_base);
fprintf(stderr, "Video Frame PTS: %d\n", (int)packet.pts);
} else {
fprintf(stderr, "Video Frame PTS: not set\n");
}
if (c->coded_frame->key_frame) {
packet.flags |= AV_PKT_FLAG_KEY;
}
packet.stream_index = video_stream->index;
packet.data = video_buffer;
packet.size = outsize;
ret = av_interleaved_write_frame(outfile, &packet);
if (ret != 0) {
fprintf(stderr, "Error writing delayed frame %d\n", ret);
break;
}
}
avcodec_flush_buffers(video_stream->codec);
}
/* **********************************************************************
* public interface
********************************************************************** */
/* Get the output filename-- similar to the other output formats */
void filepath_ffmpeg(char* string, RenderData* rd)
{
char autosplit[20];
const char ** exts = get_file_extensions(rd->ffcodecdata.type);
const char ** fe = exts;
if (!string || !exts) return;
strcpy(string, rd->pic);
BLI_path_abs(string, G.main->name);
BLI_make_existing_file(string);
autosplit[0] = 0;
if ((rd->ffcodecdata.flags & FFMPEG_AUTOSPLIT_OUTPUT) != 0) {
sprintf(autosplit, "_%03d", ffmpeg_autosplit_count);
}
while (*fe) {
if (BLI_strcasecmp(string + strlen(string) - strlen(*fe),
*fe) == 0) {
break;
}
fe++;
}
if (!*fe) {
strcat(string, autosplit);
BLI_path_frame_range(string, rd->sfra, rd->efra, 4);
strcat(string, *exts);
} else {
*(string + strlen(string) - strlen(*fe)) = 0;
strcat(string, autosplit);
strcat(string, *fe);
}
}
int start_ffmpeg(struct Scene *scene, RenderData *rd, int rectx, int recty, ReportList *reports)
{
int success;
ffmpeg_autosplit_count = 0;
success = start_ffmpeg_impl(rd, rectx, recty, reports);
#ifdef WITH_AUDASPACE
if(audio_stream)
{
AVCodecContext* c = audio_stream->codec;
AUD_DeviceSpecs specs;
specs.channels = c->channels;
specs.format = AUD_FORMAT_S16;
specs.rate = rd->ffcodecdata.audio_mixrate;
audio_mixdown_device = sound_mixdown(scene, specs, rd->sfra, rd->ffcodecdata.audio_volume);
#ifdef FFMPEG_CODEC_TIME_BASE
c->time_base.den = specs.rate;
c->time_base.num = 1;
#endif
}
#endif
return success;
}
void end_ffmpeg(void);
#ifdef WITH_AUDASPACE
static void write_audio_frames(double to_pts)
{
int finished = 0;
while (audio_stream && !finished) {
if((audio_time >= to_pts) ||
(write_audio_frame())) {
finished = 1;
}
}
}
#endif
int append_ffmpeg(RenderData *rd, int frame, int *pixels, int rectx, int recty, ReportList *reports)
{
AVFrame* avframe;
int success = 1;
fprintf(stderr, "Writing frame %i, "
"render width=%d, render height=%d\n", frame,
rectx, recty);
// why is this done before writing the video frame and again at end_ffmpeg?
// write_audio_frames(frame / (((double)rd->frs_sec) / rd->frs_sec_base));
if(video_stream)
{
avframe= generate_video_frame((unsigned char*) pixels, reports);
success= (avframe && write_video_frame(rd, avframe, reports));
if (ffmpeg_autosplit) {
if (avio_tell(outfile->pb) > FFMPEG_AUTOSPLIT_SIZE) {
end_ffmpeg();
ffmpeg_autosplit_count++;
success &= start_ffmpeg_impl(rd, rectx, recty, reports);
}
}
}
#ifdef WITH_AUDASPACE
write_audio_frames((frame - rd->sfra) / (((double)rd->frs_sec) / rd->frs_sec_base));
#endif
return success;
}
void end_ffmpeg(void)
{
unsigned int i;
fprintf(stderr, "Closing ffmpeg...\n");
/* if (audio_stream) { SEE UPPER
write_audio_frames();
}*/
#ifdef WITH_AUDASPACE
if(audio_mixdown_device)
{
AUD_closeReadDevice(audio_mixdown_device);
audio_mixdown_device = 0;
}
#endif
if (video_stream && video_stream->codec) {
fprintf(stderr, "Flushing delayed frames...\n");
flush_ffmpeg ();
}
if (outfile) {
av_write_trailer(outfile);
}
/* Close the video codec */
if (video_stream && video_stream->codec) {
avcodec_close(video_stream->codec);
printf("zero video stream %p\n", video_stream);
video_stream = 0;
}
/* Close the output file */
if (outfile) {
for (i = 0; i < outfile->nb_streams; i++) {
if (&outfile->streams[i]) {
av_freep(&outfile->streams[i]);
}
}
}
/* free the temp buffer */
if (current_frame) {
delete_picture(current_frame);
current_frame = 0;
}
if (outfile && outfile->oformat) {
if (!(outfile->oformat->flags & AVFMT_NOFILE)) {
avio_close(outfile->pb);
}
}
if (outfile) {
av_free(outfile);
outfile = 0;
}
if (video_buffer) {
MEM_freeN(video_buffer);
video_buffer = 0;
}
if (audio_output_buffer) {
av_free(audio_output_buffer);
audio_output_buffer = 0;
}
if (audio_input_buffer) {
av_free(audio_input_buffer);
audio_input_buffer = 0;
}
if (img_convert_ctx) {
sws_freeContext(img_convert_ctx);
img_convert_ctx = 0;
}
}
/* properties */
void ffmpeg_property_del(RenderData *rd, void *type, void *prop_)
{
struct IDProperty *prop = (struct IDProperty *) prop_;
IDProperty * group;
if (!rd->ffcodecdata.properties) {
return;
}
group = IDP_GetPropertyFromGroup(
rd->ffcodecdata.properties, (char*) type);
if (group && prop) {
IDP_RemFromGroup(group, prop);
IDP_FreeProperty(prop);
MEM_freeN(prop);
}
}
IDProperty *ffmpeg_property_add(RenderData *rd, char * type, int opt_index, int parent_index)
{
AVCodecContext c;
const AVOption * o;
const AVOption * parent;
IDProperty * group;
IDProperty * prop;
IDPropertyTemplate val;
int idp_type;
char name[256];
val.i = 0;
avcodec_get_context_defaults(&c);
o = c.av_class->option + opt_index;
parent = c.av_class->option + parent_index;
if (!rd->ffcodecdata.properties) {
rd->ffcodecdata.properties
= IDP_New(IDP_GROUP, val, "ffmpeg");
}
group = IDP_GetPropertyFromGroup(
rd->ffcodecdata.properties, (char*) type);
if (!group) {
group = IDP_New(IDP_GROUP, val, (char*) type);
IDP_AddToGroup(rd->ffcodecdata.properties, group);
}
if (parent_index) {
sprintf(name, "%s:%s", parent->name, o->name);
} else {
strcpy(name, o->name);
}
fprintf(stderr, "ffmpeg_property_add: %s %d %d %s\n",
type, parent_index, opt_index, name);
prop = IDP_GetPropertyFromGroup(group, name);
if (prop) {
return prop;
}
switch (o->type) {
case FF_OPT_TYPE_INT:
case FF_OPT_TYPE_INT64:
val.i = FFMPEG_DEF_OPT_VAL_INT(o);
idp_type = IDP_INT;
break;
case FF_OPT_TYPE_DOUBLE:
case FF_OPT_TYPE_FLOAT:
val.f = FFMPEG_DEF_OPT_VAL_DOUBLE(o);
idp_type = IDP_FLOAT;
break;
case FF_OPT_TYPE_STRING:
val.str = " ";
idp_type = IDP_STRING;
break;
case FF_OPT_TYPE_CONST:
val.i = 1;
idp_type = IDP_INT;
break;
default:
return NULL;
}
prop = IDP_New(idp_type, val, name);
IDP_AddToGroup(group, prop);
return prop;
}
/* not all versions of ffmpeg include that, so here we go ... */
static const AVOption *my_av_find_opt(void *v, const char *name,
const char *unit, int mask, int flags){
AVClass *c= *(AVClass**)v;
const AVOption *o= c->option;
for(;o && o->name; o++){
if(!strcmp(o->name, name) &&
(!unit || (o->unit && !strcmp(o->unit, unit))) &&
(o->flags & mask) == flags )
return o;
}
return NULL;
}
int ffmpeg_property_add_string(RenderData *rd, const char * type, const char * str)
{
AVCodecContext c;
const AVOption * o = 0;
const AVOption * p = 0;
char name_[128];
char * name;
char * param;
IDProperty * prop;
avcodec_get_context_defaults(&c);
strncpy(name_, str, sizeof(name_));
name = name_;
while (*name == ' ') name++;
param = strchr(name, ':');
if (!param) {
param = strchr(name, ' ');
}
if (param) {
*param++ = 0;
while (*param == ' ') param++;
}
o = my_av_find_opt(&c, name, NULL, 0, 0);
if (!o) {
return 0;
}
if (param && o->type == FF_OPT_TYPE_CONST) {
return 0;
}
if (param && o->type != FF_OPT_TYPE_CONST && o->unit) {
p = my_av_find_opt(&c, param, o->unit, 0, 0);
prop = ffmpeg_property_add(rd,
(char*) type, p - c.av_class->option,
o - c.av_class->option);
} else {
prop = ffmpeg_property_add(rd,
(char*) type, o - c.av_class->option, 0);
}
if (!prop) {
return 0;
}
if (param && !p) {
switch (prop->type) {
case IDP_INT:
IDP_Int(prop) = atoi(param);
break;
case IDP_FLOAT:
IDP_Float(prop) = atof(param);
break;
case IDP_STRING:
strncpy(IDP_String(prop), param, prop->len);
break;
}
}
return 1;
}
void ffmpeg_set_preset(RenderData *rd, int preset)
{
int isntsc = (rd->frs_sec != 25);
switch (preset) {
case FFMPEG_PRESET_VCD:
rd->ffcodecdata.type = FFMPEG_MPEG1;
rd->ffcodecdata.video_bitrate = 1150;
rd->xsch = 352;
rd->ysch = isntsc ? 240 : 288;
rd->ffcodecdata.gop_size = isntsc ? 18 : 15;
rd->ffcodecdata.rc_max_rate = 1150;
rd->ffcodecdata.rc_min_rate = 1150;
rd->ffcodecdata.rc_buffer_size = 40*8;
rd->ffcodecdata.mux_packet_size = 2324;
rd->ffcodecdata.mux_rate = 2352 * 75 * 8;
break;
case FFMPEG_PRESET_SVCD:
rd->ffcodecdata.type = FFMPEG_MPEG2;
rd->ffcodecdata.video_bitrate = 2040;
rd->xsch = 480;
rd->ysch = isntsc ? 480 : 576;
rd->ffcodecdata.gop_size = isntsc ? 18 : 15;
rd->ffcodecdata.rc_max_rate = 2516;
rd->ffcodecdata.rc_min_rate = 0;
rd->ffcodecdata.rc_buffer_size = 224*8;
rd->ffcodecdata.mux_packet_size = 2324;
rd->ffcodecdata.mux_rate = 0;
break;
case FFMPEG_PRESET_DVD:
rd->ffcodecdata.type = FFMPEG_MPEG2;
rd->ffcodecdata.video_bitrate = 6000;
rd->xsch = 720;
rd->ysch = isntsc ? 480 : 576;
rd->ffcodecdata.gop_size = isntsc ? 18 : 15;
rd->ffcodecdata.rc_max_rate = 9000;
rd->ffcodecdata.rc_min_rate = 0;
rd->ffcodecdata.rc_buffer_size = 224*8;
rd->ffcodecdata.mux_packet_size = 2048;
rd->ffcodecdata.mux_rate = 10080000;
break;
case FFMPEG_PRESET_DV:
rd->ffcodecdata.type = FFMPEG_DV;
rd->xsch = 720;
rd->ysch = isntsc ? 480 : 576;
break;
case FFMPEG_PRESET_H264:
rd->ffcodecdata.type = FFMPEG_AVI;
rd->ffcodecdata.codec = CODEC_ID_H264;
rd->ffcodecdata.video_bitrate = 6000;
rd->ffcodecdata.gop_size = isntsc ? 18 : 15;
rd->ffcodecdata.rc_max_rate = 9000;
rd->ffcodecdata.rc_min_rate = 0;
rd->ffcodecdata.rc_buffer_size = 224*8;
rd->ffcodecdata.mux_packet_size = 2048;
rd->ffcodecdata.mux_rate = 10080000;
/*
* All options here are for x264, but must be set via ffmpeg.
* The names are therefore different - Search for "x264 to FFmpeg option mapping"
* to get a list.
*/
/*
* Use CABAC coder. Using "coder:1", which should be equivalent,
* crashes Blender for some reason. Either way - this is no big deal.
*/
ffmpeg_property_add_string(rd, "video", "coder:vlc");
/*
* The other options were taken from the libx264-default.preset
* included in the ffmpeg distribution.
*/
ffmpeg_property_add_string(rd, "video", "flags:loop");
ffmpeg_property_add_string(rd, "video", "cmp:chroma");
ffmpeg_property_add_string(rd, "video", "partitions:parti4x4");
ffmpeg_property_add_string(rd, "video", "partitions:partp8x8");
ffmpeg_property_add_string(rd, "video", "partitions:partb8x8");
ffmpeg_property_add_string(rd, "video", "me:hex");
ffmpeg_property_add_string(rd, "video", "subq:6");
ffmpeg_property_add_string(rd, "video", "me_range:16");
ffmpeg_property_add_string(rd, "video", "qdiff:4");
ffmpeg_property_add_string(rd, "video", "keyint_min:25");
ffmpeg_property_add_string(rd, "video", "sc_threshold:40");
ffmpeg_property_add_string(rd, "video", "i_qfactor:0.71");
ffmpeg_property_add_string(rd, "video", "b_strategy:1");
ffmpeg_property_add_string(rd, "video", "bf:3");
ffmpeg_property_add_string(rd, "video", "refs:2");
ffmpeg_property_add_string(rd, "video", "qcomp:0.6");
ffmpeg_property_add_string(rd, "video", "directpred:3");
ffmpeg_property_add_string(rd, "video", "trellis:0");
ffmpeg_property_add_string(rd, "video", "flags2:wpred");
ffmpeg_property_add_string(rd, "video", "flags2:dct8x8");
ffmpeg_property_add_string(rd, "video", "flags2:fastpskip");
ffmpeg_property_add_string(rd, "video", "wpredp:2");
// This makes x264 output lossless. Will be a separate option later.
//ffmpeg_property_add_string(rd, "video", "cqp:0");
break;
case FFMPEG_PRESET_THEORA:
case FFMPEG_PRESET_XVID:
if(preset == FFMPEG_PRESET_XVID) {
rd->ffcodecdata.type = FFMPEG_AVI;
rd->ffcodecdata.codec = CODEC_ID_MPEG4;
}
else if(preset == FFMPEG_PRESET_THEORA) {
rd->ffcodecdata.type = FFMPEG_OGG; // XXX broken
rd->ffcodecdata.codec = CODEC_ID_THEORA;
}
rd->ffcodecdata.video_bitrate = 6000;
rd->ffcodecdata.gop_size = isntsc ? 18 : 15;
rd->ffcodecdata.rc_max_rate = 9000;
rd->ffcodecdata.rc_min_rate = 0;
rd->ffcodecdata.rc_buffer_size = 224*8;
rd->ffcodecdata.mux_packet_size = 2048;
rd->ffcodecdata.mux_rate = 10080000;
break;
}
}
void ffmpeg_verify_image_type(RenderData *rd)
{
int audio= 0;
if(rd->imtype == R_FFMPEG) {
if(rd->ffcodecdata.type <= 0 ||
rd->ffcodecdata.codec <= 0 ||
rd->ffcodecdata.audio_codec <= 0 ||
rd->ffcodecdata.video_bitrate <= 1) {
rd->ffcodecdata.codec = CODEC_ID_MPEG2VIDEO;
/* Don't set preset, disturbs render resolution.
* ffmpeg_set_preset(rd, FFMPEG_PRESET_DVD); */
}
if(rd->ffcodecdata.type == FFMPEG_OGG) {
rd->ffcodecdata.type = FFMPEG_MPEG2;
}
audio= 1;
}
else if(rd->imtype == R_H264) {
if(rd->ffcodecdata.codec != CODEC_ID_H264) {
ffmpeg_set_preset(rd, FFMPEG_PRESET_H264);
audio= 1;
}
}
else if(rd->imtype == R_XVID) {
if(rd->ffcodecdata.codec != CODEC_ID_MPEG4) {
ffmpeg_set_preset(rd, FFMPEG_PRESET_XVID);
audio= 1;
}
}
else if(rd->imtype == R_THEORA) {
if(rd->ffcodecdata.codec != CODEC_ID_THEORA) {
ffmpeg_set_preset(rd, FFMPEG_PRESET_THEORA);
audio= 1;
}
}
if(audio && rd->ffcodecdata.audio_codec < 0) {
rd->ffcodecdata.audio_codec = CODEC_ID_NONE;
rd->ffcodecdata.audio_bitrate = 128;
}
}
#endif
| 25.155425 | 125 | 0.674254 |
9535ce8623f1bced09099f05ed056629dc7411d4 | 3,500 | h | C | net/homenet/bridge/sys/brdgdbg.h | npocmaka/Windows-Server-2003 | 5c6fe3db626b63a384230a1aa6b92ac416b0765f | [
"Unlicense"
] | 17 | 2020-11-13T13:42:52.000Z | 2021-09-16T09:13:13.000Z | net/homenet/bridge/sys/brdgdbg.h | sancho1952007/Windows-Server-2003 | 5c6fe3db626b63a384230a1aa6b92ac416b0765f | [
"Unlicense"
] | 2 | 2020-10-19T08:02:06.000Z | 2020-10-19T08:23:18.000Z | net/homenet/bridge/sys/brdgdbg.h | sancho1952007/Windows-Server-2003 | 5c6fe3db626b63a384230a1aa6b92ac416b0765f | [
"Unlicense"
] | 14 | 2020-11-14T09:43:20.000Z | 2021-08-28T08:59:57.000Z | /*++
Copyright(c) 1999-2000 Microsoft Corporation
Module Name:
brdgdbg.h
Abstract:
Ethernet MAC level bridge.
Debugging header
Author:
Mark Aiken
Environment:
Kernel mode driver
Revision History:
December 2000 - Original version
--*/
// Alias for KeGetCurrentIrql()
#define CURRENT_IRQL (KeGetCurrentIrql())
// Module identifiers for debug spew control
#define MODULE_ALWAYS_PRINT 0x0000000
#define MODULE_GENERAL 0x0000001
#define MODULE_FWD 0x0000002
#define MODULE_PROT 0x0000004
#define MODULE_MINI 0x0000008
#define MODULE_BUF 0x0000010
#define MODULE_STA 0x0000020
#define MODULE_COMPAT 0x0000040
#define MODULE_CTL 0x0000080
#define MODULE_TDI 0x0000100
#define MODULE_GPO 0x0000200
// Spew control flags
extern ULONG gSpewFlags;
#if DBG
// Interval for debug messages that risk flooding the debugger console (i.e.,
// per-packet status messages)
#define DBG_PRINT_INTERVAL 1000
extern ULONG gLastThrottledPrint;
extern BOOLEAN gSoftAssert;
extern LARGE_INTEGER gTime;
extern const LARGE_INTEGER gCorrection;
extern TIME_FIELDS gTimeFields;
// HACKHACK: Calling RtlSystemTimeToLocalTime or ExSystemTimeToLocalTime appears to be
// forbidden for WDM drivers, so just subtract a constant amount from the system time
// to recover Pacific Time.
_inline VOID
BrdgDbgPrintDateTime()
{
KeQuerySystemTime( &gTime );
gTime.QuadPart -= gCorrection.QuadPart;
RtlTimeToTimeFields( &gTime, &gTimeFields );
DbgPrint( "%02i/%02i/%04i %02i:%02i:%02i : ", gTimeFields.Month, gTimeFields.Day,
gTimeFields.Year, gTimeFields.Hour, gTimeFields.Minute,
gTimeFields.Second );
}
#define DBGPRINT( Module, Args ) \
{ \
if( (MODULE_ ## Module == MODULE_ALWAYS_PRINT) || (gSpewFlags & MODULE_ ## Module) ) \
{ \
DbgPrint( "## BRIDGE[" #Module "] " ); \
BrdgDbgPrintDateTime(); \
DbgPrint Args; \
} \
}
#define SAFEASSERT( test ) \
if( ! (test) ) \
{ \
if( gSoftAssert ) \
{ \
DBGPRINT(ALWAYS_PRINT, ("ASSERT FAILED: " #test " at " __FILE__ " line %i -- Continuing anyway!\n", __LINE__)); \
} \
else \
{ \
ASSERT( test ); \
} \
}
_inline BOOLEAN
BrdgCanThrottledPrint()
{
ULONG NowTime;
NdisGetSystemUpTime( &NowTime );
if( NowTime - gLastThrottledPrint > DBG_PRINT_INTERVAL )
{
// It's been longer than the interval
gLastThrottledPrint = NowTime;
return TRUE;
}
else
{
// It has not been longer than the interval
return FALSE;
}
}
#define THROTTLED_DBGPRINT( Module, Args ) if(BrdgCanThrottledPrint()) { DBGPRINT(Module, Args); }
#else
#define DBGPRINT( Module, Args )
#define THROTTLED_DBGPRINT( Module, Args )
#define SAFEASSERT( test )
#endif
| 28 | 122 | 0.549714 |
16ee0e4cf601915f7499d88947b20be19933c605 | 433,467 | c | C | src/encodings/Kanji_character_set.c | jce-caba/GtkQR | ccd26749c87410395a0979784b59a7d3d354fdc3 | [
"MIT"
] | null | null | null | src/encodings/Kanji_character_set.c | jce-caba/GtkQR | ccd26749c87410395a0979784b59a7d3d354fdc3 | [
"MIT"
] | null | null | null | src/encodings/Kanji_character_set.c | jce-caba/GtkQR | ccd26749c87410395a0979784b59a7d3d354fdc3 | [
"MIT"
] | null | null | null | #include "Kanji_character_set.h"
int getKanji_character(int value)
{
if ( value >= 32 && value <= 12303 ) {
if (value <= 922 ) {
if (value == 32 )
return 33088;
else if (value == 167 )
return 33176;
else if (value == 168 )
return 33103;
else if (value == 176 )
return 33163;
else if (value == 177 )
return 33149;
else if (value == 180 )
return 33101;
else if (value == 182 )
return 33271;
else if (value == 215 )
return 33150;
else if (value == 247 )
return 33152;
else if (value == 913 )
return 33695;
else if (value == 914 )
return 33696;
else if (value == 915 )
return 33697;
else if (value == 916 )
return 33698;
else if (value == 917 )
return 33699;
else if (value == 918 )
return 33700;
else if (value == 919 )
return 33701;
else if (value == 920 )
return 33702;
else if (value == 921 )
return 33703;
else if (value == 922 )
return 33704;
}
else if (value <= 948 ) {
if (value == 923 )
return 33705;
else if (value == 924 )
return 33706;
else if (value == 925 )
return 33707;
else if (value == 926 )
return 33708;
else if (value == 927 )
return 33709;
else if (value == 928 )
return 33710;
else if (value == 929 )
return 33711;
else if (value == 931 )
return 33712;
else if (value == 932 )
return 33713;
else if (value == 933 )
return 33714;
else if (value == 934 )
return 33715;
else if (value == 935 )
return 33716;
else if (value == 936 )
return 33717;
else if (value == 937 )
return 33718;
else if (value == 945 )
return 33727;
else if (value == 946 )
return 33728;
else if (value == 947 )
return 33729;
else if (value == 948 )
return 33730;
}
else if (value <= 967 ) {
if (value == 949 )
return 33731;
else if (value == 950 )
return 33732;
else if (value == 951 )
return 33733;
else if (value == 952 )
return 33734;
else if (value == 953 )
return 33735;
else if (value == 954 )
return 33736;
else if (value == 955 )
return 33737;
else if (value == 956 )
return 33738;
else if (value == 957 )
return 33739;
else if (value == 958 )
return 33740;
else if (value == 959 )
return 33741;
else if (value == 960 )
return 33742;
else if (value == 961 )
return 33743;
else if (value == 963 )
return 33744;
else if (value == 964 )
return 33745;
else if (value == 965 )
return 33746;
else if (value == 966 )
return 33747;
else if (value == 967 )
return 33748;
}
else if (value <= 1054 ) {
if (value == 968 )
return 33749;
else if (value == 969 )
return 33750;
else if (value == 1025 )
return 33862;
else if (value == 1040 )
return 33856;
else if (value == 1041 )
return 33857;
else if (value == 1042 )
return 33858;
else if (value == 1043 )
return 33859;
else if (value == 1044 )
return 33860;
else if (value == 1045 )
return 33861;
else if (value == 1046 )
return 33863;
else if (value == 1047 )
return 33864;
else if (value == 1048 )
return 33865;
else if (value == 1049 )
return 33866;
else if (value == 1050 )
return 33867;
else if (value == 1051 )
return 33868;
else if (value == 1052 )
return 33869;
else if (value == 1053 )
return 33870;
else if (value == 1054 )
return 33871;
}
else if (value <= 1072 ) {
if (value == 1055 )
return 33872;
else if (value == 1056 )
return 33873;
else if (value == 1057 )
return 33874;
else if (value == 1058 )
return 33875;
else if (value == 1059 )
return 33876;
else if (value == 1060 )
return 33877;
else if (value == 1061 )
return 33878;
else if (value == 1062 )
return 33879;
else if (value == 1063 )
return 33880;
else if (value == 1064 )
return 33881;
else if (value == 1065 )
return 33882;
else if (value == 1066 )
return 33883;
else if (value == 1067 )
return 33884;
else if (value == 1068 )
return 33885;
else if (value == 1069 )
return 33886;
else if (value == 1070 )
return 33887;
else if (value == 1071 )
return 33888;
else if (value == 1072 )
return 33904;
}
else if (value <= 1090 ) {
if (value == 1073 )
return 33905;
else if (value == 1074 )
return 33906;
else if (value == 1075 )
return 33907;
else if (value == 1076 )
return 33908;
else if (value == 1077 )
return 33909;
else if (value == 1078 )
return 33911;
else if (value == 1079 )
return 33912;
else if (value == 1080 )
return 33913;
else if (value == 1081 )
return 33914;
else if (value == 1082 )
return 33915;
else if (value == 1083 )
return 33916;
else if (value == 1084 )
return 33917;
else if (value == 1085 )
return 33918;
else if (value == 1086 )
return 33920;
else if (value == 1087 )
return 33921;
else if (value == 1088 )
return 33922;
else if (value == 1089 )
return 33923;
else if (value == 1090 )
return 33924;
}
else if (value <= 8217 ) {
if (value == 1091 )
return 33925;
else if (value == 1092 )
return 33926;
else if (value == 1093 )
return 33927;
else if (value == 1094 )
return 33928;
else if (value == 1095 )
return 33929;
else if (value == 1096 )
return 33930;
else if (value == 1097 )
return 33931;
else if (value == 1098 )
return 33932;
else if (value == 1099 )
return 33933;
else if (value == 1100 )
return 33934;
else if (value == 1101 )
return 33935;
else if (value == 1102 )
return 33936;
else if (value == 1103 )
return 33937;
else if (value == 1105 )
return 33910;
else if (value == 8208 )
return 33117;
else if (value == 8213 )
return 33116;
else if (value == 8216 )
return 33125;
else if (value == 8217 )
return 33126;
}
else if (value <= 8547 ) {
if (value == 8220 )
return 33127;
else if (value == 8221 )
return 33128;
else if (value == 8224 )
return 33269;
else if (value == 8225 )
return 33270;
else if (value == 8229 )
return 33124;
else if (value == 8230 )
return 33123;
else if (value == 8240 )
return 33265;
else if (value == 8242 )
return 33164;
else if (value == 8243 )
return 33165;
else if (value == 8251 )
return 33190;
else if (value == 8451 )
return 33166;
else if (value == 8470 )
return 34690;
else if (value == 8481 )
return 34692;
else if (value == 8491 )
return 33264;
else if (value == 8544 )
return 34644;
else if (value == 8545 )
return 34645;
else if (value == 8546 )
return 34646;
else if (value == 8547 )
return 34647;
}
else if (value <= 8715 ) {
if (value == 8548 )
return 34648;
else if (value == 8549 )
return 34649;
else if (value == 8550 )
return 34650;
else if (value == 8551 )
return 34651;
else if (value == 8552 )
return 34652;
else if (value == 8553 )
return 34653;
else if (value == 8592 )
return 33193;
else if (value == 8593 )
return 33194;
else if (value == 8594 )
return 33192;
else if (value == 8595 )
return 33195;
else if (value == 8658 )
return 33224;
else if (value == 8660 )
return 33225;
else if (value == 8704 )
return 33226;
else if (value == 8706 )
return 33245;
else if (value == 8707 )
return 33230;
else if (value == 8711 )
return 33246;
else if (value == 8712 )
return 33208;
else if (value == 8715 )
return 33209;
}
else if (value <= 8748 ) {
if (value == 8721 )
return 34708;
else if (value == 8730 )
return 33251;
else if (value == 8730 )
return 34709;
else if (value == 8733 )
return 33253;
else if (value == 8734 )
return 33159;
else if (value == 8735 )
return 34712;
else if (value == 8736 )
return 33242;
else if (value == 8736 )
return 34711;
else if (value == 8741 )
return 33121;
else if (value == 8743 )
return 33221;
else if (value == 8744 )
return 33222;
else if (value == 8745 )
return 33215;
else if (value == 8745 )
return 34715;
else if (value == 8746 )
return 33214;
else if (value == 8746 )
return 34716;
else if (value == 8747 )
return 33255;
else if (value == 8747 )
return 34706;
else if (value == 8748 )
return 33256;
}
else if (value <= 8839 ) {
if (value == 8750 )
return 34707;
else if (value == 8756 )
return 33160;
else if (value == 8757 )
return 33254;
else if (value == 8757 )
return 34714;
else if (value == 8765 )
return 33252;
else if (value == 8786 )
return 33248;
else if (value == 8786 )
return 34704;
else if (value == 8800 )
return 33154;
else if (value == 8801 )
return 33247;
else if (value == 8801 )
return 34705;
else if (value == 8806 )
return 33157;
else if (value == 8807 )
return 33158;
else if (value == 8810 )
return 33249;
else if (value == 8811 )
return 33250;
else if (value == 8834 )
return 33212;
else if (value == 8835 )
return 33213;
else if (value == 8838 )
return 33210;
else if (value == 8839 )
return 33211;
}
else if (value <= 9325 ) {
if (value == 8869 )
return 33243;
else if (value == 8869 )
return 34710;
else if (value == 8895 )
return 34713;
else if (value == 8978 )
return 33244;
else if (value == 9312 )
return 34624;
else if (value == 9313 )
return 34625;
else if (value == 9314 )
return 34626;
else if (value == 9315 )
return 34627;
else if (value == 9316 )
return 34628;
else if (value == 9317 )
return 34629;
else if (value == 9318 )
return 34630;
else if (value == 9319 )
return 34631;
else if (value == 9320 )
return 34632;
else if (value == 9321 )
return 34633;
else if (value == 9322 )
return 34634;
else if (value == 9323 )
return 34635;
else if (value == 9324 )
return 34636;
else if (value == 9325 )
return 34637;
}
else if (value <= 9499 ) {
if (value == 9326 )
return 34638;
else if (value == 9327 )
return 34639;
else if (value == 9328 )
return 34640;
else if (value == 9329 )
return 34641;
else if (value == 9330 )
return 34642;
else if (value == 9331 )
return 34643;
else if (value == 9472 )
return 33951;
else if (value == 9473 )
return 33962;
else if (value == 9474 )
return 33952;
else if (value == 9475 )
return 33963;
else if (value == 9484 )
return 33953;
else if (value == 9487 )
return 33964;
else if (value == 9488 )
return 33954;
else if (value == 9491 )
return 33965;
else if (value == 9492 )
return 33956;
else if (value == 9495 )
return 33967;
else if (value == 9496 )
return 33955;
else if (value == 9499 )
return 33966;
}
else if (value <= 9535 ) {
if (value == 9500 )
return 33957;
else if (value == 9501 )
return 33978;
else if (value == 9504 )
return 33973;
else if (value == 9507 )
return 33968;
else if (value == 9508 )
return 33959;
else if (value == 9509 )
return 33980;
else if (value == 9512 )
return 33975;
else if (value == 9515 )
return 33970;
else if (value == 9516 )
return 33958;
else if (value == 9519 )
return 33974;
else if (value == 9520 )
return 33979;
else if (value == 9523 )
return 33969;
else if (value == 9524 )
return 33960;
else if (value == 9527 )
return 33976;
else if (value == 9528 )
return 33981;
else if (value == 9531 )
return 33971;
else if (value == 9532 )
return 33961;
else if (value == 9535 )
return 33977;
}
else if (value <= 9794 ) {
if (value == 9538 )
return 33982;
else if (value == 9547 )
return 33972;
else if (value == 9632 )
return 33185;
else if (value == 9633 )
return 33184;
else if (value == 9650 )
return 33187;
else if (value == 9651 )
return 33186;
else if (value == 9660 )
return 33189;
else if (value == 9661 )
return 33188;
else if (value == 9670 )
return 33183;
else if (value == 9671 )
return 33182;
else if (value == 9675 )
return 33179;
else if (value == 9678 )
return 33181;
else if (value == 9679 )
return 33180;
else if (value == 9711 )
return 33276;
else if (value == 9733 )
return 33178;
else if (value == 9734 )
return 33177;
else if (value == 9792 )
return 33162;
else if (value == 9794 )
return 33161;
}
else if (value <= 12303 ) {
if (value == 9834 )
return 33268;
else if (value == 9837 )
return 33267;
else if (value == 9839 )
return 33266;
else if (value == 12288 )
return 33089;
else if (value == 12289 )
return 33090;
else if (value == 12290 )
return 33091;
else if (value == 12291 )
return 33110;
else if (value == 12293 )
return 33112;
else if (value == 12294 )
return 33113;
else if (value == 12295 )
return 33114;
else if (value == 12296 )
return 33137;
else if (value == 12297 )
return 33138;
else if (value == 12298 )
return 33139;
else if (value == 12299 )
return 33140;
else if (value == 12300 )
return 33141;
else if (value == 12301 )
return 33142;
else if (value == 12302 )
return 33143;
else if (value == 12303 )
return 33144;
}
}
else if ( value >= 12304 && value <= 20123 ) {
if (value <= 12362 ) {
if (value == 12304 )
return 33145;
else if (value == 12305 )
return 33146;
else if (value == 12306 )
return 33191;
else if (value == 12307 )
return 33196;
else if (value == 12308 )
return 33131;
else if (value == 12309 )
return 33132;
else if (value == 12317 )
return 34688;
else if (value == 12319 )
return 34689;
else if (value == 12353 )
return 33439;
else if (value == 12354 )
return 33440;
else if (value == 12355 )
return 33441;
else if (value == 12356 )
return 33442;
else if (value == 12357 )
return 33443;
else if (value == 12358 )
return 33444;
else if (value == 12359 )
return 33445;
else if (value == 12360 )
return 33446;
else if (value == 12361 )
return 33447;
else if (value == 12362 )
return 33448;
}
else if (value <= 12380 ) {
if (value == 12363 )
return 33449;
else if (value == 12364 )
return 33450;
else if (value == 12365 )
return 33451;
else if (value == 12366 )
return 33452;
else if (value == 12367 )
return 33453;
else if (value == 12368 )
return 33454;
else if (value == 12369 )
return 33455;
else if (value == 12370 )
return 33456;
else if (value == 12371 )
return 33457;
else if (value == 12372 )
return 33458;
else if (value == 12373 )
return 33459;
else if (value == 12374 )
return 33460;
else if (value == 12375 )
return 33461;
else if (value == 12376 )
return 33462;
else if (value == 12377 )
return 33463;
else if (value == 12378 )
return 33464;
else if (value == 12379 )
return 33465;
else if (value == 12380 )
return 33466;
}
else if (value <= 12398 ) {
if (value == 12381 )
return 33467;
else if (value == 12382 )
return 33468;
else if (value == 12383 )
return 33469;
else if (value == 12384 )
return 33470;
else if (value == 12385 )
return 33471;
else if (value == 12386 )
return 33472;
else if (value == 12387 )
return 33473;
else if (value == 12388 )
return 33474;
else if (value == 12389 )
return 33475;
else if (value == 12390 )
return 33476;
else if (value == 12391 )
return 33477;
else if (value == 12392 )
return 33478;
else if (value == 12393 )
return 33479;
else if (value == 12394 )
return 33480;
else if (value == 12395 )
return 33481;
else if (value == 12396 )
return 33482;
else if (value == 12397 )
return 33483;
else if (value == 12398 )
return 33484;
}
else if (value <= 12416 ) {
if (value == 12399 )
return 33485;
else if (value == 12400 )
return 33486;
else if (value == 12401 )
return 33487;
else if (value == 12402 )
return 33488;
else if (value == 12403 )
return 33489;
else if (value == 12404 )
return 33490;
else if (value == 12405 )
return 33491;
else if (value == 12406 )
return 33492;
else if (value == 12407 )
return 33493;
else if (value == 12408 )
return 33494;
else if (value == 12409 )
return 33495;
else if (value == 12410 )
return 33496;
else if (value == 12411 )
return 33497;
else if (value == 12412 )
return 33498;
else if (value == 12413 )
return 33499;
else if (value == 12414 )
return 33500;
else if (value == 12415 )
return 33501;
else if (value == 12416 )
return 33502;
}
else if (value <= 12434 ) {
if (value == 12417 )
return 33503;
else if (value == 12418 )
return 33504;
else if (value == 12419 )
return 33505;
else if (value == 12420 )
return 33506;
else if (value == 12421 )
return 33507;
else if (value == 12422 )
return 33508;
else if (value == 12423 )
return 33509;
else if (value == 12424 )
return 33510;
else if (value == 12425 )
return 33511;
else if (value == 12426 )
return 33512;
else if (value == 12427 )
return 33513;
else if (value == 12428 )
return 33514;
else if (value == 12429 )
return 33515;
else if (value == 12430 )
return 33516;
else if (value == 12431 )
return 33517;
else if (value == 12432 )
return 33518;
else if (value == 12433 )
return 33519;
else if (value == 12434 )
return 33520;
}
else if (value <= 12461 ) {
if (value == 12435 )
return 33521;
else if (value == 12443 )
return 33099;
else if (value == 12444 )
return 33100;
else if (value == 12445 )
return 33108;
else if (value == 12446 )
return 33109;
else if (value == 12449 )
return 33600;
else if (value == 12450 )
return 33601;
else if (value == 12451 )
return 33602;
else if (value == 12452 )
return 33603;
else if (value == 12453 )
return 33604;
else if (value == 12454 )
return 33605;
else if (value == 12455 )
return 33606;
else if (value == 12456 )
return 33607;
else if (value == 12457 )
return 33608;
else if (value == 12458 )
return 33609;
else if (value == 12459 )
return 33610;
else if (value == 12460 )
return 33611;
else if (value == 12461 )
return 33612;
}
else if (value <= 12479 ) {
if (value == 12462 )
return 33613;
else if (value == 12463 )
return 33614;
else if (value == 12464 )
return 33615;
else if (value == 12465 )
return 33616;
else if (value == 12466 )
return 33617;
else if (value == 12467 )
return 33618;
else if (value == 12468 )
return 33619;
else if (value == 12469 )
return 33620;
else if (value == 12470 )
return 33621;
else if (value == 12471 )
return 33622;
else if (value == 12472 )
return 33623;
else if (value == 12473 )
return 33624;
else if (value == 12474 )
return 33625;
else if (value == 12475 )
return 33626;
else if (value == 12476 )
return 33627;
else if (value == 12477 )
return 33628;
else if (value == 12478 )
return 33629;
else if (value == 12479 )
return 33630;
}
else if (value <= 12497 ) {
if (value == 12480 )
return 33631;
else if (value == 12481 )
return 33632;
else if (value == 12482 )
return 33633;
else if (value == 12483 )
return 33634;
else if (value == 12484 )
return 33635;
else if (value == 12485 )
return 33636;
else if (value == 12486 )
return 33637;
else if (value == 12487 )
return 33638;
else if (value == 12488 )
return 33639;
else if (value == 12489 )
return 33640;
else if (value == 12490 )
return 33641;
else if (value == 12491 )
return 33642;
else if (value == 12492 )
return 33643;
else if (value == 12493 )
return 33644;
else if (value == 12494 )
return 33645;
else if (value == 12495 )
return 33646;
else if (value == 12496 )
return 33647;
else if (value == 12497 )
return 33648;
}
else if (value <= 12515 ) {
if (value == 12498 )
return 33649;
else if (value == 12499 )
return 33650;
else if (value == 12500 )
return 33651;
else if (value == 12501 )
return 33652;
else if (value == 12502 )
return 33653;
else if (value == 12503 )
return 33654;
else if (value == 12504 )
return 33655;
else if (value == 12505 )
return 33656;
else if (value == 12506 )
return 33657;
else if (value == 12507 )
return 33658;
else if (value == 12508 )
return 33659;
else if (value == 12509 )
return 33660;
else if (value == 12510 )
return 33661;
else if (value == 12511 )
return 33662;
else if (value == 12512 )
return 33664;
else if (value == 12513 )
return 33665;
else if (value == 12514 )
return 33666;
else if (value == 12515 )
return 33667;
}
else if (value <= 12533 ) {
if (value == 12516 )
return 33668;
else if (value == 12517 )
return 33669;
else if (value == 12518 )
return 33670;
else if (value == 12519 )
return 33671;
else if (value == 12520 )
return 33672;
else if (value == 12521 )
return 33673;
else if (value == 12522 )
return 33674;
else if (value == 12523 )
return 33675;
else if (value == 12524 )
return 33676;
else if (value == 12525 )
return 33677;
else if (value == 12526 )
return 33678;
else if (value == 12527 )
return 33679;
else if (value == 12528 )
return 33680;
else if (value == 12529 )
return 33681;
else if (value == 12530 )
return 33682;
else if (value == 12531 )
return 33683;
else if (value == 12532 )
return 33684;
else if (value == 12533 )
return 33685;
}
else if (value <= 13090 ) {
if (value == 12534 )
return 33686;
else if (value == 12539 )
return 33094;
else if (value == 12540 )
return 33115;
else if (value == 12541 )
return 33106;
else if (value == 12542 )
return 33107;
else if (value == 12849 )
return 34698;
else if (value == 12850 )
return 34699;
else if (value == 12857 )
return 34700;
else if (value == 12964 )
return 34693;
else if (value == 12965 )
return 34694;
else if (value == 12966 )
return 34695;
else if (value == 12967 )
return 34696;
else if (value == 12968 )
return 34697;
else if (value == 13059 )
return 34661;
else if (value == 13069 )
return 34665;
else if (value == 13076 )
return 34656;
else if (value == 13080 )
return 34659;
else if (value == 13090 )
return 34657;
}
else if (value <= 13212 ) {
if (value == 13091 )
return 34667;
else if (value == 13094 )
return 34666;
else if (value == 13095 )
return 34660;
else if (value == 13099 )
return 34668;
else if (value == 13110 )
return 34662;
else if (value == 13115 )
return 34670;
else if (value == 13129 )
return 34655;
else if (value == 13130 )
return 34669;
else if (value == 13133 )
return 34658;
else if (value == 13137 )
return 34663;
else if (value == 13143 )
return 34664;
else if (value == 13179 )
return 34678;
else if (value == 13180 )
return 34703;
else if (value == 13181 )
return 34702;
else if (value == 13182 )
return 34701;
else if (value == 13198 )
return 34674;
else if (value == 13199 )
return 34675;
else if (value == 13212 )
return 34671;
}
else if (value <= 19988 ) {
if (value == 13213 )
return 34672;
else if (value == 13214 )
return 34673;
else if (value == 13217 )
return 34677;
else if (value == 13252 )
return 34676;
else if (value == 13261 )
return 34691;
else if (value == 19968 )
return 35050;
else if (value == 19969 )
return 37530;
else if (value == 19971 )
return 36533;
else if (value == 19975 )
return 38556;
else if (value == 19976 )
return 36836;
else if (value == 19977 )
return 36431;
else if (value == 19978 )
return 36835;
else if (value == 19979 )
return 35258;
else if (value == 19981 )
return 38259;
else if (value == 19982 )
return 38750;
else if (value == 19984 )
return 39072;
else if (value == 19985 )
return 35150;
else if (value == 19988 )
return 35470;
}
else if (value <= 20031 ) {
if (value == 19989 )
return 39073;
else if (value == 19990 )
return 37026;
else if (value == 19991 )
return 39360;
else if (value == 19992 )
return 35701;
else if (value == 19993 )
return 38328;
else if (value == 19998 )
return 36837;
else if (value == 20001 )
return 38844;
else if (value == 20006 )
return 38336;
else if (value == 20010 )
return 39074;
else if (value == 20013 )
return 37510;
else if (value == 20017 )
return 39075;
else if (value == 20018 )
return 35832;
else if (value == 20022 )
return 39076;
else if (value == 20024 )
return 35547;
else if (value == 20025 )
return 37455;
else if (value == 20027 )
return 36581;
else if (value == 20028 )
return 39077;
else if (value == 20031 )
return 39078;
}
else if (value <= 20083 ) {
if (value == 20034 )
return 39079;
else if (value == 20035 )
return 37972;
else if (value == 20037 )
return 35702;
else if (value == 20043 )
return 37974;
else if (value == 20045 )
return 37857;
else if (value == 20046 )
return 36033;
else if (value == 20047 )
return 38482;
else if (value == 20053 )
return 58728;
else if (value == 20054 )
return 39080;
else if (value == 20055 )
return 36838;
else if (value == 20056 )
return 39081;
else if (value == 20057 )
return 35251;
else if (value == 20061 )
return 35811;
else if (value == 20062 )
return 36078;
else if (value == 20063 )
return 38631;
else if (value == 20066 )
return 39844;
else if (value == 20081 )
return 38800;
else if (value == 20083 )
return 37883;
}
else if (value <= 20123 ) {
if (value == 20094 )
return 35491;
else if (value == 20096 )
return 35668;
else if (value == 20098 )
return 39082;
else if (value == 20101 )
return 39083;
else if (value == 20102 )
return 38841;
else if (value == 20104 )
return 38748;
else if (value == 20105 )
return 37256;
else if (value == 20106 )
return 39085;
else if (value == 20107 )
return 36502;
else if (value == 20108 )
return 37873;
else if (value == 20110 )
return 39088;
else if (value == 20113 )
return 35165;
else if (value == 20114 )
return 36061;
else if (value == 20116 )
return 36060;
else if (value == 20117 )
return 35044;
else if (value == 20120 )
return 39018;
else if (value == 20121 )
return 39017;
else if (value == 20123 )
return 36273;
}
}
else if ( value >= 20124 && value <= 20896 ) {
if (value <= 20154 ) {
if (value == 20124 )
return 34975;
else if (value == 20126 )
return 39089;
else if (value == 20127 )
return 39090;
else if (value == 20128 )
return 39091;
else if (value == 20129 )
return 38483;
else if (value == 20130 )
return 39092;
else if (value == 20132 )
return 36080;
else if (value == 20133 )
return 35045;
else if (value == 20134 )
return 38546;
else if (value == 20136 )
return 35740;
else if (value == 20139 )
return 35741;
else if (value == 20140 )
return 35742;
else if (value == 20141 )
return 37600;
else if (value == 20142 )
return 38842;
else if (value == 20144 )
return 39093;
else if (value == 20147 )
return 39094;
else if (value == 20150 )
return 39095;
else if (value == 20154 )
return 36972;
}
else if (value <= 20189 ) {
if (value == 20160 )
return 36697;
else if (value == 20161 )
return 36973;
else if (value == 20162 )
return 39100;
else if (value == 20164 )
return 39098;
else if (value == 20166 )
return 39099;
else if (value == 20167 )
return 35703;
else if (value == 20170 )
return 36257;
else if (value == 20171 )
return 35310;
else if (value == 20173 )
return 39097;
else if (value == 20174 )
return 39096;
else if (value == 20175 )
return 38311;
else if (value == 20180 )
return 36453;
else if (value == 20181 )
return 36452;
else if (value == 20182 )
return 37308;
else if (value == 20183 )
return 39101;
else if (value == 20184 )
return 38260;
else if (value == 20185 )
return 37093;
else if (value == 20189 )
return 33111;
}
else if (value <= 20239 ) {
if (value == 20190 )
return 39102;
else if (value == 20191 )
return 39104;
else if (value == 20195 )
return 37347;
else if (value == 20196 )
return 38879;
else if (value == 20197 )
return 35016;
else if (value == 20205 )
return 39103;
else if (value == 20206 )
return 35260;
else if (value == 20208 )
return 35778;
else if (value == 20210 )
return 37511;
else if (value == 20214 )
return 35983;
else if (value == 20215 )
return 39105;
else if (value == 20219 )
return 37955;
else if (value == 20225 )
return 35561;
else if (value == 20233 )
return 39106;
else if (value == 20234 )
return 35017;
else if (value == 20237 )
return 36062;
else if (value == 20238 )
return 35562;
else if (value == 20239 )
return 38298;
}
else if (value <= 20302 ) {
if (value == 20240 )
return 38064;
else if (value == 20241 )
return 35704;
else if (value == 20250 )
return 35311;
else if (value == 20252 )
return 39141;
else if (value == 20253 )
return 37728;
else if (value == 20271 )
return 38028;
else if (value == 20272 )
return 39108;
else if (value == 20276 )
return 38074;
else if (value == 20278 )
return 38880;
else if (value == 20280 )
return 36940;
else if (value == 20282 )
return 36454;
else if (value == 20284 )
return 36503;
else if (value == 20285 )
return 35262;
else if (value == 20291 )
return 37583;
else if (value == 20294 )
return 37441;
else if (value == 20295 )
return 39112;
else if (value == 20301 )
return 35018;
else if (value == 20302 )
return 37601;
}
else if (value <= 20342 ) {
if (value == 20303 )
return 36698;
else if (value == 20304 )
return 36274;
else if (value == 20305 )
return 38723;
else if (value == 20307 )
return 37324;
else if (value == 20309 )
return 35261;
else if (value == 20311 )
return 39111;
else if (value == 20313 )
return 38749;
else if (value == 20314 )
return 39107;
else if (value == 20315 )
return 39109;
else if (value == 20316 )
return 36332;
else if (value == 20317 )
return 39110;
else if (value == 20318 )
return 39747;
else if (value == 20329 )
return 39118;
else if (value == 20335 )
return 39121;
else if (value == 20336 )
return 39119;
else if (value == 20339 )
return 35264;
else if (value == 20341 )
return 38329;
else if (value == 20342 )
return 39113;
}
else if (value <= 20397 ) {
if (value == 20347 )
return 39117;
else if (value == 20348 )
return 36081;
else if (value == 20351 )
return 36455;
else if (value == 20355 )
return 35492;
else if (value == 20358 )
return 39122;
else if (value == 20360 )
return 39114;
else if (value == 20363 )
return 38881;
else if (value == 20365 )
return 36504;
else if (value == 20367 )
return 39115;
else if (value == 20369 )
return 39120;
else if (value == 20374 )
return 39123;
else if (value == 20376 )
return 39116;
else if (value == 20379 )
return 35743;
else if (value == 20381 )
return 35019;
else if (value == 20384 )
return 35744;
else if (value == 20385 )
return 35263;
else if (value == 20395 )
return 39748;
else if (value == 20397 )
return 38553;
}
else if (value <= 20445 ) {
if (value == 20398 )
return 38286;
else if (value == 20399 )
return 36082;
else if (value == 20405 )
return 36942;
else if (value == 20406 )
return 38837;
else if (value == 20415 )
return 38358;
else if (value == 20418 )
return 35927;
else if (value == 20419 )
return 37283;
else if (value == 20420 )
return 35298;
else if (value == 20426 )
return 36722;
else if (value == 20430 )
return 39127;
else if (value == 20432 )
return 39132;
else if (value == 20433 )
return 39130;
else if (value == 20436 )
return 39125;
else if (value == 20439 )
return 37293;
else if (value == 20440 )
return 39128;
else if (value == 20442 )
return 39131;
else if (value == 20443 )
return 39129;
else if (value == 20445 )
return 38363;
}
else if (value <= 20493 ) {
if (value == 20447 )
return 39126;
else if (value == 20449 )
return 36941;
else if (value == 20451 )
return 38547;
else if (value == 20452 )
return 39133;
else if (value == 20453 )
return 39134;
else if (value == 20462 )
return 36675;
else if (value == 20463 )
return 39147;
else if (value == 20467 )
return 37999;
else if (value == 20469 )
return 38229;
else if (value == 20470 )
return 39142;
else if (value == 20472 )
return 38382;
else if (value == 20474 )
return 35252;
else if (value == 20478 )
return 39146;
else if (value == 20485 )
return 39140;
else if (value == 20486 )
return 39149;
else if (value == 20489 )
return 37233;
else if (value == 20491 )
return 36034;
else if (value == 20493 )
return 38011;
}
else if (value <= 20524 ) {
if (value == 20495 )
return 57541;
else if (value == 20497 )
return 39148;
else if (value == 20498 )
return 37756;
else if (value == 20500 )
return 39137;
else if (value == 20502 )
return 36084;
else if (value == 20505 )
return 36083;
else if (value == 20506 )
return 39135;
else if (value == 20511 )
return 36568;
else if (value == 20513 )
return 39143;
else if (value == 20515 )
return 38381;
else if (value == 20516 )
return 37484;
else if (value == 20517 )
return 39139;
else if (value == 20518 )
return 35985;
else if (value == 20520 )
return 39136;
else if (value == 20521 )
return 39144;
else if (value == 20522 )
return 39138;
else if (value == 20523 )
return 38863;
else if (value == 20524 )
return 39145;
}
else if (value <= 20597 ) {
if (value == 20525 )
return 39008;
else if (value == 20534 )
return 35812;
else if (value == 20537 )
return 35984;
else if (value == 20547 )
return 39150;
else if (value == 20551 )
return 39151;
else if (value == 20552 )
return 39155;
else if (value == 20553 )
return 35020;
else if (value == 20559 )
return 38350;
else if (value == 20560 )
return 39154;
else if (value == 20565 )
return 39153;
else if (value == 20566 )
return 39157;
else if (value == 20570 )
return 39156;
else if (value == 20572 )
return 37602;
else if (value == 20581 )
return 35986;
else if (value == 20588 )
return 39158;
else if (value == 20594 )
return 36547;
else if (value == 20596 )
return 37284;
else if (value == 20597 )
return 37603;
}
else if (value <= 20670 ) {
if (value == 20598 )
return 35828;
else if (value == 20600 )
return 39159;
else if (value == 20605 )
return 35669;
else if (value == 20608 )
return 39160;
else if (value == 20613 )
return 39162;
else if (value == 20621 )
return 38484;
else if (value == 20625 )
return 35974;
else if (value == 20632 )
return 36432;
else if (value == 20633 )
return 38133;
else if (value == 20634 )
return 39161;
else if (value == 20652 )
return 36291;
else if (value == 20653 )
return 38754;
else if (value == 20658 )
return 39164;
else if (value == 20659 )
return 39234;
else if (value == 20660 )
return 39163;
else if (value == 20661 )
return 36290;
else if (value == 20663 )
return 36765;
else if (value == 20670 )
return 35928;
}
else if (value <= 20729 ) {
if (value == 20674 )
return 39235;
else if (value == 20677 )
return 35789;
else if (value == 20681 )
return 39232;
else if (value == 20682 )
return 39233;
else if (value == 20685 )
return 37805;
else if (value == 20687 )
return 37276;
else if (value == 20689 )
return 35745;
else if (value == 20693 )
return 38508;
else if (value == 20694 )
return 39236;
else if (value == 20698 )
return 38843;
else if (value == 20702 )
return 39237;
else if (value == 20707 )
return 39240;
else if (value == 20709 )
return 39238;
else if (value == 20711 )
return 37229;
else if (value == 20717 )
return 39239;
else if (value == 20718 )
return 39241;
else if (value == 20725 )
return 39243;
else if (value == 20729 )
return 39242;
}
else if (value <= 20794 ) {
if (value == 20731 )
return 38342;
else if (value == 20736 )
return 35670;
else if (value == 20737 )
return 39245;
else if (value == 20738 )
return 39246;
else if (value == 20740 )
return 35245;
else if (value == 20745 )
return 39244;
else if (value == 20754 )
return 36594;
else if (value == 20756 )
return 39249;
else if (value == 20757 )
return 39248;
else if (value == 20758 )
return 39247;
else if (value == 20760 )
return 39124;
else if (value == 20762 )
return 39250;
else if (value == 20767 )
return 36766;
else if (value == 20769 )
return 39251;
else if (value == 20778 )
return 38724;
else if (value == 20786 )
return 38615;
else if (value == 20791 )
return 39253;
else if (value == 20794 )
return 39252;
}
else if (value <= 20818 ) {
if (value == 20795 )
return 39255;
else if (value == 20796 )
return 39254;
else if (value == 20799 )
return 39256;
else if (value == 20800 )
return 39257;
else if (value == 20801 )
return 35058;
else if (value == 20803 )
return 36019;
else if (value == 20804 )
return 35930;
else if (value == 20805 )
return 36699;
else if (value == 20806 )
return 37531;
else if (value == 20807 )
return 35746;
else if (value == 20808 )
return 37094;
else if (value == 20809 )
return 36085;
else if (value == 20811 )
return 36238;
else if (value == 20812 )
return 39259;
else if (value == 20813 )
return 38598;
else if (value == 20814 )
return 37733;
else if (value == 20816 )
return 36505;
else if (value == 20818 )
return 39258;
}
else if (value <= 20860 ) {
if (value == 20820 )
return 39260;
else if (value == 20826 )
return 37757;
else if (value == 20828 )
return 35477;
else if (value == 20834 )
return 39261;
else if (value == 20837 )
return 37884;
else if (value == 20840 )
return 37203;
else if (value == 20841 )
return 39263;
else if (value == 20842 )
return 39264;
else if (value == 20843 )
return 38058;
else if (value == 20844 )
return 36086;
else if (value == 20845 )
return 39002;
else if (value == 20846 )
return 39265;
else if (value == 20849 )
return 35748;
else if (value == 20853 )
return 38330;
else if (value == 20854 )
return 37300;
else if (value == 20855 )
return 35823;
else if (value == 20856 )
return 37716;
else if (value == 20860 )
return 35987;
}
else if (value <= 20896 ) {
if (value == 20864 )
return 39266;
else if (value == 20866 )
return 39267;
else if (value == 20869 )
return 37856;
else if (value == 20870 )
return 35198;
else if (value == 20873 )
return 39270;
else if (value == 20874 )
return 36347;
else if (value == 20876 )
return 39269;
else if (value == 20877 )
return 36292;
else if (value == 20879 )
return 39271;
else if (value == 20880 )
return 58348;
else if (value == 20881 )
return 39272;
else if (value == 20882 )
return 38496;
else if (value == 20883 )
return 39273;
else if (value == 20885 )
return 39274;
else if (value == 20886 )
return 39275;
else if (value == 20887 )
return 36839;
else if (value == 20889 )
return 36554;
else if (value == 20896 )
return 35493;
}
}
else if ( value >= 20898 && value <= 21563 ) {
if (value <= 20925 ) {
if (value == 20898 )
return 39278;
else if (value == 20900 )
return 39276;
else if (value == 20901 )
return 38587;
else if (value == 20902 )
return 39277;
else if (value == 20904 )
return 38265;
else if (value == 20905 )
return 39279;
else if (value == 20906 )
return 39280;
else if (value == 20907 )
return 39281;
else if (value == 20908 )
return 37758;
else if (value == 20912 )
return 39285;
else if (value == 20913 )
return 39283;
else if (value == 20914 )
return 39284;
else if (value == 20915 )
return 39282;
else if (value == 20916 )
return 36321;
else if (value == 20917 )
return 39286;
else if (value == 20918 )
return 38632;
else if (value == 20919 )
return 38882;
else if (value == 20925 )
return 39287;
}
else if (value <= 20973 ) {
if (value == 20932 )
return 37030;
else if (value == 20933 )
return 39288;
else if (value == 20934 )
return 36729;
else if (value == 20937 )
return 39289;
else if (value == 20939 )
return 37532;
else if (value == 20940 )
return 38845;
else if (value == 20941 )
return 37760;
else if (value == 20950 )
return 39363;
else if (value == 20955 )
return 39290;
else if (value == 20956 )
return 60067;
else if (value == 20957 )
return 35779;
else if (value == 20960 )
return 39291;
else if (value == 20961 )
return 38525;
else if (value == 20966 )
return 36744;
else if (value == 20967 )
return 37370;
else if (value == 20969 )
return 39293;
else if (value == 20970 )
return 37858;
else if (value == 20973 )
return 39294;
}
else if (value <= 21006 ) {
if (value == 20976 )
return 39296;
else if (value == 20977 )
return 35405;
else if (value == 20981 )
return 39297;
else if (value == 20982 )
return 35749;
else if (value == 20984 )
return 37834;
else if (value == 20985 )
return 35226;
else if (value == 20986 )
return 36719;
else if (value == 20989 )
return 38047;
else if (value == 20990 )
return 39298;
else if (value == 20992 )
return 37761;
else if (value == 20995 )
return 36974;
else if (value == 20996 )
return 39299;
else if (value == 20998 )
return 38314;
else if (value == 20999 )
return 37080;
else if (value == 21000 )
return 35488;
else if (value == 21002 )
return 35495;
else if (value == 21003 )
return 39300;
else if (value == 21006 )
return 39302;
}
else if (value <= 21051 ) {
if (value == 21009 )
return 35929;
else if (value == 21012 )
return 39301;
else if (value == 21015 )
return 38897;
else if (value == 21021 )
return 36745;
else if (value == 21028 )
return 38075;
else if (value == 21029 )
return 38346;
else if (value == 21031 )
return 39303;
else if (value == 21033 )
return 38808;
else if (value == 21034 )
return 39304;
else if (value == 21038 )
return 39305;
else if (value == 21040 )
return 37790;
else if (value == 21043 )
return 39306;
else if (value == 21046 )
return 37031;
else if (value == 21047 )
return 36348;
else if (value == 21048 )
return 35988;
else if (value == 21049 )
return 39307;
else if (value == 21050 )
return 36456;
else if (value == 21051 )
return 36239;
}
else if (value <= 21103 ) {
if (value == 21059 )
return 37604;
else if (value == 21060 )
return 39309;
else if (value == 21063 )
return 37285;
else if (value == 21066 )
return 36333;
else if (value == 21067 )
return 39310;
else if (value == 21068 )
return 39311;
else if (value == 21069 )
return 37199;
else if (value == 21071 )
return 39308;
else if (value == 21076 )
return 39313;
else if (value == 21078 )
return 38485;
else if (value == 21083 )
return 36228;
else if (value == 21086 )
return 39312;
else if (value == 21091 )
return 35989;
else if (value == 21092 )
return 36316;
else if (value == 21093 )
return 38029;
else if (value == 21097 )
return 39316;
else if (value == 21098 )
return 39314;
else if (value == 21103 )
return 38299;
}
else if (value <= 21151 ) {
if (value == 21104 )
return 36840;
else if (value == 21105 )
return 39323;
else if (value == 21106 )
return 35460;
else if (value == 21107 )
return 39317;
else if (value == 21108 )
return 39315;
else if (value == 21109 )
return 37230;
else if (value == 21117 )
return 39319;
else if (value == 21119 )
return 39318;
else if (value == 21123 )
return 35427;
else if (value == 21127 )
return 35968;
else if (value == 21128 )
return 39324;
else if (value == 21129 )
return 38827;
else if (value == 21133 )
return 39320;
else if (value == 21137 )
return 39325;
else if (value == 21138 )
return 39322;
else if (value == 21140 )
return 39321;
else if (value == 21147 )
return 38861;
else if (value == 21151 )
return 36087;
}
else if (value <= 21193 ) {
if (value == 21152 )
return 35265;
else if (value == 21155 )
return 38898;
else if (value == 21161 )
return 36757;
else if (value == 21162 )
return 37751;
else if (value == 21163 )
return 36229;
else if (value == 21164 )
return 39328;
else if (value == 21165 )
return 39329;
else if (value == 21169 )
return 38883;
else if (value == 21172 )
return 38986;
else if (value == 21173 )
return 39331;
else if (value == 21177 )
return 36088;
else if (value == 21180 )
return 39330;
else if (value == 21182 )
return 35406;
else if (value == 21185 )
return 39332;
else if (value == 21187 )
return 38517;
else if (value == 21189 )
return 37562;
else if (value == 21191 )
return 38725;
else if (value == 21193 )
return 38359;
}
else if (value <= 21237 ) {
if (value == 21197 )
return 39333;
else if (value == 21202 )
return 59603;
else if (value == 21205 )
return 37806;
else if (value == 21207 )
return 39334;
else if (value == 21208 )
return 35496;
else if (value == 21209 )
return 38577;
else if (value == 21213 )
return 36767;
else if (value == 21214 )
return 39335;
else if (value == 21215 )
return 38373;
else if (value == 21216 )
return 39339;
else if (value == 21218 )
return 37032;
else if (value == 21219 )
return 39336;
else if (value == 21220 )
return 35790;
else if (value == 21222 )
return 39337;
else if (value == 21223 )
return 35497;
else if (value == 21234 )
return 35917;
else if (value == 21235 )
return 39340;
else if (value == 21237 )
return 39341;
}
else if (value <= 21274 ) {
if (value == 21240 )
return 39342;
else if (value == 21241 )
return 39343;
else if (value == 21242 )
return 36569;
else if (value == 21246 )
return 36089;
else if (value == 21247 )
return 38620;
else if (value == 21249 )
return 38630;
else if (value == 21250 )
return 37877;
else if (value == 21253 )
return 38383;
else if (value == 21254 )
return 39344;
else if (value == 21256 )
return 39345;
else if (value == 21261 )
return 39347;
else if (value == 21263 )
return 39349;
else if (value == 21264 )
return 39348;
else if (value == 21269 )
return 39350;
else if (value == 21270 )
return 35259;
else if (value == 21271 )
return 38507;
else if (value == 21273 )
return 36346;
else if (value == 21274 )
return 39351;
}
else if (value <= 21318 ) {
if (value == 21277 )
return 37240;
else if (value == 21280 )
return 36768;
else if (value == 21281 )
return 35751;
else if (value == 21283 )
return 39352;
else if (value == 21290 )
return 38105;
else if (value == 21295 )
return 39353;
else if (value == 21297 )
return 39354;
else if (value == 21299 )
return 39355;
else if (value == 21304 )
return 39356;
else if (value == 21305 )
return 38211;
else if (value == 21306 )
return 35814;
else if (value == 21307 )
return 35043;
else if (value == 21311 )
return 37821;
else if (value == 21312 )
return 39357;
else if (value == 21313 )
return 36700;
else if (value == 21315 )
return 37095;
else if (value == 21317 )
return 39359;
else if (value == 21318 )
return 39358;
}
else if (value <= 21358 ) {
if (value == 21319 )
return 36769;
else if (value == 21320 )
return 36063;
else if (value == 21321 )
return 39361;
else if (value == 21322 )
return 38076;
else if (value == 21325 )
return 39362;
else if (value == 21329 )
return 38106;
else if (value == 21330 )
return 37298;
else if (value == 21331 )
return 37356;
else if (value == 21332 )
return 35750;
else if (value == 21335 )
return 37868;
else if (value == 21336 )
return 37456;
else if (value == 21338 )
return 38030;
else if (value == 21340 )
return 38509;
else if (value == 21342 )
return 39364;
else if (value == 21344 )
return 37096;
else if (value == 21350 )
return 35924;
else if (value == 21353 )
return 39365;
else if (value == 21358 )
return 39366;
}
else if (value <= 21413 ) {
if (value == 21359 )
return 35147;
else if (value == 21360 )
return 35059;
else if (value == 21361 )
return 35563;
else if (value == 21363 )
return 37286;
else if (value == 21364 )
return 35696;
else if (value == 21365 )
return 38801;
else if (value == 21367 )
return 39369;
else if (value == 21368 )
return 35253;
else if (value == 21371 )
return 39368;
else if (value == 21375 )
return 35752;
else if (value == 21378 )
return 39370;
else if (value == 21380 )
return 38639;
else if (value == 21398 )
return 39371;
else if (value == 21400 )
return 38864;
else if (value == 21402 )
return 36090;
else if (value == 21407 )
return 36020;
else if (value == 21408 )
return 39372;
else if (value == 21413 )
return 39374;
}
else if (value <= 21454 ) {
if (value == 21414 )
return 39373;
else if (value == 21416 )
return 36990;
else if (value == 21417 )
return 35160;
else if (value == 21421 )
return 35197;
else if (value == 21422 )
return 39375;
else if (value == 21424 )
return 39376;
else if (value == 21427 )
return 36021;
else if (value == 21430 )
return 39377;
else if (value == 21435 )
return 35726;
else if (value == 21442 )
return 36433;
else if (value == 21443 )
return 39378;
else if (value == 21448 )
return 38548;
else if (value == 21449 )
return 36275;
else if (value == 21450 )
return 35705;
else if (value == 21451 )
return 38726;
else if (value == 21452 )
return 37231;
else if (value == 21453 )
return 38077;
else if (value == 21454 )
return 36603;
}
else if (value <= 21486 ) {
if (value == 21460 )
return 36710;
else if (value == 21462 )
return 36582;
else if (value == 21463 )
return 36595;
else if (value == 21465 )
return 36758;
else if (value == 21467 )
return 38078;
else if (value == 21471 )
return 39381;
else if (value == 21473 )
return 35170;
else if (value == 21474 )
return 37232;
else if (value == 21475 )
return 36091;
else if (value == 21476 )
return 36035;
else if (value == 21477 )
return 35813;
else if (value == 21480 )
return 39385;
else if (value == 21481 )
return 37440;
else if (value == 21482 )
return 37372;
else if (value == 21483 )
return 35753;
else if (value == 21484 )
return 36770;
else if (value == 21485 )
return 39386;
else if (value == 21486 )
return 39384;
}
else if (value <= 21517 ) {
if (value == 21487 )
return 35266;
else if (value == 21488 )
return 37348;
else if (value == 21489 )
return 36534;
else if (value == 21490 )
return 36458;
else if (value == 21491 )
return 35141;
else if (value == 21494 )
return 35472;
else if (value == 21495 )
return 36230;
else if (value == 21496 )
return 36457;
else if (value == 21498 )
return 39387;
else if (value == 21505 )
return 39388;
else if (value == 21507 )
return 35688;
else if (value == 21508 )
return 35429;
else if (value == 21512 )
return 36231;
else if (value == 21513 )
return 35687;
else if (value == 21514 )
return 37597;
else if (value == 21515 )
return 35140;
else if (value == 21516 )
return 37807;
else if (value == 21517 )
return 38588;
}
else if (value <= 21563 ) {
if (value == 21518 )
return 36160;
else if (value == 21519 )
return 38809;
else if (value == 21520 )
return 37734;
else if (value == 21521 )
return 36092;
else if (value == 21531 )
return 35918;
else if (value == 21533 )
return 39397;
else if (value == 21535 )
return 35809;
else if (value == 21536 )
return 38505;
else if (value == 21542 )
return 38107;
else if (value == 21545 )
return 39396;
else if (value == 21547 )
return 35548;
else if (value == 21548 )
return 39391;
else if (value == 21549 )
return 39392;
else if (value == 21550 )
return 39394;
else if (value == 21558 )
return 39395;
else if (value == 21560 )
return 35706;
else if (value == 21561 )
return 36993;
else if (value == 21563 )
return 38315;
}
}
else if ( value >= 21564 && value <= 22618 ) {
if (value <= 21621 ) {
if (value == 21564 )
return 39393;
else if (value == 21565 )
return 39389;
else if (value == 21566 )
return 36065;
else if (value == 21568 )
return 39390;
else if (value == 21570 )
return 38979;
else if (value == 21574 )
return 38384;
else if (value == 21576 )
return 37606;
else if (value == 21577 )
return 36064;
else if (value == 21578 )
return 36240;
else if (value == 21582 )
return 39398;
else if (value == 21585 )
return 37851;
else if (value == 21599 )
return 39402;
else if (value == 21608 )
return 36604;
else if (value == 21610 )
return 36596;
else if (value == 21616 )
return 39405;
else if (value == 21617 )
return 39403;
else if (value == 21619 )
return 38561;
else if (value == 21621 )
return 39400;
}
else if (value <= 21672 ) {
if (value == 21622 )
return 39409;
else if (value == 21623 )
return 39404;
else if (value == 21627 )
return 39407;
else if (value == 21628 )
return 36036;
else if (value == 21629 )
return 38589;
else if (value == 21632 )
return 39408;
else if (value == 21636 )
return 39410;
else if (value == 21638 )
return 39412;
else if (value == 21643 )
return 36334;
else if (value == 21644 )
return 39009;
else if (value == 21646 )
return 39401;
else if (value == 21647 )
return 39399;
else if (value == 21648 )
return 39411;
else if (value == 21650 )
return 39406;
else if (value == 21666 )
return 39414;
else if (value == 21668 )
return 39490;
else if (value == 21669 )
return 39416;
else if (value == 21672 )
return 39420;
}
else if (value <= 21729 ) {
if (value == 21675 )
return 39488;
else if (value == 21676 )
return 39417;
else if (value == 21679 )
return 39517;
else if (value == 21682 )
return 36327;
else if (value == 21683 )
return 35408;
else if (value == 21688 )
return 39415;
else if (value == 21692 )
return 39492;
else if (value == 21693 )
return 35060;
else if (value == 21694 )
return 39491;
else if (value == 21696 )
return 34979;
else if (value == 21697 )
return 38249;
else if (value == 21698 )
return 39489;
else if (value == 21700 )
return 39418;
else if (value == 21703 )
return 39413;
else if (value == 21704 )
return 39419;
else if (value == 21705 )
return 36294;
else if (value == 21720 )
return 39493;
else if (value == 21729 )
return 35061;
}
else if (value <= 21806 ) {
if (value == 21730 )
return 39502;
else if (value == 21733 )
return 39494;
else if (value == 21734 )
return 39495;
else if (value == 21736 )
return 36771;
else if (value == 21737 )
return 38537;
else if (value == 21741 )
return 39500;
else if (value == 21742 )
return 39499;
else if (value == 21746 )
return 37710;
else if (value == 21754 )
return 39501;
else if (value == 21757 )
return 39498;
else if (value == 21764 )
return 35155;
else if (value == 21766 )
return 36276;
else if (value == 21767 )
return 36943;
else if (value == 21775 )
return 39496;
else if (value == 21776 )
return 37762;
else if (value == 21780 )
return 39497;
else if (value == 21782 )
return 34976;
else if (value == 21806 )
return 39507;
}
else if (value <= 21859 ) {
if (value == 21807 )
return 38722;
else if (value == 21809 )
return 36773;
else if (value == 21811 )
return 39513;
else if (value == 21816 )
return 39512;
else if (value == 21817 )
return 39503;
else if (value == 21822 )
return 37313;
else if (value == 21824 )
return 39504;
else if (value == 21828 )
return 37357;
else if (value == 21829 )
return 39509;
else if (value == 21830 )
return 36772;
else if (value == 21836 )
return 39506;
else if (value == 21839 )
return 38626;
else if (value == 21843 )
return 35931;
else if (value == 21846 )
return 39510;
else if (value == 21847 )
return 39511;
else if (value == 21852 )
return 39508;
else if (value == 21853 )
return 39514;
else if (value == 21859 )
return 39505;
}
else if (value <= 21927 ) {
if (value == 21883 )
return 39520;
else if (value == 21884 )
return 39525;
else if (value == 21886 )
return 39521;
else if (value == 21888 )
return 39516;
else if (value == 21891 )
return 39526;
else if (value == 21892 )
return 37200;
else if (value == 21895 )
return 39528;
else if (value == 21897 )
return 36161;
else if (value == 21898 )
return 39518;
else if (value == 21899 )
return 37533;
else if (value == 21912 )
return 39522;
else if (value == 21913 )
return 39515;
else if (value == 21914 )
return 35499;
else if (value == 21916 )
return 35564;
else if (value == 21917 )
return 35461;
else if (value == 21918 )
return 39523;
else if (value == 21919 )
return 39519;
else if (value == 21927 )
return 35990;
}
else if (value <= 22007 ) {
if (value == 21928 )
return 39529;
else if (value == 21929 )
return 39527;
else if (value == 21930 )
return 37234;
else if (value == 21931 )
return 35689;
else if (value == 21932 )
return 35754;
else if (value == 21934 )
return 39524;
else if (value == 21936 )
return 35826;
else if (value == 21942 )
return 35171;
else if (value == 21956 )
return 39533;
else if (value == 21957 )
return 39531;
else if (value == 21959 )
return 39589;
else if (value == 21972 )
return 39536;
else if (value == 21978 )
return 39530;
else if (value == 21980 )
return 39534;
else if (value == 21983 )
return 39532;
else if (value == 21987 )
return 36459;
else if (value == 21988 )
return 39535;
else if (value == 22007 )
return 39538;
}
else if (value <= 22082 ) {
if (value == 22009 )
return 39543;
else if (value == 22013 )
return 39541;
else if (value == 22014 )
return 39540;
else if (value == 22022 )
return 37457;
else if (value == 22025 )
return 35267;
else if (value == 22036 )
return 39537;
else if (value == 22038 )
return 39539;
else if (value == 22039 )
return 36774;
else if (value == 22040 )
return 35154;
else if (value == 22043 )
return 39542;
else if (value == 22057 )
return 35292;
else if (value == 22063 )
return 39554;
else if (value == 22065 )
return 36858;
else if (value == 22066 )
return 39549;
else if (value == 22068 )
return 39547;
else if (value == 22070 )
return 39548;
else if (value == 22072 )
return 39550;
else if (value == 22082 )
return 35164;
}
else if (value <= 22164 ) {
if (value == 22092 )
return 37208;
else if (value == 22094 )
return 39544;
else if (value == 22096 )
return 39545;
else if (value == 22107 )
return 35482;
else if (value == 22116 )
return 39553;
else if (value == 22120 )
return 35565;
else if (value == 22122 )
return 39556;
else if (value == 22123 )
return 39552;
else if (value == 22124 )
return 39555;
else if (value == 22132 )
return 38316;
else if (value == 22136 )
return 37843;
else if (value == 22138 )
return 38070;
else if (value == 22144 )
return 39558;
else if (value == 22150 )
return 39557;
else if (value == 22151 )
return 35428;
else if (value == 22154 )
return 39559;
else if (value == 22159 )
return 39562;
else if (value == 22164 )
return 39561;
}
else if (value <= 22234 ) {
if (value == 22176 )
return 39560;
else if (value == 22178 )
return 37976;
else if (value == 22181 )
return 39563;
else if (value == 22190 )
return 39564;
else if (value == 22196 )
return 39566;
else if (value == 22198 )
return 39565;
else if (value == 22204 )
return 39568;
else if (value == 22208 )
return 39571;
else if (value == 22209 )
return 39569;
else if (value == 22210 )
return 39567;
else if (value == 22211 )
return 39570;
else if (value == 22216 )
return 39572;
else if (value == 22222 )
return 39573;
else if (value == 22225 )
return 39574;
else if (value == 22227 )
return 39575;
else if (value == 22231 )
return 39576;
else if (value == 22232 )
return 39268;
else if (value == 22234 )
return 36602;
}
else if (value <= 22283 ) {
if (value == 22235 )
return 36460;
else if (value == 22238 )
return 35313;
else if (value == 22240 )
return 35062;
else if (value == 22243 )
return 37475;
else if (value == 22254 )
return 39577;
else if (value == 22256 )
return 36258;
else if (value == 22258 )
return 35021;
else if (value == 22259 )
return 36989;
else if (value == 22265 )
return 39578;
else if (value == 22266 )
return 36037;
else if (value == 22269 )
return 36241;
else if (value == 22271 )
return 39580;
else if (value == 22272 )
return 39579;
else if (value == 22275 )
return 38366;
else if (value == 22276 )
return 39581;
else if (value == 22280 )
return 39583;
else if (value == 22281 )
return 39582;
else if (value == 22283 )
return 39584;
}
else if (value <= 22338 ) {
if (value == 22285 )
return 39585;
else if (value == 22287 )
return 35991;
else if (value == 22290 )
return 35200;
else if (value == 22291 )
return 39586;
else if (value == 22294 )
return 39588;
else if (value == 22296 )
return 39587;
else if (value == 22300 )
return 39590;
else if (value == 22303 )
return 37753;
else if (value == 22310 )
return 39591;
else if (value == 22311 )
return 34995;
else if (value == 22312 )
return 36317;
else if (value == 22317 )
return 35932;
else if (value == 22320 )
return 37486;
else if (value == 22327 )
return 39592;
else if (value == 22328 )
return 39593;
else if (value == 22331 )
return 39595;
else if (value == 22336 )
return 39596;
else if (value == 22338 )
return 36322;
}
else if (value <= 22432 ) {
if (value == 22343 )
return 35791;
else if (value == 22346 )
return 38486;
else if (value == 22350 )
return 39594;
else if (value == 22351 )
return 39597;
else if (value == 22352 )
return 36287;
else if (value == 22353 )
return 36162;
else if (value == 22369 )
return 39601;
else if (value == 22372 )
return 36259;
else if (value == 22374 )
return 37458;
else if (value == 22377 )
return 39598;
else if (value == 22378 )
return 37592;
else if (value == 22399 )
return 39602;
else if (value == 22402 )
return 36994;
else if (value == 22408 )
return 39600;
else if (value == 22409 )
return 39603;
else if (value == 22411 )
return 35934;
else if (value == 22419 )
return 39604;
else if (value == 22432 )
return 39605;
}
else if (value <= 22496 ) {
if (value == 22434 )
return 36163;
else if (value == 22435 )
return 35423;
else if (value == 22436 )
return 39607;
else if (value == 22442 )
return 39608;
else if (value == 22448 )
return 39609;
else if (value == 22451 )
return 39606;
else if (value == 22464 )
return 39599;
else if (value == 22467 )
return 39610;
else if (value == 22470 )
return 39611;
else if (value == 22475 )
return 38532;
else if (value == 22478 )
return 36841;
else if (value == 22482 )
return 39613;
else if (value == 22483 )
return 39614;
else if (value == 22484 )
return 39612;
else if (value == 22486 )
return 39616;
else if (value == 22492 )
return 37975;
else if (value == 22495 )
return 35046;
else if (value == 22496 )
return 38261;
}
else if (value <= 22570 ) {
if (value == 22499 )
return 39617;
else if (value == 22516 )
return 36859;
else if (value == 22519 )
return 36535;
else if (value == 22521 )
return 38012;
else if (value == 22522 )
return 35566;
else if (value == 22524 )
return 36329;
else if (value == 22528 )
return 38520;
else if (value == 22530 )
return 37808;
else if (value == 22533 )
return 35992;
else if (value == 22534 )
return 37325;
else if (value == 22538 )
return 39615;
else if (value == 22539 )
return 39618;
else if (value == 22549 )
return 37314;
else if (value == 22553 )
return 39619;
else if (value == 22557 )
return 39620;
else if (value == 22561 )
return 39622;
else if (value == 22564 )
return 37607;
else if (value == 22570 )
return 35500;
}
else if (value <= 22618 ) {
if (value == 22575 )
return 60063;
else if (value == 22576 )
return 35201;
else if (value == 22577 )
return 38385;
else if (value == 22580 )
return 36842;
else if (value == 22581 )
return 37735;
else if (value == 22586 )
return 36324;
else if (value == 22589 )
return 39628;
else if (value == 22592 )
return 38331;
else if (value == 22593 )
return 38875;
else if (value == 22602 )
return 35314;
else if (value == 22603 )
return 39624;
else if (value == 22609 )
return 37209;
else if (value == 22610 )
return 39627;
else if (value == 22612 )
return 37763;
else if (value == 22615 )
return 37736;
else if (value == 22616 )
return 37764;
else if (value == 22617 )
return 38071;
else if (value == 22618 )
return 37579;
}
}
else if ( value >= 22622 && value <= 23544 ) {
if (value <= 22702 ) {
if (value == 22622 )
return 36295;
else if (value == 22626 )
return 39623;
else if (value == 22633 )
return 35222;
else if (value == 22635 )
return 37717;
else if (value == 22640 )
return 39625;
else if (value == 22642 )
return 39621;
else if (value == 22645 )
return 36975;
else if (value == 22649 )
return 39629;
else if (value == 22654 )
return 36717;
else if (value == 22659 )
return 35755;
else if (value == 22661 )
return 39630;
else if (value == 22675 )
return 38374;
else if (value == 22679 )
return 37277;
else if (value == 22684 )
return 37572;
else if (value == 22687 )
return 39632;
else if (value == 22696 )
return 38510;
else if (value == 22699 )
return 39633;
else if (value == 22702 )
return 39638;
}
else if (value <= 22748 ) {
if (value == 22707 )
return 38317;
else if (value == 22712 )
return 39637;
else if (value == 22713 )
return 39631;
else if (value == 22714 )
return 39634;
else if (value == 22715 )
return 39636;
else if (value == 22718 )
return 36260;
else if (value == 22721 )
return 38343;
else if (value == 22725 )
return 39639;
else if (value == 22727 )
return 37476;
else if (value == 22730 )
return 35315;
else if (value == 22732 )
return 36843;
else if (value == 22737 )
return 39641;
else if (value == 22739 )
return 39640;
else if (value == 22741 )
return 36232;
else if (value == 22743 )
return 39642;
else if (value == 22744 )
return 39644;
else if (value == 22745 )
return 39643;
else if (value == 22748 )
return 39646;
}
else if (value <= 22786 ) {
if (value == 22750 )
return 39635;
else if (value == 22751 )
return 39648;
else if (value == 22756 )
return 39647;
else if (value == 22757 )
return 39645;
else if (value == 22763 )
return 36461;
else if (value == 22764 )
return 36976;
else if (value == 22766 )
return 37235;
else if (value == 22767 )
return 39649;
else if (value == 22768 )
return 37050;
else if (value == 22769 )
return 35051;
else if (value == 22770 )
return 38020;
else if (value == 22775 )
return 37593;
else if (value == 22777 )
return 39651;
else if (value == 22778 )
return 39650;
else if (value == 22779 )
return 39652;
else if (value == 22780 )
return 39653;
else if (value == 22781 )
return 39654;
else if (value == 22786 )
return 39655;
}
else if (value <= 22828 ) {
if (value == 22793 )
return 38351;
else if (value == 22794 )
return 39656;
else if (value == 22799 )
return 35268;
else if (value == 22800 )
return 39657;
else if (value == 22805 )
return 38747;
else if (value == 22806 )
return 35407;
else if (value == 22808 )
return 39367;
else if (value == 22809 )
return 36711;
else if (value == 22810 )
return 37309;
else if (value == 22811 )
return 39658;
else if (value == 22812 )
return 38633;
else if (value == 22818 )
return 38578;
else if (value == 22821 )
return 39660;
else if (value == 22823 )
return 37349;
else if (value == 22825 )
return 37718;
else if (value == 22826 )
return 37310;
else if (value == 22827 )
return 38262;
else if (value == 22828 )
return 39661;
}
else if (value <= 22871 ) {
if (value == 22829 )
return 39662;
else if (value == 22830 )
return 35227;
else if (value == 22833 )
return 36536;
else if (value == 22834 )
return 39663;
else if (value == 22839 )
return 35022;
else if (value == 22840 )
return 39664;
else if (value == 22846 )
return 39665;
else if (value == 22852 )
return 35202;
else if (value == 22855 )
return 35567;
else if (value == 22856 )
return 37854;
else if (value == 22857 )
return 38386;
else if (value == 22862 )
return 39669;
else if (value == 22863 )
return 37236;
else if (value == 22864 )
return 39668;
else if (value == 22865 )
return 35935;
else if (value == 22868 )
return 38522;
else if (value == 22869 )
return 39667;
else if (value == 22871 )
return 37765;
}
else if (value <= 22915 ) {
if (value == 22872 )
return 39671;
else if (value == 22874 )
return 39670;
else if (value == 22880 )
return 39673;
else if (value == 22882 )
return 39672;
else if (value == 22885 )
return 35228;
else if (value == 22887 )
return 39674;
else if (value == 22888 )
return 36775;
else if (value == 22889 )
return 39676;
else if (value == 22890 )
return 37444;
else if (value == 22892 )
return 39675;
else if (value == 22894 )
return 38321;
else if (value == 22899 )
return 36759;
else if (value == 22900 )
return 37754;
else if (value == 22904 )
return 39744;
else if (value == 22909 )
return 36164;
else if (value == 22913 )
return 39745;
else if (value == 22914 )
return 37952;
else if (value == 22915 )
return 38108;
}
else if (value <= 22985 ) {
if (value == 22916 )
return 38607;
else if (value == 22922 )
return 37956;
else if (value == 22925 )
return 39754;
else if (value == 22931 )
return 35671;
else if (value == 22934 )
return 38756;
else if (value == 22937 )
return 38573;
else if (value == 22939 )
return 39850;
else if (value == 22941 )
return 39746;
else if (value == 22947 )
return 39749;
else if (value == 22949 )
return 37315;
else if (value == 22952 )
return 38487;
else if (value == 22956 )
return 37737;
else if (value == 22962 )
return 39750;
else if (value == 22969 )
return 38533;
else if (value == 22971 )
return 36296;
else if (value == 22974 )
return 36776;
else if (value == 22982 )
return 39751;
else if (value == 22985 )
return 36463;
}
else if (value <= 23043 ) {
if (value == 22987 )
return 36462;
else if (value == 22992 )
return 34999;
else if (value == 22993 )
return 36038;
else if (value == 22995 )
return 37033;
else if (value == 22996 )
return 35023;
else if (value == 23001 )
return 39755;
else if (value == 23002 )
return 39756;
else if (value == 23004 )
return 39753;
else if (value == 23013 )
return 35159;
else if (value == 23014 )
return 35501;
else if (value == 23016 )
return 39752;
else if (value == 23018 )
return 38595;
else if (value == 23019 )
return 38224;
else if (value == 23030 )
return 34982;
else if (value == 23035 )
return 35063;
else if (value == 23039 )
return 36464;
else if (value == 23041 )
return 35024;
else if (value == 23043 )
return 34977;
}
else if (value <= 23130 ) {
if (value == 23049 )
return 39761;
else if (value == 23057 )
return 39759;
else if (value == 23064 )
return 38586;
else if (value == 23066 )
return 39762;
else if (value == 23068 )
return 39760;
else if (value == 23071 )
return 39758;
else if (value == 23072 )
return 36944;
else if (value == 23077 )
return 39757;
else if (value == 23081 )
return 38360;
else if (value == 23087 )
return 36066;
else if (value == 23093 )
return 39766;
else if (value == 23094 )
return 39767;
else if (value == 23100 )
return 36777;
else if (value == 23104 )
return 39763;
else if (value == 23105 )
return 38987;
else if (value == 23110 )
return 37995;
else if (value == 23113 )
return 39765;
else if (value == 23130 )
return 36261;
}
else if (value <= 23254 ) {
if (value == 23138 )
return 39768;
else if (value == 23142 )
return 38263;
else if (value == 23146 )
return 39769;
else if (value == 23148 )
return 39764;
else if (value == 23167 )
return 38585;
else if (value == 23186 )
return 38013;
else if (value == 23194 )
return 39770;
else if (value == 23195 )
return 38225;
else if (value == 23228 )
return 39771;
else if (value == 23229 )
return 39775;
else if (value == 23230 )
return 39772;
else if (value == 23233 )
return 35269;
else if (value == 23234 )
return 39774;
else if (value == 23241 )
return 36537;
else if (value == 23243 )
return 39773;
else if (value == 23244 )
return 35993;
else if (value == 23248 )
return 39787;
else if (value == 23254 )
return 39780;
}
else if (value <= 23358 ) {
if (value == 23255 )
return 39777;
else if (value == 23265 )
return 37508;
else if (value == 23267 )
return 39776;
else if (value == 23270 )
return 39778;
else if (value == 23273 )
return 39779;
else if (value == 23290 )
return 39781;
else if (value == 23291 )
return 39782;
else if (value == 23305 )
return 35568;
else if (value == 23307 )
return 39784;
else if (value == 23308 )
return 39783;
else if (value == 23318 )
return 39785;
else if (value == 23330 )
return 36844;
else if (value == 23338 )
return 39788;
else if (value == 23340 )
return 37594;
else if (value == 23344 )
return 35172;
else if (value == 23346 )
return 39786;
else if (value == 23350 )
return 39789;
else if (value == 23358 )
return 39790;
}
else if (value <= 23398 ) {
if (value == 23360 )
return 39793;
else if (value == 23363 )
return 39791;
else if (value == 23365 )
return 39792;
else if (value == 23376 )
return 36465;
else if (value == 23377 )
return 39794;
else if (value == 23380 )
return 36165;
else if (value == 23381 )
return 39795;
else if (value == 23383 )
return 36506;
else if (value == 23384 )
return 37302;
else if (value == 23386 )
return 39796;
else if (value == 23387 )
return 39797;
else if (value == 23388 )
return 36473;
else if (value == 23389 )
return 36166;
else if (value == 23391 )
return 38608;
else if (value == 23395 )
return 35655;
else if (value == 23396 )
return 36039;
else if (value == 23397 )
return 39798;
else if (value == 23398 )
return 35447;
}
else if (value <= 23439 ) {
if (value == 23401 )
return 39799;
else if (value == 23403 )
return 37303;
else if (value == 23408 )
return 39800;
else if (value == 23409 )
return 39841;
else if (value == 23411 )
return 39801;
else if (value == 23413 )
return 39802;
else if (value == 23416 )
return 39803;
else if (value == 23418 )
return 39805;
else if (value == 23424 )
return 39806;
else if (value == 23427 )
return 39808;
else if (value == 23429 )
return 37358;
else if (value == 23431 )
return 35142;
else if (value == 23432 )
return 36583;
else if (value == 23433 )
return 35008;
else if (value == 23435 )
return 37238;
else if (value == 23436 )
return 35502;
else if (value == 23437 )
return 36531;
else if (value == 23439 )
return 36167;
}
else if (value <= 23476 ) {
if (value == 23445 )
return 37766;
else if (value == 23447 )
return 36672;
else if (value == 23448 )
return 35503;
else if (value == 23449 )
return 37512;
else if (value == 23450 )
return 37608;
else if (value == 23451 )
return 34998;
else if (value == 23452 )
return 35672;
else if (value == 23453 )
return 38387;
else if (value == 23455 )
return 36544;
else if (value == 23458 )
return 35697;
else if (value == 23459 )
return 37097;
else if (value == 23460 )
return 36538;
else if (value == 23461 )
return 38727;
else if (value == 23462 )
return 39809;
else if (value == 23470 )
return 35707;
else if (value == 23472 )
return 36297;
else if (value == 23475 )
return 35409;
else if (value == 23476 )
return 35203;
}
else if (value <= 23515 ) {
if (value == 23477 )
return 36778;
else if (value == 23478 )
return 35270;
else if (value == 23480 )
return 39810;
else if (value == 23481 )
return 38757;
else if (value == 23487 )
return 36712;
else if (value == 23490 )
return 36578;
else if (value == 23491 )
return 39811;
else if (value == 23492 )
return 35569;
else if (value == 23493 )
return 37840;
else if (value == 23494 )
return 38567;
else if (value == 23495 )
return 39812;
else if (value == 23497 )
return 39813;
else if (value == 23500 )
return 38264;
else if (value == 23504 )
return 39815;
else if (value == 23506 )
return 35494;
else if (value == 23507 )
return 35829;
else if (value == 23508 )
return 39814;
else if (value == 23515 )
return 35504;
}
else if (value <= 23544 ) {
if (value == 23517 )
return 36945;
else if (value == 23518 )
return 39819;
else if (value == 23519 )
return 36416;
else if (value == 23521 )
return 35271;
else if (value == 23522 )
return 39818;
else if (value == 23524 )
return 39816;
else if (value == 23525 )
return 39820;
else if (value == 23526 )
return 39817;
else if (value == 23527 )
return 37962;
else if (value == 23528 )
return 40651;
else if (value == 23529 )
return 36946;
else if (value == 23531 )
return 39821;
else if (value == 23534 )
return 38846;
else if (value == 23536 )
return 39822;
else if (value == 23539 )
return 39824;
else if (value == 23541 )
return 37534;
else if (value == 23542 )
return 39823;
else if (value == 23544 )
return 37025;
}
}
else if ( value >= 23546 && value <= 24376 ) {
if (value <= 23571 ) {
if (value == 23546 )
return 36507;
else if (value == 23550 )
return 37326;
else if (value == 23551 )
return 36597;
else if (value == 23553 )
return 38293;
else if (value == 23554 )
return 37098;
else if (value == 23556 )
return 36555;
else if (value == 23557 )
return 39825;
else if (value == 23558 )
return 36779;
else if (value == 23559 )
return 39826;
else if (value == 23560 )
return 39827;
else if (value == 23561 )
return 35025;
else if (value == 23562 )
return 37304;
else if (value == 23563 )
return 36977;
else if (value == 23565 )
return 39828;
else if (value == 23566 )
return 37809;
else if (value == 23567 )
return 36780;
else if (value == 23569 )
return 36781;
else if (value == 23571 )
return 39829;
}
else if (value <= 23617 ) {
if (value == 23574 )
return 37099;
else if (value == 23578 )
return 36782;
else if (value == 23584 )
return 39830;
else if (value == 23586 )
return 39831;
else if (value == 23588 )
return 38622;
else if (value == 23592 )
return 39832;
else if (value == 23597 )
return 35780;
else if (value == 23601 )
return 36673;
else if (value == 23608 )
return 39833;
else if (value == 23609 )
return 39834;
else if (value == 23610 )
return 36570;
else if (value == 23611 )
return 36939;
else if (value == 23612 )
return 37874;
else if (value == 23613 )
return 36979;
else if (value == 23614 )
return 38134;
else if (value == 23615 )
return 37953;
else if (value == 23616 )
return 35783;
else if (value == 23617 )
return 39835;
}
else if (value <= 23660 ) {
if (value == 23621 )
return 35727;
else if (value == 23622 )
return 39836;
else if (value == 23624 )
return 35836;
else if (value == 23626 )
return 37837;
else if (value == 23627 )
return 35246;
else if (value == 23629 )
return 36466;
else if (value == 23630 )
return 39837;
else if (value == 23631 )
return 39840;
else if (value == 23632 )
return 39839;
else if (value == 23633 )
return 35835;
else if (value == 23635 )
return 39838;
else if (value == 23637 )
return 37719;
else if (value == 23646 )
return 37294;
else if (value == 23648 )
return 37738;
else if (value == 23649 )
return 36550;
else if (value == 23652 )
return 37239;
else if (value == 23653 )
return 38810;
else if (value == 23660 )
return 39842;
}
else if (value <= 23735 ) {
if (value == 23662 )
return 39843;
else if (value == 23663 )
return 37844;
else if (value == 23665 )
return 36434;
else if (value == 23670 )
return 39845;
else if (value == 23673 )
return 39846;
else if (value == 23692 )
return 39847;
else if (value == 23696 )
return 35570;
else if (value == 23697 )
return 39848;
else if (value == 23700 )
return 39849;
else if (value == 23713 )
return 35242;
else if (value == 23720 )
return 37210;
else if (value == 23721 )
return 35554;
else if (value == 23723 )
return 39851;
else if (value == 23724 )
return 38566;
else if (value == 23729 )
return 37328;
else if (value == 23731 )
return 35448;
else if (value == 23734 )
return 39853;
else if (value == 23735 )
return 39855;
}
else if (value <= 23803 ) {
if (value == 23736 )
return 35549;
else if (value == 23739 )
return 39852;
else if (value == 23740 )
return 39854;
else if (value == 23742 )
return 39857;
else if (value == 23749 )
return 39856;
else if (value == 23751 )
return 39858;
else if (value == 23769 )
return 39859;
else if (value == 23776 )
return 37819;
else if (value == 23777 )
return 35756;
else if (value == 23784 )
return 35299;
else if (value == 23785 )
return 39860;
else if (value == 23786 )
return 39865;
else if (value == 23789 )
return 39863;
else if (value == 23791 )
return 38389;
else if (value == 23792 )
return 38388;
else if (value == 23798 )
return 37767;
else if (value == 23802 )
return 39862;
else if (value == 23803 )
return 36723;
}
else if (value <= 23884 ) {
if (value == 23805 )
return 39861;
else if (value == 23815 )
return 37010;
else if (value == 23819 )
return 39866;
else if (value == 23822 )
return 36328;
else if (value == 23825 )
return 39872;
else if (value == 23828 )
return 39873;
else if (value == 23829 )
return 39867;
else if (value == 23830 )
return 35410;
else if (value == 23831 )
return 39868;
else if (value == 23832 )
return 39877;
else if (value == 23833 )
return 39876;
else if (value == 23834 )
return 39875;
else if (value == 23835 )
return 39871;
else if (value == 23839 )
return 39870;
else if (value == 23842 )
return 39874;
else if (value == 23849 )
return 38390;
else if (value == 23883 )
return 39881;
else if (value == 23884 )
return 39878;
}
else if (value <= 23980 ) {
if (value == 23886 )
return 39880;
else if (value == 23888 )
return 38802;
else if (value == 23890 )
return 39879;
else if (value == 23900 )
return 39869;
else if (value == 23913 )
return 37011;
else if (value == 23916 )
return 39882;
else if (value == 23919 )
return 36277;
else if (value == 23923 )
return 39883;
else if (value == 23926 )
return 39884;
else if (value == 23938 )
return 39887;
else if (value == 23940 )
return 39886;
else if (value == 23943 )
return 39885;
else if (value == 23947 )
return 37768;
else if (value == 23948 )
return 39864;
else if (value == 23952 )
return 39893;
else if (value == 23965 )
return 39889;
else if (value == 23970 )
return 39888;
else if (value == 23980 )
return 39890;
}
else if (value <= 24038 ) {
if (value == 23982 )
return 39891;
else if (value == 23991 )
return 39894;
else if (value == 23994 )
return 38884;
else if (value == 23996 )
return 39895;
else if (value == 23997 )
return 39892;
else if (value == 24009 )
return 39896;
else if (value == 24012 )
return 35550;
else if (value == 24013 )
return 39897;
else if (value == 24018 )
return 39899;
else if (value == 24019 )
return 39898;
else if (value == 24022 )
return 39900;
else if (value == 24027 )
return 39901;
else if (value == 24029 )
return 37100;
else if (value == 24030 )
return 36674;
else if (value == 24033 )
return 36740;
else if (value == 24035 )
return 37251;
else if (value == 24037 )
return 36168;
else if (value == 24038 )
return 36278;
}
else if (value <= 24076 ) {
if (value == 24039 )
return 36169;
else if (value == 24040 )
return 35728;
else if (value == 24043 )
return 39902;
else if (value == 24046 )
return 36279;
else if (value == 24049 )
return 36040;
else if (value == 24050 )
return 39903;
else if (value == 24051 )
return 38564;
else if (value == 24052 )
return 37986;
else if (value == 24053 )
return 39904;
else if (value == 24055 )
return 36170;
else if (value == 24059 )
return 35498;
else if (value == 24061 )
return 37446;
else if (value == 24062 )
return 35792;
else if (value == 24066 )
return 36467;
else if (value == 24067 )
return 38266;
else if (value == 24070 )
return 38079;
else if (value == 24075 )
return 39905;
else if (value == 24076 )
return 35571;
}
else if (value <= 24131 ) {
if (value == 24081 )
return 39908;
else if (value == 24086 )
return 37535;
else if (value == 24089 )
return 39907;
else if (value == 24090 )
return 39906;
else if (value == 24091 )
return 39909;
else if (value == 24093 )
return 37609;
else if (value == 24101 )
return 36995;
else if (value == 24107 )
return 36468;
else if (value == 24109 )
return 37064;
else if (value == 24111 )
return 37329;
else if (value == 24112 )
return 35649;
else if (value == 24115 )
return 37536;
else if (value == 24118 )
return 39910;
else if (value == 24119 )
return 39911;
else if (value == 24120 )
return 36845;
else if (value == 24125 )
return 38488;
else if (value == 24128 )
return 39914;
else if (value == 24131 )
return 39913;
}
else if (value <= 24182 ) {
if (value == 24132 )
return 39912;
else if (value == 24133 )
return 38301;
else if (value == 24135 )
return 39921;
else if (value == 24140 )
return 38521;
else if (value == 24142 )
return 39915;
else if (value == 24148 )
return 39917;
else if (value == 24149 )
return 38539;
else if (value == 24151 )
return 39916;
else if (value == 24159 )
return 39918;
else if (value == 24161 )
return 38054;
else if (value == 24162 )
return 39919;
else if (value == 24163 )
return 38332;
else if (value == 24164 )
return 39920;
else if (value == 24178 )
return 35505;
else if (value == 24179 )
return 38333;
else if (value == 24180 )
return 37966;
else if (value == 24181 )
return 39922;
else if (value == 24182 )
return 39923;
}
else if (value <= 24218 ) {
if (value == 24184 )
return 36171;
else if (value == 24185 )
return 35506;
else if (value == 24186 )
return 39924;
else if (value == 24187 )
return 36022;
else if (value == 24188 )
return 38755;
else if (value == 24189 )
return 38728;
else if (value == 24190 )
return 35572;
else if (value == 24191 )
return 39926;
else if (value == 24193 )
return 37537;
else if (value == 24195 )
return 36172;
else if (value == 24196 )
return 36783;
else if (value == 24199 )
return 38109;
else if (value == 24202 )
return 36784;
else if (value == 24207 )
return 36760;
else if (value == 24213 )
return 37610;
else if (value == 24214 )
return 38391;
else if (value == 24215 )
return 37720;
else if (value == 24218 )
return 36173;
}
else if (value <= 24272 ) {
if (value == 24220 )
return 38267;
else if (value == 24224 )
return 39927;
else if (value == 24230 )
return 37752;
else if (value == 24231 )
return 36288;
else if (value == 24235 )
return 36041;
else if (value == 24237 )
return 37611;
else if (value == 24245 )
return 35009;
else if (value == 24246 )
return 36750;
else if (value == 24247 )
return 36174;
else if (value == 24248 )
return 38758;
else if (value == 24257 )
return 39928;
else if (value == 24258 )
return 39929;
else if (value == 24259 )
return 38000;
else if (value == 24264 )
return 39930;
else if (value == 24265 )
return 38901;
else if (value == 24266 )
return 38988;
else if (value == 24271 )
return 39932;
else if (value == 24272 )
return 39931;
}
else if (value <= 24310 ) {
if (value == 24275 )
return 35430;
else if (value == 24278 )
return 40000;
else if (value == 24282 )
return 40003;
else if (value == 24283 )
return 40004;
else if (value == 24285 )
return 40002;
else if (value == 24287 )
return 38239;
else if (value == 24288 )
return 36785;
else if (value == 24289 )
return 40006;
else if (value == 24290 )
return 40005;
else if (value == 24291 )
return 40001;
else if (value == 24296 )
return 40007;
else if (value == 24297 )
return 40008;
else if (value == 24300 )
return 40009;
else if (value == 24304 )
return 40012;
else if (value == 24305 )
return 40010;
else if (value == 24307 )
return 40011;
else if (value == 24308 )
return 40013;
else if (value == 24310 )
return 35204;
}
else if (value <= 24337 ) {
if (value == 24311 )
return 37612;
else if (value == 24312 )
return 40014;
else if (value == 24314 )
return 35994;
else if (value == 24315 )
return 35316;
else if (value == 24316 )
return 37973;
else if (value == 24318 )
return 40015;
else if (value == 24319 )
return 37881;
else if (value == 24321 )
return 38361;
else if (value == 24323 )
return 40016;
else if (value == 24324 )
return 38989;
else if (value == 24329 )
return 40017;
else if (value == 24330 )
return 38334;
else if (value == 24331 )
return 40020;
else if (value == 24332 )
return 39071;
else if (value == 24333 )
return 39087;
else if (value == 24335 )
return 36526;
else if (value == 24336 )
return 37875;
else if (value == 24337 )
return 40021;
}
else if (value <= 24376 ) {
if (value == 24339 )
return 35708;
else if (value == 24340 )
return 37538;
else if (value == 24341 )
return 35064;
else if (value == 24342 )
return 40022;
else if (value == 24343 )
return 38308;
else if (value == 24344 )
return 36175;
else if (value == 24347 )
return 37487;
else if (value == 24351 )
return 37613;
else if (value == 24357 )
return 38637;
else if (value == 24358 )
return 36023;
else if (value == 24359 )
return 36042;
else if (value == 24361 )
return 40023;
else if (value == 24365 )
return 40024;
else if (value == 24367 )
return 40030;
else if (value == 24369 )
return 36579;
else if (value == 24373 )
return 37539;
else if (value == 24375 )
return 35757;
else if (value == 24376 )
return 40025;
}
}
else if ( value >= 24380 && value <= 25108 ) {
if (value <= 24425 ) {
if (value == 24380 )
return 38218;
else if (value == 24382 )
return 37477;
else if (value == 24385 )
return 40026;
else if (value == 24392 )
return 40027;
else if (value == 24394 )
return 35758;
else if (value == 24396 )
return 40028;
else if (value == 24398 )
return 40029;
else if (value == 24401 )
return 40031;
else if (value == 24403 )
return 37782;
else if (value == 24406 )
return 40032;
else if (value == 24407 )
return 40033;
else if (value == 24409 )
return 40034;
else if (value == 24412 )
return 40019;
else if (value == 24413 )
return 40018;
else if (value == 24417 )
return 40035;
else if (value == 24418 )
return 35936;
else if (value == 24422 )
return 38214;
else if (value == 24425 )
return 36298;
}
else if (value <= 24455 ) {
if (value == 24426 )
return 38230;
else if (value == 24427 )
return 37540;
else if (value == 24428 )
return 38250;
else if (value == 24429 )
return 40036;
else if (value == 24432 )
return 36786;
else if (value == 24433 )
return 35173;
else if (value == 24435 )
return 40037;
else if (value == 24439 )
return 40038;
else if (value == 24441 )
return 38640;
else if (value == 24444 )
return 38110;
else if (value == 24447 )
return 40041;
else if (value == 24448 )
return 35229;
else if (value == 24449 )
return 37034;
else if (value == 24450 )
return 40040;
else if (value == 24451 )
return 40039;
else if (value == 24452 )
return 35937;
else if (value == 24453 )
return 37330;
else if (value == 24455 )
return 40045;
}
else if (value <= 24493 ) {
if (value == 24456 )
return 40043;
else if (value == 24458 )
return 40042;
else if (value == 24459 )
return 38821;
else if (value == 24460 )
return 36067;
else if (value == 24464 )
return 36761;
else if (value == 24465 )
return 40044;
else if (value == 24466 )
return 37739;
else if (value == 24467 )
return 36701;
else if (value == 24471 )
return 37822;
else if (value == 24472 )
return 40048;
else if (value == 24473 )
return 40047;
else if (value == 24478 )
return 40046;
else if (value == 24480 )
return 40049;
else if (value == 24481 )
return 36068;
else if (value == 24488 )
return 40050;
else if (value == 24489 )
return 38300;
else if (value == 24490 )
return 36730;
else if (value == 24493 )
return 40051;
}
else if (value <= 24548 ) {
if (value == 24494 )
return 38135;
else if (value == 24499 )
return 37823;
else if (value == 24500 )
return 37541;
else if (value == 24505 )
return 37711;
else if (value == 24508 )
return 40052;
else if (value == 24509 )
return 35658;
else if (value == 24515 )
return 36947;
else if (value == 24517 )
return 38219;
else if (value == 24524 )
return 35573;
else if (value == 24525 )
return 37957;
else if (value == 24534 )
return 40053;
else if (value == 24535 )
return 36469;
else if (value == 24536 )
return 38489;
else if (value == 24537 )
return 38490;
else if (value == 24540 )
return 35230;
else if (value == 24541 )
return 40058;
else if (value == 24544 )
return 37513;
else if (value == 24548 )
return 40055;
}
else if (value <= 24605 ) {
if (value == 24555 )
return 35317;
else if (value == 24560 )
return 40107;
else if (value == 24561 )
return 40057;
else if (value == 24565 )
return 37967;
else if (value == 24568 )
return 40056;
else if (value == 24571 )
return 40054;
else if (value == 24573 )
return 36250;
else if (value == 24575 )
return 40060;
else if (value == 24590 )
return 40067;
else if (value == 24591 )
return 40073;
else if (value == 24592 )
return 40065;
else if (value == 24594 )
return 37755;
else if (value == 24597 )
return 40070;
else if (value == 24598 )
return 38268;
else if (value == 24601 )
return 40064;
else if (value == 24603 )
return 40069;
else if (value == 24604 )
return 38885;
else if (value == 24605 )
return 36470;
}
else if (value <= 24651 ) {
if (value == 24608 )
return 37331;
else if (value == 24609 )
return 40061;
else if (value == 24613 )
return 35709;
else if (value == 24614 )
return 40072;
else if (value == 24615 )
return 37035;
else if (value == 24616 )
return 35205;
else if (value == 24617 )
return 40066;
else if (value == 24618 )
return 35318;
else if (value == 24619 )
return 40071;
else if (value == 24623 )
return 35759;
else if (value == 24625 )
return 40068;
else if (value == 24634 )
return 40074;
else if (value == 24641 )
return 40076;
else if (value == 24642 )
return 40086;
else if (value == 24643 )
return 40084;
else if (value == 24646 )
return 40081;
else if (value == 24650 )
return 40080;
else if (value == 24651 )
return 38902;
}
else if (value <= 24685 ) {
if (value == 24653 )
return 40082;
else if (value == 24656 )
return 35760;
else if (value == 24658 )
return 36176;
else if (value == 24661 )
return 36762;
else if (value == 24665 )
return 40089;
else if (value == 24666 )
return 40075;
else if (value == 24671 )
return 40079;
else if (value == 24672 )
return 40062;
else if (value == 24674 )
return 35320;
else if (value == 24675 )
return 40083;
else if (value == 24676 )
return 40085;
else if (value == 24677 )
return 37488;
else if (value == 24680 )
return 36262;
else if (value == 24681 )
return 35254;
else if (value == 24682 )
return 40077;
else if (value == 24683 )
return 40088;
else if (value == 24684 )
return 40087;
else if (value == 24685 )
return 35761;
}
else if (value <= 24735 ) {
if (value == 24687 )
return 37287;
else if (value == 24688 )
return 35462;
else if (value == 24693 )
return 35938;
else if (value == 24695 )
return 40078;
else if (value == 24705 )
return 40090;
else if (value == 24707 )
return 40093;
else if (value == 24708 )
return 40095;
else if (value == 24713 )
return 36539;
else if (value == 24715 )
return 40101;
else if (value == 24716 )
return 37614;
else if (value == 24717 )
return 40091;
else if (value == 24722 )
return 40099;
else if (value == 24724 )
return 35319;
else if (value == 24726 )
return 40097;
else if (value == 24727 )
return 40098;
else if (value == 24730 )
return 40094;
else if (value == 24731 )
return 40096;
else if (value == 24735 )
return 36069;
}
else if (value <= 24785 ) {
if (value == 24736 )
return 38729;
else if (value == 24739 )
return 35507;
else if (value == 24742 )
return 35192;
else if (value == 24743 )
return 40100;
else if (value == 24745 )
return 37977;
else if (value == 24746 )
return 34987;
else if (value == 24754 )
return 38111;
else if (value == 24755 )
return 40059;
else if (value == 24756 )
return 40106;
else if (value == 24757 )
return 40110;
else if (value == 24758 )
return 38627;
else if (value == 24760 )
return 40103;
else if (value == 24764 )
return 37769;
else if (value == 24765 )
return 40108;
else if (value == 24773 )
return 36846;
else if (value == 24774 )
return 40109;
else if (value == 24775 )
return 37845;
else if (value == 24785 )
return 39014;
}
else if (value <= 24826 ) {
if (value == 24787 )
return 40105;
else if (value == 24792 )
return 40111;
else if (value == 24794 )
return 36251;
else if (value == 24796 )
return 37065;
else if (value == 24799 )
return 35026;
else if (value == 24800 )
return 40104;
else if (value == 24801 )
return 40102;
else if (value == 24803 )
return 37241;
else if (value == 24807 )
return 40092;
else if (value == 24808 )
return 36435;
else if (value == 24816 )
return 37316;
else if (value == 24817 )
return 40123;
else if (value == 24819 )
return 37242;
else if (value == 24820 )
return 40118;
else if (value == 24822 )
return 40115;
else if (value == 24823 )
return 40116;
else if (value == 24825 )
return 36580;
else if (value == 24826 )
return 40119;
}
else if (value <= 24876 ) {
if (value == 24827 )
return 40122;
else if (value == 24832 )
return 40117;
else if (value == 24833 )
return 36676;
else if (value == 24835 )
return 40120;
else if (value == 24838 )
return 40114;
else if (value == 24840 )
return 38650;
else if (value == 24841 )
return 38649;
else if (value == 24845 )
return 40124;
else if (value == 24846 )
return 40125;
else if (value == 24847 )
return 35027;
else if (value == 24853 )
return 40113;
else if (value == 24858 )
return 35824;
else if (value == 24859 )
return 34980;
else if (value == 24863 )
return 35508;
else if (value == 24865 )
return 40121;
else if (value == 24871 )
return 40129;
else if (value == 24872 )
return 40128;
else if (value == 24876 )
return 40133;
}
else if (value <= 24921 ) {
if (value == 24884 )
return 40134;
else if (value == 24892 )
return 40132;
else if (value == 24893 )
return 40135;
else if (value == 24894 )
return 40127;
else if (value == 24895 )
return 40131;
else if (value == 24898 )
return 40136;
else if (value == 24900 )
return 40137;
else if (value == 24903 )
return 40126;
else if (value == 24904 )
return 36508;
else if (value == 24906 )
return 40130;
else if (value == 24907 )
return 37332;
else if (value == 24908 )
return 36177;
else if (value == 24909 )
return 40112;
else if (value == 24910 )
return 36948;
else if (value == 24915 )
return 40150;
else if (value == 24917 )
return 38375;
else if (value == 24920 )
return 40140;
else if (value == 24921 )
return 40141;
}
else if (value <= 24951 ) {
if (value == 24922 )
return 40142;
else if (value == 24925 )
return 40149;
else if (value == 24927 )
return 40148;
else if (value == 24930 )
return 38557;
else if (value == 24931 )
return 35509;
else if (value == 24933 )
return 40146;
else if (value == 24935 )
return 35940;
else if (value == 24936 )
return 35411;
else if (value == 24939 )
return 40143;
else if (value == 24942 )
return 38838;
else if (value == 24943 )
return 40145;
else if (value == 24944 )
return 35028;
else if (value == 24945 )
return 40147;
else if (value == 24947 )
return 40138;
else if (value == 24948 )
return 40144;
else if (value == 24949 )
return 40151;
else if (value == 24950 )
return 35939;
else if (value == 24951 )
return 40139;
}
else if (value <= 25010 ) {
if (value == 24958 )
return 38780;
else if (value == 24962 )
return 38730;
else if (value == 24967 )
return 40154;
else if (value == 24970 )
return 40158;
else if (value == 24974 )
return 37278;
else if (value == 24976 )
return 38903;
else if (value == 24977 )
return 40159;
else if (value == 24980 )
return 40156;
else if (value == 24982 )
return 40153;
else if (value == 24985 )
return 40152;
else if (value == 24986 )
return 40157;
else if (value == 24996 )
return 38318;
else if (value == 24999 )
return 37810;
else if (value == 25001 )
return 35941;
else if (value == 25003 )
return 40160;
else if (value == 25004 )
return 40155;
else if (value == 25006 )
return 40161;
else if (value == 25010 )
return 35995;
}
else if (value <= 25078 ) {
if (value == 25014 )
return 35247;
else if (value == 25018 )
return 40169;
else if (value == 25022 )
return 35510;
else if (value == 25027 )
return 40167;
else if (value == 25030 )
return 40168;
else if (value == 25031 )
return 36263;
else if (value == 25032 )
return 40166;
else if (value == 25033 )
return 40164;
else if (value == 25034 )
return 40163;
else if (value == 25035 )
return 40170;
else if (value == 25036 )
return 40162;
else if (value == 25037 )
return 40172;
else if (value == 25040 )
return 35321;
else if (value == 25059 )
return 40174;
else if (value == 25062 )
return 40173;
else if (value == 25074 )
return 37542;
else if (value == 25076 )
return 40177;
else if (value == 25078 )
return 40175;
}
else if (value <= 25108 ) {
if (value == 25079 )
return 40165;
else if (value == 25080 )
return 35996;
else if (value == 25082 )
return 40176;
else if (value == 25084 )
return 40180;
else if (value == 25085 )
return 40179;
else if (value == 25086 )
return 40181;
else if (value == 25087 )
return 40178;
else if (value == 25088 )
return 40182;
else if (value == 25096 )
return 40183;
else if (value == 25097 )
return 40184;
else if (value == 25098 )
return 38376;
else if (value == 25100 )
return 40186;
else if (value == 25101 )
return 40185;
else if (value == 25102 )
return 36702;
else if (value == 25104 )
return 37036;
else if (value == 25105 )
return 35300;
else if (value == 25106 )
return 35322;
else if (value == 25108 )
return 40187;
}
}
else if ( value >= 25110 && value <= 25975 ) {
if (value <= 25151 ) {
if (value == 25110 )
return 35005;
else if (value == 25114 )
return 37066;
else if (value == 25115 )
return 40188;
else if (value == 25117 )
return 59073;
else if (value == 25118 )
return 40256;
else if (value == 25119 )
return 35969;
else if (value == 25121 )
return 40257;
else if (value == 25126 )
return 37101;
else if (value == 25130 )
return 40258;
else if (value == 25134 )
return 40259;
else if (value == 25135 )
return 35673;
else if (value == 25136 )
return 40260;
else if (value == 25138 )
return 40261;
else if (value == 25139 )
return 40262;
else if (value == 25140 )
return 37333;
else if (value == 25144 )
return 36043;
else if (value == 25147 )
return 38623;
else if (value == 25151 )
return 38491;
}
else if (value <= 25201 ) {
if (value == 25152 )
return 36746;
else if (value == 25153 )
return 40263;
else if (value == 25159 )
return 37102;
else if (value == 25160 )
return 59323;
else if (value == 25161 )
return 38112;
else if (value == 25163 )
return 36584;
else if (value == 25165 )
return 36299;
else if (value == 25166 )
return 40264;
else if (value == 25171 )
return 37317;
else if (value == 25173 )
return 38309;
else if (value == 25176 )
return 37359;
else if (value == 25179 )
return 40267;
else if (value == 25182 )
return 40265;
else if (value == 25184 )
return 40268;
else if (value == 25187 )
return 40266;
else if (value == 25192 )
return 40269;
else if (value == 25198 )
return 38319;
else if (value == 25201 )
return 34997;
}
else if (value <= 25239 ) {
if (value == 25206 )
return 38269;
else if (value == 25209 )
return 38113;
else if (value == 25212 )
return 40270;
else if (value == 25214 )
return 40273;
else if (value == 25215 )
return 36787;
else if (value == 25216 )
return 35674;
else if (value == 25218 )
return 40271;
else if (value == 25219 )
return 40278;
else if (value == 25220 )
return 36788;
else if (value == 25225 )
return 40272;
else if (value == 25226 )
return 37987;
else if (value == 25233 )
return 38781;
else if (value == 25234 )
return 40274;
else if (value == 25235 )
return 40275;
else if (value == 25236 )
return 40279;
else if (value == 25237 )
return 37770;
else if (value == 25238 )
return 40276;
else if (value == 25239 )
return 36178;
}
else if (value <= 25289 ) {
if (value == 25240 )
return 37084;
else if (value == 25243 )
return 40293;
else if (value == 25244 )
return 38066;
else if (value == 25246 )
return 37360;
else if (value == 25259 )
return 38114;
else if (value == 25260 )
return 40363;
else if (value == 25265 )
return 38392;
else if (value == 25269 )
return 37615;
else if (value == 25273 )
return 38549;
else if (value == 25275 )
return 40282;
else if (value == 25276 )
return 35231;
else if (value == 25277 )
return 37514;
else if (value == 25282 )
return 40291;
else if (value == 25285 )
return 37459;
else if (value == 25286 )
return 40285;
else if (value == 25287 )
return 40292;
else if (value == 25288 )
return 40287;
else if (value == 25289 )
return 40294;
}
else if (value <= 25324 ) {
if (value == 25290 )
return 40290;
else if (value == 25292 )
return 40289;
else if (value == 25293 )
return 38031;
else if (value == 25295 )
return 40283;
else if (value == 25296 )
return 35323;
else if (value == 25297 )
return 40281;
else if (value == 25298 )
return 35729;
else if (value == 25299 )
return 37361;
else if (value == 25300 )
return 40277;
else if (value == 25303 )
return 40280;
else if (value == 25304 )
return 36179;
else if (value == 25305 )
return 37081;
else if (value == 25307 )
return 36789;
else if (value == 25308 )
return 40288;
else if (value == 25309 )
return 38001;
else if (value == 25312 )
return 35730;
else if (value == 25313 )
return 35431;
else if (value == 25324 )
return 35463;
}
else if (value <= 25369 ) {
if (value == 25325 )
return 36928;
else if (value == 25326 )
return 40296;
else if (value == 25327 )
return 40301;
else if (value == 25329 )
return 40297;
else if (value == 25331 )
return 35997;
else if (value == 25333 )
return 40302;
else if (value == 25334 )
return 36417;
else if (value == 25335 )
return 36233;
else if (value == 25342 )
return 36677;
else if (value == 25343 )
return 40284;
else if (value == 25345 )
return 36509;
else if (value == 25346 )
return 40299;
else if (value == 25351 )
return 36471;
else if (value == 25352 )
return 40300;
else if (value == 25353 )
return 35010;
else if (value == 25356 )
return 40295;
else if (value == 25361 )
return 37543;
else if (value == 25369 )
return 35731;
}
else if (value <= 25447 ) {
if (value == 25375 )
return 35762;
else if (value == 25383 )
return 40298;
else if (value == 25384 )
return 34981;
else if (value == 25387 )
return 36289;
else if (value == 25391 )
return 36949;
else if (value == 25402 )
return 37616;
else if (value == 25405 )
return 38098;
else if (value == 25406 )
return 40304;
else if (value == 25407 )
return 37245;
else if (value == 25417 )
return 37288;
else if (value == 25420 )
return 36426;
else if (value == 25421 )
return 40305;
else if (value == 25423 )
return 40307;
else if (value == 25424 )
return 40303;
else if (value == 25429 )
return 38367;
else if (value == 25431 )
return 37563;
else if (value == 25436 )
return 37243;
else if (value == 25447 )
return 38393;
}
else if (value <= 25494 ) {
if (value == 25448 )
return 36556;
else if (value == 25449 )
return 40320;
else if (value == 25451 )
return 40318;
else if (value == 25454 )
return 37016;
else if (value == 25458 )
return 35998;
else if (value == 25462 )
return 40312;
else if (value == 25463 )
return 36791;
else if (value == 25466 )
return 37862;
else if (value == 25467 )
return 37968;
else if (value == 25472 )
return 40310;
else if (value == 25475 )
return 37244;
else if (value == 25480 )
return 36598;
else if (value == 25481 )
return 40315;
else if (value == 25484 )
return 36790;
else if (value == 25486 )
return 40309;
else if (value == 25487 )
return 40314;
else if (value == 25490 )
return 38002;
else if (value == 25494 )
return 40308;
}
else if (value <= 25531 ) {
if (value == 25496 )
return 35904;
else if (value == 25499 )
return 35452;
else if (value == 25503 )
return 40316;
else if (value == 25504 )
return 38825;
else if (value == 25505 )
return 36300;
else if (value == 25506 )
return 37460;
else if (value == 25507 )
return 40313;
else if (value == 25509 )
return 37082;
else if (value == 25511 )
return 36180;
else if (value == 25512 )
return 36996;
else if (value == 25513 )
return 35206;
else if (value == 25514 )
return 37211;
else if (value == 25515 )
return 40311;
else if (value == 25516 )
return 35684;
else if (value == 25522 )
return 35942;
else if (value == 25524 )
return 37581;
else if (value == 25525 )
return 40317;
else if (value == 25531 )
return 37246;
}
else if (value <= 25590 ) {
if (value == 25534 )
return 40321;
else if (value == 25536 )
return 40323;
else if (value == 25539 )
return 37301;
else if (value == 25540 )
return 40329;
else if (value == 25542 )
return 40324;
else if (value == 25545 )
return 40326;
else if (value == 25551 )
return 38240;
else if (value == 25552 )
return 37617;
else if (value == 25554 )
return 40327;
else if (value == 25558 )
return 38731;
else if (value == 25562 )
return 38759;
else if (value == 25563 )
return 35511;
else if (value == 25569 )
return 34988;
else if (value == 25571 )
return 40325;
else if (value == 25577 )
return 40322;
else if (value == 25582 )
return 35574;
else if (value == 25588 )
return 35207;
else if (value == 25590 )
return 40328;
}
else if (value <= 25678 ) {
if (value == 25594 )
return 38760;
else if (value == 25606 )
return 40332;
else if (value == 25613 )
return 37305;
else if (value == 25615 )
return 40339;
else if (value == 25619 )
return 40333;
else if (value == 25622 )
return 40330;
else if (value == 25623 )
return 40337;
else if (value == 25628 )
return 40306;
else if (value == 25638 )
return 40334;
else if (value == 25640 )
return 40338;
else if (value == 25644 )
return 38080;
else if (value == 25645 )
return 37771;
else if (value == 25652 )
return 40331;
else if (value == 25654 )
return 40335;
else if (value == 25658 )
return 35943;
else if (value == 25662 )
return 36335;
else if (value == 25666 )
return 37083;
else if (value == 25678 )
return 40343;
}
else if (value <= 25771 ) {
if (value == 25688 )
return 37701;
else if (value == 25703 )
return 40340;
else if (value == 25705 )
return 38528;
else if (value == 25711 )
return 40341;
else if (value == 25718 )
return 40342;
else if (value == 25720 )
return 38604;
else if (value == 25722 )
return 37024;
else if (value == 25731 )
return 35970;
else if (value == 25736 )
return 40349;
else if (value == 25746 )
return 36436;
else if (value == 25747 )
return 40346;
else if (value == 25749 )
return 40345;
else if (value == 25754 )
return 37969;
else if (value == 25758 )
return 37811;
else if (value == 25764 )
return 37712;
else if (value == 25765 )
return 40347;
else if (value == 25769 )
return 40348;
else if (value == 25771 )
return 38287;
}
else if (value <= 25825 ) {
if (value == 25773 )
return 37988;
else if (value == 25774 )
return 36418;
else if (value == 25776 )
return 37103;
else if (value == 25778 )
return 38511;
else if (value == 25785 )
return 35432;
else if (value == 25787 )
return 40355;
else if (value == 25788 )
return 40350;
else if (value == 25793 )
return 38761;
else if (value == 25794 )
return 40357;
else if (value == 25797 )
return 40353;
else if (value == 25799 )
return 40354;
else if (value == 25805 )
return 37248;
else if (value == 25810 )
return 40352;
else if (value == 25812 )
return 40286;
else if (value == 25816 )
return 40356;
else if (value == 25818 )
return 40351;
else if (value == 25824 )
return 40361;
else if (value == 25825 )
return 40362;
}
else if (value <= 25885 ) {
if (value == 25826 )
return 37702;
else if (value == 25827 )
return 40364;
else if (value == 25830 )
return 36419;
else if (value == 25831 )
return 40359;
else if (value == 25836 )
return 35675;
else if (value == 25839 )
return 40365;
else if (value == 25841 )
return 40358;
else if (value == 25842 )
return 40369;
else if (value == 25844 )
return 40368;
else if (value == 25846 )
return 40367;
else if (value == 25850 )
return 40370;
else if (value == 25853 )
return 40372;
else if (value == 25854 )
return 36847;
else if (value == 25856 )
return 40371;
else if (value == 25861 )
return 40375;
else if (value == 25880 )
return 40373;
else if (value == 25884 )
return 40374;
else if (value == 25885 )
return 40336;
}
else if (value <= 25933 ) {
if (value == 25891 )
return 40377;
else if (value == 25892 )
return 40376;
else if (value == 25898 )
return 40344;
else if (value == 25899 )
return 40378;
else if (value == 25900 )
return 40366;
else if (value == 25903 )
return 36472;
else if (value == 25908 )
return 40379;
else if (value == 25909 )
return 40380;
else if (value == 25910 )
return 40382;
else if (value == 25911 )
return 40381;
else if (value == 25912 )
return 40383;
else if (value == 25913 )
return 35324;
else if (value == 25915 )
return 36181;
else if (value == 25918 )
return 38394;
else if (value == 25919 )
return 37037;
else if (value == 25925 )
return 36044;
else if (value == 25928 )
return 40385;
else if (value == 25933 )
return 40388;
}
else if (value <= 25975 ) {
if (value == 25935 )
return 38257;
else if (value == 25937 )
return 35710;
else if (value == 25941 )
return 40387;
else if (value == 25942 )
return 40386;
else if (value == 25943 )
return 38003;
else if (value == 25944 )
return 40389;
else if (value == 25945 )
return 35763;
else if (value == 25949 )
return 40391;
else if (value == 25950 )
return 40390;
else if (value == 25954 )
return 35512;
else if (value == 25955 )
return 36437;
else if (value == 25958 )
return 37846;
else if (value == 25964 )
return 35944;
else if (value == 25968 )
return 37012;
else if (value == 25970 )
return 40392;
else if (value == 25972 )
return 37038;
else if (value == 25973 )
return 37703;
else if (value == 25975 )
return 38270;
}
}
else if ( value >= 25976 && value <= 26713 ) {
if (value <= 26021 ) {
if (value == 25976 )
return 40393;
else if (value == 25986 )
return 40394;
else if (value == 25987 )
return 40395;
else if (value == 25991 )
return 38326;
else if (value == 25992 )
return 39804;
else if (value == 25993 )
return 37060;
else if (value == 25996 )
return 38251;
else if (value == 25998 )
return 36310;
else if (value == 26000 )
return 38115;
else if (value == 26001 )
return 38081;
else if (value == 26007 )
return 37740;
else if (value == 26009 )
return 38847;
else if (value == 26011 )
return 40397;
else if (value == 26012 )
return 36558;
else if (value == 26015 )
return 40398;
else if (value == 26017 )
return 34996;
else if (value == 26020 )
return 35794;
else if (value == 26021 )
return 37067;
}
else if (value <= 26063 ) {
if (value == 26023 )
return 38272;
else if (value == 26027 )
return 40399;
else if (value == 26028 )
return 36449;
else if (value == 26029 )
return 37478;
else if (value == 26031 )
return 36474;
else if (value == 26032 )
return 36950;
else if (value == 26039 )
return 40400;
else if (value == 26041 )
return 38395;
else if (value == 26044 )
return 35223;
else if (value == 26045 )
return 36475;
else if (value == 26049 )
return 40403;
else if (value == 26051 )
return 40401;
else if (value == 26052 )
return 40404;
else if (value == 26053 )
return 38839;
else if (value == 26054 )
return 40402;
else if (value == 26059 )
return 37113;
else if (value == 26060 )
return 40405;
else if (value == 26063 )
return 37296;
}
else if (value <= 26114 ) {
if (value == 26066 )
return 40406;
else if (value == 26071 )
return 35576;
else if (value == 26073 )
return 40408;
else if (value == 26075 )
return 40407;
else if (value == 26080 )
return 40409;
else if (value == 26081 )
return 40410;
else if (value == 26082 )
return 35577;
else if (value == 26085 )
return 37882;
else if (value == 26086 )
return 37461;
else if (value == 26087 )
return 35724;
else if (value == 26088 )
return 36476;
else if (value == 26089 )
return 37249;
else if (value == 26092 )
return 36731;
else if (value == 26093 )
return 34990;
else if (value == 26097 )
return 40411;
else if (value == 26106 )
return 35232;
else if (value == 26107 )
return 40415;
else if (value == 26114 )
return 36182;
}
else if (value <= 26164 ) {
if (value == 26115 )
return 40414;
else if (value == 26118 )
return 36265;
else if (value == 26119 )
return 36792;
else if (value == 26122 )
return 40413;
else if (value == 26124 )
return 36793;
else if (value == 26126 )
return 38590;
else if (value == 26127 )
return 36264;
else if (value == 26131 )
return 35029;
else if (value == 26132 )
return 37068;
else if (value == 26140 )
return 40420;
else if (value == 26143 )
return 37039;
else if (value == 26144 )
return 35174;
else if (value == 26149 )
return 36724;
else if (value == 26151 )
return 38534;
else if (value == 26152 )
return 36336;
else if (value == 26157 )
return 36794;
else if (value == 26159 )
return 37029;
else if (value == 26164 )
return 40419;
}
else if (value <= 26214 ) {
if (value == 26165 )
return 40417;
else if (value == 26166 )
return 40418;
else if (value == 26172 )
return 37515;
else if (value == 26175 )
return 40517;
else if (value == 26177 )
return 40424;
else if (value == 26178 )
return 36510;
else if (value == 26179 )
return 36183;
else if (value == 26180 )
return 40422;
else if (value == 26185 )
return 40423;
else if (value == 26187 )
return 36951;
else if (value == 26191 )
return 40421;
else if (value == 26194 )
return 36430;
else if (value == 26205 )
return 40426;
else if (value == 26206 )
return 40425;
else if (value == 26207 )
return 40430;
else if (value == 26210 )
return 40431;
else if (value == 26212 )
return 40427;
else if (value == 26214 )
return 35393;
}
else if (value <= 26262 ) {
if (value == 26215 )
return 40428;
else if (value == 26216 )
return 40429;
else if (value == 26217 )
return 38099;
else if (value == 26222 )
return 38273;
else if (value == 26223 )
return 35945;
else if (value == 26224 )
return 40432;
else if (value == 26228 )
return 37040;
else if (value == 26230 )
return 36795;
else if (value == 26234 )
return 37489;
else if (value == 26241 )
return 35781;
else if (value == 26243 )
return 40433;
else if (value == 26244 )
return 40437;
else if (value == 26247 )
return 35273;
else if (value == 26248 )
return 40434;
else if (value == 26249 )
return 40436;
else if (value == 26254 )
return 40435;
else if (value == 26257 )
return 36747;
else if (value == 26262 )
return 37479;
}
else if (value <= 26329 ) {
if (value == 26263 )
return 35011;
else if (value == 26264 )
return 40438;
else if (value == 26269 )
return 40439;
else if (value == 26274 )
return 37544;
else if (value == 26278 )
return 38895;
else if (value == 26283 )
return 36450;
else if (value == 26286 )
return 38377;
else if (value == 26292 )
return 38492;
else if (value == 26296 )
return 40513;
else if (value == 26297 )
return 40441;
else if (value == 26300 )
return 40444;
else if (value == 26302 )
return 40443;
else if (value == 26305 )
return 40440;
else if (value == 26308 )
return 40512;
else if (value == 26311 )
return 37852;
else if (value == 26313 )
return 40442;
else if (value == 26326 )
return 40514;
else if (value == 26329 )
return 36748;
}
else if (value <= 26367 ) {
if (value == 26330 )
return 40515;
else if (value == 26332 )
return 38762;
else if (value == 26333 )
return 38040;
else if (value == 26336 )
return 40516;
else if (value == 26342 )
return 40518;
else if (value == 26345 )
return 40519;
else if (value == 26352 )
return 40520;
else if (value == 26354 )
return 35784;
else if (value == 26355 )
return 35175;
else if (value == 26356 )
return 36184;
else if (value == 26357 )
return 40521;
else if (value == 26359 )
return 40522;
else if (value == 26360 )
return 36753;
else if (value == 26361 )
return 37250;
else if (value == 26364 )
return 39382;
else if (value == 26365 )
return 37213;
else if (value == 26366 )
return 37212;
else if (value == 26367 )
return 37334;
}
else if (value <= 26408 ) {
if (value == 26368 )
return 36293;
else if (value == 26371 )
return 39152;
else if (value == 26376 )
return 35982;
else if (value == 26377 )
return 38732;
else if (value == 26379 )
return 38396;
else if (value == 26381 )
return 38302;
else if (value == 26383 )
return 40523;
else if (value == 26388 )
return 36337;
else if (value == 26389 )
return 37565;
else if (value == 26390 )
return 40524;
else if (value == 26391 )
return 38990;
else if (value == 26395 )
return 38493;
else if (value == 26397 )
return 37545;
else if (value == 26398 )
return 40525;
else if (value == 26399 )
return 35578;
else if (value == 26406 )
return 40526;
else if (value == 26407 )
return 40527;
else if (value == 26408 )
return 38616;
}
else if (value <= 26447 ) {
if (value == 26410 )
return 38562;
else if (value == 26411 )
return 38550;
else if (value == 26412 )
return 38523;
else if (value == 26413 )
return 36420;
else if (value == 26414 )
return 40529;
else if (value == 26417 )
return 36585;
else if (value == 26420 )
return 38512;
else if (value == 26422 )
return 40531;
else if (value == 26423 )
return 40534;
else if (value == 26424 )
return 40533;
else if (value == 26426 )
return 35575;
else if (value == 26429 )
return 35712;
else if (value == 26431 )
return 40530;
else if (value == 26433 )
return 40532;
else if (value == 26438 )
return 40535;
else if (value == 26441 )
return 37017;
else if (value == 26446 )
return 38811;
else if (value == 26447 )
return 35015;
}
else if (value <= 26480 ) {
if (value == 26448 )
return 36318;
else if (value == 26449 )
return 37306;
else if (value == 26451 )
return 36571;
else if (value == 26454 )
return 36849;
else if (value == 26457 )
return 40538;
else if (value == 26460 )
return 37741;
else if (value == 26462 )
return 40536;
else if (value == 26463 )
return 37289;
else if (value == 26464 )
return 40537;
else if (value == 26465 )
return 36848;
else if (value == 26466 )
return 38619;
else if (value == 26467 )
return 40539;
else if (value == 26468 )
return 40540;
else if (value == 26469 )
return 38792;
else if (value == 26474 )
return 40545;
else if (value == 26477 )
return 36185;
else if (value == 26479 )
return 38004;
else if (value == 26480 )
return 40542;
}
else if (value <= 26524 ) {
if (value == 26481 )
return 37772;
else if (value == 26482 )
return 40412;
else if (value == 26483 )
return 40416;
else if (value == 26485 )
return 35694;
else if (value == 26487 )
return 37990;
else if (value == 26492 )
return 40544;
else if (value == 26494 )
return 36796;
else if (value == 26495 )
return 38082;
else if (value == 26501 )
return 40550;
else if (value == 26503 )
return 38136;
else if (value == 26505 )
return 40541;
else if (value == 26507 )
return 40547;
else if (value == 26508 )
return 40546;
else if (value == 26512 )
return 37069;
else if (value == 26517 )
return 38541;
else if (value == 26519 )
return 38865;
else if (value == 26522 )
return 38535;
else if (value == 26524 )
return 35274;
}
else if (value <= 26574 ) {
if (value == 26525 )
return 36477;
else if (value == 26528 )
return 39015;
else if (value == 26529 )
return 40549;
else if (value == 26530 )
return 37013;
else if (value == 26534 )
return 40548;
else if (value == 26537 )
return 40543;
else if (value == 26543 )
return 36045;
else if (value == 26547 )
return 40555;
else if (value == 26548 )
return 40553;
else if (value == 26550 )
return 35275;
else if (value == 26551 )
return 40551;
else if (value == 26552 )
return 40557;
else if (value == 26553 )
return 40563;
else if (value == 26561 )
return 37318;
else if (value == 26564 )
return 38335;
else if (value == 26566 )
return 40565;
else if (value == 26570 )
return 38209;
else if (value == 26574 )
return 40564;
}
else if (value <= 26611 ) {
if (value == 26575 )
return 38032;
else if (value == 26576 )
return 38494;
else if (value == 26577 )
return 35513;
else if (value == 26579 )
return 37109;
else if (value == 26580 )
return 36703;
else if (value == 26584 )
return 37585;
else if (value == 26586 )
return 38733;
else if (value == 26589 )
return 40560;
else if (value == 26590 )
return 40559;
else if (value == 26594 )
return 40561;
else if (value == 26596 )
return 40558;
else if (value == 26599 )
return 40566;
else if (value == 26601 )
return 40556;
else if (value == 26604 )
return 40554;
else if (value == 26606 )
return 40562;
else if (value == 26607 )
return 40552;
else if (value == 26609 )
return 37516;
else if (value == 26611 )
return 38646;
}
else if (value <= 26674 ) {
if (value == 26612 )
return 36548;
else if (value == 26613 )
return 36338;
else if (value == 26619 )
return 36280;
else if (value == 26622 )
return 38543;
else if (value == 26623 )
return 35424;
else if (value == 26626 )
return 37580;
else if (value == 26627 )
return 37832;
else if (value == 26628 )
return 35176;
else if (value == 26643 )
return 37104;
else if (value == 26646 )
return 37042;
else if (value == 26647 )
return 35913;
else if (value == 26654 )
return 40568;
else if (value == 26657 )
return 36186;
else if (value == 26658 )
return 35484;
else if (value == 26665 )
return 40570;
else if (value == 26666 )
return 35476;
else if (value == 26667 )
return 40577;
else if (value == 26674 )
return 40573;
}
else if (value <= 26713 ) {
if (value == 26676 )
return 37105;
else if (value == 26680 )
return 35434;
else if (value == 26681 )
return 36266;
else if (value == 26684 )
return 35433;
else if (value == 26685 )
return 36301;
else if (value == 26688 )
return 40571;
else if (value == 26689 )
return 35973;
else if (value == 26690 )
return 35946;
else if (value == 26691 )
return 37773;
else if (value == 26694 )
return 40569;
else if (value == 26696 )
return 35012;
else if (value == 26701 )
return 40572;
else if (value == 26702 )
return 40574;
else if (value == 26704 )
return 35787;
else if (value == 26705 )
return 35915;
else if (value == 26707 )
return 35514;
else if (value == 26708 )
return 35690;
else if (value == 26713 )
return 40578;
}
}
else if ( value >= 26716 && value <= 27579 ) {
if (value <= 26775 ) {
if (value == 26716 )
return 36343;
else if (value == 26717 )
return 38545;
else if (value == 26719 )
return 36438;
else if (value == 26723 )
return 40579;
else if (value == 26727 )
return 38223;
else if (value == 26740 )
return 40591;
else if (value == 26742 )
return 35249;
else if (value == 26743 )
return 40580;
else if (value == 26750 )
return 40597;
else if (value == 26751 )
return 40581;
else if (value == 26753 )
return 38848;
else if (value == 26755 )
return 40588;
else if (value == 26757 )
return 38014;
else if (value == 26765 )
return 40596;
else if (value == 26767 )
return 40583;
else if (value == 26771 )
return 34994;
else if (value == 26772 )
return 40585;
else if (value == 26775 )
return 36187;
}
else if (value <= 26812 ) {
if (value == 26779 )
return 40587;
else if (value == 26781 )
return 40586;
else if (value == 26783 )
return 40582;
else if (value == 26784 )
return 40593;
else if (value == 26786 )
return 36797;
else if (value == 26790 )
return 39659;
else if (value == 26791 )
return 36070;
else if (value == 26792 )
return 38812;
else if (value == 26797 )
return 40584;
else if (value == 26799 )
return 37618;
else if (value == 26800 )
return 35394;
else if (value == 26801 )
return 36267;
else if (value == 26803 )
return 40576;
else if (value == 26805 )
return 40592;
else if (value == 26806 )
return 35457;
else if (value == 26809 )
return 40590;
else if (value == 26810 )
return 40594;
else if (value == 26812 )
return 37774;
}
else if (value <= 26862 ) {
if (value == 26820 )
return 35580;
else if (value == 26822 )
return 40624;
else if (value == 26825 )
return 38599;
else if (value == 26826 )
return 40599;
else if (value == 26827 )
return 35579;
else if (value == 26829 )
return 40606;
else if (value == 26834 )
return 38495;
else if (value == 26836 )
return 40607;
else if (value == 26837 )
return 40609;
else if (value == 26839 )
return 40613;
else if (value == 26840 )
return 40601;
else if (value == 26842 )
return 37449;
else if (value == 26847 )
return 37775;
else if (value == 26848 )
return 40617;
else if (value == 26849 )
return 40604;
else if (value == 26851 )
return 40614;
else if (value == 26855 )
return 40608;
else if (value == 26862 )
return 36952;
}
else if (value <= 26907 ) {
if (value == 26863 )
return 40618;
else if (value == 26866 )
return 37041;
else if (value == 26873 )
return 40616;
else if (value == 26874 )
return 35515;
else if (value == 26880 )
return 39023;
else if (value == 26881 )
return 40598;
else if (value == 26884 )
return 40612;
else if (value == 26885 )
return 35030;
else if (value == 26888 )
return 40600;
else if (value == 26891 )
return 38584;
else if (value == 26892 )
return 40605;
else if (value == 26893 )
return 36929;
else if (value == 26894 )
return 37573;
else if (value == 26895 )
return 40595;
else if (value == 26898 )
return 40611;
else if (value == 26905 )
return 37018;
else if (value == 26906 )
return 40621;
else if (value == 26907 )
return 35473;
}
else if (value <= 26965 ) {
if (value == 26908 )
return 35999;
else if (value == 26913 )
return 40623;
else if (value == 26914 )
return 40602;
else if (value == 26915 )
return 40622;
else if (value == 26917 )
return 40615;
else if (value == 26918 )
return 40603;
else if (value == 26920 )
return 40619;
else if (value == 26922 )
return 40620;
else if (value == 26928 )
return 40637;
else if (value == 26932 )
return 37836;
else if (value == 26934 )
return 40610;
else if (value == 26937 )
return 40633;
else if (value == 26941 )
return 40635;
else if (value == 26943 )
return 37590;
else if (value == 26954 )
return 38763;
else if (value == 26963 )
return 38294;
else if (value == 26964 )
return 40630;
else if (value == 26965 )
return 37320;
}
else if (value <= 27000 ) {
if (value == 26969 )
return 40636;
else if (value == 26970 )
return 37214;
else if (value == 26972 )
return 40627;
else if (value == 26973 )
return 40640;
else if (value == 26974 )
return 40639;
else if (value == 26976 )
return 37869;
else if (value == 26977 )
return 40638;
else if (value == 26978 )
return 37864;
else if (value == 26986 )
return 40642;
else if (value == 26987 )
return 40629;
else if (value == 26989 )
return 35782;
else if (value == 26990 )
return 40632;
else if (value == 26991 )
return 36732;
else if (value == 26995 )
return 38016;
else if (value == 26996 )
return 40634;
else if (value == 26997 )
return 35785;
else if (value == 26999 )
return 40626;
else if (value == 27000 )
return 40628;
}
else if (value <= 27058 ) {
if (value == 27001 )
return 40625;
else if (value == 27004 )
return 38991;
else if (value == 27005 )
return 35449;
else if (value == 27006 )
return 40631;
else if (value == 27009 )
return 40641;
else if (value == 27010 )
return 35412;
else if (value == 27018 )
return 36325;
else if (value == 27022 )
return 35196;
else if (value == 27025 )
return 40658;
else if (value == 27028 )
return 38992;
else if (value == 27029 )
return 40661;
else if (value == 27035 )
return 36953;
else if (value == 27036 )
return 40660;
else if (value == 27040 )
return 40659;
else if (value == 27047 )
return 40656;
else if (value == 27054 )
return 40644;
else if (value == 27057 )
return 40673;
else if (value == 27058 )
return 40643;
}
else if (value <= 27102 ) {
if (value == 27060 )
return 40662;
else if (value == 27067 )
return 40654;
else if (value == 27070 )
return 40649;
else if (value == 27071 )
return 40646;
else if (value == 27073 )
return 40647;
else if (value == 27075 )
return 40655;
else if (value == 27079 )
return 60064;
else if (value == 27082 )
return 40652;
else if (value == 27083 )
return 36188;
else if (value == 27084 )
return 37574;
else if (value == 27085 )
return 37252;
else if (value == 27086 )
return 40650;
else if (value == 27088 )
return 40645;
else if (value == 27091 )
return 40648;
else if (value == 27096 )
return 38764;
else if (value == 27097 )
return 38538;
else if (value == 27101 )
return 40653;
else if (value == 27102 )
return 40663;
}
else if (value <= 27159 ) {
if (value == 27111 )
return 40671;
else if (value == 27112 )
return 40664;
else if (value == 27115 )
return 40677;
else if (value == 27117 )
return 40675;
else if (value == 27122 )
return 40670;
else if (value == 27129 )
return 40669;
else if (value == 27131 )
return 37582;
else if (value == 27133 )
return 37253;
else if (value == 27135 )
return 40667;
else if (value == 27138 )
return 40665;
else if (value == 27141 )
return 40672;
else if (value == 27146 )
return 40678;
else if (value == 27147 )
return 38131;
else if (value == 27148 )
return 40684;
else if (value == 27154 )
return 40679;
else if (value == 27155 )
return 40682;
else if (value == 27156 )
return 40676;
else if (value == 27159 )
return 37524;
}
else if (value <= 27204 ) {
if (value == 27161 )
return 38231;
else if (value == 27163 )
return 40666;
else if (value == 27166 )
return 40674;
else if (value == 27167 )
return 36798;
else if (value == 27169 )
return 38605;
else if (value == 27170 )
return 40694;
else if (value == 27171 )
return 40681;
else if (value == 27177 )
return 36000;
else if (value == 27178 )
return 35233;
else if (value == 27179 )
return 35454;
else if (value == 27182 )
return 40657;
else if (value == 27189 )
return 36799;
else if (value == 27190 )
return 40686;
else if (value == 27192 )
return 40693;
else if (value == 27193 )
return 36599;
else if (value == 27194 )
return 35474;
else if (value == 27197 )
return 37453;
else if (value == 27204 )
return 40683;
}
else if (value <= 27287 ) {
if (value == 27207 )
return 40688;
else if (value == 27208 )
return 40692;
else if (value == 27211 )
return 35764;
else if (value == 27224 )
return 35691;
else if (value == 27225 )
return 40690;
else if (value == 27231 )
return 35648;
else if (value == 27233 )
return 37833;
else if (value == 27234 )
return 40689;
else if (value == 27238 )
return 40691;
else if (value == 27250 )
return 40685;
else if (value == 27256 )
return 40687;
else if (value == 27263 )
return 35456;
else if (value == 27264 )
return 37480;
else if (value == 27268 )
return 40698;
else if (value == 27277 )
return 40696;
else if (value == 27278 )
return 36071;
else if (value == 27280 )
return 40695;
else if (value == 27287 )
return 40768;
}
else if (value <= 27358 ) {
if (value == 27292 )
return 40567;
else if (value == 27296 )
return 40697;
else if (value == 27298 )
return 40699;
else if (value == 27299 )
return 40700;
else if (value == 27306 )
return 40779;
else if (value == 27308 )
return 40775;
else if (value == 27310 )
return 40589;
else if (value == 27315 )
return 40774;
else if (value == 27320 )
return 40773;
else if (value == 27323 )
return 40770;
else if (value == 27329 )
return 40680;
else if (value == 27330 )
return 40772;
else if (value == 27331 )
return 40771;
else if (value == 27345 )
return 40777;
else if (value == 27347 )
return 38981;
else if (value == 27354 )
return 40780;
else if (value == 27355 )
return 35833;
else if (value == 27358 )
return 40776;
}
else if (value <= 27447 ) {
if (value == 27359 )
return 40778;
else if (value == 27368 )
return 38053;
else if (value == 27370 )
return 40781;
else if (value == 27386 )
return 40785;
else if (value == 27387 )
return 40782;
else if (value == 27396 )
return 38803;
else if (value == 27397 )
return 40783;
else if (value == 27402 )
return 40668;
else if (value == 27410 )
return 40786;
else if (value == 27414 )
return 40787;
else if (value == 27421 )
return 35156;
else if (value == 27423 )
return 40789;
else if (value == 27424 )
return 35975;
else if (value == 27425 )
return 36511;
else if (value == 27427 )
return 35795;
else if (value == 27431 )
return 35234;
else if (value == 27442 )
return 38782;
else if (value == 27447 )
return 40791;
}
else if (value <= 27490 ) {
if (value == 27448 )
return 40790;
else if (value == 27449 )
return 40793;
else if (value == 27450 )
return 35676;
else if (value == 27453 )
return 35796;
else if (value == 27454 )
return 35516;
else if (value == 27459 )
return 40796;
else if (value == 27463 )
return 40795;
else if (value == 27465 )
return 40797;
else if (value == 27468 )
return 35276;
else if (value == 27470 )
return 37462;
else if (value == 27472 )
return 40798;
else if (value == 27475 )
return 35517;
else if (value == 27476 )
return 40800;
else if (value == 27481 )
return 40799;
else if (value == 27483 )
return 40801;
else if (value == 27487 )
return 40802;
else if (value == 27489 )
return 40803;
else if (value == 27490 )
return 36478;
}
else if (value <= 27530 ) {
if (value == 27491 )
return 37043;
else if (value == 27492 )
return 36255;
else if (value == 27494 )
return 38288;
else if (value == 27497 )
return 38368;
else if (value == 27498 )
return 39011;
else if (value == 27503 )
return 36501;
else if (value == 27507 )
return 36302;
else if (value == 27508 )
return 38896;
else if (value == 27512 )
return 40804;
else if (value == 27513 )
return 40805;
else if (value == 27515 )
return 36480;
else if (value == 27519 )
return 40806;
else if (value == 27520 )
return 40807;
else if (value == 27523 )
return 40809;
else if (value == 27524 )
return 40808;
else if (value == 27526 )
return 38519;
else if (value == 27529 )
return 36733;
else if (value == 27530 )
return 36586;
}
else if (value <= 27579 ) {
if (value == 27531 )
return 36451;
else if (value == 27533 )
return 40810;
else if (value == 27541 )
return 40812;
else if (value == 27542 )
return 36930;
else if (value == 27544 )
return 40811;
else if (value == 27550 )
return 40813;
else if (value == 27556 )
return 40814;
else if (value == 27562 )
return 40815;
else if (value == 27563 )
return 40816;
else if (value == 27567 )
return 40817;
else if (value == 27569 )
return 40819;
else if (value == 27570 )
return 40818;
else if (value == 27571 )
return 40820;
else if (value == 27572 )
return 35235;
else if (value == 27573 )
return 37481;
else if (value == 27575 )
return 40821;
else if (value == 27578 )
return 36421;
else if (value == 27579 )
return 35435;
}
}
else if ( value >= 27580 && value <= 28511 ) {
if (value <= 27635 ) {
if (value == 27580 )
return 40822;
else if (value == 27583 )
return 37729;
else if (value == 27584 )
return 39626;
else if (value == 27589 )
return 35650;
else if (value == 27590 )
return 40823;
else if (value == 27595 )
return 40824;
else if (value == 27597 )
return 38378;
else if (value == 27598 )
return 38536;
else if (value == 27602 )
return 37829;
else if (value == 27603 )
return 40825;
else if (value == 27604 )
return 38116;
else if (value == 27608 )
return 38137;
else if (value == 27611 )
return 38609;
else if (value == 27615 )
return 40826;
else if (value == 27627 )
return 40828;
else if (value == 27628 )
return 40827;
else if (value == 27631 )
return 40830;
else if (value == 27635 )
return 40829;
}
else if (value <= 27728 ) {
if (value == 27656 )
return 40833;
else if (value == 27663 )
return 36481;
else if (value == 27665 )
return 38575;
else if (value == 27667 )
return 40834;
else if (value == 27668 )
return 40835;
else if (value == 27671 )
return 35651;
else if (value == 27675 )
return 40836;
else if (value == 27683 )
return 40838;
else if (value == 27684 )
return 40837;
else if (value == 27700 )
return 36997;
else if (value == 27703 )
return 38232;
else if (value == 27704 )
return 35177;
else if (value == 27710 )
return 38083;
else if (value == 27712 )
return 37619;
else if (value == 27713 )
return 36704;
else if (value == 27714 )
return 35713;
else if (value == 27726 )
return 38084;
else if (value == 27728 )
return 36524;
}
else if (value <= 27778 ) {
if (value == 27733 )
return 40840;
else if (value == 27735 )
return 35518;
else if (value == 27738 )
return 35224;
else if (value == 27741 )
return 37872;
else if (value == 27742 )
return 40839;
else if (value == 27743 )
return 36189;
else if (value == 27744 )
return 37490;
else if (value == 27746 )
return 40841;
else if (value == 27752 )
return 40849;
else if (value == 27754 )
return 40842;
else if (value == 27760 )
return 37311;
else if (value == 27762 )
return 35714;
else if (value == 27763 )
return 40850;
else if (value == 27770 )
return 35976;
else if (value == 27773 )
return 35652;
else if (value == 27774 )
return 40848;
else if (value == 27777 )
return 40846;
else if (value == 27778 )
return 40843;
}
else if (value <= 27832 ) {
if (value == 27779 )
return 38784;
else if (value == 27784 )
return 37566;
else if (value == 27788 )
return 37847;
else if (value == 27789 )
return 40844;
else if (value == 27792 )
return 40852;
else if (value == 27794 )
return 40851;
else if (value == 27795 )
return 35906;
else if (value == 27798 )
return 35243;
else if (value == 27801 )
return 36281;
else if (value == 27802 )
return 40845;
else if (value == 27803 )
return 40847;
else if (value == 27809 )
return 38518;
else if (value == 27810 )
return 37362;
else if (value == 27819 )
return 38551;
else if (value == 27822 )
return 40860;
else if (value == 27825 )
return 40861;
else if (value == 27827 )
return 35277;
else if (value == 27832 )
return 38310;
}
else if (value <= 27867 ) {
if (value == 27833 )
return 38651;
else if (value == 27834 )
return 40863;
else if (value == 27835 )
return 36513;
else if (value == 27836 )
return 36800;
else if (value == 27837 )
return 40856;
else if (value == 27838 )
return 40862;
else if (value == 27839 )
return 35208;
else if (value == 27841 )
return 35765;
else if (value == 27844 )
return 40853;
else if (value == 27845 )
return 40858;
else if (value == 27849 )
return 37106;
else if (value == 27850 )
return 38033;
else if (value == 27852 )
return 38117;
else if (value == 27859 )
return 40855;
else if (value == 27861 )
return 38464;
else if (value == 27863 )
return 40857;
else if (value == 27865 )
return 40866;
else if (value == 27867 )
return 40864;
}
else if (value <= 27934 ) {
if (value == 27869 )
return 40859;
else if (value == 27873 )
return 38465;
else if (value == 27874 )
return 37991;
else if (value == 27875 )
return 35715;
else if (value == 27877 )
return 37700;
else if (value == 27880 )
return 37517;
else if (value == 27882 )
return 40867;
else if (value == 27887 )
return 40865;
else if (value == 27888 )
return 37335;
else if (value == 27889 )
return 40854;
else if (value == 27891 )
return 35178;
else if (value == 27915 )
return 38765;
else if (value == 27916 )
return 40878;
else if (value == 27922 )
return 40877;
else if (value == 27927 )
return 37108;
else if (value == 27929 )
return 40874;
else if (value == 27931 )
return 38796;
else if (value == 27934 )
return 37812;
}
else if (value <= 27994 ) {
if (value == 27935 )
return 40868;
else if (value == 27941 )
return 37571;
else if (value == 27945 )
return 35179;
else if (value == 27946 )
return 36190;
else if (value == 27947 )
return 40871;
else if (value == 27954 )
return 36678;
else if (value == 27955 )
return 40876;
else if (value == 27957 )
return 40875;
else if (value == 27958 )
return 40870;
else if (value == 27960 )
return 40873;
else if (value == 27963 )
return 35464;
else if (value == 27965 )
return 40872;
else if (value == 27966 )
return 37992;
else if (value == 27969 )
return 38828;
else if (value == 27972 )
return 36850;
else if (value == 27973 )
return 37107;
else if (value == 27993 )
return 40884;
else if (value == 27994 )
return 40882;
}
else if (value <= 28053 ) {
if (value == 27996 )
return 38252;
else if (value == 28003 )
return 40879;
else if (value == 28004 )
return 40881;
else if (value == 28006 )
return 35161;
else if (value == 28009 )
return 36191;
else if (value == 28010 )
return 38993;
else if (value == 28012 )
return 35420;
else if (value == 28014 )
return 38274;
else if (value == 28020 )
return 38785;
else if (value == 28023 )
return 35395;
else if (value == 28024 )
return 36954;
else if (value == 28025 )
return 40883;
else if (value == 28037 )
return 40888;
else if (value == 28040 )
return 36801;
else if (value == 28044 )
return 38735;
else if (value == 28046 )
return 40885;
else if (value == 28051 )
return 40880;
else if (value == 28053 )
return 40886;
}
else if (value <= 28120 ) {
if (value == 28057 )
return 38876;
else if (value == 28059 )
return 37779;
else if (value == 28060 )
return 37824;
else if (value == 28079 )
return 35413;
else if (value == 28082 )
return 35188;
else if (value == 28085 )
return 40892;
else if (value == 28088 )
return 40895;
else if (value == 28092 )
return 38849;
else if (value == 28096 )
return 38788;
else if (value == 28101 )
return 40902;
else if (value == 28102 )
return 40896;
else if (value == 28103 )
return 40893;
else if (value == 28107 )
return 38866;
else if (value == 28108 )
return 40899;
else if (value == 28113 )
return 36713;
else if (value == 28114 )
return 40901;
else if (value == 28117 )
return 40906;
else if (value == 28120 )
return 37777;
}
else if (value <= 28165 ) {
if (value == 28121 )
return 40904;
else if (value == 28126 )
return 40898;
else if (value == 28129 )
return 37463;
else if (value == 28132 )
return 40905;
else if (value == 28134 )
return 40894;
else if (value == 28136 )
return 40900;
else if (value == 28138 )
return 40907;
else if (value == 28139 )
return 35066;
else if (value == 28140 )
return 40897;
else if (value == 28142 )
return 40908;
else if (value == 28145 )
return 36955;
else if (value == 28147 )
return 36734;
else if (value == 28149 )
return 38307;
else if (value == 28151 )
return 36268;
else if (value == 28153 )
return 40889;
else if (value == 28154 )
return 40903;
else if (value == 28155 )
return 37721;
else if (value == 28165 )
return 37044;
}
else if (value <= 28198 ) {
if (value == 28167 )
return 35465;
else if (value == 28168 )
return 36303;
else if (value == 28169 )
return 36802;
else if (value == 28170 )
return 40891;
else if (value == 28171 )
return 36705;
else if (value == 28179 )
return 35947;
else if (value == 28181 )
return 40890;
else if (value == 28185 )
return 40912;
else if (value == 28186 )
return 36749;
else if (value == 28187 )
return 36024;
else if (value == 28189 )
return 40927;
else if (value == 28191 )
return 40921;
else if (value == 28192 )
return 35732;
else if (value == 28193 )
return 37742;
else if (value == 28195 )
return 40916;
else if (value == 28196 )
return 40925;
else if (value == 28197 )
return 34989;
else if (value == 28198 )
return 35153;
}
else if (value <= 28263 ) {
if (value == 28201 )
return 35255;
else if (value == 28203 )
return 40918;
else if (value == 28204 )
return 37290;
else if (value == 28205 )
return 40909;
else if (value == 28206 )
return 40911;
else if (value == 28207 )
return 36192;
else if (value == 28216 )
return 40928;
else if (value == 28218 )
return 40923;
else if (value == 28222 )
return 40915;
else if (value == 28227 )
return 40922;
else if (value == 28234 )
return 38569;
else if (value == 28237 )
return 40920;
else if (value == 28238 )
return 40924;
else if (value == 28246 )
return 36046;
else if (value == 28248 )
return 36803;
else if (value == 28251 )
return 37464;
else if (value == 28255 )
return 40914;
else if (value == 28263 )
return 38734;
}
else if (value <= 28322 ) {
if (value == 28267 )
return 40917;
else if (value == 28270 )
return 40910;
else if (value == 28271 )
return 37778;
else if (value == 28274 )
return 40913;
else if (value == 28278 )
return 40919;
else if (value == 28286 )
return 39024;
else if (value == 28287 )
return 36540;
else if (value == 28288 )
return 38558;
else if (value == 28290 )
return 40929;
else if (value == 28300 )
return 38060;
else if (value == 28303 )
return 40941;
else if (value == 28304 )
return 36025;
else if (value == 28310 )
return 36736;
else if (value == 28312 )
return 40931;
else if (value == 28316 )
return 38829;
else if (value == 28317 )
return 36193;
else if (value == 28319 )
return 40944;
else if (value == 28322 )
return 35052;
}
else if (value <= 28373 ) {
if (value == 28325 )
return 40942;
else if (value == 28330 )
return 40930;
else if (value == 28335 )
return 40936;
else if (value == 28338 )
return 40938;
else if (value == 28342 )
return 38766;
else if (value == 28343 )
return 40933;
else if (value == 28346 )
return 37709;
else if (value == 28349 )
return 40935;
else if (value == 28354 )
return 40943;
else if (value == 28356 )
return 40937;
else if (value == 28357 )
return 38597;
else if (value == 28361 )
return 40932;
else if (value == 28363 )
return 36512;
else if (value == 28364 )
return 40956;
else if (value == 28369 )
return 35466;
else if (value == 28371 )
return 40934;
else if (value == 28372 )
return 40939;
else if (value == 28373 )
return 40940;
}
else if (value <= 28436 ) {
if (value == 28381 )
return 37354;
else if (value == 28382 )
return 37336;
else if (value == 28396 )
return 40948;
else if (value == 28399 )
return 40954;
else if (value == 28402 )
return 40952;
else if (value == 28404 )
return 37704;
else if (value == 28407 )
return 57410;
else if (value == 28408 )
return 40949;
else if (value == 28414 )
return 40950;
else if (value == 28415 )
return 40926;
else if (value == 28417 )
return 35737;
else if (value == 28418 )
return 38233;
else if (value == 28422 )
return 36541;
else if (value == 28425 )
return 36247;
else if (value == 28431 )
return 38994;
else if (value == 28433 )
return 40946;
else if (value == 28435 )
return 57409;
else if (value == 28436 )
return 35209;
}
else if (value <= 28511 ) {
if (value == 28437 )
return 37254;
else if (value == 28448 )
return 38041;
else if (value == 28450 )
return 35519;
else if (value == 28451 )
return 38904;
else if (value == 28459 )
return 38559;
else if (value == 28460 )
return 37584;
else if (value == 28465 )
return 40953;
else if (value == 28466 )
return 40955;
else if (value == 28472 )
return 37201;
else if (value == 28478 )
return 57408;
else if (value == 28479 )
return 40951;
else if (value == 28481 )
return 40945;
else if (value == 28485 )
return 35521;
else if (value == 28500 )
return 35977;
else if (value == 28504 )
return 57422;
else if (value == 28507 )
return 57417;
else if (value == 28508 )
return 37110;
else if (value == 28511 )
return 35459;
}
}
else if ( value >= 28516 && value <= 29701 ) {
if (value <= 28567 ) {
if (value == 28516 )
return 36737;
else if (value == 28518 )
return 57426;
else if (value == 28525 )
return 57419;
else if (value == 28526 )
return 37546;
else if (value == 28527 )
return 57416;
else if (value == 28528 )
return 37591;
else if (value == 28532 )
return 57451;
else if (value == 28536 )
return 57413;
else if (value == 28538 )
return 57412;
else if (value == 28540 )
return 57421;
else if (value == 28544 )
return 57415;
else if (value == 28545 )
return 57414;
else if (value == 28546 )
return 57420;
else if (value == 28548 )
return 37023;
else if (value == 28550 )
return 57411;
else if (value == 28558 )
return 57423;
else if (value == 28561 )
return 57424;
else if (value == 28567 )
return 35520;
}
else if (value <= 28640 ) {
if (value == 28577 )
return 57429;
else if (value == 28579 )
return 57428;
else if (value == 28580 )
return 57430;
else if (value == 28586 )
return 57433;
else if (value == 28593 )
return 37730;
else if (value == 28595 )
return 57427;
else if (value == 28601 )
return 57431;
else if (value == 28608 )
return 35971;
else if (value == 28609 )
return 37367;
else if (value == 28610 )
return 57425;
else if (value == 28611 )
return 37978;
else if (value == 28614 )
return 57432;
else if (value == 28628 )
return 57437;
else if (value == 28629 )
return 57435;
else if (value == 28632 )
return 57438;
else if (value == 28635 )
return 57441;
else if (value == 28639 )
return 57434;
else if (value == 28640 )
return 36234;
}
else if (value <= 28696 ) {
if (value == 28641 )
return 37959;
else if (value == 28644 )
return 40887;
else if (value == 28651 )
return 38804;
else if (value == 28652 )
return 57436;
else if (value == 28654 )
return 57440;
else if (value == 28655 )
return 37363;
else if (value == 28657 )
return 57439;
else if (value == 28659 )
return 57418;
else if (value == 28662 )
return 59529;
else if (value == 28666 )
return 57444;
else if (value == 28670 )
return 57448;
else if (value == 28673 )
return 57446;
else if (value == 28681 )
return 57442;
else if (value == 28683 )
return 57443;
else if (value == 28687 )
return 57447;
else if (value == 28689 )
return 57445;
else if (value == 28693 )
return 38253;
else if (value == 28696 )
return 57453;
}
else if (value <= 28784 ) {
if (value == 28698 )
return 57450;
else if (value == 28699 )
return 57449;
else if (value == 28701 )
return 57452;
else if (value == 28702 )
return 37842;
else if (value == 28703 )
return 57454;
else if (value == 28710 )
return 37525;
else if (value == 28711 )
return 37355;
else if (value == 28716 )
return 37027;
else if (value == 28720 )
return 57455;
else if (value == 28722 )
return 57457;
else if (value == 28734 )
return 57456;
else if (value == 28748 )
return 40947;
else if (value == 28753 )
return 57458;
else if (value == 28760 )
return 37861;
else if (value == 28771 )
return 57459;
else if (value == 28779 )
return 35278;
else if (value == 28783 )
return 37780;
else if (value == 28784 )
return 35396;
}
else if (value <= 28875 ) {
if (value == 28792 )
return 35716;
else if (value == 28796 )
return 36572;
else if (value == 28797 )
return 36304;
else if (value == 28809 )
return 38982;
else if (value == 28810 )
return 36998;
else if (value == 28814 )
return 35210;
else if (value == 28818 )
return 57461;
else if (value == 28825 )
return 57460;
else if (value == 28844 )
return 57464;
else if (value == 28845 )
return 37465;
else if (value == 28846 )
return 57467;
else if (value == 28847 )
return 57462;
else if (value == 28851 )
return 57466;
else if (value == 28856 )
return 57465;
else if (value == 28857 )
return 37727;
else if (value == 28858 )
return 35031;
else if (value == 28872 )
return 38899;
else if (value == 28875 )
return 57469;
}
else if (value <= 29004 ) {
if (value == 28879 )
return 35143;
else if (value == 28889 )
return 57472;
else if (value == 28893 )
return 57470;
else if (value == 28895 )
return 57468;
else if (value == 28913 )
return 57463;
else if (value == 28921 )
return 38466;
else if (value == 28925 )
return 57474;
else if (value == 28937 )
return 57473;
else if (value == 28948 )
return 35211;
else if (value == 28953 )
return 57476;
else if (value == 28954 )
return 38320;
else if (value == 28956 )
return 57475;
else if (value == 28961 )
return 38579;
else if (value == 28966 )
return 36805;
else if (value == 28982 )
return 37202;
else if (value == 28988 )
return 36804;
else if (value == 29001 )
return 38905;
else if (value == 29004 )
return 57482;
}
else if (value <= 29076 ) {
if (value == 29006 )
return 37111;
else if (value == 29013 )
return 57478;
else if (value == 29014 )
return 57483;
else if (value == 29017 )
return 35212;
else if (value == 29026 )
return 57481;
else if (value == 29028 )
return 38017;
else if (value == 29029 )
return 57477;
else if (value == 29030 )
return 57480;
else if (value == 29031 )
return 36806;
else if (value == 29033 )
return 38095;
else if (value == 29036 )
return 57484;
else if (value == 29038 )
return 36559;
else if (value == 29053 )
return 37112;
else if (value == 29060 )
return 57487;
else if (value == 29064 )
return 57479;
else if (value == 29066 )
return 35910;
else if (value == 29071 )
return 57485;
else if (value == 29076 )
return 38767;
}
else if (value <= 29151 ) {
if (value == 29077 )
return 57488;
else if (value == 29081 )
return 60068;
else if (value == 29087 )
return 36718;
else if (value == 29096 )
return 57489;
else if (value == 29100 )
return 57490;
else if (value == 29105 )
return 37965;
else if (value == 29113 )
return 57492;
else if (value == 29118 )
return 57493;
else if (value == 29123 )
return 37970;
else if (value == 29128 )
return 37781;
else if (value == 29129 )
return 57495;
else if (value == 29134 )
return 57497;
else if (value == 29136 )
return 38867;
else if (value == 29138 )
return 57494;
else if (value == 29140 )
return 57496;
else if (value == 29141 )
return 35213;
else if (value == 29143 )
return 57491;
else if (value == 29151 )
return 39546;
}
else if (value <= 29226 ) {
if (value == 29152 )
return 57498;
else if (value == 29157 )
return 37255;
else if (value == 29158 )
return 36439;
else if (value == 29159 )
return 57500;
else if (value == 29164 )
return 57499;
else if (value == 29165 )
return 36931;
else if (value == 29166 )
return 39383;
else if (value == 29173 )
return 57501;
else if (value == 29177 )
return 57503;
else if (value == 29179 )
return 57486;
else if (value == 29180 )
return 57502;
else if (value == 29183 )
return 57504;
else if (value == 29190 )
return 38042;
else if (value == 29197 )
return 57505;
else if (value == 29200 )
return 57506;
else if (value == 29211 )
return 57507;
else if (value == 29224 )
return 57508;
else if (value == 29226 )
return 37596;
}
else if (value <= 29260 ) {
if (value == 29228 )
return 57510;
else if (value == 29229 )
return 57509;
else if (value == 29232 )
return 57511;
else if (value == 29234 )
return 57512;
else if (value == 29237 )
return 36573;
else if (value == 29238 )
return 38275;
else if (value == 29242 )
return 38634;
else if (value == 29243 )
return 57513;
else if (value == 29244 )
return 57514;
else if (value == 29245 )
return 37237;
else if (value == 29246 )
return 36514;
else if (value == 29247 )
return 57515;
else if (value == 29248 )
return 57516;
else if (value == 29254 )
return 57517;
else if (value == 29255 )
return 38352;
else if (value == 29256 )
return 38085;
else if (value == 29259 )
return 57518;
else if (value == 29260 )
return 38006;
}
else if (value <= 29314 ) {
if (value == 29266 )
return 37547;
else if (value == 29272 )
return 57519;
else if (value == 29273 )
return 35301;
else if (value == 29275 )
return 35725;
else if (value == 29277 )
return 38596;
else if (value == 29279 )
return 38580;
else if (value == 29281 )
return 35250;
else if (value == 29282 )
return 38995;
else if (value == 29287 )
return 38513;
else if (value == 29289 )
return 38312;
else if (value == 29298 )
return 37045;
else if (value == 29300 )
return 57520;
else if (value == 29305 )
return 37825;
else if (value == 29309 )
return 36001;
else if (value == 29310 )
return 57521;
else if (value == 29312 )
return 36306;
else if (value == 29313 )
return 57523;
else if (value == 29314 )
return 57522;
}
else if (value <= 29394 ) {
if (value == 29319 )
return 57524;
else if (value == 29330 )
return 57525;
else if (value == 29334 )
return 57526;
else if (value == 29344 )
return 35677;
else if (value == 29346 )
return 57527;
else if (value == 29351 )
return 57528;
else if (value == 29356 )
return 36002;
else if (value == 29359 )
return 38086;
else if (value == 29362 )
return 57530;
else if (value == 29366 )
return 36851;
else if (value == 29369 )
return 57529;
else if (value == 29378 )
return 35766;
else if (value == 29379 )
return 57531;
else if (value == 29380 )
return 57533;
else if (value == 29382 )
return 57532;
else if (value == 29390 )
return 57534;
else if (value == 29392 )
return 36047;
else if (value == 29394 )
return 57535;
}
else if (value <= 29467 ) {
if (value == 29399 )
return 35815;
else if (value == 29401 )
return 37215;
else if (value == 29403 )
return 36253;
else if (value == 29408 )
return 57537;
else if (value == 29409 )
return 57538;
else if (value == 29410 )
return 57536;
else if (value == 29417 )
return 36587;
else if (value == 29420 )
return 37830;
else if (value == 29421 )
return 35767;
else if (value == 29431 )
return 57540;
else if (value == 29432 )
return 37451;
else if (value == 29433 )
return 57539;
else if (value == 29436 )
return 38996;
else if (value == 29437 )
return 38018;
else if (value == 29450 )
return 57543;
else if (value == 29462 )
return 57545;
else if (value == 29463 )
return 57542;
else if (value == 29467 )
return 38610;
}
else if (value <= 29519 ) {
if (value == 29468 )
return 57544;
else if (value == 29469 )
return 57546;
else if (value == 29471 )
return 38850;
else if (value == 29477 )
return 57550;
else if (value == 29481 )
return 57549;
else if (value == 29482 )
return 37526;
else if (value == 29483 )
return 37964;
else if (value == 29486 )
return 36003;
else if (value == 29487 )
return 57548;
else if (value == 29492 )
return 57547;
else if (value == 29494 )
return 38736;
else if (value == 29495 )
return 38737;
else if (value == 29502 )
return 57551;
else if (value == 29503 )
return 35214;
else if (value == 29508 )
return 36246;
else if (value == 29509 )
return 36482;
else if (value == 29518 )
return 57552;
else if (value == 29519 )
return 57553;
}
else if (value <= 29619 ) {
if (value == 29527 )
return 57555;
else if (value == 29539 )
return 36706;
else if (value == 29544 )
return 57557;
else if (value == 29546 )
return 57556;
else if (value == 29552 )
return 57558;
else if (value == 29554 )
return 35436;
else if (value == 29557 )
return 57560;
else if (value == 29560 )
return 57559;
else if (value == 29562 )
return 57562;
else if (value == 29563 )
return 57561;
else if (value == 29572 )
return 36026;
else if (value == 29575 )
return 38822;
else if (value == 29577 )
return 35786;
else if (value == 29579 )
return 35236;
else if (value == 29590 )
return 35816;
else if (value == 29609 )
return 35551;
else if (value == 29618 )
return 38886;
else if (value == 29619 )
return 57564;
}
else if (value <= 29701 ) {
if (value == 29627 )
return 57566;
else if (value == 29632 )
return 57567;
else if (value == 29634 )
return 35279;
else if (value == 29640 )
return 57563;
else if (value == 29642 )
return 36440;
else if (value == 29645 )
return 37567;
else if (value == 29646 )
return 57565;
else if (value == 29662 )
return 57570;
else if (value == 29664 )
return 36588;
else if (value == 29669 )
return 57568;
else if (value == 29674 )
return 35933;
else if (value == 29677 )
return 38087;
else if (value == 29678 )
return 57569;
else if (value == 29681 )
return 57596;
else if (value == 29688 )
return 57575;
else if (value == 29694 )
return 36027;
else if (value == 29699 )
return 35717;
else if (value == 29701 )
return 57572;
}
}
else if ( value >= 29702 && value <= 30643 ) {
if (value <= 29790 ) {
if (value == 29702 )
return 38813;
else if (value == 29705 )
return 38830;
else if (value == 29730 )
return 37364;
else if (value == 29733 )
return 57574;
else if (value == 29746 )
return 57576;
else if (value == 29747 )
return 38868;
else if (value == 29748 )
return 35797;
else if (value == 29749 )
return 38138;
else if (value == 29750 )
return 37993;
else if (value == 29754 )
return 57577;
else if (value == 29759 )
return 57579;
else if (value == 29761 )
return 57582;
else if (value == 29781 )
return 57578;
else if (value == 29785 )
return 57581;
else if (value == 29786 )
return 36072;
else if (value == 29787 )
return 35180;
else if (value == 29788 )
return 57583;
else if (value == 29790 )
return 37008;
}
else if (value <= 29885 ) {
if (value == 29791 )
return 57580;
else if (value == 29792 )
return 38874;
else if (value == 29795 )
return 57586;
else if (value == 29796 )
return 60066;
else if (value == 29801 )
return 57584;
else if (value == 29802 )
return 57587;
else if (value == 29807 )
return 57573;
else if (value == 29808 )
return 57585;
else if (value == 29811 )
return 36282;
else if (value == 29814 )
return 57588;
else if (value == 29822 )
return 57589;
else if (value == 29827 )
return 38814;
else if (value == 29835 )
return 57590;
else if (value == 29854 )
return 57591;
else if (value == 29858 )
return 57571;
else if (value == 29863 )
return 57592;
else if (value == 29872 )
return 35522;
else if (value == 29885 )
return 36515;
}
else if (value <= 29955 ) {
if (value == 29898 )
return 57593;
else if (value == 29903 )
return 57594;
else if (value == 29908 )
return 57595;
else if (value == 29916 )
return 35162;
else if (value == 29920 )
return 57664;
else if (value == 29922 )
return 38234;
else if (value == 29923 )
return 57665;
else if (value == 29926 )
return 35490;
else if (value == 29927 )
return 57666;
else if (value == 29929 )
return 57667;
else if (value == 29934 )
return 57668;
else if (value == 29936 )
return 57670;
else if (value == 29937 )
return 57671;
else if (value == 29938 )
return 57669;
else if (value == 29942 )
return 38258;
else if (value == 29943 )
return 57673;
else if (value == 29944 )
return 57672;
else if (value == 29955 )
return 57675;
}
else if (value <= 29995 ) {
if (value == 29956 )
return 57674;
else if (value == 29957 )
return 57676;
else if (value == 29964 )
return 57677;
else if (value == 29965 )
return 57679;
else if (value == 29966 )
return 57678;
else if (value == 29969 )
return 36249;
else if (value == 29971 )
return 57681;
else if (value == 29973 )
return 57680;
else if (value == 29976 )
return 35523;
else if (value == 29978 )
return 36978;
else if (value == 29980 )
return 37723;
else if (value == 29982 )
return 57682;
else if (value == 29983 )
return 37046;
else if (value == 29987 )
return 36441;
else if (value == 29989 )
return 35225;
else if (value == 29990 )
return 57683;
else if (value == 29992 )
return 38768;
else if (value == 29995 )
return 38369;
}
else if (value <= 30031 ) {
if (value == 29996 )
return 57684;
else if (value == 30000 )
return 37731;
else if (value == 30001 )
return 38738;
else if (value == 30002 )
return 36194;
else if (value == 30003 )
return 36956;
else if (value == 30007 )
return 37482;
else if (value == 30008 )
return 39346;
else if (value == 30010 )
return 37548;
else if (value == 30011 )
return 35302;
else if (value == 30012 )
return 57685;
else if (value == 30020 )
return 57686;
else if (value == 30022 )
return 57691;
else if (value == 30025 )
return 57689;
else if (value == 30026 )
return 57688;
else if (value == 30027 )
return 40384;
else if (value == 30028 )
return 35397;
else if (value == 30029 )
return 57687;
else if (value == 30031 )
return 35032;
}
else if (value <= 30064 ) {
if (value == 30033 )
return 38056;
else if (value == 30036 )
return 38088;
else if (value == 30041 )
return 38831;
else if (value == 30042 )
return 57692;
else if (value == 30043 )
return 57690;
else if (value == 30044 )
return 37499;
else if (value == 30045 )
return 37028;
else if (value == 30048 )
return 38057;
else if (value == 30050 )
return 38220;
else if (value == 30052 )
return 57694;
else if (value == 30053 )
return 38826;
else if (value == 30054 )
return 35948;
else if (value == 30055 )
return 57695;
else if (value == 30057 )
return 57693;
else if (value == 30058 )
return 38100;
else if (value == 30059 )
return 57696;
else if (value == 30061 )
return 57697;
else if (value == 30064 )
return 35033;
}
else if (value <= 30109 ) {
if (value == 30067 )
return 36852;
else if (value == 30068 )
return 57702;
else if (value == 30070 )
return 57699;
else if (value == 30071 )
return 37867;
else if (value == 30072 )
return 57698;
else if (value == 30079 )
return 35653;
else if (value == 30082 )
return 57705;
else if (value == 30086 )
return 57700;
else if (value == 30087 )
return 57701;
else if (value == 30089 )
return 57704;
else if (value == 30090 )
return 57703;
else if (value == 30091 )
return 38212;
else if (value == 30094 )
return 37217;
else if (value == 30095 )
return 37216;
else if (value == 30097 )
return 35678;
else if (value == 30100 )
return 57706;
else if (value == 30106 )
return 57707;
else if (value == 30109 )
return 57708;
}
else if (value <= 30157 ) {
if (value == 30115 )
return 57710;
else if (value == 30117 )
return 57709;
else if (value == 30123 )
return 35189;
else if (value == 30129 )
return 57718;
else if (value == 30130 )
return 38118;
else if (value == 30131 )
return 57712;
else if (value == 30133 )
return 57714;
else if (value == 30136 )
return 57716;
else if (value == 30137 )
return 36957;
else if (value == 30140 )
return 57717;
else if (value == 30141 )
return 57715;
else if (value == 30142 )
return 36542;
else if (value == 30146 )
return 57711;
else if (value == 30147 )
return 57713;
else if (value == 30149 )
return 38241;
else if (value == 30151 )
return 36807;
else if (value == 30154 )
return 57720;
else if (value == 30157 )
return 57719;
}
else if (value <= 30207 ) {
if (value == 30162 )
return 57721;
else if (value == 30164 )
return 36516;
else if (value == 30165 )
return 36269;
else if (value == 30168 )
return 37783;
else if (value == 30169 )
return 57722;
else if (value == 30171 )
return 37577;
else if (value == 30174 )
return 57724;
else if (value == 30178 )
return 38815;
else if (value == 30179 )
return 57723;
else if (value == 30185 )
return 37257;
else if (value == 30192 )
return 57730;
else if (value == 30194 )
return 57732;
else if (value == 30195 )
return 57733;
else if (value == 30196 )
return 37491;
else if (value == 30202 )
return 57731;
else if (value == 30204 )
return 57728;
else if (value == 30206 )
return 57725;
else if (value == 30207 )
return 57726;
}
else if (value <= 30284 ) {
if (value == 30209 )
return 57729;
else if (value == 30217 )
return 57736;
else if (value == 30219 )
return 57734;
else if (value == 30221 )
return 57735;
else if (value == 30239 )
return 57737;
else if (value == 30240 )
return 57739;
else if (value == 30241 )
return 57740;
else if (value == 30242 )
return 57741;
else if (value == 30244 )
return 57742;
else if (value == 30247 )
return 57738;
else if (value == 30256 )
return 57744;
else if (value == 30260 )
return 57743;
else if (value == 30267 )
return 57745;
else if (value == 30274 )
return 38851;
else if (value == 30278 )
return 57748;
else if (value == 30279 )
return 57746;
else if (value == 30280 )
return 57747;
else if (value == 30284 )
return 35552;
}
else if (value <= 30332 ) {
if (value == 30290 )
return 38652;
else if (value == 30294 )
return 38344;
else if (value == 30296 )
return 57750;
else if (value == 30300 )
return 57749;
else if (value == 30305 )
return 57751;
else if (value == 30306 )
return 57752;
else if (value == 30311 )
return 57756;
else if (value == 30312 )
return 57753;
else if (value == 30313 )
return 57754;
else if (value == 30314 )
return 57755;
else if (value == 30316 )
return 57757;
else if (value == 30320 )
return 57758;
else if (value == 30322 )
return 57759;
else if (value == 30326 )
return 57760;
else if (value == 30328 )
return 57761;
else if (value == 30330 )
return 38061;
else if (value == 30331 )
return 37743;
else if (value == 30332 )
return 57762;
}
else if (value <= 30388 ) {
if (value == 30333 )
return 38034;
else if (value == 30334 )
return 38227;
else if (value == 30336 )
return 57763;
else if (value == 30339 )
return 57764;
else if (value == 30340 )
return 37705;
else if (value == 30342 )
return 35398;
else if (value == 30343 )
return 36195;
else if (value == 30344 )
return 57765;
else if (value == 30347 )
return 57766;
else if (value == 30350 )
return 57767;
else if (value == 30352 )
return 36424;
else if (value == 30355 )
return 57769;
else if (value == 30358 )
return 57768;
else if (value == 30361 )
return 57770;
else if (value == 30362 )
return 57771;
else if (value == 30382 )
return 38119;
else if (value == 30384 )
return 57772;
else if (value == 30388 )
return 57773;
}
else if (value <= 30431 ) {
if (value == 30391 )
return 60041;
else if (value == 30392 )
return 57774;
else if (value == 30393 )
return 57775;
else if (value == 30394 )
return 57776;
else if (value == 30399 )
return 36429;
else if (value == 30402 )
return 57777;
else if (value == 30403 )
return 38005;
else if (value == 30406 )
return 38526;
else if (value == 30408 )
return 35181;
else if (value == 30410 )
return 35190;
else if (value == 30413 )
return 57778;
else if (value == 30418 )
return 57780;
else if (value == 30422 )
return 57779;
else if (value == 30423 )
return 37776;
else if (value == 30427 )
return 37047;
else if (value == 30428 )
return 40792;
else if (value == 30430 )
return 57781;
else if (value == 30431 )
return 38591;
}
else if (value <= 30475 ) {
if (value == 30433 )
return 57782;
else if (value == 30435 )
return 35524;
else if (value == 30436 )
return 38101;
else if (value == 30437 )
return 57783;
else if (value == 30439 )
return 57784;
else if (value == 30442 )
return 57785;
else if (value == 30446 )
return 38618;
else if (value == 30450 )
return 38611;
else if (value == 30452 )
return 37564;
else if (value == 30456 )
return 37258;
else if (value == 30459 )
return 57787;
else if (value == 30462 )
return 36738;
else if (value == 30465 )
return 36808;
else if (value == 30468 )
return 57790;
else if (value == 30471 )
return 57789;
else if (value == 30472 )
return 57788;
else if (value == 30473 )
return 38139;
else if (value == 30475 )
return 35525;
}
else if (value <= 30561 ) {
if (value == 30476 )
return 36007;
else if (value == 30491 )
return 57796;
else if (value == 30494 )
return 57793;
else if (value == 30495 )
return 36958;
else if (value == 30496 )
return 38576;
else if (value == 30500 )
return 57792;
else if (value == 30501 )
return 57794;
else if (value == 30502 )
return 57795;
else if (value == 30505 )
return 57791;
else if (value == 30519 )
return 57797;
else if (value == 30520 )
return 57798;
else if (value == 30522 )
return 37549;
else if (value == 30524 )
return 35553;
else if (value == 30528 )
return 37509;
else if (value == 30535 )
return 57799;
else if (value == 30554 )
return 57800;
else if (value == 30555 )
return 57803;
else if (value == 30561 )
return 36999;
}
else if (value <= 30643 ) {
if (value == 30563 )
return 37826;
else if (value == 30565 )
return 57804;
else if (value == 30566 )
return 38514;
else if (value == 30568 )
return 57801;
else if (value == 30571 )
return 57802;
else if (value == 30585 )
return 57807;
else if (value == 30590 )
return 57806;
else if (value == 30591 )
return 57805;
else if (value == 30603 )
return 57809;
else if (value == 30606 )
return 57808;
else if (value == 30609 )
return 57810;
else if (value == 30622 )
return 57812;
else if (value == 30624 )
return 57811;
else if (value == 30629 )
return 38347;
else if (value == 30636 )
return 36725;
else if (value == 30637 )
return 38852;
else if (value == 30640 )
return 57813;
else if (value == 30643 )
return 37813;
}
}
else if ( value >= 30646 && value <= 31604 ) {
if (value <= 30701 ) {
if (value == 30646 )
return 57814;
else if (value == 30649 )
return 57815;
else if (value == 30651 )
return 57819;
else if (value == 30652 )
return 57817;
else if (value == 30653 )
return 57818;
else if (value == 30655 )
return 57816;
else if (value == 30663 )
return 57820;
else if (value == 30669 )
return 57821;
else if (value == 30679 )
return 57822;
else if (value == 30682 )
return 57823;
else if (value == 30683 )
return 38581;
else if (value == 30684 )
return 57824;
else if (value == 30690 )
return 38638;
else if (value == 30691 )
return 57825;
else if (value == 30693 )
return 37485;
else if (value == 30695 )
return 38026;
else if (value == 30697 )
return 35817;
else if (value == 30701 )
return 37466;
}
else if (value <= 30789 ) {
if (value == 30702 )
return 57826;
else if (value == 30703 )
return 35768;
else if (value == 30707 )
return 37070;
else if (value == 30716 )
return 57827;
else if (value == 30722 )
return 36283;
else if (value == 30732 )
return 57828;
else if (value == 30738 )
return 57829;
else if (value == 30740 )
return 36004;
else if (value == 30741 )
return 36307;
else if (value == 30752 )
return 57831;
else if (value == 30757 )
return 37749;
else if (value == 30758 )
return 36308;
else if (value == 30759 )
return 35693;
else if (value == 30770 )
return 38467;
else if (value == 30772 )
return 37994;
else if (value == 30778 )
return 37750;
else if (value == 30783 )
return 36219;
else if (value == 30789 )
return 57833;
}
else if (value <= 30874 ) {
if (value == 30813 )
return 36809;
else if (value == 30827 )
return 38832;
else if (value == 30828 )
return 36196;
else if (value == 30831 )
return 36005;
else if (value == 30834 )
return 38049;
else if (value == 30836 )
return 57835;
else if (value == 30844 )
return 57837;
else if (value == 30849 )
return 36073;
else if (value == 30854 )
return 57836;
else if (value == 30855 )
return 37620;
else if (value == 30860 )
return 57839;
else if (value == 30861 )
return 35414;
else if (value == 30862 )
return 57834;
else if (value == 30865 )
return 38120;
else if (value == 30867 )
return 35151;
else if (value == 30869 )
return 36330;
else if (value == 30871 )
return 39025;
else if (value == 30874 )
return 57838;
}
else if (value <= 30938 ) {
if (value == 30883 )
return 57840;
else if (value == 30887 )
return 38345;
else if (value == 30889 )
return 37079;
else if (value == 30890 )
return 57842;
else if (value == 30895 )
return 57843;
else if (value == 30901 )
return 57841;
else if (value == 30906 )
return 35437;
else if (value == 30908 )
return 57849;
else if (value == 30910 )
return 57848;
else if (value == 30913 )
return 36517;
else if (value == 30917 )
return 57850;
else if (value == 30918 )
return 57845;
else if (value == 30922 )
return 57851;
else if (value == 30923 )
return 57846;
else if (value == 30928 )
return 38102;
else if (value == 30929 )
return 57844;
else if (value == 30932 )
return 57847;
else if (value == 30938 )
return 57921;
}
else if (value <= 31036 ) {
if (value == 30951 )
return 57920;
else if (value == 30952 )
return 38529;
else if (value == 30956 )
return 57852;
else if (value == 30959 )
return 35049;
else if (value == 30964 )
return 57923;
else if (value == 30973 )
return 57922;
else if (value == 30977 )
return 36810;
else if (value == 30983 )
return 57924;
else if (value == 30990 )
return 37218;
else if (value == 30993 )
return 57926;
else if (value == 30994 )
return 57925;
else if (value == 31001 )
return 57927;
else if (value == 31014 )
return 57830;
else if (value == 31018 )
return 57832;
else if (value == 31019 )
return 57929;
else if (value == 31020 )
return 57928;
else if (value == 31034 )
return 36518;
else if (value == 31036 )
return 38887;
}
else if (value <= 31077 ) {
if (value == 31038 )
return 36560;
else if (value == 31040 )
return 57930;
else if (value == 31041 )
return 35926;
else if (value == 31047 )
return 35679;
else if (value == 31048 )
return 35654;
else if (value == 31049 )
return 36483;
else if (value == 31056 )
return 38739;
else if (value == 31059 )
return 57936;
else if (value == 31061 )
return 57935;
else if (value == 31062 )
return 37219;
else if (value == 31063 )
return 57932;
else if (value == 31066 )
return 57934;
else if (value == 31069 )
return 36714;
else if (value == 31070 )
return 36959;
else if (value == 31071 )
return 57933;
else if (value == 31072 )
return 57931;
else if (value == 31074 )
return 37961;
else if (value == 31077 )
return 36811;
}
else if (value <= 31150 ) {
if (value == 31080 )
return 38235;
else if (value == 31085 )
return 36309;
else if (value == 31095 )
return 37784;
else if (value == 31098 )
return 57937;
else if (value == 31103 )
return 57938;
else if (value == 31104 )
return 57960;
else if (value == 31105 )
return 35798;
else if (value == 31108 )
return 39004;
else if (value == 31109 )
return 37204;
else if (value == 31114 )
return 57939;
else if (value == 31117 )
return 35280;
else if (value == 31118 )
return 37621;
else if (value == 31119 )
return 38303;
else if (value == 31133 )
return 57940;
else if (value == 31142 )
return 35738;
else if (value == 31143 )
return 57941;
else if (value == 31146 )
return 57943;
else if (value == 31150 )
return 57944;
}
else if (value <= 31203 ) {
if (value == 31152 )
return 37960;
else if (value == 31155 )
return 57945;
else if (value == 31161 )
return 57946;
else if (value == 31162 )
return 57947;
else if (value == 31165 )
return 35799;
else if (value == 31166 )
return 35281;
else if (value == 31167 )
return 37827;
else if (value == 31168 )
return 36679;
else if (value == 31169 )
return 36484;
else if (value == 31177 )
return 57948;
else if (value == 31179 )
return 36680;
else if (value == 31185 )
return 35272;
else if (value == 31186 )
return 38242;
else if (value == 31189 )
return 57949;
else if (value == 31192 )
return 38121;
else if (value == 31199 )
return 37220;
else if (value == 31201 )
return 57952;
else if (value == 31203 )
return 57953;
}
else if (value <= 31260 ) {
if (value == 31204 )
return 38025;
else if (value == 31206 )
return 36960;
else if (value == 31207 )
return 57950;
else if (value == 31209 )
return 37505;
else if (value == 31212 )
return 57951;
else if (value == 31216 )
return 36812;
else if (value == 31227 )
return 35034;
else if (value == 31232 )
return 35656;
else if (value == 31240 )
return 57954;
else if (value == 31243 )
return 37622;
else if (value == 31245 )
return 57955;
else if (value == 31246 )
return 37061;
else if (value == 31252 )
return 38571;
else if (value == 31255 )
return 38210;
else if (value == 31256 )
return 57956;
else if (value == 31257 )
return 57957;
else if (value == 31258 )
return 37492;
else if (value == 31260 )
return 38853;
}
else if (value <= 31310 ) {
if (value == 31263 )
return 57959;
else if (value == 31264 )
return 57958;
else if (value == 31278 )
return 36589;
else if (value == 31281 )
return 57961;
else if (value == 31282 )
return 35054;
else if (value == 31287 )
return 57964;
else if (value == 31291 )
return 57962;
else if (value == 31292 )
return 35282;
else if (value == 31293 )
return 35949;
else if (value == 31294 )
return 57963;
else if (value == 31295 )
return 36197;
else if (value == 31296 )
return 36242;
else if (value == 31298 )
return 38372;
else if (value == 31299 )
return 57965;
else if (value == 31302 )
return 38515;
else if (value == 31305 )
return 57967;
else if (value == 31309 )
return 37071;
else if (value == 31310 )
return 35182;
}
else if (value <= 31364 ) {
if (value == 31311 )
return 35256;
else if (value == 31312 )
return 34986;
else if (value == 31319 )
return 57966;
else if (value == 31329 )
return 57968;
else if (value == 31330 )
return 57969;
else if (value == 31331 )
return 36853;
else if (value == 31337 )
return 57970;
else if (value == 31339 )
return 35438;
else if (value == 31344 )
return 57972;
else if (value == 31348 )
return 35978;
else if (value == 31350 )
return 35718;
else if (value == 31353 )
return 57973;
else if (value == 31354 )
return 35827;
else if (value == 31357 )
return 57974;
else if (value == 31359 )
return 37114;
else if (value == 31361 )
return 37835;
else if (value == 31363 )
return 37086;
else if (value == 31364 )
return 36339;
}
else if (value <= 31428 ) {
if (value == 31368 )
return 57975;
else if (value == 31378 )
return 37506;
else if (value == 31379 )
return 37259;
else if (value == 31381 )
return 57977;
else if (value == 31382 )
return 57979;
else if (value == 31383 )
return 57976;
else if (value == 31384 )
return 57978;
else if (value == 31391 )
return 35905;
else if (value == 31401 )
return 57980;
else if (value == 31402 )
return 35909;
else if (value == 31406 )
return 35719;
else if (value == 31407 )
return 38769;
else if (value == 31408 )
return 57982;
else if (value == 31414 )
return 57984;
else if (value == 31418 )
return 35149;
else if (value == 31423 )
return 57987;
else if (value == 31427 )
return 35478;
else if (value == 31428 )
return 57986;
}
else if (value <= 31458 ) {
if (value == 31429 )
return 57985;
else if (value == 31431 )
return 57989;
else if (value == 31432 )
return 57981;
else if (value == 31434 )
return 57990;
else if (value == 31435 )
return 38823;
else if (value == 31437 )
return 57991;
else if (value == 31439 )
return 57992;
else if (value == 31442 )
return 39666;
else if (value == 31443 )
return 57994;
else if (value == 31445 )
return 57993;
else if (value == 31449 )
return 57995;
else if (value == 31450 )
return 57996;
else if (value == 31452 )
return 38835;
else if (value == 31453 )
return 57997;
else if (value == 31455 )
return 59629;
else if (value == 31456 )
return 36813;
else if (value == 31457 )
return 57998;
else if (value == 31458 )
return 57999;
}
else if (value <= 31499 ) {
if (value == 31459 )
return 36726;
else if (value == 31461 )
return 37814;
else if (value == 31462 )
return 58000;
else if (value == 31466 )
return 37447;
else if (value == 31469 )
return 58001;
else if (value == 31471 )
return 37467;
else if (value == 31472 )
return 58002;
else if (value == 31478 )
return 35747;
else if (value == 31480 )
return 39262;
else if (value == 31481 )
return 37500;
else if (value == 31482 )
return 36529;
else if (value == 31487 )
return 35526;
else if (value == 31490 )
return 58003;
else if (value == 31492 )
return 58016;
else if (value == 31494 )
return 58006;
else if (value == 31496 )
return 35720;
else if (value == 31498 )
return 58005;
else if (value == 31499 )
return 58018;
}
else if (value <= 31560 ) {
if (value == 31503 )
return 58004;
else if (value == 31505 )
return 36814;
else if (value == 31512 )
return 58008;
else if (value == 31513 )
return 58009;
else if (value == 31515 )
return 37706;
else if (value == 31518 )
return 58010;
else if (value == 31520 )
return 35453;
else if (value == 31525 )
return 36985;
else if (value == 31526 )
return 38276;
else if (value == 31528 )
return 58012;
else if (value == 31532 )
return 37350;
else if (value == 31539 )
return 58007;
else if (value == 31541 )
return 58011;
else if (value == 31542 )
return 58013;
else if (value == 31545 )
return 36345;
else if (value == 31557 )
return 58020;
else if (value == 31558 )
return 38221;
else if (value == 31560 )
return 38052;
}
else if (value <= 31604 ) {
if (value == 31561 )
return 37785;
else if (value == 31563 )
return 35800;
else if (value == 31564 )
return 58019;
else if (value == 31565 )
return 58017;
else if (value == 31567 )
return 38067;
else if (value == 31568 )
return 58014;
else if (value == 31569 )
return 37501;
else if (value == 31570 )
return 37787;
else if (value == 31572 )
return 37786;
else if (value == 31574 )
return 36340;
else if (value == 31581 )
return 58038;
else if (value == 31589 )
return 58022;
else if (value == 31591 )
return 58024;
else if (value == 31596 )
return 58027;
else if (value == 31598 )
return 58028;
else if (value == 31600 )
return 58025;
else if (value == 31601 )
return 58026;
else if (value == 31604 )
return 58023;
}
}
else if ( value >= 31605 && value <= 32398 ) {
if (value <= 31649 ) {
if (value == 31605 )
return 58021;
else if (value == 31610 )
return 58015;
else if (value == 31622 )
return 38349;
else if (value == 31623 )
return 35283;
else if (value == 31627 )
return 58035;
else if (value == 31629 )
return 58032;
else if (value == 31631 )
return 58037;
else if (value == 31634 )
return 58036;
else if (value == 31636 )
return 38035;
else if (value == 31637 )
return 38565;
else if (value == 31639 )
return 36442;
else if (value == 31640 )
return 58030;
else if (value == 31641 )
return 58039;
else if (value == 31642 )
return 58034;
else if (value == 31644 )
return 58033;
else if (value == 31645 )
return 58029;
else if (value == 31647 )
return 58031;
else if (value == 31649 )
return 35527;
}
else if (value <= 31717 ) {
if (value == 31658 )
return 37468;
else if (value == 31661 )
return 37115;
else if (value == 31665 )
return 38048;
else if (value == 31668 )
return 58044;
else if (value == 31672 )
return 38050;
else if (value == 31680 )
return 37087;
else if (value == 31681 )
return 58041;
else if (value == 31684 )
return 38093;
else if (value == 31686 )
return 58045;
else if (value == 31687 )
return 38353;
else if (value == 31689 )
return 37498;
else if (value == 31691 )
return 58040;
else if (value == 31692 )
return 58042;
else if (value == 31695 )
return 58043;
else if (value == 31709 )
return 58046;
else if (value == 31712 )
return 36546;
else if (value == 31716 )
return 37828;
else if (value == 31717 )
return 58051;
}
else if (value <= 31783 ) {
if (value == 31718 )
return 58050;
else if (value == 31721 )
return 58047;
else if (value == 31725 )
return 38997;
else if (value == 31731 )
return 58056;
else if (value == 31734 )
return 58060;
else if (value == 31735 )
return 58057;
else if (value == 31744 )
return 58053;
else if (value == 31751 )
return 58054;
else if (value == 31757 )
return 58059;
else if (value == 31761 )
return 58048;
else if (value == 31762 )
return 39379;
else if (value == 31763 )
return 58055;
else if (value == 31764 )
return 58049;
else if (value == 31767 )
return 58058;
else if (value == 31775 )
return 58064;
else if (value == 31777 )
return 35528;
else if (value == 31779 )
return 58061;
else if (value == 31783 )
return 58062;
}
else if (value <= 31840 ) {
if (value == 31786 )
return 58063;
else if (value == 31787 )
return 58066;
else if (value == 31799 )
return 58065;
else if (value == 31800 )
return 38132;
else if (value == 31805 )
return 58067;
else if (value == 31806 )
return 38906;
else if (value == 31807 )
return 38379;
else if (value == 31808 )
return 58072;
else if (value == 31811 )
return 58069;
else if (value == 31820 )
return 58068;
else if (value == 31821 )
return 37072;
else if (value == 31823 )
return 58071;
else if (value == 31824 )
return 58073;
else if (value == 31828 )
return 58070;
else if (value == 31830 )
return 58077;
else if (value == 31832 )
return 58074;
else if (value == 31839 )
return 58075;
else if (value == 31840 )
return 58052;
}
else if (value <= 31899 ) {
if (value == 31844 )
return 58076;
else if (value == 31845 )
return 58078;
else if (value == 31852 )
return 58079;
else if (value == 31859 )
return 38340;
else if (value == 31861 )
return 58080;
else if (value == 31870 )
return 38624;
else if (value == 31873 )
return 35788;
else if (value == 31874 )
return 35912;
else if (value == 31875 )
return 58081;
else if (value == 31881 )
return 38322;
else if (value == 31883 )
return 37000;
else if (value == 31885 )
return 38574;
else if (value == 31888 )
return 58082;
else if (value == 31890 )
return 38833;
else if (value == 31893 )
return 38036;
else if (value == 31895 )
return 37221;
else if (value == 31896 )
return 37971;
else if (value == 31899 )
return 36716;
}
else if (value <= 31938 ) {
if (value == 31903 )
return 35006;
else if (value == 31905 )
return 58087;
else if (value == 31906 )
return 58085;
else if (value == 31908 )
return 58083;
else if (value == 31909 )
return 35487;
else if (value == 31911 )
return 36815;
else if (value == 31912 )
return 58088;
else if (value == 31915 )
return 58086;
else if (value == 31917 )
return 58084;
else if (value == 31918 )
return 58092;
else if (value == 31921 )
return 58091;
else if (value == 31922 )
return 58090;
else if (value == 31923 )
return 58089;
else if (value == 31929 )
return 58093;
else if (value == 31933 )
return 58094;
else if (value == 31934 )
return 37048;
else if (value == 31936 )
return 58095;
else if (value == 31938 )
return 58097;
}
else if (value <= 31994 ) {
if (value == 31941 )
return 58096;
else if (value == 31946 )
return 36048;
else if (value == 31950 )
return 37207;
else if (value == 31954 )
return 58099;
else if (value == 31958 )
return 37788;
else if (value == 31960 )
return 58098;
else if (value == 31964 )
return 58100;
else if (value == 31966 )
return 38323;
else if (value == 31967 )
return 37260;
else if (value == 31968 )
return 36198;
else if (value == 31970 )
return 58101;
else if (value == 31975 )
return 38854;
else if (value == 31983 )
return 58103;
else if (value == 31986 )
return 58104;
else if (value == 31988 )
return 58105;
else if (value == 31990 )
return 58106;
else if (value == 31992 )
return 36485;
else if (value == 31994 )
return 58107;
}
else if (value <= 32027 ) {
if (value == 31995 )
return 35950;
else if (value == 31998 )
return 35722;
else if (value == 32000 )
return 35657;
else if (value == 32002 )
return 58176;
else if (value == 32004 )
return 38641;
else if (value == 32005 )
return 36199;
else if (value == 32006 )
return 58108;
else if (value == 32010 )
return 58179;
else if (value == 32011 )
return 38628;
else if (value == 32013 )
return 37979;
else if (value == 32016 )
return 38226;
else if (value == 32020 )
return 36739;
else if (value == 32021 )
return 58178;
else if (value == 32023 )
return 36561;
else if (value == 32024 )
return 36200;
else if (value == 32025 )
return 36486;
else if (value == 32026 )
return 35721;
else if (value == 32027 )
return 38324;
}
else if (value <= 32068 ) {
if (value == 32028 )
return 58177;
else if (value == 32032 )
return 37222;
else if (value == 32033 )
return 38497;
else if (value == 32034 )
return 36341;
else if (value == 32043 )
return 36487;
else if (value == 32044 )
return 37595;
else if (value == 32046 )
return 58182;
else if (value == 32047 )
return 38877;
else if (value == 32048 )
return 36311;
else if (value == 32050 )
return 58183;
else if (value == 32051 )
return 36961;
else if (value == 32053 )
return 58185;
else if (value == 32057 )
return 36816;
else if (value == 32058 )
return 36270;
else if (value == 32063 )
return 58184;
else if (value == 32066 )
return 36681;
else if (value == 32067 )
return 36028;
else if (value == 32068 )
return 37223;
}
else if (value <= 32114 ) {
if (value == 32069 )
return 58180;
else if (value == 32070 )
return 58186;
else if (value == 32075 )
return 58181;
else if (value == 32076 )
return 35951;
else if (value == 32078 )
return 58189;
else if (value == 32079 )
return 58193;
else if (value == 32080 )
return 35979;
else if (value == 32086 )
return 58188;
else if (value == 32091 )
return 58197;
else if (value == 32094 )
return 36201;
else if (value == 32097 )
return 38797;
else if (value == 32098 )
return 35002;
else if (value == 32099 )
return 58194;
else if (value == 32102 )
return 35723;
else if (value == 32104 )
return 58191;
else if (value == 32110 )
return 58192;
else if (value == 32113 )
return 37789;
else if (value == 32114 )
return 58190;
}
else if (value <= 32173 ) {
if (value == 32115 )
return 58187;
else if (value == 32117 )
return 35399;
else if (value == 32118 )
return 37090;
else if (value == 32121 )
return 36006;
else if (value == 32125 )
return 58199;
else if (value == 32137 )
return 58196;
else if (value == 32143 )
return 58198;
else if (value == 32147 )
return 58195;
else if (value == 32153 )
return 35952;
else if (value == 32154 )
return 37297;
else if (value == 32155 )
return 58200;
else if (value == 32156 )
return 37262;
else if (value == 32159 )
return 58213;
else if (value == 32162 )
return 58209;
else if (value == 32163 )
return 58203;
else if (value == 32171 )
return 58207;
else if (value == 32172 )
return 36600;
else if (value == 32173 )
return 35035;
}
else if (value <= 32209 ) {
if (value == 32174 )
return 58202;
else if (value == 32175 )
return 58210;
else if (value == 32176 )
return 58214;
else if (value == 32177 )
return 36202;
else if (value == 32178 )
return 38612;
else if (value == 32180 )
return 37588;
else if (value == 32181 )
return 58204;
else if (value == 32184 )
return 58212;
else if (value == 32186 )
return 58201;
else if (value == 32187 )
return 37469;
else if (value == 32189 )
return 58206;
else if (value == 32190 )
return 35003;
else if (value == 32191 )
return 38600;
else if (value == 32199 )
return 58205;
else if (value == 32202 )
return 35801;
else if (value == 32203 )
return 38122;
else if (value == 32207 )
return 37261;
else if (value == 32209 )
return 38862;
}
else if (value <= 32257 ) {
if (value == 32210 )
return 36751;
else if (value == 32213 )
return 58254;
else if (value == 32216 )
return 58215;
else if (value == 32218 )
return 37116;
else if (value == 32220 )
return 58211;
else if (value == 32221 )
return 58216;
else if (value == 32222 )
return 58218;
else if (value == 32224 )
return 37623;
else if (value == 32225 )
return 58221;
else if (value == 32228 )
return 58217;
else if (value == 32232 )
return 38354;
else if (value == 32233 )
return 35529;
else if (value == 32236 )
return 38601;
else if (value == 32239 )
return 35036;
else if (value == 32242 )
return 58220;
else if (value == 32244 )
return 38907;
else if (value == 32251 )
return 58219;
else if (value == 32257 )
return 35215;
}
else if (value <= 32309 ) {
if (value == 32260 )
return 37866;
else if (value == 32261 )
return 58222;
else if (value == 32265 )
return 58229;
else if (value == 32266 )
return 58223;
else if (value == 32267 )
return 58230;
else if (value == 32274 )
return 58226;
else if (value == 32283 )
return 38043;
else if (value == 32286 )
return 36552;
else if (value == 32287 )
return 58228;
else if (value == 32289 )
return 58225;
else if (value == 32290 )
return 58231;
else if (value == 32291 )
return 58224;
else if (value == 32294 )
return 36707;
else if (value == 32299 )
return 38468;
else if (value == 32302 )
return 36715;
else if (value == 32305 )
return 58227;
else if (value == 32306 )
return 58240;
else if (value == 32309 )
return 58235;
}
else if (value <= 32349 ) {
if (value == 32311 )
return 58238;
else if (value == 32313 )
return 58236;
else if (value == 32314 )
return 58241;
else if (value == 32315 )
return 58234;
else if (value == 32317 )
return 58208;
else if (value == 32318 )
return 37073;
else if (value == 32321 )
return 38089;
else if (value == 32323 )
return 58237;
else if (value == 32326 )
return 58232;
else if (value == 32330 )
return 37184;
else if (value == 32331 )
return 35953;
else if (value == 32333 )
return 36682;
else if (value == 32340 )
return 36932;
else if (value == 32341 )
return 37205;
else if (value == 32342 )
return 58244;
else if (value == 32345 )
return 58246;
else if (value == 32346 )
return 58247;
else if (value == 32349 )
return 58243;
}
else if (value <= 32398 ) {
if (value == 32350 )
return 58245;
else if (value == 32358 )
return 58233;
else if (value == 32359 )
return 58242;
else if (value == 32361 )
return 58250;
else if (value == 32362 )
return 58249;
else if (value == 32365 )
return 38554;
else if (value == 32368 )
return 35914;
else if (value == 32377 )
return 58248;
else if (value == 32379 )
return 58252;
else if (value == 32380 )
return 58251;
else if (value == 32381 )
return 58255;
else if (value == 32383 )
return 58257;
else if (value == 32386 )
return 36443;
else if (value == 32387 )
return 58253;
else if (value == 32392 )
return 58258;
else if (value == 32393 )
return 58259;
else if (value == 32396 )
return 58260;
else if (value == 32398 )
return 58266;
}
}
else if ( value >= 32399 && value <= 33378 ) {
if (value <= 32596 ) {
if (value == 32399 )
return 37722;
else if (value == 32400 )
return 58262;
else if (value == 32402 )
return 58261;
else if (value == 32403 )
return 58263;
else if (value == 32404 )
return 58264;
else if (value == 32406 )
return 58265;
else if (value == 32411 )
return 58267;
else if (value == 32412 )
return 58268;
else if (value == 32566 )
return 35530;
else if (value == 32568 )
return 58269;
else if (value == 32570 )
return 58270;
else if (value == 32581 )
return 58271;
else if (value == 32588 )
return 58272;
else if (value == 32589 )
return 58273;
else if (value == 32590 )
return 58274;
else if (value == 32592 )
return 58275;
else if (value == 32593 )
return 58276;
else if (value == 32596 )
return 58278;
}
else if (value <= 32643 ) {
if (value == 32597 )
return 58277;
else if (value == 32600 )
return 58279;
else if (value == 32607 )
return 58280;
else if (value == 32608 )
return 58281;
else if (value == 32615 )
return 58284;
else if (value == 32616 )
return 58282;
else if (value == 32617 )
return 58283;
else if (value == 32618 )
return 36319;
else if (value == 32619 )
return 35954;
else if (value == 32622 )
return 37493;
else if (value == 32624 )
return 38065;
else if (value == 32626 )
return 36752;
else if (value == 32629 )
return 37996;
else if (value == 32631 )
return 38123;
else if (value == 32632 )
return 58285;
else if (value == 32633 )
return 40171;
else if (value == 32642 )
return 58286;
else if (value == 32643 )
return 58288;
}
else if (value <= 32690 ) {
if (value == 32645 )
return 38789;
else if (value == 32646 )
return 58287;
else if (value == 32647 )
return 58290;
else if (value == 32648 )
return 58289;
else if (value == 32650 )
return 38770;
else if (value == 32652 )
return 58291;
else if (value == 32654 )
return 38140;
else if (value == 32660 )
return 58292;
else if (value == 32666 )
return 58295;
else if (value == 32669 )
return 58294;
else if (value == 32670 )
return 58293;
else if (value == 32675 )
return 58296;
else if (value == 32676 )
return 35921;
else if (value == 32680 )
return 37185;
else if (value == 32681 )
return 35680;
else if (value == 32686 )
return 58300;
else if (value == 32687 )
return 58297;
else if (value == 32690 )
return 58298;
}
else if (value <= 32752 ) {
if (value == 32694 )
return 58301;
else if (value == 32696 )
return 58302;
else if (value == 32697 )
return 58299;
else if (value == 32701 )
return 35144;
else if (value == 32705 )
return 35237;
else if (value == 32709 )
return 58304;
else if (value == 32710 )
return 58305;
else if (value == 32714 )
return 58306;
else if (value == 32716 )
return 38786;
else if (value == 32722 )
return 36683;
else if (value == 32724 )
return 58308;
else if (value == 32725 )
return 58307;
else if (value == 32736 )
return 37001;
else if (value == 32737 )
return 58309;
else if (value == 32742 )
return 58310;
else if (value == 32745 )
return 58311;
else if (value == 32747 )
return 35555;
else if (value == 32752 )
return 35531;
}
else if (value <= 32793 ) {
if (value == 32755 )
return 58312;
else if (value == 32761 )
return 58313;
else if (value == 32763 )
return 38524;
else if (value == 32764 )
return 38787;
else if (value == 32768 )
return 38771;
else if (value == 32769 )
return 38998;
else if (value == 32771 )
return 36204;
else if (value == 32772 )
return 58316;
else if (value == 32773 )
return 36562;
else if (value == 32774 )
return 58315;
else if (value == 32779 )
return 58317;
else if (value == 32780 )
return 36519;
else if (value == 32784 )
return 37327;
else if (value == 32786 )
return 58318;
else if (value == 32789 )
return 36203;
else if (value == 32791 )
return 38613;
else if (value == 32792 )
return 58319;
else if (value == 32793 )
return 58320;
}
else if (value <= 32866 ) {
if (value == 32796 )
return 58321;
else if (value == 32801 )
return 58322;
else if (value == 32808 )
return 58323;
else if (value == 32819 )
return 36520;
else if (value == 32822 )
return 38635;
else if (value == 32827 )
return 58325;
else if (value == 32829 )
return 37470;
else if (value == 32831 )
return 58324;
else if (value == 32838 )
return 58327;
else if (value == 32842 )
return 58326;
else if (value == 32850 )
return 58328;
else if (value == 32854 )
return 37049;
else if (value == 32856 )
return 58329;
else if (value == 32858 )
return 58330;
else if (value == 32862 )
return 38327;
else if (value == 32863 )
return 58331;
else if (value == 32865 )
return 37263;
else if (value == 32866 )
return 58332;
}
else if (value <= 32907 ) {
if (value == 32872 )
return 58333;
else if (value == 32879 )
return 38908;
else if (value == 32880 )
return 58336;
else if (value == 32882 )
return 58335;
else if (value == 32883 )
return 58334;
else if (value == 32884 )
return 37550;
else if (value == 32886 )
return 58337;
else if (value == 32887 )
return 36933;
else if (value == 32889 )
return 58338;
else if (value == 32893 )
return 58339;
else if (value == 32894 )
return 38999;
else if (value == 32895 )
return 58340;
else if (value == 32900 )
return 58341;
else if (value == 32901 )
return 58343;
else if (value == 32902 )
return 58342;
else if (value == 32903 )
return 38051;
else if (value == 32905 )
return 37879;
else if (value == 32907 )
return 39005;
}
else if (value <= 32948 ) {
if (value == 32908 )
return 38055;
else if (value == 32915 )
return 58345;
else if (value == 32918 )
return 36817;
else if (value == 32920 )
return 38217;
else if (value == 32922 )
return 58346;
else if (value == 32923 )
return 58344;
else if (value == 32925 )
return 35532;
else if (value == 32929 )
return 36050;
else if (value == 32930 )
return 36488;
else if (value == 32933 )
return 38124;
else if (value == 32937 )
return 36008;
else if (value == 32938 )
return 38498;
else if (value == 32940 )
return 58349;
else if (value == 32941 )
return 58347;
else if (value == 32943 )
return 36205;
else if (value == 32945 )
return 36206;
else if (value == 32946 )
return 35047;
else if (value == 32948 )
return 36326;
}
else if (value <= 33012 ) {
if (value == 32954 )
return 38008;
else if (value == 32963 )
return 35037;
else if (value == 32964 )
return 58354;
else if (value == 32966 )
return 37471;
else if (value == 32972 )
return 38007;
else if (value == 32974 )
return 37337;
else if (value == 32982 )
return 58356;
else if (value == 32985 )
return 58352;
else if (value == 32986 )
return 58355;
else if (value == 32987 )
return 58350;
else if (value == 32989 )
return 58353;
else if (value == 32990 )
return 38469;
else if (value == 32993 )
return 36051;
else if (value == 32996 )
return 35067;
else if (value == 32997 )
return 58351;
else if (value == 33007 )
return 58358;
else if (value == 33009 )
return 58359;
else if (value == 33012 )
return 37815;
}
else if (value <= 33081 ) {
if (value == 33016 )
return 35769;
else if (value == 33020 )
return 58437;
else if (value == 33021 )
return 37980;
else if (value == 33026 )
return 36489;
else if (value == 33029 )
return 35770;
else if (value == 33030 )
return 37062;
else if (value == 33031 )
return 39013;
else if (value == 33032 )
return 38572;
else if (value == 33033 )
return 58357;
else if (value == 33034 )
return 37074;
else if (value == 33050 )
return 35698;
else if (value == 33051 )
return 58360;
else if (value == 33059 )
return 58362;
else if (value == 33065 )
return 58361;
else if (value == 33071 )
return 58363;
else if (value == 33073 )
return 37445;
else if (value == 33075 )
return 37981;
else if (value == 33081 )
return 37551;
}
else if (value <= 33144 ) {
if (value == 33086 )
return 58434;
else if (value == 33094 )
return 58433;
else if (value == 33099 )
return 58364;
else if (value == 33102 )
return 36980;
else if (value == 33104 )
return 38277;
else if (value == 33105 )
return 58436;
else if (value == 33107 )
return 58435;
else if (value == 33108 )
return 36207;
else if (value == 33109 )
return 39026;
else if (value == 33119 )
return 58452;
else if (value == 33125 )
return 58440;
else if (value == 33126 )
return 58441;
else if (value == 33131 )
return 36590;
else if (value == 33134 )
return 58439;
else if (value == 33136 )
return 36248;
else if (value == 33137 )
return 58438;
else if (value == 33140 )
return 58442;
else if (value == 33144 )
return 37552;
}
else if (value <= 33192 ) {
if (value == 33145 )
return 38304;
else if (value == 33146 )
return 37186;
else if (value == 33151 )
return 37338;
else if (value == 33152 )
return 58446;
else if (value == 33154 )
return 58447;
else if (value == 33155 )
return 58443;
else if (value == 33160 )
return 58444;
else if (value == 33162 )
return 58445;
else if (value == 33167 )
return 36208;
else if (value == 33171 )
return 58453;
else if (value == 33173 )
return 58449;
else if (value == 33178 )
return 38278;
else if (value == 33180 )
return 38540;
else if (value == 33181 )
return 38215;
else if (value == 33184 )
return 58448;
else if (value == 33187 )
return 58451;
else if (value == 33188 )
return 58450;
else if (value == 33192 )
return 38499;
}
else if (value <= 33240 ) {
if (value == 33193 )
return 58454;
else if (value == 33200 )
return 58455;
else if (value == 33203 )
return 37206;
else if (value == 33205 )
return 58456;
else if (value == 33208 )
return 58458;
else if (value == 33210 )
return 58462;
else if (value == 33213 )
return 58459;
else if (value == 33214 )
return 58457;
else if (value == 33215 )
return 37982;
else if (value == 33216 )
return 58460;
else if (value == 33218 )
return 58461;
else if (value == 33222 )
return 35248;
else if (value == 33224 )
return 58468;
else if (value == 33225 )
return 58463;
else if (value == 33229 )
return 58464;
else if (value == 33233 )
return 58465;
else if (value == 33235 )
return 37279;
else if (value == 33240 )
return 58467;
}
else if (value <= 33282 ) {
if (value == 33241 )
return 58466;
else if (value == 33242 )
return 58469;
else if (value == 33247 )
return 58470;
else if (value == 33248 )
return 58471;
else if (value == 33251 )
return 36962;
else if (value == 33253 )
return 35303;
else if (value == 33255 )
return 58472;
else if (value == 33256 )
return 38869;
else if (value == 33258 )
return 36521;
else if (value == 33261 )
return 36684;
else if (value == 33267 )
return 36490;
else if (value == 33268 )
return 37494;
else if (value == 33274 )
return 58473;
else if (value == 33275 )
return 58474;
else if (value == 33276 )
return 35152;
else if (value == 33278 )
return 58475;
else if (value == 33281 )
return 58476;
else if (value == 33282 )
return 58477;
}
else if (value <= 33321 ) {
if (value == 33285 )
return 58478;
else if (value == 33287 )
return 58479;
else if (value == 33288 )
return 35771;
else if (value == 33289 )
return 40360;
else if (value == 33290 )
return 58480;
else if (value == 33292 )
return 37091;
else if (value == 33293 )
return 58481;
else if (value == 33294 )
return 36553;
else if (value == 33296 )
return 58482;
else if (value == 33298 )
return 39086;
else if (value == 33302 )
return 58483;
else if (value == 33303 )
return 38364;
else if (value == 33304 )
return 35546;
else if (value == 33307 )
return 37187;
else if (value == 33308 )
return 36727;
else if (value == 33310 )
return 38289;
else if (value == 33311 )
return 36685;
else if (value == 33321 )
return 58484;
}
else if (value <= 33378 ) {
if (value == 33322 )
return 36209;
else if (value == 33323 )
return 58485;
else if (value == 33324 )
return 38090;
else if (value == 33326 )
return 58500;
else if (value == 33331 )
return 58487;
else if (value == 33333 )
return 37319;
else if (value == 33334 )
return 38037;
else if (value == 33335 )
return 36029;
else if (value == 33336 )
return 58486;
else if (value == 33337 )
return 37188;
else if (value == 33344 )
return 58488;
else if (value == 33351 )
return 37624;
else if (value == 33368 )
return 58490;
else if (value == 33369 )
return 58489;
else if (value == 33370 )
return 58492;
else if (value == 33373 )
return 58491;
else if (value == 33375 )
return 58493;
else if (value == 33378 )
return 58496;
}
}
else if ( value >= 33380 && value <= 34367 ) {
if (value <= 33437 ) {
if (value == 33380 )
return 58494;
else if (value == 33382 )
return 35533;
else if (value == 33384 )
return 58497;
else if (value == 33386 )
return 58498;
else if (value == 33387 )
return 58499;
else if (value == 33390 )
return 36271;
else if (value == 33391 )
return 38855;
else if (value == 33393 )
return 58501;
else if (value == 33394 )
return 36934;
else if (value == 33398 )
return 35216;
else if (value == 33399 )
return 58502;
else if (value == 33400 )
return 58503;
else if (value == 33406 )
return 58504;
else if (value == 33419 )
return 35056;
else if (value == 33421 )
return 58505;
else if (value == 33426 )
return 58506;
else if (value == 33433 )
return 38279;
else if (value == 33437 )
return 36549;
}
else if (value <= 33492 ) {
if (value == 33439 )
return 58508;
else if (value == 33445 )
return 35400;
else if (value == 33446 )
return 34992;
else if (value == 33451 )
return 58507;
else if (value == 33452 )
return 58510;
else if (value == 33453 )
return 37997;
else if (value == 33455 )
return 36963;
else if (value == 33457 )
return 35284;
else if (value == 33459 )
return 38470;
else if (value == 33464 )
return 35964;
else if (value == 33465 )
return 35802;
else if (value == 33467 )
return 58509;
else if (value == 33469 )
return 35304;
else if (value == 33477 )
return 35489;
else if (value == 33489 )
return 35217;
else if (value == 33490 )
return 58514;
else if (value == 33491 )
return 38888;
else if (value == 33492 )
return 37339;
}
else if (value <= 33531 ) {
if (value == 33495 )
return 38243;
else if (value == 33497 )
return 58526;
else if (value == 33499 )
return 35285;
else if (value == 33500 )
return 58524;
else if (value == 33502 )
return 58522;
else if (value == 33503 )
return 58513;
else if (value == 33505 )
return 58511;
else if (value == 33507 )
return 58512;
else if (value == 33509 )
return 36577;
else if (value == 33510 )
return 35818;
else if (value == 33511 )
return 37527;
else if (value == 33515 )
return 37839;
else if (value == 33521 )
return 35184;
else if (value == 33523 )
return 58516;
else if (value == 33524 )
return 58515;
else if (value == 33529 )
return 58521;
else if (value == 33530 )
return 58517;
else if (value == 33531 )
return 58520;
}
else if (value <= 33588 ) {
if (value == 33538 )
return 38606;
else if (value == 33539 )
return 58519;
else if (value == 33540 )
return 35286;
else if (value == 33541 )
return 35485;
else if (value == 33542 )
return 58523;
else if (value == 33545 )
return 58525;
else if (value == 33550 )
return 35955;
else if (value == 33558 )
return 58529;
else if (value == 33559 )
return 58538;
else if (value == 33560 )
return 58539;
else if (value == 33564 )
return 34985;
else if (value == 33571 )
return 58546;
else if (value == 33576 )
return 35055;
else if (value == 33579 )
return 58537;
else if (value == 33583 )
return 58536;
else if (value == 33585 )
return 58531;
else if (value == 33586 )
return 58530;
else if (value == 33588 )
return 58528;
}
else if (value <= 33669 ) {
if (value == 33589 )
return 58527;
else if (value == 33590 )
return 37507;
else if (value == 33592 )
return 37369;
else if (value == 33593 )
return 58533;
else if (value == 33600 )
return 58532;
else if (value == 33605 )
return 58535;
else if (value == 33609 )
return 37264;
else if (value == 33610 )
return 35956;
else if (value == 33615 )
return 35168;
else if (value == 33616 )
return 58534;
else if (value == 33618 )
return 36210;
else if (value == 33624 )
return 37265;
else if (value == 33651 )
return 58552;
else if (value == 33653 )
return 58553;
else if (value == 33655 )
return 35287;
else if (value == 33659 )
return 35244;
else if (value == 33660 )
return 58550;
else if (value == 33669 )
return 58540;
}
else if (value <= 33729 ) {
if (value == 33671 )
return 58548;
else if (value == 33673 )
return 58555;
else if (value == 33674 )
return 58549;
else if (value == 33678 )
return 58547;
else if (value == 33683 )
return 58518;
else if (value == 33686 )
return 58545;
else if (value == 33690 )
return 58541;
else if (value == 33694 )
return 35534;
else if (value == 33695 )
return 58543;
else if (value == 33696 )
return 58554;
else if (value == 33698 )
return 58544;
else if (value == 33704 )
return 58556;
else if (value == 33706 )
return 58542;
else if (value == 33707 )
return 38044;
else if (value == 33713 )
return 38793;
else if (value == 33717 )
return 58551;
else if (value == 33725 )
return 58573;
else if (value == 33729 )
return 58565;
}
else if (value <= 33783 ) {
if (value == 33733 )
return 37019;
else if (value == 33738 )
return 35685;
else if (value == 33740 )
return 35803;
else if (value == 33742 )
return 58560;
else if (value == 33747 )
return 35289;
else if (value == 33750 )
return 36818;
else if (value == 33752 )
return 58563;
else if (value == 33756 )
return 36312;
else if (value == 33759 )
return 37744;
else if (value == 33760 )
return 58568;
else if (value == 33769 )
return 38380;
else if (value == 33771 )
return 58559;
else if (value == 33775 )
return 35288;
else if (value == 33776 )
return 36052;
else if (value == 33777 )
return 38216;
else if (value == 33778 )
return 58569;
else if (value == 33780 )
return 58557;
else if (value == 33783 )
return 58566;
}
else if (value <= 33848 ) {
if (value == 33787 )
return 58576;
else if (value == 33789 )
return 58561;
else if (value == 33795 )
return 58562;
else if (value == 33796 )
return 37816;
else if (value == 33799 )
return 58567;
else if (value == 33803 )
return 58564;
else if (value == 33804 )
return 38471;
else if (value == 33805 )
return 58570;
else if (value == 33806 )
return 35038;
else if (value == 33811 )
return 58558;
else if (value == 33824 )
return 58572;
else if (value == 33826 )
return 58571;
else if (value == 33833 )
return 38027;
else if (value == 33834 )
return 58578;
else if (value == 33836 )
return 58589;
else if (value == 33841 )
return 35486;
else if (value == 33845 )
return 58592;
else if (value == 33848 )
return 58574;
}
else if (value <= 33905 ) {
if (value == 33852 )
return 58579;
else if (value == 33853 )
return 38798;
else if (value == 33862 )
return 58588;
else if (value == 33865 )
return 38772;
else if (value == 33870 )
return 38824;
else if (value == 33879 )
return 37528;
else if (value == 33883 )
return 35467;
else if (value == 33889 )
return 38290;
else if (value == 33890 )
return 58594;
else if (value == 33891 )
return 37791;
else if (value == 33894 )
return 34991;
else if (value == 33897 )
return 58587;
else if (value == 33899 )
return 58583;
else if (value == 33900 )
return 37266;
else if (value == 33901 )
return 58577;
else if (value == 33902 )
return 58585;
else if (value == 33903 )
return 58590;
else if (value == 33905 )
return 37963;
}
else if (value <= 33979 ) {
if (value == 33909 )
return 34984;
else if (value == 33911 )
return 58582;
else if (value == 33913 )
return 58591;
else if (value == 33914 )
return 38296;
else if (value == 33922 )
return 58586;
else if (value == 33924 )
return 58581;
else if (value == 33931 )
return 36819;
else if (value == 33936 )
return 36686;
else if (value == 33940 )
return 36522;
else if (value == 33945 )
return 38614;
else if (value == 33948 )
return 38246;
else if (value == 33951 )
return 58597;
else if (value == 33953 )
return 58606;
else if (value == 33965 )
return 58584;
else if (value == 33970 )
return 35479;
else if (value == 33976 )
return 36854;
else if (value == 33977 )
return 58595;
else if (value == 33979 )
return 58600;
}
else if (value <= 34044 ) {
if (value == 33980 )
return 37267;
else if (value == 33983 )
return 58596;
else if (value == 33985 )
return 58603;
else if (value == 33988 )
return 37502;
else if (value == 33990 )
return 58604;
else if (value == 33993 )
return 38773;
else if (value == 33994 )
return 58593;
else if (value == 33995 )
return 35415;
else if (value == 33997 )
return 58599;
else if (value == 34000 )
return 58602;
else if (value == 34001 )
return 38570;
else if (value == 34006 )
return 58605;
else if (value == 34009 )
return 58598;
else if (value == 34010 )
return 58601;
else if (value == 34028 )
return 38472;
else if (value == 34030 )
return 38976;
else if (value == 34036 )
return 58609;
else if (value == 34044 )
return 58616;
}
else if (value <= 34112 ) {
if (value == 34047 )
return 58608;
else if (value == 34048 )
return 36545;
else if (value == 34054 )
return 58575;
else if (value == 34065 )
return 38348;
else if (value == 34067 )
return 38560;
else if (value == 34068 )
return 58615;
else if (value == 34069 )
return 58614;
else if (value == 34071 )
return 58610;
else if (value == 34072 )
return 58611;
else if (value == 34074 )
return 35157;
else if (value == 34079 )
return 58613;
else if (value == 34081 )
return 58607;
else if (value == 34086 )
return 37587;
else if (value == 34092 )
return 58612;
else if (value == 34093 )
return 35068;
else if (value == 34101 )
return 37280;
else if (value == 34109 )
return 38337;
else if (value == 34112 )
return 58617;
}
else if (value <= 34174 ) {
if (value == 34113 )
return 58688;
else if (value == 34115 )
return 38103;
else if (value == 34120 )
return 58620;
else if (value == 34121 )
return 36820;
else if (value == 34122 )
return 36551;
else if (value == 34123 )
return 58690;
else if (value == 34126 )
return 35772;
else if (value == 34133 )
return 58691;
else if (value == 34135 )
return 38297;
else if (value == 34136 )
return 58619;
else if (value == 34138 )
return 58580;
else if (value == 34147 )
return 58618;
else if (value == 34152 )
return 39022;
else if (value == 34153 )
return 37792;
else if (value == 34154 )
return 38291;
else if (value == 34157 )
return 58698;
else if (value == 34167 )
return 58704;
else if (value == 34174 )
return 58705;
}
else if (value <= 34219 ) {
if (value == 34176 )
return 58692;
else if (value == 34180 )
return 38038;
else if (value == 34183 )
return 58702;
else if (value == 34184 )
return 58694;
else if (value == 34186 )
return 58696;
else if (value == 34192 )
return 58706;
else if (value == 34193 )
return 58695;
else if (value == 34196 )
return 58699;
else if (value == 34199 )
return 35218;
else if (value == 34201 )
return 37859;
else if (value == 34203 )
return 58700;
else if (value == 34204 )
return 58703;
else if (value == 34212 )
return 58693;
else if (value == 34214 )
return 37189;
else if (value == 34216 )
return 58697;
else if (value == 34217 )
return 36422;
else if (value == 34218 )
return 36964;
else if (value == 34219 )
return 35919;
}
else if (value <= 34295 ) {
if (value == 34220 )
return 38642;
else if (value == 34222 )
return 38647;
else if (value == 34223 )
return 36754;
else if (value == 34233 )
return 58710;
else if (value == 34234 )
return 58708;
else if (value == 34241 )
return 39021;
else if (value == 34249 )
return 58707;
else if (value == 34253 )
return 38805;
else if (value == 34255 )
return 58709;
else if (value == 34256 )
return 58711;
else if (value == 34261 )
return 58712;
else if (value == 34268 )
return 58715;
else if (value == 34269 )
return 58713;
else if (value == 34276 )
return 37793;
else if (value == 34277 )
return 58714;
else if (value == 34281 )
return 38091;
else if (value == 34282 )
return 58701;
else if (value == 34295 )
return 36755;
}
else if (value <= 34367 ) {
if (value == 34297 )
return 58716;
else if (value == 34298 )
return 58721;
else if (value == 34299 )
return 37268;
else if (value == 34302 )
return 58720;
else if (value == 34306 )
return 58689;
else if (value == 34310 )
return 58722;
else if (value == 34311 )
return 37224;
else if (value == 34314 )
return 58717;
else if (value == 34315 )
return 58719;
else if (value == 34323 )
return 58718;
else if (value == 34326 )
return 40784;
else if (value == 34327 )
return 40769;
else if (value == 34330 )
return 58724;
else if (value == 34338 )
return 58723;
else if (value == 34349 )
return 38806;
else if (value == 34351 )
return 57786;
else if (value == 34352 )
return 58725;
else if (value == 34367 )
return 58726;
}
}
else if ( value >= 34381 && value <= 35382 ) {
if (value <= 34451 ) {
if (value == 34381 )
return 58727;
else if (value == 34382 )
return 36053;
else if (value == 34384 )
return 35699;
else if (value == 34388 )
return 58729;
else if (value == 34389 )
return 39292;
else if (value == 34394 )
return 35733;
else if (value == 34396 )
return 38840;
else if (value == 34398 )
return 35825;
else if (value == 34399 )
return 58730;
else if (value == 34407 )
return 58731;
else if (value == 34411 )
return 37518;
else if (value == 34417 )
return 58732;
else if (value == 34425 )
return 37880;
else if (value == 34427 )
return 35000;
else if (value == 34442 )
return 35297;
else if (value == 34443 )
return 58737;
else if (value == 34444 )
return 58738;
else if (value == 34451 )
return 58733;
}
else if (value <= 34521 ) {
if (value == 34453 )
return 36444;
else if (value == 34467 )
return 58734;
else if (value == 34468 )
return 37985;
else if (value == 34473 )
return 58735;
else if (value == 34474 )
return 58736;
else if (value == 34475 )
return 58746;
else if (value == 34479 )
return 58740;
else if (value == 34480 )
return 58743;
else if (value == 34486 )
return 58739;
else if (value == 34500 )
return 58741;
else if (value == 34502 )
return 58742;
else if (value == 34503 )
return 36566;
else if (value == 34505 )
return 58744;
else if (value == 34507 )
return 37472;
else if (value == 34509 )
return 35957;
else if (value == 34510 )
return 35425;
else if (value == 34516 )
return 58747;
else if (value == 34521 )
return 35422;
}
else if (value <= 34568 ) {
if (value == 34523 )
return 58753;
else if (value == 34526 )
return 58748;
else if (value == 34527 )
return 58752;
else if (value == 34532 )
return 38072;
else if (value == 34537 )
return 58749;
else if (value == 34540 )
return 58750;
else if (value == 34541 )
return 38247;
else if (value == 34542 )
return 38104;
else if (value == 34543 )
return 58754;
else if (value == 34552 )
return 37371;
else if (value == 34553 )
return 58764;
else if (value == 34555 )
return 58760;
else if (value == 34558 )
return 35305;
else if (value == 34560 )
return 58758;
else if (value == 34562 )
return 38473;
else if (value == 34563 )
return 58759;
else if (value == 34566 )
return 58756;
else if (value == 34568 )
return 58757;
}
else if (value <= 34638 ) {
if (value == 34569 )
return 58762;
else if (value == 34570 )
return 58765;
else if (value == 34573 )
return 58763;
else if (value == 34577 )
return 58761;
else if (value == 34578 )
return 58755;
else if (value == 34584 )
return 37495;
else if (value == 34586 )
return 58772;
else if (value == 34588 )
return 38568;
else if (value == 34597 )
return 58770;
else if (value == 34601 )
return 58771;
else if (value == 34612 )
return 58766;
else if (value == 34615 )
return 58768;
else if (value == 34619 )
return 58769;
else if (value == 34623 )
return 58767;
else if (value == 34633 )
return 37092;
else if (value == 34635 )
return 39000;
else if (value == 34636 )
return 58776;
else if (value == 34638 )
return 58777;
}
else if (value <= 34719 ) {
if (value == 34643 )
return 58783;
else if (value == 34645 )
return 36937;
else if (value == 34647 )
return 58779;
else if (value == 34649 )
return 58782;
else if (value == 34655 )
return 58774;
else if (value == 34656 )
return 58773;
else if (value == 34659 )
return 58784;
else if (value == 34662 )
return 35290;
else if (value == 34664 )
return 58780;
else if (value == 34666 )
return 58785;
else if (value == 34670 )
return 58781;
else if (value == 34676 )
return 58778;
else if (value == 34678 )
return 37553;
else if (value == 34680 )
return 58775;
else if (value == 34687 )
return 38024;
else if (value == 34690 )
return 58789;
else if (value == 34701 )
return 38746;
else if (value == 34719 )
return 58788;
}
else if (value <= 34806 ) {
if (value == 34722 )
return 58787;
else if (value == 34731 )
return 58796;
else if (value == 34735 )
return 58790;
else if (value == 34739 )
return 58798;
else if (value == 34746 )
return 38790;
else if (value == 34747 )
return 58801;
else if (value == 34749 )
return 58792;
else if (value == 34752 )
return 58793;
else if (value == 34756 )
return 58797;
else if (value == 34758 )
return 58800;
else if (value == 34759 )
return 58799;
else if (value == 34763 )
return 58791;
else if (value == 34768 )
return 58794;
else if (value == 34770 )
return 58811;
else if (value == 34784 )
return 58804;
else if (value == 34799 )
return 58802;
else if (value == 34802 )
return 58803;
else if (value == 34806 )
return 58808;
}
else if (value <= 34873 ) {
if (value == 34807 )
return 58809;
else if (value == 34809 )
return 35401;
else if (value == 34811 )
return 35681;
else if (value == 34814 )
return 58807;
else if (value == 34821 )
return 58786;
else if (value == 34829 )
return 58806;
else if (value == 34830 )
return 58810;
else if (value == 34831 )
return 58805;
else if (value == 34833 )
return 58812;
else if (value == 34837 )
return 58814;
else if (value == 34838 )
return 58813;
else if (value == 34849 )
return 58816;
else if (value == 34850 )
return 58815;
else if (value == 34851 )
return 58745;
else if (value == 34855 )
return 58820;
else if (value == 34865 )
return 58817;
else if (value == 34870 )
return 58818;
else if (value == 34873 )
return 58819;
}
else if (value <= 34920 ) {
if (value == 34875 )
return 58821;
else if (value == 34880 )
return 35980;
else if (value == 34882 )
return 58823;
else if (value == 34884 )
return 58822;
else if (value == 34886 )
return 36687;
else if (value == 34892 )
return 36211;
else if (value == 34893 )
return 40869;
else if (value == 34898 )
return 58824;
else if (value == 34899 )
return 36720;
else if (value == 34903 )
return 35416;
else if (value == 34905 )
return 58825;
else if (value == 34907 )
return 35185;
else if (value == 34909 )
return 36821;
else if (value == 34910 )
return 58826;
else if (value == 34913 )
return 36212;
else if (value == 34914 )
return 58827;
else if (value == 34915 )
return 35039;
else if (value == 34920 )
return 38236;
}
else if (value <= 34974 ) {
if (value == 34923 )
return 58828;
else if (value == 34928 )
return 37002;
else if (value == 34930 )
return 58835;
else if (value == 34933 )
return 58832;
else if (value == 34935 )
return 37519;
else if (value == 34941 )
return 58833;
else if (value == 34942 )
return 58830;
else if (value == 34943 )
return 35804;
else if (value == 34945 )
return 58829;
else if (value == 34946 )
return 58836;
else if (value == 34952 )
return 35925;
else if (value == 34955 )
return 37340;
else if (value == 34957 )
return 58842;
else if (value == 34962 )
return 58838;
else if (value == 34966 )
return 37299;
else if (value == 34967 )
return 58837;
else if (value == 34969 )
return 58840;
else if (value == 34974 )
return 58831;
}
else if (value <= 35029 ) {
if (value == 34978 )
return 58841;
else if (value == 34980 )
return 58843;
else if (value == 34987 )
return 38125;
else if (value == 34990 )
return 58839;
else if (value == 34992 )
return 58844;
else if (value == 34993 )
return 58846;
else if (value == 34996 )
return 36049;
else if (value == 34997 )
return 58834;
else if (value == 34999 )
return 35007;
else if (value == 35007 )
return 58845;
else if (value == 35009 )
return 36313;
else if (value == 35010 )
return 38900;
else if (value == 35011 )
return 58847;
else if (value == 35012 )
return 58848;
else if (value == 35013 )
return 37269;
else if (value == 35023 )
return 38816;
else if (value == 35028 )
return 58849;
else if (value == 35029 )
return 38740;
}
else if (value <= 35079 ) {
if (value == 35032 )
return 58850;
else if (value == 35033 )
return 58851;
else if (value == 35036 )
return 38370;
else if (value == 35037 )
return 58852;
else if (value == 35039 )
return 36286;
else if (value == 35041 )
return 38817;
else if (value == 35048 )
return 58857;
else if (value == 35058 )
return 58858;
else if (value == 35059 )
return 36822;
else if (value == 35060 )
return 58856;
else if (value == 35064 )
return 38791;
else if (value == 35065 )
return 58853;
else if (value == 35068 )
return 58855;
else if (value == 35069 )
return 37051;
else if (value == 35070 )
return 37022;
else if (value == 35074 )
return 58854;
else if (value == 35076 )
return 58859;
else if (value == 35079 )
return 38305;
}
else if (value <= 35149 ) {
if (value == 35082 )
return 58861;
else if (value == 35084 )
return 58860;
else if (value == 35088 )
return 35468;
else if (value == 35090 )
return 38474;
else if (value == 35091 )
return 58862;
else if (value == 35101 )
return 58874;
else if (value == 35102 )
return 58864;
else if (value == 35109 )
return 58865;
else if (value == 35114 )
return 58866;
else if (value == 35115 )
return 58867;
else if (value == 35126 )
return 58871;
else if (value == 35128 )
return 58872;
else if (value == 35131 )
return 58870;
else if (value == 35137 )
return 58868;
else if (value == 35139 )
return 58863;
else if (value == 35140 )
return 58869;
else if (value == 35148 )
return 58873;
else if (value == 35149 )
return 59573;
}
else if (value <= 35207 ) {
if (value == 35158 )
return 35238;
else if (value == 35166 )
return 58876;
else if (value == 35167 )
return 35805;
else if (value == 35168 )
return 58875;
else if (value == 35172 )
return 58945;
else if (value == 35174 )
return 58944;
else if (value == 35178 )
return 58947;
else if (value == 35181 )
return 58946;
else if (value == 35183 )
return 58948;
else if (value == 35186 )
return 36688;
else if (value == 35188 )
return 58949;
else if (value == 35191 )
return 58950;
else if (value == 35198 )
return 58951;
else if (value == 35199 )
return 37052;
else if (value == 35201 )
return 38774;
else if (value == 35203 )
return 58952;
else if (value == 35206 )
return 38306;
else if (value == 35207 )
return 37989;
}
else if (value <= 35251 ) {
if (value == 35208 )
return 58953;
else if (value == 35210 )
return 58954;
else if (value == 35211 )
return 36009;
else if (value == 35215 )
return 35659;
else if (value == 35219 )
return 58955;
else if (value == 35222 )
return 36491;
else if (value == 35223 )
return 37984;
else if (value == 35224 )
return 58956;
else if (value == 35226 )
return 35439;
else if (value == 35233 )
return 58957;
else if (value == 35238 )
return 58959;
else if (value == 35239 )
return 38807;
else if (value == 35241 )
return 58958;
else if (value == 35242 )
return 36965;
else if (value == 35244 )
return 58960;
else if (value == 35247 )
return 58961;
else if (value == 35250 )
return 58962;
else if (value == 35251 )
return 35535;
}
else if (value <= 35338 ) {
if (value == 35258 )
return 58963;
else if (value == 35261 )
return 58964;
else if (value == 35263 )
return 58965;
else if (value == 35264 )
return 58966;
else if (value == 35282 )
return 35440;
else if (value == 35290 )
return 58967;
else if (value == 35292 )
return 58968;
else if (value == 35293 )
return 58969;
else if (value == 35299 )
return 35312;
else if (value == 35302 )
return 36935;
else if (value == 35303 )
return 58970;
else if (value == 35316 )
return 58971;
else if (value == 35320 )
return 58972;
else if (value == 35328 )
return 36030;
else if (value == 35330 )
return 37625;
else if (value == 35331 )
return 58973;
else if (value == 35336 )
return 35958;
else if (value == 35338 )
return 36981;
}
else if (value <= 35382 ) {
if (value == 35340 )
return 58976;
else if (value == 35342 )
return 37794;
else if (value == 35344 )
return 58975;
else if (value == 35347 )
return 35920;
else if (value == 35350 )
return 58974;
else if (value == 35351 )
return 37365;
else if (value == 35352 )
return 35660;
else if (value == 35355 )
return 58977;
else if (value == 35357 )
return 58978;
else if (value == 35359 )
return 36823;
else if (value == 35363 )
return 35981;
else if (value == 35365 )
return 58979;
else if (value == 35370 )
return 38475;
else if (value == 35373 )
return 37085;
else if (value == 35377 )
return 35734;
else if (value == 35379 )
return 38643;
else if (value == 35380 )
return 37225;
else if (value == 35382 )
return 58980;
}
}
else if ( value >= 35386 && value <= 36426 ) {
if (value <= 35433 ) {
if (value == 35386 )
return 36966;
else if (value == 35387 )
return 37520;
else if (value == 35388 )
return 36824;
else if (value == 35393 )
return 58981;
else if (value == 35398 )
return 58984;
else if (value == 35400 )
return 58985;
else if (value == 35408 )
return 36284;
else if (value == 35409 )
return 37312;
else if (value == 35410 )
return 58983;
else if (value == 35412 )
return 36825;
else if (value == 35413 )
return 38237;
else if (value == 35419 )
return 58982;
else if (value == 35422 )
return 36492;
else if (value == 35424 )
return 35186;
else if (value == 35426 )
return 58989;
else if (value == 35427 )
return 35959;
else if (value == 35430 )
return 36494;
else if (value == 35433 )
return 36493;
}
else if (value <= 35475 ) {
if (value == 35435 )
return 39020;
else if (value == 35436 )
return 58988;
else if (value == 35437 )
return 58987;
else if (value == 35438 )
return 37190;
else if (value == 35440 )
return 35692;
else if (value == 35441 )
return 39010;
else if (value == 35442 )
return 35417;
else if (value == 35443 )
return 36826;
else if (value == 35452 )
return 58986;
else if (value == 35458 )
return 58991;
else if (value == 35460 )
return 58992;
else if (value == 35461 )
return 58990;
else if (value == 35463 )
return 36054;
else if (value == 35465 )
return 38751;
else if (value == 35468 )
return 36495;
else if (value == 35469 )
return 37958;
else if (value == 35473 )
return 58995;
else if (value == 35475 )
return 37054;
}
else if (value <= 35519 ) {
if (value == 35477 )
return 37473;
else if (value == 35480 )
return 38741;
else if (value == 35482 )
return 58998;
else if (value == 35486 )
return 36074;
else if (value == 35488 )
return 37053;
else if (value == 35489 )
return 58994;
else if (value == 35491 )
return 58999;
else if (value == 35492 )
return 36075;
else if (value == 35493 )
return 58996;
else if (value == 35494 )
return 58997;
else if (value == 35496 )
return 58993;
else if (value == 35500 )
return 37088;
else if (value == 35501 )
return 37831;
else if (value == 35504 )
return 37454;
else if (value == 35506 )
return 35291;
else if (value == 35513 )
return 38126;
else if (value == 35516 )
return 35682;
else if (value == 35519 )
return 37554;
}
else if (value <= 35558 ) {
if (value == 35522 )
return 59002;
else if (value == 35524 )
return 59000;
else if (value == 35527 )
return 37483;
else if (value == 35531 )
return 37055;
else if (value == 35532 )
return 35536;
else if (value == 35533 )
return 59001;
else if (value == 35535 )
return 36986;
else if (value == 35538 )
return 38856;
else if (value == 35542 )
return 39007;
else if (value == 35546 )
return 59003;
else if (value == 35547 )
return 59015;
else if (value == 35548 )
return 37555;
else if (value == 35550 )
return 59014;
else if (value == 35552 )
return 59011;
else if (value == 35553 )
return 59019;
else if (value == 35554 )
return 59012;
else if (value == 35556 )
return 59008;
else if (value == 35558 )
return 37626;
}
else if (value <= 35600 ) {
if (value == 35559 )
return 59006;
else if (value == 35563 )
return 59004;
else if (value == 35565 )
return 38720;
else if (value == 35566 )
return 36496;
else if (value == 35569 )
return 59009;
else if (value == 35571 )
return 59005;
else if (value == 35575 )
return 59013;
else if (value == 35576 )
return 36756;
else if (value == 35578 )
return 36031;
else if (value == 35582 )
return 37368;
else if (value == 35584 )
return 38500;
else if (value == 35585 )
return 35193;
else if (value == 35586 )
return 35040;
else if (value == 35588 )
return 37795;
else if (value == 35591 )
return 59017;
else if (value == 35596 )
return 59016;
else if (value == 35598 )
return 37860;
else if (value == 35600 )
return 59021;
}
else if (value <= 35657 ) {
if (value == 35604 )
return 59010;
else if (value == 35606 )
return 59020;
else if (value == 35607 )
return 59022;
else if (value == 35609 )
return 36010;
else if (value == 35610 )
return 59018;
else if (value == 35611 )
return 36213;
else if (value == 35613 )
return 36563;
else if (value == 35616 )
return 59023;
else if (value == 35617 )
return 38775;
else if (value == 35622 )
return 59026;
else if (value == 35624 )
return 59029;
else if (value == 35627 )
return 59027;
else if (value == 35628 )
return 38228;
else if (value == 35635 )
return 59024;
else if (value == 35641 )
return 35806;
else if (value == 35646 )
return 59028;
else if (value == 35649 )
return 59030;
else if (value == 35657 )
return 59034;
}
else if (value <= 35703 ) {
if (value == 35660 )
return 59031;
else if (value == 35662 )
return 59033;
else if (value == 35663 )
return 59032;
else if (value == 35670 )
return 59035;
else if (value == 35672 )
return 36527;
else if (value == 35674 )
return 59037;
else if (value == 35675 )
return 59036;
else if (value == 35676 )
return 38280;
else if (value == 35679 )
return 59039;
else if (value == 35686 )
return 35960;
else if (value == 35691 )
return 59038;
else if (value == 35692 )
return 59040;
else if (value == 35695 )
return 59041;
else if (value == 35696 )
return 35683;
else if (value == 35697 )
return 58303;
else if (value == 35698 )
return 36855;
else if (value == 35700 )
return 59042;
else if (value == 35703 )
return 36076;
}
else if (value <= 35912 ) {
if (value == 35709 )
return 59043;
else if (value == 35712 )
return 59044;
else if (value == 35715 )
return 36445;
else if (value == 35722 )
return 40396;
else if (value == 35724 )
return 59045;
else if (value == 35726 )
return 59046;
else if (value == 35728 )
return 36689;
else if (value == 35730 )
return 59047;
else if (value == 35731 )
return 59048;
else if (value == 35734 )
return 59049;
else if (value == 35737 )
return 59050;
else if (value == 35738 )
return 59051;
else if (value == 35895 )
return 37450;
else if (value == 35898 )
return 59052;
else if (value == 35903 )
return 59054;
else if (value == 35905 )
return 59053;
else if (value == 35910 )
return 37796;
else if (value == 35912 )
return 59055;
}
else if (value <= 35977 ) {
if (value == 35914 )
return 38476;
else if (value == 35916 )
return 59056;
else if (value == 35918 )
return 59057;
else if (value == 35920 )
return 59058;
else if (value == 35925 )
return 59059;
else if (value == 35930 )
return 37848;
else if (value == 35937 )
return 36827;
else if (value == 35938 )
return 59060;
else if (value == 35946 )
return 36235;
else if (value == 35947 )
return 39084;
else if (value == 35948 )
return 59061;
else if (value == 35960 )
return 59062;
else if (value == 35961 )
return 38238;
else if (value == 35962 )
return 59063;
else if (value == 35964 )
return 59071;
else if (value == 35970 )
return 59064;
else if (value == 35973 )
return 59066;
else if (value == 35977 )
return 59065;
}
else if (value <= 36013 ) {
if (value == 35978 )
return 59067;
else if (value == 35980 )
return 38501;
else if (value == 35981 )
return 59068;
else if (value == 35982 )
return 59069;
else if (value == 35988 )
return 59070;
else if (value == 35992 )
return 59072;
else if (value == 35997 )
return 35404;
else if (value == 35998 )
return 37605;
else if (value == 36000 )
return 38281;
else if (value == 36001 )
return 36320;
else if (value == 36002 )
return 36214;
else if (value == 36007 )
return 38254;
else if (value == 36008 )
return 35293;
else if (value == 36009 )
return 38092;
else if (value == 36010 )
return 59075;
else if (value == 36011 )
return 35537;
else if (value == 36012 )
return 37075;
else if (value == 36013 )
return 59074;
}
else if (value <= 36036 ) {
if (value == 36014 )
return 59079;
else if (value == 36015 )
return 37529;
else if (value == 36016 )
return 38625;
else if (value == 36018 )
return 59077;
else if (value == 36019 )
return 59078;
else if (value == 36020 )
return 35661;
else if (value == 36022 )
return 59080;
else if (value == 36023 )
return 38019;
else if (value == 36024 )
return 37341;
else if (value == 36027 )
return 38127;
else if (value == 36028 )
return 37724;
else if (value == 36029 )
return 59076;
else if (value == 36031 )
return 38502;
else if (value == 36032 )
return 35306;
else if (value == 36033 )
return 59082;
else if (value == 36034 )
return 38983;
else if (value == 36035 )
return 37568;
else if (value == 36036 )
return 39012;
}
else if (value <= 36077 ) {
if (value == 36039 )
return 36497;
else if (value == 36040 )
return 59081;
else if (value == 36042 )
return 37295;
else if (value == 36045 )
return 59098;
else if (value == 36046 )
return 37191;
else if (value == 36049 )
return 37878;
else if (value == 36051 )
return 38255;
else if (value == 36058 )
return 59085;
else if (value == 36059 )
return 36446;
else if (value == 36060 )
return 36498;
else if (value == 36062 )
return 36828;
else if (value == 36064 )
return 38021;
else if (value == 36066 )
return 36011;
else if (value == 36067 )
return 59084;
else if (value == 36068 )
return 59083;
else if (value == 36070 )
return 38282;
else if (value == 36074 )
return 36543;
else if (value == 36077 )
return 37745;
}
else if (value <= 36198 ) {
if (value == 36090 )
return 59087;
else if (value == 36091 )
return 59088;
else if (value == 36092 )
return 36215;
else if (value == 36093 )
return 59086;
else if (value == 36100 )
return 59089;
else if (value == 36101 )
return 59090;
else if (value == 36103 )
return 59092;
else if (value == 36104 )
return 37281;
else if (value == 36106 )
return 59091;
else if (value == 36107 )
return 35556;
else if (value == 36109 )
return 59094;
else if (value == 36111 )
return 59093;
else if (value == 36112 )
return 59095;
else if (value == 36115 )
return 59097;
else if (value == 36116 )
return 59099;
else if (value == 36118 )
return 59100;
else if (value == 36196 )
return 37076;
else if (value == 36198 )
return 36557;
}
else if (value <= 36290 ) {
if (value == 36199 )
return 59101;
else if (value == 36203 )
return 35441;
else if (value == 36205 )
return 59102;
else if (value == 36208 )
return 37270;
else if (value == 36209 )
return 59103;
else if (value == 36211 )
return 59104;
else if (value == 36212 )
return 38283;
else if (value == 36215 )
return 35662;
else if (value == 36225 )
return 59105;
else if (value == 36229 )
return 37556;
else if (value == 36234 )
return 35194;
else if (value == 36249 )
return 59106;
else if (value == 36259 )
return 36591;
else if (value == 36264 )
return 37014;
else if (value == 36275 )
return 37291;
else if (value == 36282 )
return 59109;
else if (value == 36286 )
return 59108;
else if (value == 36290 )
return 59107;
}
else if (value <= 36351 ) {
if (value == 36299 )
return 59115;
else if (value == 36300 )
return 59113;
else if (value == 36303 )
return 59110;
else if (value == 36310 )
return 59112;
else if (value == 36314 )
return 59111;
else if (value == 36315 )
return 59114;
else if (value == 36317 )
return 35735;
else if (value == 36319 )
return 59118;
else if (value == 36321 )
return 37077;
else if (value == 36323 )
return 59119;
else if (value == 36328 )
return 36055;
else if (value == 36330 )
return 59116;
else if (value == 36331 )
return 59117;
else if (value == 36335 )
return 38984;
else if (value == 36339 )
return 37557;
else if (value == 36341 )
return 37192;
else if (value == 36348 )
return 59120;
else if (value == 36351 )
return 59123;
}
else if (value <= 36426 ) {
if (value == 36360 )
return 59121;
else if (value == 36361 )
return 59122;
else if (value == 36362 )
return 38776;
else if (value == 36367 )
return 37797;
else if (value == 36368 )
return 59126;
else if (value == 36381 )
return 59124;
else if (value == 36382 )
return 59125;
else if (value == 36383 )
return 59127;
else if (value == 36394 )
return 59208;
else if (value == 36400 )
return 59130;
else if (value == 36404 )
return 59131;
else if (value == 36405 )
return 59129;
else if (value == 36418 )
return 59128;
else if (value == 36420 )
return 37627;
else if (value == 36423 )
return 59200;
else if (value == 36424 )
return 59204;
else if (value == 36425 )
return 59201;
else if (value == 36426 )
return 59132;
}
}
else if ( value >= 36428 && value <= 37327 ) {
if (value <= 36491 ) {
if (value == 36428 )
return 59202;
else if (value == 36432 )
return 59203;
else if (value == 36437 )
return 59210;
else if (value == 36441 )
return 59205;
else if (value == 36447 )
return 37078;
else if (value == 36448 )
return 59207;
else if (value == 36451 )
return 59209;
else if (value == 36452 )
return 59206;
else if (value == 36466 )
return 59212;
else if (value == 36468 )
return 36690;
else if (value == 36470 )
return 59211;
else if (value == 36476 )
return 59213;
else if (value == 36481 )
return 59214;
else if (value == 36484 )
return 59217;
else if (value == 36485 )
return 59216;
else if (value == 36487 )
return 59215;
else if (value == 36490 )
return 59219;
else if (value == 36491 )
return 59218;
}
else if (value <= 36555 ) {
if (value == 36493 )
return 38644;
else if (value == 36497 )
return 59221;
else if (value == 36499 )
return 59220;
else if (value == 36500 )
return 59222;
else if (value == 36505 )
return 59223;
else if (value == 36513 )
return 59225;
else if (value == 36522 )
return 59224;
else if (value == 36523 )
return 36967;
else if (value == 36524 )
return 59226;
else if (value == 36527 )
return 35819;
else if (value == 36528 )
return 59227;
else if (value == 36529 )
return 59229;
else if (value == 36542 )
return 59230;
else if (value == 36549 )
return 59231;
else if (value == 36550 )
return 59228;
else if (value == 36552 )
return 59232;
else if (value == 36554 )
return 36564;
else if (value == 36555 )
return 59233;
}
else if (value <= 36620 ) {
if (value == 36556 )
return 35663;
else if (value == 36557 )
return 35922;
else if (value == 36562 )
return 36012;
else if (value == 36571 )
return 59234;
else if (value == 36575 )
return 37870;
else if (value == 36578 )
return 37725;
else if (value == 36579 )
return 59235;
else if (value == 36587 )
return 59238;
else if (value == 36600 )
return 36530;
else if (value == 36603 )
return 59237;
else if (value == 36604 )
return 59236;
else if (value == 36605 )
return 35961;
else if (value == 36606 )
return 59239;
else if (value == 36611 )
return 35442;
else if (value == 36613 )
return 59241;
else if (value == 36617 )
return 36314;
else if (value == 36618 )
return 59240;
else if (value == 36620 )
return 59249;
}
else if (value <= 36670 ) {
if (value == 36626 )
return 59243;
else if (value == 36627 )
return 59245;
else if (value == 36628 )
return 38371;
else if (value == 36629 )
return 59242;
else if (value == 36633 )
return 59244;
else if (value == 36635 )
return 59248;
else if (value == 36636 )
return 59246;
else if (value == 36637 )
return 35664;
else if (value == 36639 )
return 59247;
else if (value == 36646 )
return 59250;
else if (value == 36649 )
return 38009;
else if (value == 36650 )
return 38870;
else if (value == 36655 )
return 36691;
else if (value == 36659 )
return 59251;
else if (value == 36664 )
return 38721;
else if (value == 36665 )
return 59253;
else if (value == 36667 )
return 59252;
else if (value == 36670 )
return 59256;
}
else if (value <= 36764 ) {
if (value == 36671 )
return 38752;
else if (value == 36674 )
return 59255;
else if (value == 36676 )
return 35469;
else if (value == 36677 )
return 59254;
else if (value == 36678 )
return 59259;
else if (value == 36681 )
return 59258;
else if (value == 36684 )
return 59257;
else if (value == 36685 )
return 37713;
else if (value == 36686 )
return 59260;
else if (value == 36695 )
return 59261;
else if (value == 36700 )
return 59262;
else if (value == 36703 )
return 36236;
else if (value == 36705 )
return 35908;
else if (value == 36706 )
return 59264;
else if (value == 36707 )
return 59265;
else if (value == 36708 )
return 59266;
else if (value == 36763 )
return 36968;
else if (value == 36764 )
return 59267;
}
else if (value <= 36804 ) {
if (value == 36766 )
return 36523;
else if (value == 36767 )
return 59268;
else if (value == 36771 )
return 59269;
else if (value == 36775 )
return 39327;
else if (value == 36776 )
return 39326;
else if (value == 36781 )
return 59270;
else if (value == 36782 )
return 58256;
else if (value == 36783 )
return 59271;
else if (value == 36784 )
return 37443;
else if (value == 36785 )
return 36938;
else if (value == 36786 )
return 37983;
else if (value == 36791 )
return 59272;
else if (value == 36794 )
return 38355;
else if (value == 36795 )
return 37586;
else if (value == 36796 )
return 36254;
else if (value == 36799 )
return 37448;
else if (value == 36802 )
return 35145;
else if (value == 36804 )
return 38552;
}
else if (value <= 36857 ) {
if (value == 36805 )
return 36982;
else if (value == 36814 )
return 35965;
else if (value == 36817 )
return 35807;
else if (value == 36820 )
return 38356;
else if (value == 36826 )
return 59273;
else if (value == 36834 )
return 59275;
else if (value == 36837 )
return 59274;
else if (value == 36838 )
return 35294;
else if (value == 36841 )
return 37876;
else if (value == 36842 )
return 59276;
else if (value == 36843 )
return 38039;
else if (value == 36845 )
return 37714;
else if (value == 36847 )
return 59277;
else if (value == 36848 )
return 36721;
else if (value == 36852 )
return 59279;
else if (value == 36855 )
return 38592;
else if (value == 36856 )
return 59294;
else if (value == 36857 )
return 59281;
}
else if (value <= 36887 ) {
if (value == 36858 )
return 59282;
else if (value == 36861 )
return 37575;
else if (value == 36864 )
return 37342;
else if (value == 36865 )
return 37271;
else if (value == 36867 )
return 37798;
else if (value == 36869 )
return 59280;
else if (value == 36870 )
return 35700;
else if (value == 36875 )
return 59289;
else if (value == 36877 )
return 59286;
else if (value == 36878 )
return 59299;
else if (value == 36879 )
return 37799;
else if (value == 36880 )
return 37504;
else if (value == 36881 )
return 59283;
else if (value == 36883 )
return 37628;
else if (value == 36884 )
return 37746;
else if (value == 36885 )
return 59284;
else if (value == 36886 )
return 59288;
else if (value == 36887 )
return 36992;
}
else if (value <= 36924 ) {
if (value == 36889 )
return 38023;
else if (value == 36890 )
return 37578;
else if (value == 36893 )
return 37056;
else if (value == 36894 )
return 59287;
else if (value == 36895 )
return 37292;
else if (value == 36896 )
return 37282;
else if (value == 36897 )
return 59285;
else if (value == 36898 )
return 34983;
else if (value == 36899 )
return 38977;
else if (value == 36903 )
return 59290;
else if (value == 36910 )
return 37343;
else if (value == 36913 )
return 36692;
else if (value == 36914 )
return 36969;
else if (value == 36917 )
return 59292;
else if (value == 36918 )
return 59291;
else if (value == 36920 )
return 35053;
else if (value == 36921 )
return 59293;
else if (value == 36924 )
return 38222;
}
else if (value <= 36950 ) {
if (value == 36926 )
return 59301;
else if (value == 36929 )
return 37849;
else if (value == 36930 )
return 37003;
else if (value == 36933 )
return 37496;
else if (value == 36935 )
return 35830;
else if (value == 36937 )
return 59300;
else if (value == 36938 )
return 38742;
else if (value == 36939 )
return 35166;
else if (value == 36941 )
return 38357;
else if (value == 36942 )
return 35295;
else if (value == 36943 )
return 59295;
else if (value == 36944 )
return 59296;
else if (value == 36945 )
return 59297;
else if (value == 36946 )
return 59298;
else if (value == 36947 )
return 37817;
else if (value == 36948 )
return 37442;
else if (value == 36949 )
return 35041;
else if (value == 36950 )
return 59302;
}
else if (value <= 36984 ) {
if (value == 36952 )
return 59303;
else if (value == 36953 )
return 60065;
else if (value == 36956 )
return 37307;
else if (value == 36958 )
return 59304;
else if (value == 36960 )
return 35219;
else if (value == 36961 )
return 37227;
else if (value == 36963 )
return 36013;
else if (value == 36965 )
return 38777;
else if (value == 36968 )
return 59305;
else if (value == 36969 )
return 37707;
else if (value == 36973 )
return 37272;
else if (value == 36974 )
return 36565;
else if (value == 36975 )
return 59306;
else if (value == 36978 )
return 59309;
else if (value == 36981 )
return 36741;
else if (value == 36982 )
return 59307;
else if (value == 36983 )
return 37194;
else if (value == 36984 )
return 37193;
}
else if (value <= 37034 ) {
if (value == 36986 )
return 35042;
else if (value == 36988 )
return 38857;
else if (value == 36989 )
return 59311;
else if (value == 36991 )
return 38128;
else if (value == 36992 )
return 59313;
else if (value == 36993 )
return 59312;
else if (value == 36994 )
return 59310;
else if (value == 36995 )
return 57988;
else if (value == 36996 )
return 35538;
else if (value == 36999 )
return 59278;
else if (value == 37001 )
return 59315;
else if (value == 37002 )
return 59314;
else if (value == 37007 )
return 59316;
else if (value == 37009 )
return 38743;
else if (value == 37027 )
return 37855;
else if (value == 37030 )
return 38477;
else if (value == 37032 )
return 59317;
else if (value == 37034 )
return 36567;
}
else if (value <= 37138 ) {
if (value == 37039 )
return 59318;
else if (value == 37041 )
return 59319;
else if (value == 37045 )
return 59320;
else if (value == 37048 )
return 37696;
else if (value == 37057 )
return 35048;
else if (value == 37066 )
return 36216;
else if (value == 37070 )
return 39001;
else if (value == 37083 )
return 59324;
else if (value == 37089 )
return 35923;
else if (value == 37090 )
return 59321;
else if (value == 37092 )
return 59322;
else if (value == 37096 )
return 38292;
else if (value == 37101 )
return 35443;
else if (value == 37109 )
return 38744;
else if (value == 37111 )
return 35773;
else if (value == 37117 )
return 37747;
else if (value == 37122 )
return 59325;
else if (value == 37138 )
return 59326;
}
else if (value <= 37225 ) {
if (value == 37145 )
return 59327;
else if (value == 37165 )
return 37697;
else if (value == 37168 )
return 59329;
else if (value == 37170 )
return 59328;
else if (value == 37193 )
return 37841;
else if (value == 37194 )
return 59330;
else if (value == 37195 )
return 36693;
else if (value == 37196 )
return 36574;
else if (value == 37197 )
return 38010;
else if (value == 37198 )
return 37521;
else if (value == 37202 )
return 36592;
else if (value == 37204 )
return 37004;
else if (value == 37206 )
return 59331;
else if (value == 37208 )
return 59332;
else if (value == 37218 )
return 36988;
else if (value == 37219 )
return 59333;
else if (value == 37221 )
return 59334;
else if (value == 37225 )
return 59335;
}
else if (value <= 37284 ) {
if (value == 37226 )
return 38799;
else if (value == 37228 )
return 36694;
else if (value == 37234 )
return 59337;
else if (value == 37235 )
return 59336;
else if (value == 37237 )
return 36217;
else if (value == 37239 )
return 36243;
else if (value == 37240 )
return 36447;
else if (value == 37250 )
return 59340;
else if (value == 37255 )
return 36742;
else if (value == 37257 )
return 59339;
else if (value == 37259 )
return 59338;
else if (value == 37261 )
return 37351;
else if (value == 37264 )
return 36077;
else if (value == 37266 )
return 37057;
else if (value == 37271 )
return 38062;
else if (value == 37276 )
return 36696;
else if (value == 37282 )
return 59341;
else if (value == 37284 )
return 36829;
}
else if (value <= 37327 ) {
if (value == 37290 )
return 59344;
else if (value == 37291 )
return 59342;
else if (value == 37295 )
return 59343;
else if (value == 37300 )
return 59346;
else if (value == 37301 )
return 59345;
else if (value == 37304 )
return 36856;
else if (value == 37306 )
return 59347;
else if (value == 37312 )
return 59348;
else if (value == 37313 )
return 59349;
else if (value == 37318 )
return 38094;
else if (value == 37319 )
return 36305;
else if (value == 37320 )
return 36575;
else if (value == 37321 )
return 59350;
else if (value == 37323 )
return 59351;
else if (value == 37324 )
return 38818;
else if (value == 37325 )
return 36708;
else if (value == 37326 )
return 38636;
else if (value == 37327 )
return 38858;
}
}
else if ( value >= 37328 && value <= 38642 ) {
if (value <= 37390 ) {
if (value == 37328 )
return 59352;
else if (value == 37329 )
return 35808;
else if (value == 37334 )
return 59353;
else if (value == 37336 )
return 37698;
else if (value == 37339 )
return 59356;
else if (value == 37340 )
return 35480;
else if (value == 37341 )
return 36970;
else if (value == 37343 )
return 59354;
else if (value == 37345 )
return 59355;
else if (value == 37347 )
return 37598;
else if (value == 37350 )
return 38516;
else if (value == 37351 )
return 35834;
else if (value == 37365 )
return 59358;
else if (value == 37366 )
return 59359;
else if (value == 37372 )
return 59357;
else if (value == 37375 )
return 59361;
else if (value == 37389 )
return 37853;
else if (value == 37390 )
return 35426;
}
else if (value <= 37467 ) {
if (value == 37393 )
return 59365;
else if (value == 37396 )
return 59362;
else if (value == 37397 )
return 59364;
else if (value == 37406 )
return 59360;
else if (value == 37417 )
return 59502;
else if (value == 37420 )
return 59363;
else if (value == 37428 )
return 38889;
else if (value == 37431 )
return 36056;
else if (value == 37439 )
return 59373;
else if (value == 37444 )
return 37715;
else if (value == 37445 )
return 59368;
else if (value == 37448 )
return 59371;
else if (value == 37449 )
return 59369;
else if (value == 37451 )
return 59374;
else if (value == 37456 )
return 59375;
else if (value == 37463 )
return 59367;
else if (value == 37466 )
return 59380;
else if (value == 37467 )
return 35220;
}
else if (value <= 37549 ) {
if (value == 37470 )
return 59366;
else if (value == 37474 )
return 38059;
else if (value == 37476 )
return 59370;
else if (value == 37478 )
return 36830;
else if (value == 37489 )
return 36218;
else if (value == 37502 )
return 38503;
else if (value == 37504 )
return 35810;
else if (value == 37507 )
return 36709;
else if (value == 37509 )
return 37818;
else if (value == 37521 )
return 37196;
else if (value == 37523 )
return 59378;
else if (value == 37525 )
return 59372;
else if (value == 37526 )
return 59377;
else if (value == 37528 )
return 38593;
else if (value == 37530 )
return 37558;
else if (value == 37531 )
return 59379;
else if (value == 37532 )
return 59376;
else if (value == 37549 )
return 37195;
}
else if (value <= 37657 ) {
if (value == 37559 )
return 59383;
else if (value == 37561 )
return 59382;
else if (value == 37583 )
return 59381;
else if (value == 37586 )
return 38478;
else if (value == 37604 )
return 36763;
else if (value == 37609 )
return 59384;
else if (value == 37610 )
return 38365;
else if (value == 37613 )
return 35187;
else if (value == 37618 )
return 38245;
else if (value == 37619 )
return 37522;
else if (value == 37624 )
return 35736;
else if (value == 37626 )
return 59386;
else if (value == 37628 )
return 36220;
else if (value == 37638 )
return 36427;
else if (value == 37647 )
return 59385;
else if (value == 37648 )
return 37005;
else if (value == 37656 )
return 37006;
else if (value == 37657 )
return 59456;
}
else if (value <= 37716 ) {
if (value == 37658 )
return 59458;
else if (value == 37664 )
return 36857;
else if (value == 37666 )
return 59457;
else if (value == 37667 )
return 59459;
else if (value == 37670 )
return 35793;
else if (value == 37672 )
return 38244;
else if (value == 37675 )
return 36576;
else if (value == 37676 )
return 38978;
else if (value == 37678 )
return 59388;
else if (value == 37679 )
return 36342;
else if (value == 37682 )
return 39006;
else if (value == 37685 )
return 59461;
else if (value == 37690 )
return 59460;
else if (value == 37691 )
return 59462;
else if (value == 37700 )
return 59387;
else if (value == 37707 )
return 37863;
else if (value == 37709 )
return 37748;
else if (value == 37716 )
return 37589;
}
else if (value <= 37806 ) {
if (value == 37718 )
return 59467;
else if (value == 37723 )
return 37474;
else if (value == 37724 )
return 59463;
else if (value == 37728 )
return 59464;
else if (value == 37740 )
return 35916;
else if (value == 37742 )
return 59466;
else if (value == 37749 )
return 36014;
else if (value == 37756 )
return 59465;
else if (value == 37758 )
return 36831;
else if (value == 37772 )
return 35481;
else if (value == 37780 )
return 59471;
else if (value == 37782 )
return 36285;
else if (value == 37783 )
return 37273;
else if (value == 37786 )
return 37576;
else if (value == 37799 )
return 35418;
else if (value == 37804 )
return 59469;
else if (value == 37805 )
return 59470;
else if (value == 37806 )
return 37569;
}
else if (value <= 37907 ) {
if (value == 37808 )
return 59468;
else if (value == 37817 )
return 59472;
else if (value == 37827 )
return 59478;
else if (value == 37832 )
return 59481;
else if (value == 37840 )
return 59480;
else if (value == 37841 )
return 37708;
else if (value == 37846 )
return 59473;
else if (value == 37847 )
return 59474;
else if (value == 37848 )
return 59477;
else if (value == 37853 )
return 59479;
else if (value == 37857 )
return 35774;
else if (value == 37860 )
return 59482;
else if (value == 37861 )
return 59476;
else if (value == 37864 )
return 59475;
else if (value == 37891 )
return 59486;
else if (value == 37895 )
return 59487;
else if (value == 37904 )
return 59488;
else if (value == 37907 )
return 59485;
}
else if (value <= 37982 ) {
if (value == 37908 )
return 59484;
else if (value == 37912 )
return 36832;
else if (value == 37913 )
return 37800;
else if (value == 37914 )
return 59483;
else if (value == 37921 )
return 59492;
else if (value == 37931 )
return 59490;
else if (value == 37941 )
return 59491;
else if (value == 37942 )
return 59489;
else if (value == 37944 )
return 37366;
else if (value == 37946 )
return 59493;
else if (value == 37953 )
return 59494;
else if (value == 37956 )
return 59496;
else if (value == 37969 )
return 35539;
else if (value == 37970 )
return 59495;
else if (value == 37971 )
return 38648;
else if (value == 37978 )
return 59507;
else if (value == 37979 )
return 59497;
else if (value == 37982 )
return 59500;
}
else if (value <= 38282 ) {
if (value == 37984 )
return 59498;
else if (value == 37986 )
return 59499;
else if (value == 37994 )
return 59501;
else if (value == 38000 )
return 59503;
else if (value == 38005 )
return 59504;
else if (value == 38007 )
return 59505;
else if (value == 38012 )
return 59508;
else if (value == 38013 )
return 59506;
else if (value == 38014 )
return 59509;
else if (value == 38015 )
return 59511;
else if (value == 38017 )
return 59510;
else if (value == 38263 )
return 37559;
else if (value == 38272 )
return 38629;
else if (value == 38274 )
return 59512;
else if (value == 38275 )
return 37197;
else if (value == 38279 )
return 59513;
else if (value == 38281 )
return 38338;
else if (value == 38282 )
return 59514;
}
else if (value <= 38329 ) {
if (value == 38283 )
return 35402;
else if (value == 38287 )
return 35163;
else if (value == 38289 )
return 35541;
else if (value == 38291 )
return 35540;
else if (value == 38292 )
return 59515;
else if (value == 38294 )
return 59516;
else if (value == 38296 )
return 59517;
else if (value == 38297 )
return 59518;
else if (value == 38304 )
return 59520;
else if (value == 38306 )
return 35542;
else if (value == 38307 )
return 35444;
else if (value == 38308 )
return 36221;
else if (value == 38309 )
return 38068;
else if (value == 38311 )
return 59522;
else if (value == 38312 )
return 59521;
else if (value == 38317 )
return 59523;
else if (value == 38322 )
return 35195;
else if (value == 38329 )
return 59526;
}
else if (value <= 38433 ) {
if (value == 38331 )
return 59525;
else if (value == 38332 )
return 59524;
else if (value == 38334 )
return 59527;
else if (value == 38339 )
return 59530;
else if (value == 38343 )
return 35013;
else if (value == 38346 )
return 59528;
else if (value == 38348 )
return 59532;
else if (value == 38349 )
return 59531;
else if (value == 38356 )
return 59534;
else if (value == 38357 )
return 59533;
else if (value == 38358 )
return 59535;
else if (value == 38360 )
return 37804;
else if (value == 38364 )
return 59536;
else if (value == 38369 )
return 59537;
else if (value == 38370 )
return 59539;
else if (value == 38373 )
return 59538;
else if (value == 38428 )
return 38284;
else if (value == 38433 )
return 59540;
}
else if (value <= 38493 ) {
if (value == 38440 )
return 59541;
else if (value == 38442 )
return 36323;
else if (value == 38446 )
return 59542;
else if (value == 38447 )
return 59543;
else if (value == 38450 )
return 38504;
else if (value == 38459 )
return 37226;
else if (value == 38463 )
return 34978;
else if (value == 38464 )
return 37321;
else if (value == 38466 )
return 59544;
else if (value == 38468 )
return 38285;
else if (value == 38475 )
return 59547;
else if (value == 38476 )
return 59545;
else if (value == 38477 )
return 36222;
else if (value == 38479 )
return 59546;
else if (value == 38480 )
return 36032;
else if (value == 38491 )
return 38339;
else if (value == 38492 )
return 59549;
else if (value == 38493 )
return 59551;
}
else if (value <= 38525 ) {
if (value == 38494 )
return 59550;
else if (value == 38495 )
return 59552;
else if (value == 38498 )
return 35136;
else if (value == 38499 )
return 36983;
else if (value == 38500 )
return 36764;
else if (value == 38501 )
return 35543;
else if (value == 38502 )
return 59553;
else if (value == 38506 )
return 38022;
else if (value == 38508 )
return 59555;
else if (value == 38512 )
return 35137;
else if (value == 38514 )
return 59554;
else if (value == 38515 )
return 37570;
else if (value == 38517 )
return 38859;
else if (value == 38518 )
return 37801;
else if (value == 38519 )
return 59548;
else if (value == 38520 )
return 38820;
else if (value == 38522 )
return 36015;
else if (value == 38525 )
return 38778;
}
else if (value <= 38567 ) {
if (value == 38533 )
return 35831;
else if (value == 38534 )
return 38834;
else if (value == 38536 )
return 35911;
else if (value == 38538 )
return 37344;
else if (value == 38539 )
return 58432;
else if (value == 38541 )
return 59556;
else if (value == 38542 )
return 35403;
else if (value == 38543 )
return 37007;
else if (value == 38548 )
return 35445;
else if (value == 38549 )
return 59558;
else if (value == 38551 )
return 59559;
else if (value == 38552 )
return 59557;
else if (value == 38553 )
return 35972;
else if (value == 38555 )
return 36315;
else if (value == 38556 )
return 36833;
else if (value == 38560 )
return 35138;
else if (value == 38563 )
return 38871;
else if (value == 38567 )
return 59561;
}
else if (value <= 38599 ) {
if (value == 38568 )
return 59308;
else if (value == 38570 )
return 59560;
else if (value == 38576 )
return 59564;
else if (value == 38577 )
return 59562;
else if (value == 38578 )
return 59563;
else if (value == 38580 )
return 59565;
else if (value == 38582 )
return 59566;
else if (value == 38583 )
return 38890;
else if (value == 38584 )
return 59567;
else if (value == 38585 )
return 59568;
else if (value == 38587 )
return 37063;
else if (value == 38588 )
return 38073;
else if (value == 38592 )
return 37021;
else if (value == 38593 )
return 35557;
else if (value == 38596 )
return 38745;
else if (value == 38597 )
return 35307;
else if (value == 38598 )
return 36695;
else if (value == 38599 )
return 36057;
}
else if (value <= 38642 ) {
if (value == 38601 )
return 59571;
else if (value == 38603 )
return 59570;
else if (value == 38604 )
return 36499;
else if (value == 38605 )
return 59572;
else if (value == 38606 )
return 59569;
else if (value == 38609 )
return 36423;
else if (value == 38613 )
return 59576;
else if (value == 38614 )
return 58795;
else if (value == 38617 )
return 39380;
else if (value == 38619 )
return 37015;
else if (value == 38620 )
return 59574;
else if (value == 38626 )
return 38819;
else if (value == 38627 )
return 37871;
else if (value == 38632 )
return 35146;
else if (value == 38634 )
return 37089;
else if (value == 38635 )
return 36532;
else if (value == 38640 )
return 38325;
else if (value == 38642 )
return 35167;
}
}
else if ( value >= 38646 && value <= 39749 ) {
if (value <= 38684 ) {
if (value == 38646 )
return 38891;
else if (value == 38647 )
return 38795;
else if (value == 38649 )
return 59577;
else if (value == 38651 )
return 37732;
else if (value == 38656 )
return 36601;
else if (value == 38660 )
return 59578;
else if (value == 38662 )
return 59579;
else if (value == 38663 )
return 36971;
else if (value == 38664 )
return 59580;
else if (value == 38666 )
return 38892;
else if (value == 38669 )
return 59575;
else if (value == 38670 )
return 59582;
else if (value == 38671 )
return 59584;
else if (value == 38673 )
return 59583;
else if (value == 38675 )
return 59581;
else if (value == 38678 )
return 59585;
else if (value == 38681 )
return 59586;
else if (value == 38684 )
return 37274;
}
else if (value <= 38745 ) {
if (value == 38686 )
return 35296;
else if (value == 38692 )
return 59587;
else if (value == 38695 )
return 38582;
else if (value == 38698 )
return 59588;
else if (value == 38704 )
return 59589;
else if (value == 38706 )
return 38985;
else if (value == 38712 )
return 40528;
else if (value == 38713 )
return 59590;
else if (value == 38717 )
return 59591;
else if (value == 38718 )
return 59592;
else if (value == 38722 )
return 59596;
else if (value == 38724 )
return 59593;
else if (value == 38726 )
return 59594;
else if (value == 38728 )
return 59595;
else if (value == 38729 )
return 59597;
else if (value == 38738 )
return 37058;
else if (value == 38742 )
return 38645;
else if (value == 38745 )
return 37059;
}
else if (value <= 38788 ) {
if (value == 38748 )
return 59598;
else if (value == 38750 )
return 38129;
else if (value == 38752 )
return 59599;
else if (value == 38753 )
return 60018;
else if (value == 38754 )
return 38602;
else if (value == 38756 )
return 59600;
else if (value == 38758 )
return 59601;
else if (value == 38760 )
return 59602;
else if (value == 38761 )
return 35446;
else if (value == 38763 )
return 59604;
else if (value == 38765 )
return 36984;
else if (value == 38769 )
return 59605;
else if (value == 38772 )
return 35907;
else if (value == 38777 )
return 59606;
else if (value == 38778 )
return 59610;
else if (value == 38780 )
return 59608;
else if (value == 38785 )
return 59609;
else if (value == 38788 )
return 35475;
}
else if (value <= 38854 ) {
if (value == 38789 )
return 59607;
else if (value == 38790 )
return 59611;
else if (value == 38795 )
return 59612;
else if (value == 38797 )
return 35014;
else if (value == 38799 )
return 59613;
else if (value == 38800 )
return 59614;
else if (value == 38808 )
return 36834;
else if (value == 38812 )
return 59615;
else if (value == 38816 )
return 35686;
else if (value == 38819 )
return 59618;
else if (value == 38822 )
return 59617;
else if (value == 38824 )
return 59616;
else if (value == 38827 )
return 59025;
else if (value == 38829 )
return 38362;
else if (value == 38835 )
return 59619;
else if (value == 38836 )
return 59620;
else if (value == 38851 )
return 59621;
else if (value == 38854 )
return 59622;
}
else if (value <= 38920 ) {
if (value == 38856 )
return 59623;
else if (value == 38859 )
return 59624;
else if (value == 38867 )
return 35544;
else if (value == 38876 )
return 59625;
else if (value == 38893 )
return 59626;
else if (value == 38894 )
return 37954;
else if (value == 38898 )
return 59628;
else if (value == 38899 )
return 35257;
else if (value == 38901 )
return 59631;
else if (value == 38902 )
return 59630;
else if (value == 38907 )
return 35139;
else if (value == 38911 )
return 35775;
else if (value == 38913 )
return 38341;
else if (value == 38914 )
return 37560;
else if (value == 38915 )
return 36256;
else if (value == 38917 )
return 36224;
else if (value == 38918 )
return 36743;
else if (value == 38920 )
return 36987;
}
else if (value <= 38972 ) {
if (value == 38924 )
return 59633;
else if (value == 38927 )
return 59632;
else if (value == 38928 )
return 38753;
else if (value == 38929 )
return 35558;
else if (value == 38930 )
return 38096;
else if (value == 38931 )
return 37850;
else if (value == 38935 )
return 37020;
else if (value == 38936 )
return 38860;
else if (value == 38938 )
return 35962;
else if (value == 38945 )
return 59636;
else if (value == 38948 )
return 59635;
else if (value == 38956 )
return 38506;
else if (value == 38957 )
return 37802;
else if (value == 38964 )
return 35183;
else if (value == 38967 )
return 59637;
else if (value == 38968 )
return 59634;
else if (value == 38971 )
return 38256;
else if (value == 38972 )
return 38794;
}
else if (value <= 39027 ) {
if (value == 38973 )
return 59638;
else if (value == 38982 )
return 59639;
else if (value == 38987 )
return 59641;
else if (value == 38988 )
return 37352;
else if (value == 38989 )
return 35450;
else if (value == 38990 )
return 35451;
else if (value == 38991 )
return 59640;
else if (value == 38996 )
return 35559;
else if (value == 38997 )
return 36016;
else if (value == 39000 )
return 35560;
else if (value == 39003 )
return 37726;
else if (value == 39006 )
return 38878;
else if (value == 39015 )
return 36058;
else if (value == 39019 )
return 59642;
else if (value == 39023 )
return 59643;
else if (value == 39024 )
return 59644;
else if (value == 39025 )
return 59712;
else if (value == 39027 )
return 59714;
}
else if (value <= 39151 ) {
if (value == 39028 )
return 59713;
else if (value == 39080 )
return 38295;
else if (value == 39082 )
return 59715;
else if (value == 39087 )
return 59716;
else if (value == 39089 )
return 59717;
else if (value == 39094 )
return 59718;
else if (value == 39107 )
return 59720;
else if (value == 39108 )
return 59719;
else if (value == 39110 )
return 59721;
else if (value == 39131 )
return 38130;
else if (value == 39132 )
return 58314;
else if (value == 39135 )
return 36936;
else if (value == 39138 )
return 35665;
else if (value == 39145 )
return 59722;
else if (value == 39147 )
return 59723;
else if (value == 39149 )
return 39338;
else if (value == 39150 )
return 40794;
else if (value == 39151 )
return 38097;
}
else if (value <= 39200 ) {
if (value == 39154 )
return 35065;
else if (value == 39156 )
return 35001;
else if (value == 39164 )
return 36500;
else if (value == 39165 )
return 38479;
else if (value == 39166 )
return 36860;
else if (value == 39171 )
return 59724;
else if (value == 39173 )
return 38621;
else if (value == 39177 )
return 59725;
else if (value == 39178 )
return 38779;
else if (value == 39180 )
return 35169;
else if (value == 39184 )
return 36448;
else if (value == 39186 )
return 59726;
else if (value == 39187 )
return 35308;
else if (value == 39188 )
return 59727;
else if (value == 39192 )
return 59728;
else if (value == 39197 )
return 59730;
else if (value == 39198 )
return 59731;
else if (value == 39200 )
return 59733;
}
else if (value <= 39318 ) {
if (value == 39201 )
return 59729;
else if (value == 39204 )
return 59732;
else if (value == 39208 )
return 35545;
else if (value == 39212 )
return 59734;
else if (value == 39214 )
return 59735;
else if (value == 39229 )
return 59736;
else if (value == 39230 )
return 59737;
else if (value == 39234 )
return 59738;
else if (value == 39237 )
return 59740;
else if (value == 39241 )
return 59739;
else if (value == 39243 )
return 59742;
else if (value == 39244 )
return 59745;
else if (value == 39248 )
return 59741;
else if (value == 39249 )
return 59743;
else if (value == 39250 )
return 59744;
else if (value == 39253 )
return 59746;
else if (value == 39255 )
return 35776;
else if (value == 39318 )
return 36593;
}
else if (value <= 39377 ) {
if (value == 39319 )
return 59747;
else if (value == 39320 )
return 59748;
else if (value == 39321 )
return 36225;
else if (value == 39333 )
return 59749;
else if (value == 39336 )
return 35421;
else if (value == 39340 )
return 37998;
else if (value == 39341 )
return 59750;
else if (value == 39342 )
return 59751;
else if (value == 39347 )
return 37497;
else if (value == 39348 )
return 37865;
else if (value == 39356 )
return 59752;
else if (value == 39361 )
return 38045;
else if (value == 39364 )
return 37322;
else if (value == 39365 )
return 35191;
else if (value == 39366 )
return 35820;
else if (value == 39368 )
return 35821;
else if (value == 39376 )
return 37523;
else if (value == 39377 )
return 59757;
}
else if (value <= 39439 ) {
if (value == 39378 )
return 35822;
else if (value == 39381 )
return 35309;
else if (value == 39384 )
return 59756;
else if (value == 39387 )
return 59754;
else if (value == 39389 )
return 59755;
else if (value == 39391 )
return 59753;
else if (value == 39394 )
return 59767;
else if (value == 39405 )
return 59758;
else if (value == 39406 )
return 59759;
else if (value == 39409 )
return 59760;
else if (value == 39410 )
return 59761;
else if (value == 39416 )
return 59763;
else if (value == 39419 )
return 59762;
else if (value == 39423 )
return 36728;
else if (value == 39425 )
return 59764;
else if (value == 39429 )
return 59766;
else if (value == 39438 )
return 35666;
else if (value == 39439 )
return 59765;
}
else if (value <= 39519 ) {
if (value == 39442 )
return 37275;
else if (value == 39443 )
return 36017;
else if (value == 39449 )
return 59768;
else if (value == 39464 )
return 37323;
else if (value == 39467 )
return 59769;
else if (value == 39472 )
return 37803;
else if (value == 39479 )
return 59770;
else if (value == 39486 )
return 59776;
else if (value == 39488 )
return 59773;
else if (value == 39490 )
return 59772;
else if (value == 39491 )
return 59774;
else if (value == 39493 )
return 59771;
else if (value == 39501 )
return 59778;
else if (value == 39509 )
return 59777;
else if (value == 39511 )
return 59780;
else if (value == 39514 )
return 35777;
else if (value == 39515 )
return 59779;
else if (value == 39519 )
return 59781;
}
else if (value <= 39640 ) {
if (value == 39522 )
return 59782;
else if (value == 39524 )
return 59784;
else if (value == 39525 )
return 59783;
else if (value == 39529 )
return 59785;
else if (value == 39530 )
return 59787;
else if (value == 39531 )
return 59786;
else if (value == 39592 )
return 36252;
else if (value == 39597 )
return 59788;
else if (value == 39600 )
return 59789;
else if (value == 39608 )
return 35419;
else if (value == 39612 )
return 59790;
else if (value == 39616 )
return 59791;
else if (value == 39620 )
return 37009;
else if (value == 39631 )
return 59792;
else if (value == 39633 )
return 59793;
else if (value == 39635 )
return 59794;
else if (value == 39636 )
return 59795;
else if (value == 39640 )
return 36226;
}
else if (value <= 39711 ) {
if (value == 39646 )
return 59796;
else if (value == 39647 )
return 59797;
else if (value == 39650 )
return 59798;
else if (value == 39651 )
return 59799;
else if (value == 39654 )
return 59800;
else if (value == 39658 )
return 38063;
else if (value == 39659 )
return 59802;
else if (value == 39661 )
return 38213;
else if (value == 39662 )
return 59803;
else if (value == 39663 )
return 59801;
else if (value == 39665 )
return 59805;
else if (value == 39668 )
return 59804;
else if (value == 39671 )
return 59806;
else if (value == 39675 )
return 59807;
else if (value == 39686 )
return 59808;
else if (value == 39704 )
return 59809;
else if (value == 39706 )
return 59810;
else if (value == 39711 )
return 59811;
}
else if (value <= 39749 ) {
if (value == 39714 )
return 59812;
else if (value == 39715 )
return 59813;
else if (value == 39717 )
return 59814;
else if (value == 39719 )
return 59815;
else if (value == 39720 )
return 59816;
else if (value == 39721 )
return 59817;
else if (value == 39722 )
return 59818;
else if (value == 39726 )
return 59819;
else if (value == 39727 )
return 59820;
else if (value == 39729 )
return 40788;
else if (value == 39730 )
return 59821;
else if (value == 39739 )
return 58102;
else if (value == 39740 )
return 35667;
else if (value == 39745 )
return 35392;
else if (value == 39746 )
return 36272;
else if (value == 39747 )
return 59823;
else if (value == 39748 )
return 59822;
else if (value == 39749 )
return 38563;
}
}
else if ( value >= 39757 && value <= 65329 ) {
if (value <= 39840 ) {
if (value == 39757 )
return 59825;
else if (value == 39758 )
return 59826;
else if (value == 39759 )
return 59824;
else if (value == 39761 )
return 59827;
else if (value == 39764 )
return 38530;
else if (value == 39768 )
return 59828;
else if (value == 39770 )
return 35739;
else if (value == 39791 )
return 38980;
else if (value == 39796 )
return 59829;
else if (value == 39811 )
return 59831;
else if (value == 39822 )
return 35004;
else if (value == 39825 )
return 59832;
else if (value == 39826 )
return 38313;
else if (value == 39827 )
return 59830;
else if (value == 39830 )
return 59833;
else if (value == 39831 )
return 59834;
else if (value == 39839 )
return 59835;
else if (value == 39840 )
return 59836;
}
else if (value <= 39905 ) {
if (value == 39848 )
return 59837;
else if (value == 39850 )
return 38542;
else if (value == 39851 )
return 36428;
else if (value == 39853 )
return 36344;
else if (value == 39854 )
return 37198;
else if (value == 39860 )
return 59838;
else if (value == 39865 )
return 59841;
else if (value == 39872 )
return 59839;
else if (value == 39878 )
return 59842;
else if (value == 39881 )
return 36079;
else if (value == 39882 )
return 59840;
else if (value == 39887 )
return 59843;
else if (value == 39889 )
return 59844;
else if (value == 39890 )
return 59845;
else if (value == 39892 )
return 59849;
else if (value == 39894 )
return 36425;
else if (value == 39899 )
return 37346;
else if (value == 39905 )
return 59850;
}
else if (value <= 39955 ) {
if (value == 39906 )
return 59847;
else if (value == 39907 )
return 59846;
else if (value == 39908 )
return 59848;
else if (value == 39912 )
return 35966;
else if (value == 39920 )
return 59854;
else if (value == 39921 )
return 59853;
else if (value == 39922 )
return 59852;
else if (value == 39925 )
return 34993;
else if (value == 39940 )
return 59864;
else if (value == 39942 )
return 59860;
else if (value == 39944 )
return 59861;
else if (value == 39945 )
return 59857;
else if (value == 39946 )
return 59863;
else if (value == 39948 )
return 59859;
else if (value == 39949 )
return 35458;
else if (value == 39952 )
return 39019;
else if (value == 39954 )
return 59862;
else if (value == 39955 )
return 59858;
}
else if (value <= 40008 ) {
if (value == 39956 )
return 59856;
else if (value == 39957 )
return 59855;
else if (value == 39963 )
return 59866;
else if (value == 39969 )
return 59869;
else if (value == 39972 )
return 59868;
else if (value == 39973 )
return 59867;
else if (value == 39981 )
return 38248;
else if (value == 39982 )
return 59865;
else if (value == 39983 )
return 35057;
else if (value == 39984 )
return 59870;
else if (value == 39986 )
return 59872;
else if (value == 39993 )
return 35471;
else if (value == 39994 )
return 59851;
else if (value == 39995 )
return 35158;
else if (value == 39998 )
return 59874;
else if (value == 40006 )
return 59873;
else if (value == 40007 )
return 59871;
else if (value == 40008 )
return 37452;
}
else if (value <= 40198 ) {
if (value == 40018 )
return 38544;
else if (value == 40023 )
return 38872;
else if (value == 40026 )
return 59875;
else if (value == 40032 )
return 59876;
else if (value == 40039 )
return 59877;
else if (value == 40054 )
return 59878;
else if (value == 40056 )
return 59879;
else if (value == 40165 )
return 37561;
else if (value == 40167 )
return 59880;
else if (value == 40169 )
return 38069;
else if (value == 40171 )
return 59885;
else if (value == 40172 )
return 59881;
else if (value == 40176 )
return 59882;
else if (value == 40179 )
return 38480;
else if (value == 40180 )
return 38594;
else if (value == 40182 )
return 37838;
else if (value == 40195 )
return 59886;
else if (value == 40198 )
return 59887;
}
else if (value <= 40257 ) {
if (value == 40199 )
return 37820;
else if (value == 40200 )
return 59884;
else if (value == 40201 )
return 59883;
else if (value == 40206 )
return 35240;
else if (value == 40210 )
return 59895;
else if (value == 40213 )
return 59894;
else if (value == 40219 )
return 35221;
else if (value == 40223 )
return 59892;
else if (value == 40227 )
return 59891;
else if (value == 40230 )
return 59889;
else if (value == 40232 )
return 35483;
else if (value == 40234 )
return 59888;
else if (value == 40235 )
return 36528;
else if (value == 40236 )
return 35239;
else if (value == 40251 )
return 36227;
else if (value == 40254 )
return 59898;
else if (value == 40255 )
return 59897;
else if (value == 40257 )
return 59896;
}
else if (value <= 40329 ) {
if (value == 40260 )
return 59893;
else if (value == 40262 )
return 59899;
else if (value == 40264 )
return 59900;
else if (value == 40272 )
return 59972;
else if (value == 40273 )
return 59971;
else if (value == 40281 )
return 59973;
else if (value == 40284 )
return 35148;
else if (value == 40285 )
return 59968;
else if (value == 40286 )
return 59969;
else if (value == 40288 )
return 36244;
else if (value == 40289 )
return 38583;
else if (value == 40292 )
return 59970;
else if (value == 40300 )
return 38481;
else if (value == 40303 )
return 59978;
else if (value == 40306 )
return 59974;
else if (value == 40314 )
return 59979;
else if (value == 40327 )
return 59976;
else if (value == 40329 )
return 59975;
}
else if (value <= 40409 ) {
if (value == 40335 )
return 35963;
else if (value == 40346 )
return 59980;
else if (value == 40356 )
return 59981;
else if (value == 40361 )
return 59982;
else if (value == 40363 )
return 59977;
else if (value == 40367 )
return 59890;
else if (value == 40370 )
return 59983;
else if (value == 40372 )
return 37599;
else if (value == 40376 )
return 59987;
else if (value == 40378 )
return 59988;
else if (value == 40379 )
return 59986;
else if (value == 40385 )
return 59985;
else if (value == 40386 )
return 59991;
else if (value == 40388 )
return 59984;
else if (value == 40390 )
return 59989;
else if (value == 40399 )
return 59990;
else if (value == 40403 )
return 59993;
else if (value == 40409 )
return 59992;
}
else if (value <= 40584 ) {
if (value == 40422 )
return 59995;
else if (value == 40429 )
return 59996;
else if (value == 40431 )
return 59997;
else if (value == 40434 )
return 39016;
else if (value == 40440 )
return 59994;
else if (value == 40441 )
return 37353;
else if (value == 40442 )
return 36331;
else if (value == 40445 )
return 59998;
else if (value == 40474 )
return 59999;
else if (value == 40475 )
return 60000;
else if (value == 40478 )
return 60001;
else if (value == 40565 )
return 60002;
else if (value == 40568 )
return 36018;
else if (value == 40569 )
return 60003;
else if (value == 40573 )
return 60004;
else if (value == 40575 )
return 36525;
else if (value == 40577 )
return 60005;
else if (value == 40584 )
return 60006;
}
else if (value <= 40635 ) {
if (value == 40587 )
return 60007;
else if (value == 40588 )
return 60008;
else if (value == 40593 )
return 60011;
else if (value == 40594 )
return 60009;
else if (value == 40595 )
return 39003;
else if (value == 40597 )
return 60010;
else if (value == 40599 )
return 38893;
else if (value == 40605 )
return 60012;
else if (value == 40607 )
return 38873;
else if (value == 40613 )
return 60013;
else if (value == 40614 )
return 38046;
else if (value == 40617 )
return 60014;
else if (value == 40618 )
return 60016;
else if (value == 40621 )
return 60017;
else if (value == 40632 )
return 60015;
else if (value == 40633 )
return 36237;
else if (value == 40634 )
return 38603;
else if (value == 40635 )
return 38531;
}
else if (value <= 40672 ) {
if (value == 40636 )
return 39925;
else if (value == 40638 )
return 40832;
else if (value == 40639 )
return 38555;
else if (value == 40644 )
return 35241;
else if (value == 40652 )
return 60019;
else if (value == 40653 )
return 35695;
else if (value == 40654 )
return 60020;
else if (value == 40655 )
return 60021;
else if (value == 40656 )
return 60022;
else if (value == 40658 )
return 36245;
else if (value == 40660 )
return 60023;
else if (value == 40664 )
return 57554;
else if (value == 40665 )
return 38617;
else if (value == 40667 )
return 37345;
else if (value == 40668 )
return 60024;
else if (value == 40669 )
return 60026;
else if (value == 40670 )
return 60025;
else if (value == 40672 )
return 60027;
}
else if (value <= 40748 ) {
if (value == 40677 )
return 60028;
else if (value == 40680 )
return 60029;
else if (value == 40687 )
return 60030;
else if (value == 40692 )
return 60032;
else if (value == 40694 )
return 60033;
else if (value == 40695 )
return 60034;
else if (value == 40697 )
return 60035;
else if (value == 40699 )
return 60036;
else if (value == 40700 )
return 60037;
else if (value == 40701 )
return 60038;
else if (value == 40711 )
return 60039;
else if (value == 40712 )
return 60040;
else if (value == 40718 )
return 37699;
else if (value == 40723 )
return 36059;
else if (value == 40725 )
return 60042;
else if (value == 40736 )
return 37228;
else if (value == 40737 )
return 60043;
else if (value == 40748 )
return 60044;
}
else if (value <= 40818 ) {
if (value == 40763 )
return 38208;
else if (value == 40766 )
return 60045;
else if (value == 40778 )
return 60046;
else if (value == 40779 )
return 57942;
else if (value == 40782 )
return 59096;
else if (value == 40783 )
return 59627;
else if (value == 40786 )
return 60047;
else if (value == 40788 )
return 60048;
else if (value == 40799 )
return 60050;
else if (value == 40800 )
return 60051;
else if (value == 40801 )
return 60052;
else if (value == 40802 )
return 38894;
else if (value == 40803 )
return 60049;
else if (value == 40806 )
return 60053;
else if (value == 40807 )
return 60054;
else if (value == 40810 )
return 60056;
else if (value == 40812 )
return 60055;
else if (value == 40818 )
return 60058;
}
else if (value <= 65293 ) {
if (value == 40822 )
return 60059;
else if (value == 40823 )
return 60057;
else if (value == 40845 )
return 38836;
else if (value == 40853 )
return 60060;
else if (value == 40860 )
return 60061;
else if (value == 40861 )
return 57971;
else if (value == 40864 )
return 60062;
else if (value == 65281 )
return 33098;
else if (value == 65283 )
return 33172;
else if (value == 65284 )
return 33168;
else if (value == 65285 )
return 33171;
else if (value == 65286 )
return 33173;
else if (value == 65288 )
return 33129;
else if (value == 65289 )
return 33130;
else if (value == 65290 )
return 33174;
else if (value == 65291 )
return 33147;
else if (value == 65292 )
return 33092;
else if (value == 65293 )
return 33148;
}
else if (value <= 65311 ) {
if (value == 65294 )
return 33093;
else if (value == 65295 )
return 33118;
else if (value == 65296 )
return 33359;
else if (value == 65297 )
return 33360;
else if (value == 65298 )
return 33361;
else if (value == 65299 )
return 33362;
else if (value == 65300 )
return 33363;
else if (value == 65301 )
return 33364;
else if (value == 65302 )
return 33365;
else if (value == 65303 )
return 33366;
else if (value == 65304 )
return 33367;
else if (value == 65305 )
return 33368;
else if (value == 65306 )
return 33095;
else if (value == 65307 )
return 33096;
else if (value == 65308 )
return 33155;
else if (value == 65309 )
return 33153;
else if (value == 65310 )
return 33156;
else if (value == 65311 )
return 33097;
}
else if (value <= 65329 ) {
if (value == 65312 )
return 33175;
else if (value == 65313 )
return 33376;
else if (value == 65314 )
return 33377;
else if (value == 65315 )
return 33378;
else if (value == 65316 )
return 33379;
else if (value == 65317 )
return 33380;
else if (value == 65318 )
return 33381;
else if (value == 65319 )
return 33382;
else if (value == 65320 )
return 33383;
else if (value == 65321 )
return 33384;
else if (value == 65322 )
return 33385;
else if (value == 65323 )
return 33386;
else if (value == 65324 )
return 33387;
else if (value == 65325 )
return 33388;
else if (value == 65326 )
return 33389;
else if (value == 65327 )
return 33390;
else if (value == 65328 )
return 33391;
else if (value == 65329 )
return 33392;
}
}
else if ( value >= 65330 && value <= 65509 ) {
if (value <= 65347 ) {
if (value == 65330 )
return 33393;
else if (value == 65331 )
return 33394;
else if (value == 65332 )
return 33395;
else if (value == 65333 )
return 33396;
else if (value == 65334 )
return 33397;
else if (value == 65335 )
return 33398;
else if (value == 65336 )
return 33399;
else if (value == 65337 )
return 33400;
else if (value == 65338 )
return 33401;
else if (value == 65339 )
return 33133;
else if (value == 65340 )
return 33119;
else if (value == 65341 )
return 33134;
else if (value == 65342 )
return 33103;
else if (value == 65343 )
return 33105;
else if (value == 65344 )
return 33102;
else if (value == 65345 )
return 33409;
else if (value == 65346 )
return 33410;
else if (value == 65347 )
return 33411;
}
else if (value <= 65365 ) {
if (value == 65348 )
return 33412;
else if (value == 65349 )
return 33413;
else if (value == 65350 )
return 33414;
else if (value == 65351 )
return 33415;
else if (value == 65352 )
return 33416;
else if (value == 65353 )
return 33417;
else if (value == 65354 )
return 33418;
else if (value == 65355 )
return 33419;
else if (value == 65356 )
return 33420;
else if (value == 65357 )
return 33421;
else if (value == 65358 )
return 33422;
else if (value == 65359 )
return 33423;
else if (value == 65360 )
return 33424;
else if (value == 65361 )
return 33425;
else if (value == 65362 )
return 33426;
else if (value == 65363 )
return 33427;
else if (value == 65364 )
return 33428;
else if (value == 65365 )
return 33429;
}
else if (value <= 65509 ) {
if (value == 65366 )
return 33430;
else if (value == 65367 )
return 33431;
else if (value == 65368 )
return 33432;
else if (value == 65369 )
return 33433;
else if (value == 65370 )
return 33434;
else if (value == 65371 )
return 33135;
else if (value == 65372 )
return 33122;
else if (value == 65373 )
return 33136;
else if (value == 65374 )
return 33120;
else if (value == 65504 )
return 33169;
else if (value == 65505 )
return 33170;
else if (value == 65506 )
return 33223;
else if (value == 65507 )
return 33104;
else if (value == 65509 )
return 33167;
}
}
return -1;
}
| 28.572078 | 49 | 0.445019 |
af06516471467817b835bdb9caae1483c29e6949 | 1,955 | h | C | win8/metro_driver/ime/text_store_delegate.h | SlimKatLegacy/android_external_chromium_org | ee480ef5039d7c561fc66ccf52169ead186f1bea | [
"BSD-3-Clause-No-Nuclear-License-2014",
"BSD-3-Clause"
] | 2 | 2015-03-04T02:36:53.000Z | 2016-06-25T11:22:17.000Z | win8/metro_driver/ime/text_store_delegate.h | j4ckfrost/android_external_chromium_org | a1a3dad8b08d1fcf6b6b36c267158ed63217c780 | [
"BSD-3-Clause-No-Nuclear-License-2014",
"BSD-3-Clause"
] | null | null | null | win8/metro_driver/ime/text_store_delegate.h | j4ckfrost/android_external_chromium_org | a1a3dad8b08d1fcf6b6b36c267158ed63217c780 | [
"BSD-3-Clause-No-Nuclear-License-2014",
"BSD-3-Clause"
] | 4 | 2015-02-09T08:49:30.000Z | 2017-08-26T02:03:34.000Z | // Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WIN8_METRO_DRIVER_IME_TEXT_STORE_DELEGATE_H_
#define WIN8_METRO_DRIVER_IME_TEXT_STORE_DELEGATE_H_
#include <vector>
#include <windows.h>
#include "base/basictypes.h"
#include "base/strings/string16.h"
namespace metro_viewer {
struct UnderlineInfo;
}
namespace metro_driver {
// A delegate which works together with virtual text stores.
// Objects that implement this delegate will receive notifications from a
// virtual text store whenever an IME updates the composition or commits text.
// Objects that implement this delegate are also responsible for calculating
// the character position of composition and caret position upon request.
class TextStoreDelegate {
public:
virtual ~TextStoreDelegate() {}
// Called when on-going composition is updated. An empty |text| represents
// that the composition is canceled.
virtual void OnCompositionChanged(
const string16& text,
int32 selection_start,
int32 selection_end,
const std::vector<metro_viewer::UnderlineInfo>& underlines) = 0;
// Called when |text| is committed.
virtual void OnTextCommitted(const string16& text) = 0;
// Called when an IME requests the caret position. Objects that implement
// this method must return the caret position in screen coordinates.
virtual RECT GetCaretBounds() = 0;
// Called when an IME requests the bounding box of an character whose
// index is |index| in the on-going composition. position. Objects that
// implement this method must return true and fill the character bounds into
// |rect| in screen coordinates.
// Should return false if |index| is invalid.
virtual bool GetCompositionCharacterBounds(uint32 index, RECT* rect) = 0;
};
} // namespace metro_driver
#endif // WIN8_METRO_DRIVER_IME_TEXT_STORE_DELEGATE_H_
| 34.910714 | 78 | 0.766752 |
e8c886dde1777fc4c479bd811d75d1ec7293e9d1 | 1,620 | h | C | usr/lib/libcoreroutine.dylib/RTReachabilityManager.h | lechium/tvOS124Headers | 11d1b56dd4c0ffd88b9eac43f87a5fd6f7228475 | [
"MIT"
] | 4 | 2019-08-27T18:03:47.000Z | 2021-09-18T06:29:00.000Z | usr/lib/libcoreroutine.dylib/RTReachabilityManager.h | lechium/tvOS124Headers | 11d1b56dd4c0ffd88b9eac43f87a5fd6f7228475 | [
"MIT"
] | null | null | null | usr/lib/libcoreroutine.dylib/RTReachabilityManager.h | lechium/tvOS124Headers | 11d1b56dd4c0ffd88b9eac43f87a5fd6f7228475 | [
"MIT"
] | null | null | null | /*
* This header is generated by classdump-dyld 1.0
* on Saturday, August 24, 2019 at 9:49:28 PM Mountain Standard Time
* Operating System: Version 12.4 (Build 16M568)
* Image Source: /usr/lib/libcoreroutine.dylib
* classdump-dyld is licensed under GPLv3, Copyright © 2013-2016 by Elias Limneos.
*/
#import <libcoreroutine.dylib/libcoreroutine.dylib-Structs.h>
#import <libcoreroutine.dylib/RTService.h>
@interface RTReachabilityManager : RTService {
SCNetworkReachabilityRef _reachabilityRef;
long long _currentReachability;
}
@property (assign,nonatomic) SCNetworkReachabilityRef reachabilityRef; //@synthesize reachabilityRef=_reachabilityRef - In the implementation block
@property (nonatomic,readonly) long long currentReachability; //@synthesize currentReachability=_currentReachability - In the implementation block
+(long long)_processReachabilityChange:(unsigned)arg1 ;
+(id)reachabilityToString:(long long)arg1 ;
-(void)setCurrentReachability:(long long)arg1 ;
-(long long)currentReachability;
-(void)_shutdown;
-(void)internalAddObserver:(id)arg1 name:(id)arg2 ;
-(void)internalRemoveObserver:(id)arg1 name:(id)arg2 ;
-(void)_startMonitoringReachability;
-(void)_stopMonitoringReachability;
-(SCNetworkReachabilityRef)reachabilityRef;
-(BOOL)_getCurrentReachability:(unsigned*)arg1 ;
-(void)setReachabilityRef:(SCNetworkReachabilityRef)arg1 ;
-(id)currentReachabilityString;
-(void)_fetchCurrentReachability:(/*^block*/id)arg1 ;
-(void)processReachabilityChange:(unsigned)arg1 ;
-(void)fetchCurrentReachability:(/*^block*/id)arg1 ;
-(id)init;
-(id)description;
@end
| 39.512195 | 168 | 0.783951 |
795076e9603a2c9b10b01d600575dfbe17712657 | 307 | c | C | variables/3_types/bool.c | EmiMaJi/C | 2401be54cfb4b3a88200f8e0a97b4e8a6114c301 | [
"MIT"
] | 25 | 2019-08-19T18:26:00.000Z | 2022-03-11T06:15:44.000Z | variables/3_types/bool.c | EmiMaJi/C | 2401be54cfb4b3a88200f8e0a97b4e8a6114c301 | [
"MIT"
] | 9 | 2019-04-24T16:35:08.000Z | 2022-03-02T19:28:31.000Z | variables/3_types/bool.c | taller-programacion/C | 5a32f2894f26a6101543872ff32b5aa5fb4daa83 | [
"MIT"
] | 166 | 2019-04-25T19:38:15.000Z | 2022-03-21T22:18:44.000Z | #include<stdio.h>
#include<stdbool.h>// Boolean
int main(){
//tipo_dato identificador = valor;
bool reprobado = false; //true / false
// if(false){}
/* if(true){
}
*/
if(reprobado){
printf("Reprobaste el taller\n");
}else{
printf("Aprobaste con 6\n");
}
}
| 16.157895 | 42 | 0.550489 |
6f013d46176cef44692fd818acb9347e91047d17 | 90,630 | c | C | examples/omp/shtns/sht_init.c | byu-vv-lab/civl | f599229ff4830acc75c33149611c65ff4052d516 | [
"BSD-3-Clause"
] | null | null | null | examples/omp/shtns/sht_init.c | byu-vv-lab/civl | f599229ff4830acc75c33149611c65ff4052d516 | [
"BSD-3-Clause"
] | null | null | null | examples/omp/shtns/sht_init.c | byu-vv-lab/civl | f599229ff4830acc75c33149611c65ff4052d516 | [
"BSD-3-Clause"
] | null | null | null | /*
* Copyright (c) 2010-2015 Centre National de la Recherche Scientifique.
* written by Nathanael Schaeffer (CNRS, ISTerre, Grenoble, France).
*
* nathanael.schaeffer@ujf-grenoble.fr
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
*/
/********************************************************************
* SHTns : Spherical Harmonic Transform for numerical simulations. *
* written by Nathanael Schaeffer / CNRS *
********************************************************************/
/** \internal \file SHT.c
* \brief main source file for SHTns.
* This files contains initialization code and also some partial transforms (point or latitudinal evaluations)
*/
#include <stdio.h>
#include <string.h>
// global variables definitions
#include "sht_private.h"
// cycle counter from FFTW
#include "fftw3/cycle.h"
// chained list of sht_setup : start with NULL
shtns_cfg sht_data = NULL;
#ifdef _OPENMP
int omp_threads = 1; // multi-thread disabled by default.
#if HAVE_LIBFFTW3_OMP
#define OMP_FFTW
#endif
#else
#define omp_threads 1
#endif
static int verbose = 0; // runtime verbosity control: 0 no output, 1 output, 2 debug (if compiled in)
void shtns_verbose(int v) {
verbose = v;
}
/// \internal Abort program with error message.
static void shtns_runerr(const char * error_text)
{
printf("*** [" PACKAGE_NAME "] Run-time error : %s\n",error_text);
exit(1);
}
/* PUBLIC useful functions */
/// returns the l=0, m=0 SH coefficient corresponding to a uniform value of 1.
double sh00_1(shtns_cfg shtns) {
return shtns->Y00_1;
}
/// returns the l=1, m=0 SH coefficient corresponding to cos(theta).
double sh10_ct(shtns_cfg shtns) {
return shtns->Y10_ct;
}
/// returns the l=1, m=1 SH coefficient corresponding to sin(theta).cos(phi).
double sh11_st(shtns_cfg shtns) {
return shtns->Y11_st;
}
/// returns the l,m SH coefficient corresponding to unit energy.
double shlm_e1(shtns_cfg shtns, int l, int m) {
double x = shtns->Y00_1/sqrt(4.*M_PI);
if (SHT_NORM == sht_schmidt) x *= sqrt(2*l+1);
if ((m!=0)&&((shtns->norm & SHT_REAL_NORM)==0)) x *= sqrt(0.5);
return(x);
}
/// \code return (mmax+1)*(lmax+1) - mres*(mmax*(mmax+1))/2; \endcode */
/// \ingroup init
long nlm_calc(long lmax, long mmax, long mres)
{
if (mmax*mres > lmax) mmax = lmax/mres;
return (mmax+1)*(lmax+1) - ((mmax*mres)*(mmax+1))/2; // this is wrong if lmax < mmax*mres
}
/* LEGENDRE FUNCTIONS */
#include "sht_legendre.c"
/* SHT FUNCTIONS */
#include "sht_func.c"
#include "sht_com.c"
/*
INTERNAL INITIALIZATION FUNCTIONS
*/
// sht algorithms (hyb, fly1, ...)
enum sht_algos { SHT_DCT, SHT_MEM, SHT_SV,
SHT_FLY1, SHT_FLY2, SHT_FLY3, SHT_FLY4, SHT_FLY6, SHT_FLY8,
SHT_OMP1, SHT_OMP2, SHT_OMP3, SHT_OMP4, SHT_OMP6, SHT_OMP8,
SHT_NALG };
char* sht_name[SHT_NALG] = {"dct", "mem", "s+v", "fly1", "fly2", "fly3", "fly4", "fly6", "fly8", "omp1", "omp2", "omp3", "omp4", "omp6", "omp8" };
char* sht_type[SHT_NTYP] = {"syn", "ana", "vsy", "van", "gsp", "gto", "v3s", "v3a" };
char* sht_var[SHT_NVAR] = {"std", "ltr", "m" };
int sht_npar[SHT_NTYP] = {2, 2, 4, 4, 3, 3, 6, 6};
#ifdef SHTNS_MEM
extern void* fmem[SHT_NTYP];
extern void* fmem_l[SHT_NTYP];
extern void* fmem_m0[SHT_NTYP];
extern void* fmem_m0l[SHT_NTYP];
#endif
#ifdef SHTNS_DCT
extern void* fdct[SHT_NTYP];
extern void* fdct_l[SHT_NTYP];
extern void* fdct_m0[SHT_NTYP];
extern void* fdct_m0l[SHT_NTYP];
#endif
extern void* ffly[6][SHT_NTYP];
extern void* ffly_m[6][SHT_NTYP];
extern void* ffly_m0[6][SHT_NTYP];
#ifdef _OPENMP
extern void* fomp[6][SHT_NTYP];
#endif
// big array holding all sht functions, variants and algorithms
void* sht_func[SHT_NVAR][SHT_NALG][SHT_NTYP];
/// \internal use on-the-fly alogorithm (guess without measuring)
static void set_sht_fly(shtns_cfg shtns, int typ_start)
{
int algo = SHT_FLY2;
if ((shtns->nthreads > 1) && (sht_func[0][SHT_OMP2][typ_start])) algo = SHT_OMP2;
for (int it=typ_start; it<SHT_NTYP; it++) {
for (int v=0; v<SHT_NVAR; v++)
shtns->ftable[v][it] = sht_func[v][algo][it];
}
}
#ifdef SHTNS_MEM
/// \internal choose memory algorithm everywhere.
static void set_sht_mem(shtns_cfg shtns) {
for (int it=0; it<SHT_NTYP; it++) {
for (int v=0; v<SHT_NVAR; v++)
shtns->ftable[v][it] = sht_func[v][SHT_MEM][it];
shtns->ftable[SHT_M][it] = sht_func[SHT_M][SHT_FLY2][it]; // there is no "mem" algo for SHT_M
}
}
#endif
/// \internal copy all algos to sht_func array (should be called by set_grid before choosing variants).
/// if nphi is 1, axisymmetric algorithms are used.
static void init_sht_array_func(shtns_cfg shtns)
{
int it, j;
int alg_lim = SHT_FLY8;
if (shtns->nlat_2 < 8*VSIZE2) { // limit available on-the-fly algorithm to avoid overflow (and segfaults).
it = shtns->nlat_2 / VSIZE2;
switch(it) {
case 0 : alg_lim = SHT_FLY1-1; break;
case 1 : alg_lim = SHT_FLY1; break;
case 2 : alg_lim = SHT_FLY2; break;
case 3 : alg_lim = SHT_FLY3; break;
case 4 : ;
case 5 : alg_lim = SHT_FLY4; break;
default : alg_lim = SHT_FLY6;
}
}
alg_lim -= SHT_FLY1;
memset(sht_func, 0, SHT_NVAR*SHT_NTYP*SHT_NALG*sizeof(void*) ); // zero out.
sht_func[SHT_STD][SHT_SV][SHT_TYP_3SY] = SHqst_to_spat_2;
sht_func[SHT_LTR][SHT_SV][SHT_TYP_3SY] = SHqst_to_spat_2l;
sht_func[SHT_STD][SHT_SV][SHT_TYP_3AN] = spat_to_SHqst_2;
sht_func[SHT_LTR][SHT_SV][SHT_TYP_3AN] = spat_to_SHqst_2l;
sht_func[SHT_M][SHT_SV][SHT_TYP_3SY] = SHqst_to_spat_2ml;
sht_func[SHT_M][SHT_SV][SHT_TYP_3AN] = spat_to_SHqst_2ml;
if (shtns->nphi==1) { // axisymmetric transform requested.
for (int j=0; j<=alg_lim; j++) {
memcpy(sht_func[SHT_STD][SHT_FLY1 + j], &ffly_m0[j], sizeof(void*)*SHT_NTYP);
memcpy(sht_func[SHT_LTR][SHT_FLY1 + j], &ffly_m0[j], sizeof(void*)*SHT_NTYP);
}
#ifdef SHTNS_DCT
memcpy(sht_func[SHT_STD][SHT_DCT], &fdct_m0, sizeof(void*)*SHT_NTYP);
memcpy(sht_func[SHT_LTR][SHT_DCT], &fdct_m0l, sizeof(void*)*SHT_NTYP);
#endif
#ifdef SHTNS_MEM
memcpy(sht_func[SHT_STD][SHT_MEM], &fmem_m0, sizeof(void*)*SHT_NTYP);
memcpy(sht_func[SHT_LTR][SHT_MEM], &fmem_m0l, sizeof(void*)*SHT_NTYP);
#endif
} else {
for (int j=0; j<=alg_lim; j++) {
memcpy(sht_func[SHT_STD][SHT_FLY1 + j], &ffly[j], sizeof(void*)*SHT_NTYP);
memcpy(sht_func[SHT_LTR][SHT_FLY1 + j], &ffly[j], sizeof(void*)*SHT_NTYP);
memcpy(sht_func[SHT_M][SHT_FLY1 + j], &ffly_m[j], sizeof(void*)*SHT_NTYP);
#ifdef _OPENMP
memcpy(sht_func[SHT_STD][SHT_OMP1 + j], &fomp[j], sizeof(void*)*SHT_NTYP);
memcpy(sht_func[SHT_LTR][SHT_OMP1 + j], &fomp[j], sizeof(void*)*SHT_NTYP);
memcpy(sht_func[SHT_M][SHT_OMP1 + j], &ffly_m[j], sizeof(void*)*SHT_NTYP); // no omp algo for SHT_M, use fly instead
#endif
}
#ifdef SHTNS_DCT
memcpy(sht_func[SHT_STD][SHT_DCT], &fdct, sizeof(void*)*SHT_NTYP);
memcpy(sht_func[SHT_LTR][SHT_DCT], &fdct_l, sizeof(void*)*SHT_NTYP);
#endif
#ifdef SHTNS_MEM
memcpy(sht_func[SHT_STD][SHT_MEM], &fmem, sizeof(void*)*SHT_NTYP);
memcpy(sht_func[SHT_LTR][SHT_MEM], &fmem_l, sizeof(void*)*SHT_NTYP);
#endif
}
#ifdef SHTNS_MEM
set_sht_mem(shtns); // default transform is MEM
#else
set_sht_fly(shtns, 0);
#endif
}
/// \internal return the smallest power of 2 larger than n.
static int next_power_of_2(int n)
{
int f = 1;
if ( (n<=0) || (n>(1<<(sizeof(int)*8-2))) ) return 0;
while (f<n) f*=2;
return f;
}
/// \internal find the closest integer that is larger than n and that contains only factors up to fmax.
/// fmax is 7 for optimal FFTW fourier transforms.
/// return only even integers for n>fmax.
static int fft_int(int n, int fmax)
{
int k,f;
if (n<=fmax) return n;
if (fmax<2) return 0;
if (fmax==2) return next_power_of_2(n);
n -= 2-(n&1); // only even n
do {
n+=2; f=2;
while ((2*f <= n) && ((n&f)==0)) f *= 2; // no divisions for factor 2.
k=3;
while ((k<=fmax) && (k*f <= n)) {
while ((k*f <= n) && (n%(k*f)==0)) f *= k;
k+=2;
}
} while (f != n);
k = next_power_of_2(n); // what is the closest power of 2 ?
if ((k-n)*33 < n) return k; // rather choose power of 2 if not too far (3%)
return n;
}
/// \internal returns an aproximation of the memory usage in mega bytes for the scalar matrices.
/// \ingroup init
static double sht_mem_size(int lmax, int mmax, int mres, int nlat)
{
double s = 1./(1024*1024);
s *= ((nlat+1)/2) * sizeof(double) * nlm_calc(lmax, mmax, mres);
return s;
}
/// \internal return the number of shtns config that contain a reference to the memory location *pp.
static int ref_count(shtns_cfg shtns, void* pp)
{
shtns_cfg s2 = sht_data;
void* p;
long int nref, offset;
if ((pp==NULL) || (shtns==NULL)) return -1; // error.
p = *(void**)pp; // the pointer to memory location that we want to free
if (p == NULL) return 0; // nothing to do.
offset = (char*)pp - (char*)shtns; // relative location in shtns_info structure.
nref = 0; // reference count.
while (s2 != NULL) { // scan all configs.
if ( *(void**)(((char*)s2) + offset) == p ) nref++;
s2 = s2->next;
}
return nref; // will be >= 1 (as shtns is included in search)
}
/// \internal check if the memory location *pp is referenced by another sht config before freeing it.
/// returns the number of other references, or -1 on error. If >=1, the memory location could not be freed.
/// If the return value is 0, the ressource has been freed.
static int free_unused(shtns_cfg shtns, void* pp)
{
int n = ref_count(shtns, pp); // howmany shtns config do reference this memory location ?
if (n <= 0) return n; // nothing to free.
if (n == 1) { // no other reference found...
void** ap = (void**) pp;
free(*ap); // ...so we can free it...
*ap = NULL; // ...and mark as unaloccated.
}
return (n-1);
}
#ifdef SHTNS_MEM
/// \internal Free matrices if on-the-fly has been selected.
static void free_unused_matrices(shtns_cfg shtns)
{
long int marray_size = (MMAX+1)*sizeof(double) + (MIN_ALIGNMENT-1);
int count[SHT_NTYP];
int it, iv, ia, iv2;
for (it=0; it<SHT_NTYP; it++) {
count[it] = 0;
for (iv=0; iv<SHT_NVAR; iv++) {
void* fptr = shtns->ftable[iv][it];
if (fptr != NULL) {
for (ia=0; ia<=SHT_MEM; ia++) // count occurences to mem algo
for (iv2=0; iv2<SHT_NVAR; iv2++)
if (sht_func[iv2][ia][it] == fptr) count[it]++;
}
}
#if SHT_VERBOSE > 1
if (verbose>1) printf(" %d ",count[it]);
#endif
}
if (shtns->dylm == NULL) { // no vector transform : do not try to free
count[SHT_TYP_VAN] = -1; count[SHT_TYP_VSY] = -1;
}
if (count[SHT_TYP_3AN] == 0) { // analysis may be freed.
if (count[SHT_TYP_VAN] == 0) {
PRINT_VERB("freeing vector analysis matrix\n");
free_unused(shtns, &shtns->dzlm);
}
if (count[SHT_TYP_SAN] == 0) {
PRINT_VERB("freeing scalar analysis matrix\n");
free_unused(shtns, &shtns->zlm);
}
} else if (shtns->mmax > 0) { // scalar may be reduced to m=0
if ((count[SHT_TYP_SAN] == 0) && (ref_count(shtns, &shtns->zlm) == 1)) {
PRINT_VERB("keeping scalar analysis matrix up to m=0\n");
shtns->zlm = realloc(shtns->zlm, ((LMAX+1)*NLAT_2 +3)*sizeof(double) + marray_size );
}
}
if (count[SHT_TYP_3SY] == 0) { // synthesis may be freed.
if (count[SHT_TYP_VSY] + count[SHT_TYP_GSP] + count[SHT_TYP_GTO] == 0) {
PRINT_VERB("freeing vector synthesis matrix\n");
free_unused(shtns, &shtns->dylm);
}
if (count[SHT_TYP_SSY] == 0) {
PRINT_VERB("freeing scalar synthesis matrix\n");
free_unused(shtns, &shtns->ylm);
}
} else if (shtns->mmax > 0) { // scalar may be reduced to m=0
if ((count[SHT_TYP_SSY] == 0) && (ref_count(shtns, &shtns->ylm) == 1)) {
PRINT_VERB("keeping scalar synthesis matrix up to m=0\n");
shtns->ylm = realloc(shtns->ylm, (LMAX+2)*NLAT_2*sizeof(double) + marray_size );
}
}
}
#endif
/// \internal allocate arrays for SHT related to a given grid.
static void alloc_SHTarrays(shtns_cfg shtns, int on_the_fly, int vect, int analys)
{
long int im, l0;
long int size, marray_size, lstride;
im = (VSIZE2 > 2) ? VSIZE2 : 2;
l0 = ((NLAT+im-1)/im)*im; // align on vector
shtns->ct = (double *) VMALLOC( sizeof(double) * l0*3 ); /// ct[] (including st and st_1)
shtns->st = shtns->ct + l0; shtns->st_1 = shtns->ct + 2*l0;
shtns->ylm = NULL; shtns->dylm = NULL; // synthesis
shtns->zlm = NULL; shtns->dzlm = NULL; // analysis
if (on_the_fly == 0) { // Allocate legendre functions lookup tables.
marray_size = (MMAX+1)*sizeof(double*) + (MIN_ALIGNMENT-1); // for sse2 alignement
/* ylm */
lstride = (LMAX+1); lstride += (lstride&1); // even stride.
size = sizeof(double) * ((NLM-(LMAX+1)+lstride)*NLAT_2);
if (MMAX == 0) size += 3*sizeof(double); // some overflow needed.
shtns->ylm = (double **) malloc( marray_size + size );
shtns->ylm[0] = (double *) PTR_ALIGN( shtns->ylm + (MMAX+1) );
if (MMAX>0) shtns->ylm[1] = shtns->ylm[0] + NLAT_2*lstride;
for (im=1; im<MMAX; im++) shtns->ylm[im+1] = shtns->ylm[im] + NLAT_2*(LMAX+1-im*MRES);
/* dylm */
if (vect) {
lstride = LMAX; lstride += (lstride&1); // even stride.
size = sizeof(struct DtDp) * ((NLM-(LMAX+1) +lstride/2)*NLAT_2);
if (MMAX == 0) size += 2*sizeof(double); // some overflow needed.
shtns->dylm = (struct DtDp **) malloc( marray_size + size );
shtns->dylm[0] = (struct DtDp *) PTR_ALIGN( shtns->dylm + (MMAX+1) );
if (MMAX>0) shtns->dylm[1] = shtns->dylm[0] + (lstride/2)*NLAT_2; // phi-derivative is zero for m=0
for (im=1; im<MMAX; im++) shtns->dylm[im+1] = shtns->dylm[im] + NLAT_2*(LMAX+1-im*MRES);
}
if (analys) {
/* zlm */
size = sizeof(double) * (NLM*NLAT_2 + (NLAT_2 & 1));
if (MMAX == 0) size += 2*(NLAT_2 & 1)*((LMAX+1) & 1) * sizeof(double);
shtns->zlm = (double **) malloc( marray_size + size );
shtns->zlm[0] = (double *) PTR_ALIGN( shtns->zlm + (MMAX+1) );
if (MMAX>0) shtns->zlm[1] = shtns->zlm[0] + NLAT_2*(LMAX+1) + (NLAT_2&1);
for (im=1; im<MMAX; im++) shtns->zlm[im+1] = shtns->zlm[im] + NLAT_2*(LMAX+1-im*MRES);
/* dzlm */
if (vect) {
size = sizeof(struct DtDp)* (NLM-1)*NLAT_2; // remove l=0
shtns->dzlm = (struct DtDp **) malloc( marray_size + size );
shtns->dzlm[0] = (struct DtDp *) PTR_ALIGN( shtns->dzlm + (MMAX+1) );
if (MMAX>0) shtns->dzlm[1] = shtns->dzlm[0] + NLAT_2*(LMAX);
for (im=1; im<MMAX; im++) shtns->dzlm[im+1] = shtns->dzlm[im] + NLAT_2*(LMAX+1-im*MRES);
}
}
}
#if SHT_VERBOSE > 1
if (verbose>1) printf(" Memory used for Ylm and Zlm matrices = %.3f Mb x2\n",3.0*sizeof(double)*NLM*NLAT_2/(1024.*1024.));
#endif
}
/// \internal free arrays allocated by init_SH_dct
static void free_SH_dct(shtns_cfg shtns)
{
if (shtns->zlm_dct0 == NULL) return;
if (ref_count(shtns, &shtns->dzlm_dct0) == 1) VFREE(shtns->dzlm_dct0);
if (ref_count(shtns, &shtns->zlm_dct0) == 1) VFREE(shtns->zlm_dct0);
shtns->dzlm_dct0 = NULL; shtns->zlm_dct0 = NULL;
free_unused(shtns, &shtns->dykm_dct);
free_unused(shtns, &shtns->ykm_dct);
if (ref_count(shtns, &shtns->idct) == 1) fftw_destroy_plan(shtns->idct); // free unused dct plans
if (ref_count(shtns, &shtns->dct_m0) == 1) fftw_destroy_plan(shtns->dct_m0);
shtns->idct = NULL; shtns->dct_m0 = NULL;
}
/// \internal free arrays allocated by alloc_SHTarrays.
static void free_SHTarrays(shtns_cfg shtns)
{
free_SH_dct(shtns);
free_unused(shtns, &shtns->ylm);
free_unused(shtns, &shtns->dylm);
free_unused(shtns, &shtns->zlm);
free_unused(shtns, &shtns->dzlm);
if (ref_count(shtns, &shtns->ct) == 1) VFREE(shtns->ct);
shtns->ct = NULL; shtns->st = NULL;
if (ref_count(shtns, &shtns->fft) == 1) fftw_destroy_plan(shtns->fft);
if (ref_count(shtns, &shtns->ifft) == 1) fftw_destroy_plan(shtns->ifft);
shtns->fft = NULL; shtns->ifft = NULL; shtns->ncplx_fft = -1; // no fft
}
#ifndef HAVE_FFTW_COST
// substitute undefined symbol in mkl and fftw older than 3.3
#define fftw_cost(a) 0.0
#endif
/// \internal initialize FFTs using FFTW.
/// \param[in] layout defines the spatial layout (see \ref spat).
/// \param[in] on_the_fly is one, if only on-the-fly transform are considered.
/// returns the number of double to be allocated for a spatial field.
static void planFFT(shtns_cfg shtns, int layout, int on_the_fly)
{
double cost_fft_ip, cost_fft_oop, cost_ifft_ip, cost_ifft_oop;
cplx *ShF;
double *Sh;
fftw_plan fft2, ifft2, fft, ifft;
int nfft, ncplx, nreal;
int theta_inc, phi_inc, phi_embed;
#ifdef HAVE_FFTW_COST
int in_place = 1; // try to use in-place real fft.
#else
int in_place = 0; // do not try to use in-place real fft if no timing data available.
#endif
if (NPHI <= 2*MMAX) shtns_runerr("the sampling condition Nphi > 2*Mmax is not met.");
#ifdef OMP_FFTW
if ((shtns->fftw_plan_mode & (FFTW_EXHAUSTIVE | FFTW_PATIENT)) && (omp_threads > 1)) {
shtns->fftw_plan_mode = FFTW_PATIENT;
fftw_plan_with_nthreads(omp_threads);
} else fftw_plan_with_nthreads(shtns->nthreads);
#endif
shtns->k_stride_a = 1; shtns->m_stride_a = NLAT; // default strides
shtns->fft = NULL; shtns->ifft = NULL;
shtns->dct_m0 = NULL; shtns->idct = NULL; // set dct plans to uninitialized.
shtns->nspat = NPHI * NLAT; // default spatial size
if (NPHI==1) // no FFT needed.
{
shtns->fftc_mode = -1; // no FFT
#if SHT_VERBOSE > 0
if (verbose) printf(" => no fft : Mmax=0, Nphi=1, Nlat=%d\n",NLAT);
#endif
shtns->ncplx_fft = -1; // no fft.
return;
}
/* NPHI > 1 */
theta_inc=1; phi_inc=NLAT; phi_embed=2*(NPHI/2+1); // SHT_NATIVE_LAYOUT is the default.
if (layout & SHT_THETA_CONTIGUOUS) { theta_inc=1; phi_inc=NLAT; phi_embed=NPHI; }
if (layout & SHT_PHI_CONTIGUOUS) { phi_inc=1; theta_inc=NPHI; phi_embed=NPHI; }
nfft = NPHI;
ncplx = NPHI/2 +1;
nreal = phi_embed;
if ((theta_inc != 1)||(phi_inc != NLAT)||(nreal < 2*ncplx)) in_place = 0; // we need to do the fft out-of-place.
#if SHT_VERBOSE > 0
if (verbose) {
printf(" => using FFTW : Mmax=%d, Nphi=%d, Nlat=%d (data layout : phi_inc=%d, theta_inc=%d, phi_embed=%d)\n",MMAX,NPHI,NLAT,phi_inc,theta_inc,phi_embed);
if (NPHI <= (SHT_NL_ORDER+1)*MMAX) printf(" !! Warning : anti-aliasing condition Nphi > %d*Mmax is not met !\n", SHT_NL_ORDER+1);
if (NPHI != fft_int(NPHI,7)) printf(" !! Warning : Nphi is not optimal for FFTW !\n");
}
#endif
// Allocate dummy Spatial Fields.
ShF = (cplx *) VMALLOC(ncplx * NLAT * sizeof(cplx));
Sh = (double *) VMALLOC(ncplx * NLAT * sizeof(cplx));
fft = NULL; ifft = NULL; fft2 = NULL; ifft2 = NULL;
// complex fft for fly transform is a bit different.
if (layout & SHT_PHI_CONTIGUOUS) { // out-of-place split dft
fftw_iodim dim, many;
shtns->fftc_mode = 1;
//default internal
dim.n = NPHI; dim.os = 1; dim.is = NLAT; // complex transpose
many.n = NLAT/2; many.os = 2*NPHI; many.is = 2;
shtns->ifftc = fftw_plan_guru_split_dft(1, &dim, 1, &many, ((double*)ShF)+1, (double*)ShF, Sh+NPHI, Sh, shtns->fftw_plan_mode);
// legacy analysis fft
//dim.n = NPHI; dim.is = 1; dim.os = NLAT;
//many.n = NLAT/2; many.is = 2*NPHI; many.os = 2;
// new internal
dim.n = NPHI; dim.is = 1; dim.os = 2; // split complex, but without global transpose (faster).
many.n = NLAT/2; many.is = 2*NPHI; many.os = 2*NPHI;
shtns->fftc = fftw_plan_guru_split_dft(1, &dim, 1, &many, Sh+NPHI, Sh, ((double*)ShF)+1, (double*)ShF, shtns->fftw_plan_mode);
shtns->k_stride_a = NPHI; shtns->m_stride_a = 2;
#if SHT_VERBOSE > 1
if (verbose>1) {
printf(" fftw cost ifftc=%lg, fftc=%lg ",fftw_cost(shtns->ifftc), fftw_cost(shtns->fftc)); fflush(stdout);
}
#endif
} else { //if (layout & SHT_THETA_CONTIGUOUS) { // use only in-place here, supposed to be faster.
shtns->fftc_mode = 0;
shtns->ifftc = fftw_plan_many_dft(1, &nfft, NLAT/2, ShF, &nfft, NLAT/2, 1, ShF, &nfft, NLAT/2, 1, FFTW_BACKWARD, shtns->fftw_plan_mode);
shtns->fftc = shtns->ifftc; // same thing, with m>0 and m<0 exchanged.
#if SHT_VERBOSE > 1
if (verbose>1) {
printf(" fftw cost ifftc=%lg ",fftw_cost(shtns->ifftc)); fflush(stdout);
}
#endif
}
#if _GCC_VEC_
if (on_the_fly == 0)
#endif
{ // the real ffts are required if _GCC_VEC_ == 0 or if on_the_fly is zero.
// IFFT : unnormalized. FFT : must be normalized.
cost_fft_ip = 0.0; cost_ifft_ip = 0.0; cost_fft_oop = 0.0; cost_ifft_oop = 0.0;
if (in_place) { // in-place FFT (if allowed)
ifft2 = fftw_plan_many_dft_c2r(1, &nfft, NLAT, ShF, &ncplx, NLAT, 1, (double*) ShF, &nreal, phi_inc, theta_inc, shtns->fftw_plan_mode);
#if SHT_VERBOSE > 1
if (verbose>1) {
printf(" in-place cost : ifft=%lg ",fftw_cost(ifft2)); fflush(stdout);
}
#endif
if (ifft2 != NULL) {
fft2 = fftw_plan_many_dft_r2c(1, &nfft, NLAT, (double*) ShF, &nreal, phi_inc, theta_inc, ShF, &ncplx, NLAT, 1, shtns->fftw_plan_mode);
#if SHT_VERBOSE > 1
if (verbose>1) {
printf("fft=%lg\n",fftw_cost(fft2)); fflush(stdout);
}
#endif
if (fft2 != NULL) {
cost_fft_ip = fftw_cost(fft2); cost_ifft_ip = fftw_cost(ifft2);
}
}
}
if ( (in_place == 0) || (cost_fft_ip * cost_ifft_ip > 0.0) )
{ // out-of-place FFT
ifft = fftw_plan_many_dft_c2r(1, &nfft, NLAT, ShF, &ncplx, NLAT, 1, Sh, &nreal, phi_inc, theta_inc, shtns->fftw_plan_mode);
#if SHT_VERBOSE > 1
if (verbose>1) { printf(" oop cost : ifft=%lg ",fftw_cost(ifft)); fflush(stdout); }
#endif
if (ifft == NULL) shtns_runerr("[FFTW] ifft planning failed !");
fft = fftw_plan_many_dft_r2c(1, &nfft, NLAT, Sh, &nreal, phi_inc, theta_inc, ShF, &ncplx, NLAT, 1, shtns->fftw_plan_mode);
#if SHT_VERBOSE > 1
if (verbose>1) { printf("fft=%lg\n",fftw_cost(fft)); fflush(stdout); }
#endif
if (fft == NULL) shtns_runerr("[FFTW] fft planning failed !");
cost_fft_oop = fftw_cost(fft); cost_ifft_oop = fftw_cost(ifft);
}
if ( (cost_fft_ip * cost_ifft_ip > 0.0) && (cost_fft_oop * cost_ifft_oop > 0.0) ) { // both have been succesfully timed.
if ( cost_fft_oop + SHT_NL_ORDER*cost_ifft_oop < cost_fft_ip + SHT_NL_ORDER*cost_ifft_ip )
in_place = 0; // disable in-place, because out-of-place is faster.
}
if (in_place) {
/* IN-PLACE FFT */
if (fft != NULL) fftw_destroy_plan(fft);
if (ifft != NULL) fftw_destroy_plan(ifft);
fft = fft2; ifft = ifft2;
shtns->ncplx_fft = 0; // fft is done in-place, no allocation needed.
shtns->nspat = phi_embed * NLAT; // more space must be reserved for inplace ffts.
} else {
/* OUT-OF-PLACE FFT */
if (fft2 != NULL) fftw_destroy_plan(fft2); // use OUT-OF-PLACE FFT
if (ifft2 != NULL) fftw_destroy_plan(ifft2);
shtns->ncplx_fft = ncplx * NLAT; // fft is done out-of-place, store allocation size.
#if SHT_VERBOSE > 1
if (verbose>1) printf(" ** out-of-place fft **\n");
#endif
}
shtns->fft = fft; shtns->ifft = ifft;
}
VFREE(Sh); VFREE(ShF);
#if SHT_VERBOSE > 2
if (verbose>2) {
printf(" *** fft plan :\n");
fftw_print_plan(fft);
printf("\n *** ifft plan :\n");
fftw_print_plan(ifft);
printf("\n");
}
#endif
}
#ifdef SHTNS_DCT
/// \internal initialize DCTs using FFTW. Must be called if MTR_DCT is changed.
static int planDCT(shtns_cfg shtns)
{
double *Sh;
int ndct = NLAT;
fftw_r2r_kind r2r_kind;
fftw_iodim dims, hdims[2];
double Sh0[NLAT] SSE; // temp storage on the stack, aligned.
#ifdef OMP_FFTW
if (shtns->fftw_plan_mode & (FFTW_EXHAUSTIVE | FFTW_PATIENT)) {
fftw_plan_with_nthreads(omp_threads);
} else fftw_plan_with_nthreads(1);
#endif
// Allocate dummy Spatial Fields.
Sh = (double *) VMALLOC((NPHI/2 +1) * NLAT*2 * sizeof(double));
if (shtns->dct_m0 == NULL) { // allocate only once since it does not change.
int stride = (NPHI>1) ? 2 : 1;
r2r_kind = FFTW_REDFT10; // out-of-place.
shtns->dct_m0 = fftw_plan_many_r2r(1, &ndct, 1, Sh, &ndct, stride, stride*NLAT, Sh0, &ndct, 1, NLAT, &r2r_kind, shtns->fftw_plan_mode); // out-of-place.
if (shtns->dct_m0 == NULL) return 0; // dct_m0 planning failed.
#if SHT_VERBOSE > 2
if (verbose>2) {
printf(" *** dct_m0 plan :\n"); fftw_print_plan(shtns->dct_m0); printf("\n");
}
#endif
}
if (NPHI > 1) { // complex data for NPHI>1, recompute as it does depend on MTR_DCT
if (shtns->idct != NULL) fftw_destroy_plan(shtns->idct);
dims.n = NLAT; dims.is = 2; dims.os = 2; // real and imaginary part.
hdims[0].n = MTR_DCT+1; hdims[0].is = 2*NLAT; hdims[0].os = 2*NLAT;
hdims[1].n = 2; hdims[1].is = 1; hdims[1].os = 1;
r2r_kind = FFTW_REDFT01;
shtns->idct = fftw_plan_guru_r2r(1, &dims, 2, hdims, Sh, Sh, &r2r_kind, shtns->fftw_plan_mode);
} else { // NPHI == 1
if (shtns->idct == NULL) {
r2r_kind = FFTW_REDFT01;
shtns->idct = fftw_plan_many_r2r(1, &ndct, 1, Sh, &ndct, 1, NLAT, Sh, &ndct, 1, NLAT, &r2r_kind, shtns->fftw_plan_mode);
}
}
VFREE(Sh);
if (shtns->idct == NULL) return 0; // idct planning failed.
#if SHT_VERBOSE > 2
if (verbose>2) {
printf(" *** idct plan :\n"); fftw_print_plan(shtns->idct); printf("\n");
}
#endif
return 1; // success.
}
/// \internal SET MTR_DCT and updates fftw_plan for DCT's
static int Set_MTR_DCT(shtns_cfg shtns, int m)
{
if ((shtns->zlm_dct0 == NULL)||(m == MTR_DCT)) return MTR_DCT;
if ( m < 0 ) { // don't use dct
shtns->mtr_dct = -1;
} else {
if (m>MMAX) m=MMAX;
shtns->mtr_dct = m;
if (planDCT(shtns) == 0)
shtns->mtr_dct = -1; // failure
}
return MTR_DCT;
}
/// \internal returns the m-truncation of DCT part of synthesis
static int Get_MTR_DCT(shtns_cfg shtns) {
return MTR_DCT;
}
#endif /* SHTNS_DCT */
/// \internal Sets the value tm[im] used for polar optimiation on-the-fly.
static void PolarOptimize(shtns_cfg shtns, double eps)
{
int im, m, l, it;
double v;
double y[LMAX+1];
for (im=0;im<=MMAX;im++) shtns->tm[im] = 0;
if (eps > 0.0) {
for (im=1;im<=MMAX;im++) {
m = im*MRES;
it = shtns->tm[im-1] -1; // tm[im] is monotonic.
do {
it++;
legendre_sphPlm_array(shtns, LMAX, im, shtns->ct[it], y+m);
v = 0.0;
for (l=m; l<=LMAX; l++) {
double ya = fabs(y[l]);
if ( v < ya ) v = ya;
}
} while (v < eps);
shtns->tm[im] = it;
}
#if SHT_VERBOSE > 0
if (verbose) printf(" + polar optimization threshold = %.1e\n",eps);
#endif
#if SHT_VERBOSE > 1
if (verbose>1) {
printf(" tm[im]=");
for (im=0;im<=MMAX;im++)
printf(" %d",shtns->tm[im]);
printf("\n");
}
#endif
}
}
#ifdef SHTNS_MEM
/// \internal Perform some optimization on the SHT matrices.
static void OptimizeMatrices(shtns_cfg shtns, double eps)
{
unsigned short *tm;
double **ylm, **zlm;
struct DtDp** dylm;
struct DtDp** dzlm;
int im,m,l,it;
int vector = (shtns->dylm != NULL);
tm = shtns->tm;
ylm = shtns->ylm; dylm = shtns->dylm;
zlm = shtns->zlm; dzlm = shtns->dzlm;
for (im=0;im<=MMAX;im++) tm[im] = 0;
/// POLAR OPTIMIZATION : analyzing coefficients, some can be safely neglected.
if (eps > 0.0) {
for (im=1;im<=MMAX;im++) {
m = im*MRES;
tm[im] = NLAT_2;
for (l=m;l<=LMAX;l++) {
it = tm[im-1]; // tm[im] is monotonic.
while( fabs(ylm[im][it*(LMAX-m+1) + (l-m)]) < eps ) { it++; }
if (tm[im] > it) tm[im] = it;
}
}
#if SHT_VERBOSE > 0
if (verbose) printf(" + polar optimization threshold = %.1e\n",eps);
#endif
#if SHT_VERBOSE > 1
if (verbose>1) {
printf(" tm[im]=");
for (im=0;im<=MMAX;im++)
printf(" %d",tm[im]);
printf("\n");
}
#endif
for (im=1; im<=MMAX; im++) { // im >= 1
if (tm[im] > 0) { // we can remove the data corresponding to polar values.
m = im*MRES;
ylm[im] += tm[im]*(LMAX-m+1); // shift pointers (still one block for each m)
if (vector) dylm[im] += tm[im]*(LMAX-m+1);
if (zlm[0] != NULL) {
for (l=m; l<LMAX; l+=2) {
for (it=0; it<NLAT_2-tm[im]; it++) { // copy data to avoid cache misses.
zlm[im][(l-m)*(NLAT_2-tm[im]) + it*2] = zlm[im][(l-m)*NLAT_2 + (it+tm[im])*2];
zlm[im][(l-m)*(NLAT_2-tm[im]) + it*2+1] = zlm[im][(l-m)*NLAT_2 + (it+tm[im])*2+1];
if (vector) {
dzlm[im][(l-m)*(NLAT_2-tm[im]) + it*2].t = dzlm[im][(l-m)*NLAT_2 + (it+tm[im])*2].t;
dzlm[im][(l-m)*(NLAT_2-tm[im]) + it*2].p = dzlm[im][(l-m)*NLAT_2 + (it+tm[im])*2].p;
dzlm[im][(l-m)*(NLAT_2-tm[im]) + it*2+1].t = dzlm[im][(l-m)*NLAT_2 + (it+tm[im])*2+1].t;
dzlm[im][(l-m)*(NLAT_2-tm[im]) + it*2+1].p = dzlm[im][(l-m)*NLAT_2 + (it+tm[im])*2+1].p;
}
}
}
if (l==LMAX) {
for (it=0; it<NLAT_2-tm[im]; it++) {
zlm[im][(l-m)*(NLAT_2-tm[im]) + it] = zlm[im][(l-m)*NLAT_2 + (it+tm[im])];
if (vector) {
dzlm[im][(l-m)*(NLAT_2-tm[im]) + it].t = dzlm[im][(l-m)*NLAT_2 + (it+tm[im])].t;
dzlm[im][(l-m)*(NLAT_2-tm[im]) + it].p = dzlm[im][(l-m)*NLAT_2 + (it+tm[im])].p;
}
}
}
}
}
}
}
/// Compression of dzlm for m=0, as .p is 0
if ((vector) && (dzlm[0] != NULL)) { // for sht_reg_poles there is no dzlm defined.
im=0; m=0;
double* yg = (double *) dzlm[im];
for (l=1; l<LMAX; l+=2) { // l=0 is zero, so we start at l=1.
for (it=0; it<NLAT_2; it++) {
yg[(l-1)*NLAT_2 + it*2] = dzlm[im][(l-1)*NLAT_2 + it*2].t; // l
yg[(l-1)*NLAT_2 + it*2+1] = dzlm[im][(l-1)*NLAT_2 + it*2+1].t; // l+1
}
}
if (l==LMAX) { // last l is stored right away, without interleaving.
for (it=0; it<NLAT_2; it++) {
yg[(l-1)*NLAT_2 + it] = dzlm[im][(l-1)*NLAT_2 + it].t; // l (odd)
}
}
}
if ((zlm[0] != NULL) && (NLAT_2 & 1)) {
zlm[0][NLAT_2] = 0.0; // take care to write 0.0 for this sse2 padding value.
if ( (MMAX==0) && (!(LMAX & 1)) ) { // NLAT_2 odd + LMAX even
zlm[0][(LMAX+1)*NLAT_2 +1] = 0.0; // overflow for im=0
zlm[0][(LMAX+1)*NLAT_2 +2] = 0.0;
}
}
}
// how to access the ylm matrix for im=0
#define YL0(it, l) ( shtns->ylm[0][ (it)*(((LMAX+2)>>1)*2) + (l) ] )
#define DYL0(it, l) ( ((double*)(shtns->dylm[0]))[ (it)*(((LMAX+1)>>1)*2) + (l-1) ] )
#define YLM(it, l, im) ( (im==0) ? YL0(it,l) : shtns->ylm[im][(it)*(LMAX-(im)*MRES+1) + ((l)-(im)*MRES)] )
#define DTYLM(it, l, im) ( (im==0) ? ( (l==0) ? 0.0 : DYL0(it,l) ) : shtns->dylm[im][(it)*(LMAX-(im)*MRES+1) + ((l)-(im)*MRES)].t )
#define DPYLM(it, l, im) ( (im==0) ? 0.0 : shtns->dylm[im][(it)*(LMAX-(im)*MRES+1) + ((l)-(im)*MRES)].p )
/// \internal Precompute the matrix for SH synthesis.
static void init_SH_synth(shtns_cfg shtns)
{
double *yl, *dyl; // temp storage for derivative for legendre function values.
long int it,im,m,l;
double *ct = shtns->ct;
double *st = shtns->st;
int vector = (shtns->dylm != NULL);
yl = (double*) malloc( 2*sizeof(double) *(LMAX+1) );
dyl = yl + (LMAX+1);
{ im=0; m=0;
for (it=0; it<NLAT_2; it++) {
legendre_sphPlm_deriv_array_hp(shtns, LMAX, im, ct[it], st[it], yl, dyl); // fixed im legendre functions lookup table.
for (l=0; l<=LMAX; l++) YL0(it, l) = yl[l];
for (l=LMAX+1; l<=LMAX+3; l++) YL0(it, l) = 0.0; // allow overflow.
if (vector) {
for (l=1; l<=LMAX; l++) DYL0(it, l) = dyl[l];
for (l=LMAX+1; l<=LMAX+2; l++) DYL0(it, l) = 0.0; // allow overflow.
}
}
}
for (im=1; im<=MMAX; im++) {
double *ylm = shtns->ylm[im];
struct DtDp* dylm = vector ? shtns->dylm[im] : NULL;
m = im*MRES;
for (it=0; it<NLAT_2; it++) {
legendre_sphPlm_deriv_array_hp(shtns, LMAX, im, ct[it], st[it], yl, dyl); // fixed im legendre functions lookup table.
for (l=m; l<=LMAX; l++) {
ylm[it*(LMAX-m+1) + (l-m)] = yl[l-m] * st[it];
if (vector) {
dylm[it*(LMAX-m+1) + (l-m)].t = dyl[l-m];
dylm[it*(LMAX-m+1) + (l-m)].p = yl[l-m] *m; // 1/sint(t) dYlm/dphi
}
}
}
}
free(yl);
}
/// \internal Precompute matrices for SH synthesis and analysis, on a Gauss-Legendre grid.
static void init_SH_gauss(shtns_cfg shtns)
{
long int it,im,m,l;
int vector = (shtns->dylm != NULL);
init_SH_synth(shtns);
// for analysis (decomposition, direct transform) : transpose and multiply by gauss weight and other normalizations.
// interleave l and l+1 : this stores data in the way it will be read.
double **zlm = shtns->zlm;
struct DtDp** dzlm = shtns->dzlm;
for (im=0; im<=MMAX; im++) {
m = im*MRES;
long int talign = 0;
for (it=0;it<NLAT_2;it++) {
double norm = shtns->wg[it];
if ( (m>0) && (shtns->norm & SHT_REAL_NORM) ) norm *= 2; // "Real" norm : zlm must be doubled for m>0
long int l0 = m;
if (m==0) {
zlm[im][it] = YL0(it, 0) * norm;
// les derivees sont nulles pour l=0
l0++;
talign = (NLAT_2&1);
}
for (l=l0; l<LMAX; l+=2) {
double nz0 = norm; double nz1 = norm;
if (SHT_NORM == sht_schmidt) {
nz0 *= (2*l+1); nz1 *= (2*l+3);
}
zlm[im][(l-m)*NLAT_2 + it*2 +talign] = YLM(it, l, im) * nz0;
zlm[im][(l-m)*NLAT_2 + it*2 +1 +talign] = YLM(it, l+1, im) * nz1;
if (vector) {
nz0 *= shtns->l_2[l]; nz1 *= shtns->l_2[l+1];
dzlm[im][(l-l0)*NLAT_2 + it*2].t = DTYLM(it, l, im) * nz0;
dzlm[im][(l-l0)*NLAT_2 + it*2].p = DPYLM(it, l, im) * nz0;
dzlm[im][(l-l0)*NLAT_2 + it*2+1].t = DTYLM(it, l+1, im) * nz1;
dzlm[im][(l-l0)*NLAT_2 + it*2+1].p = DPYLM(it, l+1, im) * nz1;
}
}
if (l==LMAX) { // last l is stored right away, without interleaving.
double nz0 = norm;
if (SHT_NORM == sht_schmidt) nz0 *= (2*l+1);
zlm[im][(l-m)*NLAT_2 + it +talign] = YLM(it, l, im) * nz0;
if (vector) {
nz0 *= shtns->l_2[l];
dzlm[im][(l-l0)*NLAT_2 + it].t = DTYLM(it, l, im) * nz0;
dzlm[im][(l-l0)*NLAT_2 + it].p = DPYLM(it, l, im) * nz0;
}
}
}
}
}
#endif
#ifdef SHTNS_DCT
static void init_SH_dct_m(shtns_cfg shtns, double* is1, fftw_plan dct, fftw_plan idct, int analysis, const int m0, const int mstep)
{
double *yk, *yk0, *dyk0, *yg; // temp storage
struct DtDp *dyg, *dyk;
int it,im,m,l;
double Z[2*NLAT_2] SSE;
double dZt[2*NLAT_2] SSE;
double dZp[2*NLAT_2] SSE; // equally spaced theta points.
double *st = shtns->st;
double *st_1 = shtns->st_1;
const int vector = (shtns->dylm != NULL);
const int KMAX = LMAX+1;
real iylm_fft_norm = 1.0; // FFT/SHT normalization for zlm (4pi normalized)
if ((SHT_NORM != sht_fourpi)&&(SHT_NORM != sht_schmidt)) iylm_fft_norm = 4*M_PIl; // FFT/SHT normalization for zlm (orthonormalized)
iylm_fft_norm /= (2*NPHI*NLAT_2);
// Even/Odd symmetry : ylm is even or odd across equator, as l-m is even or odd => only NLAT_2 points required.
// temp memory for ykm_dct.
yk = (double *) malloc( sizeof(double) * (KMAX+1)*(LMAX+1) );
dyk = (struct DtDp *) malloc( sizeof(struct DtDp)* (KMAX+1)*(LMAX+1) );
if ((m0==0)&&(analysis)) {
yk0 = (double *) malloc( sizeof(double) * (LMAX/2+1)*(2*NLAT_2) * 2 ); // temp for zlm_dct0
dyk0 = yk0 + (LMAX/2+1)*(2*NLAT_2);
}
for (im=m0; im<=MMAX; im+=mstep) {
m = im*MRES;
// go to DCT space
for (it=0;it<=KMAX;it+=2) {
for(l=m; l<=LMAX; l++) {
yk[(it/2)*(LMAX+1-m) + (l-m)] = 0.0;
dyk[(it/2)*(LMAX+1-m) + (l-m)].t = 0.0;
dyk[(it/2)*(LMAX+1-m) + (l-m)].p = 0.0;
}
}
for (l=m; l<=LMAX; l++) {
if (m & 1) { // m odd
for (it=0; it<NLAT_2; it++) {
Z[it] = YLM(it, l, im) * st[it]; // P[l+1](x) *st
if (vector) {
dZt[it] = DTYLM(it, l, im); // P[l](x) *1
dZp[it] = DPYLM(it, l, im); // P[l-1](x) *1
}
}
} else { // m even
for (it=0; it<NLAT_2; it++) {
Z[it] = YLM(it, l, im); // P[l](x) *1
if (vector) {
dZt[it] = DTYLM(it, l, im) *st[it]; // P[l+1](x) *st
dZp[it] = YLM(it, l, im) * m; // P[l](x) *st
}
}
}
if ((l-m)&1) { // odd
for (it=NLAT_2; it<2*NLAT_2; it++) {
Z[it] = - Z[2*NLAT_2-it-1]; // reconstruct even/odd part
dZt[it] = dZt[2*NLAT_2-it-1];
dZp[it] = - dZp[2*NLAT_2-it-1];
}
} else { // even
for (it=NLAT_2; it<2*NLAT_2; it++) {
Z[it] = Z[2*NLAT_2-it-1]; // reconstruct even/odd part
dZt[it] = - dZt[2*NLAT_2-it-1];
dZp[it] = dZp[2*NLAT_2-it-1];
}
}
fftw_execute_r2r(dct, Z, Z);
fftw_execute_r2r(dct, dZt, dZt);
fftw_execute_r2r(dct, dZp, dZp);
#if SHT_VERBOSE > 1
if ((LMAX <= 12) && (verbose>1))
#pragma omp critical
{
printf("\nl=%d, m=%d ::\t", l,m);
for(it=0;it<2*NLAT_2;it++) printf("%e ",Z[it]/(2*NLAT));
printf("\n dYt ::\t");
for(it=0;it<2*NLAT_2;it++) printf("%e ",dZt[it]/(2*NLAT));
printf("\n dYp ::\t");
for(it=0;it<2*NLAT_2;it++) printf("%e ",dZp[it]/(2*NLAT));
}
#endif
for (it=(l-m)&1; it<=l+1; it+=2) {
yk[(it/2)*(LMAX+1-m) + (l-m)] = Z[it]/(2*NLAT); // and transpose
dyk[(it/2)*(LMAX+1-m) + (l-m)].p = dZp[it]/(2*NLAT);
}
for (it=(l+1-m)&1; it<=l+1; it+=2) {
dyk[(it/2)*(LMAX+1-m) + (l-m)].t = dZt[it]/(2*NLAT);
}
}
/* compute analysis coefficients (fast way)
* Wklm = int(Tk*Ylm) = int(Tk.sum(i,a_ilm*Ti)) = sum(i, a_ilm* int(Tk*Ti)) = sum(i, a_ilm*Jik)
* with Jik = int(Tk*Ti) = 1/(1-(k-i)^2) + 1/(1-(k+i)^2)
*/
if (analysis) {
#if SHT_VERBOSE > 0
if ((LMAX>126)&&(m0==0)&&(verbose)) { // only one thread prints this message.
printf("computing weights m=%d\r",m); fflush(stdout);
}
#endif
for (l=m; l<=LMAX; l++) {
unsigned k0,k1, k,i,d;
double Jik0, Jik1, yy, dyp, dyt;
double lnorm = iylm_fft_norm;
if (SHT_NORM == sht_schmidt) lnorm *= (2*l+1); // Schmidt semi-normalization
if ( (m>0) && (shtns->norm & SHT_REAL_NORM) ) lnorm *= 2; // "real" norm : zlm must be doubled for m>0
k0 = (l-m)&1; k1 = 1-k0;
for(k=0; k<NLAT; k++) { Z[k] = 0.0; dZt[k] = 0.0; dZp[k] = 0.0; }
for (i=0; i<=(l+1)/2; i++) {
yy = yk[i*(LMAX+1-m) + (l-m)] * lnorm;
dyp = dyk[i*(LMAX+1-m) + (l-m)].p * lnorm/(l*(l+1));
dyt = dyk[i*(LMAX+1-m) + (l-m)].t * lnorm/(l*(l+1));
if (i+k0==0) { yy*=0.5; dyp*=0.5; }
if (i+k1==0) dyt*=0.5;
for (k=0; k<NLAT_2; k++) {
d = (k<i) ? i-k : k-i;
Jik0 = is1[(i+k0)+k] + is1[d];
Jik1 = is1[(i+k1)+k] + is1[d];
Z[2*k+k0] += yy * Jik0;
dZt[2*k+k1] += dyt * Jik1;
if (m&1) dZp[2*k+k0] += dyp * Jik0;
}
}
#if SHT_VERBOSE > 1
if ((LMAX <= 12)&&(verbose>1))
#pragma omp critical
{
printf("\nl=%d, m=%d ::\t",l,m);
for (k=0; k<(2*NLAT_2); k++) printf("%f ",Z[k]);
printf("\n dZt ::\t");
for (k=0; k<(2*NLAT_2); k++) printf("%f ",dZt[k]);
if (m&1) {
printf("\n dZp ::\t");
for (k=0; k<(2*NLAT_2); k++) printf("%f ",dZp[k]);
}
}
#endif
if (m == 0) { // we store zlm in dct space for m=0
if (k0==0) {
yk0[((l-m)>>1)*(2*NLAT_2)] = Z[0]*0.5; // store zlm_dct (k=0)
for (k=1; k<(2*NLAT_2); k++) yk0[((l-m)>>1)*(2*NLAT_2) +k] = 0.0; // zero out.
k0=2;
}
for (k=k0; k<(2*NLAT_2); k+=2)
yk0[((l-m)>>1)*(2*NLAT_2) +k] = Z[k]; // store zlm_dct
if (l>0) {
if (k1==0) {
dyk0[((l-1-m)>>1)*(2*NLAT_2)] = dZt[0]*0.5; // store dzlm_dct (k=0)
for (k=1; k<(2*NLAT_2); k++) dyk0[((l-1-m)>>1)*(2*NLAT_2) +k] = 0.0; // zero out.
k1=2;
}
for (k=k1; k<(2*NLAT_2); k+=2)
dyk0[((l-1-m)>>1)*(2*NLAT_2) +k] = dZt[k]; // store dzlm_dct
}
}
fftw_execute_r2r(idct, Z, Z); fftw_execute_r2r(idct, dZt, dZt);
if (m == 0) {
for (it=0; it<NLAT; it++) { dZp[it] = 0.0; dZt[it] *= st_1[it]; }
} else if (m & 1) { // m odd
fftw_execute_r2r(idct, dZp, dZp);
for (it=0; it<NLAT; it++) { Z[it] *= st_1[it]; }
} else { // m even
for (it=0; it<NLAT; it++) { dZp[it] = Z[it]*m/(l*(l+1)*st[it]); dZt[it] *= st_1[it]; }
}
long int l0 = (m==0) ? 1 : m;
long int talign = (m==0)*(NLAT_2 & 1);
long int sk = (l-l0)&1;
if (l==0) {
for (it=0; it<NLAT_2; it++) {
shtns->zlm[im][it] = Z[it];
}
} else if ((sk == 0)&&(l == LMAX)) {
for (it=0; it<NLAT_2; it++) {
shtns->zlm[im][(l-m)*NLAT_2 + it + talign] = Z[it];
if (vector) {
shtns->dzlm[im][(l-l0)*NLAT_2 + it].p = dZp[it];
shtns->dzlm[im][(l-l0)*NLAT_2 + it].t = dZt[it];
}
}
} else {
for (it=0; it<NLAT_2; it++) {
shtns->zlm[im][(l-m-sk)*NLAT_2 + it*2 +sk + talign] = Z[it];
if (vector) {
shtns->dzlm[im][(l-l0-sk)*NLAT_2 + it*2 +sk].p = dZp[it];
shtns->dzlm[im][(l-l0-sk)*NLAT_2 + it*2 +sk].t = dZt[it];
}
}
}
}
}
// Compact the coefficients for improved cache efficiency.
yg = shtns->ykm_dct[im];
for (it=0; it<= KMAX; it+=2) {
l = (it < m) ? m : it-(m&1);
while (l<=LMAX) {
yg[0] = yk[(it/2)*(LMAX+1-m) + (l-m)];
l++; yg++;
}
if ((m==0) && ((LMAX & 1) == 0)) { yg[0] = 0; yg++; } // SSE2 padding.
}
if (MMAX==0) for (int j=0; j<3; j++) yg[j] = 0; // allow some overflow.
if (vector) {
dyg = shtns->dykm_dct[im];
for (it=0; it<= KMAX; it+=2) {
l = (it-2 < m) ? m : it-2+(m&1);
while (l<=LMAX) {
dyg[0].t = dyk[(it/2)*(LMAX+1-m) + (l-m)].t;
dyg[0].p = dyk[(it/2)*(LMAX+1-m) + (l-m)].p;
l++; dyg++;
}
}
if (im == 0) { // compact and reorder m=0 dylm because .p = 0 :
dyg = shtns->dykm_dct[im];
yg = (double *) shtns->dykm_dct[im];
for (it=0; it<= KMAX; it+=2) {
dyg++;
for (l=it-1; l<=LMAX; l++) {
if (l>0) {
yg[0] = dyg[0].t;
yg++; dyg++;
}
}
if (LMAX&1) { // padding for SSE2 alignement.
yg[0] = 0.0; yg++;
}
}
}
}
}
// compact yk to zlm_dct0
if ((m0==0)&&(analysis)) {
long int klim = (LMAX * SHT_NL_ORDER) + 2; // max k needed for nl-terms...
klim = (klim/2)*2; // must be even...
if (klim > 2*NLAT_2) klim = 2*NLAT_2; // but no more than 2*NLAT_2.
shtns->klim = klim; // store for use in codelets.
yg = shtns->zlm_dct0;
for (l=0; l<=LMAX; l+=2) {
for (it=l; it<klim; it++) { // for m=0, zl coeff with i<l are zeros.
*yg = yk0[it];
yg++;
}
yk0 += 2*NLAT_2;
}
if (vector) {
yg = shtns->dzlm_dct0;
for (l=1; l<=LMAX; l+=2) {
for (it=l-1; it<klim; it++) { // for m=0, dzl coeff with i<l-1 are zeros.
*yg = dyk0[it];
yg++;
}
dyk0 += 2*NLAT_2;
}
}
free(yk0 - (2*NLAT_2)*(LMAX/2+1));
}
free(dyk); free(yk);
}
/// \internal Computes the matrices required for SH transform on a regular grid (with or without DCT).
/// \param analysis : 0 => synthesis only.
static void init_SH_dct(shtns_cfg shtns, int analysis)
{
fftw_plan dct, idct;
long int it,im,m,l;
long int sk, dsk;
double Z[2*NLAT_2] SSE;
double is1[NLAT]; // tabulate values for integrals.
const long int marray_size = sizeof(void*)*(MMAX+1) + (MIN_ALIGNMENT-1);
const int vector = (shtns->dylm != NULL);
const int KMAX = LMAX+1;
for(im=0, sk=0, dsk=0; im<=MMAX; im++) { // how much memory to allocate for ykm_dct ?
m = im*MRES;
for (it=0; it<= KMAX; it+=2) {
l = (it < m) ? m : it-(m&1);
sk += LMAX+1 - l;
if ((m==0) && ((LMAX & 1) ==0)) sk++; // SSE padding for m=0
}
for (it=0; it<= KMAX; it+=2) {
l = (it-2 < m) ? m : it-2+(m&1);
dsk += LMAX+1 - l;
}
}
if (MMAX == 0) sk+=3; // allow some overflow.
for (l=0, it=0; l<=LMAX; l+=2) // how much memory for zlm_dct0 ?
it += (2*NLAT_2 -l);
for (l=1, im=0; l<=LMAX; l+=2) // how much memory for dzlm_dct0 ?
im += (2*NLAT_2 -l+1);
#if SHT_VERBOSE > 1
if (verbose>1) printf(" Memory used for Ykm_dct matrices = %.3f Mb\n",sizeof(double)*(sk + 2.*dsk + it)/(1024.*1024.));
#endif
shtns->ykm_dct = (double **) malloc( marray_size + sizeof(double)*sk );
shtns->ykm_dct[0] = (double *) PTR_ALIGN( shtns->ykm_dct + (MMAX+1) );
if (vector) {
shtns->dykm_dct = (struct DtDp **) malloc( marray_size + sizeof(struct DtDp)*dsk );
shtns->dykm_dct[0] = (struct DtDp *) PTR_ALIGN( shtns->dykm_dct + (MMAX+1) );
}
shtns->zlm_dct0 = (double *) VMALLOC( sizeof(double)* it );
if (vector) {
shtns->dzlm_dct0 = (double *) VMALLOC( sizeof(double)* im );
}
for (im=0; im<MMAX; im++) {
m = im*MRES;
for (it=0, sk=0; it<= KMAX; it+=2) {
l = (it < m) ? m : it-(m&1);
sk += LMAX+1 - l;
if ((m==0) && ((LMAX & 1) ==0)) sk++; // SSE padding for m=0
}
for (it=0, dsk=0; it<= KMAX; it+=2) {
l = (it-2 < m) ? m : it-2+(m&1);
dsk += LMAX+1 - l;
}
shtns->ykm_dct[im+1] = shtns->ykm_dct[im] + sk;
if (vector) shtns->dykm_dct[im+1] = shtns->dykm_dct[im] + dsk;
}
#if SHT_VERBOSE > 1
ticks tik0, tik1;
tik0 = getticks();
#endif
#ifdef OMP_FFTW
fftw_plan_with_nthreads(1);
#endif
dct = fftw_plan_r2r_1d( 2*NLAT_2, Z, Z, FFTW_REDFT10, FFTW_MEASURE ); // quick and dirty dct.
idct = fftw_plan_r2r_1d( 2*NLAT_2, Z, Z, FFTW_REDFT01, FFTW_MEASURE ); // quick and dirty idct.
init_SH_synth(shtns);
// precomputation for scalar product of Chebychev polynomials.
for(it=0; it<NLAT; it++)
is1[it] = 1./(1. - 4.*it*it);
#ifdef _OPENMP
#pragma omp parallel
{
int n=omp_get_num_threads();
int k=omp_get_thread_num();
init_SH_dct_m(shtns, is1, dct, idct, analysis, k, n);
}
#else
init_SH_dct_m(shtns, is1, dct, idct, analysis, 0, 1);
#endif
#if SHT_VERBOSE > 1
tik1 = getticks();
if (verbose>1) printf("\n ticks : %.3f\n", elapsed(tik1,tik0)/(NLM*NLAT*(MMAX+1)));
#endif
fftw_destroy_plan(idct); fftw_destroy_plan(dct);
}
#endif /* SHTNS_DCT */
/// \internal Generate a gauss grid (including weights)
static void grid_gauss(shtns_cfg shtns, double latdir)
{
long int it;
real iylm_fft_norm;
real xg[NLAT], wgl[NLAT]; // gauss points and weights.
const int overflow = 8*VSIZE2-1;
shtns->grid = GRID_GAUSS;
shtns->wg = VMALLOC((NLAT_2 +overflow) * sizeof(double)); // gauss weights, double precision.
iylm_fft_norm = 1.0; // FFT/SHT normalization for zlm (4pi normalized)
if ((SHT_NORM != sht_fourpi)&&(SHT_NORM != sht_schmidt)) iylm_fft_norm = 4*M_PIl; // FFT/SHT normalization for zlm (orthonormalized)
iylm_fft_norm /= (2*NPHI);
#if SHT_VERBOSE > 0
if (verbose) {
printf(" => using Gauss nodes\n");
if (2*NLAT <= (SHT_NL_ORDER +1)*LMAX) printf(" !! Warning : Gauss-Legendre anti-aliasing condition 2*Nlat > %d*Lmax is not met.\n",SHT_NL_ORDER+1);
}
#endif
gauss_nodes(xg,wgl,NLAT); // generate gauss nodes and weights : ct = ]1,-1[ = cos(theta)
for (it=0; it<NLAT; it++) {
shtns->ct[it] = latdir * xg[it];
shtns->st[it] = SQRT((1.-xg[it])*(1.+xg[it]));
shtns->st_1[it] = 1.0/SQRT((1.-xg[it])*(1.+xg[it]));
}
for (it=0; it<NLAT_2; it++)
shtns->wg[it] = wgl[it]*iylm_fft_norm; // faster double-precision computations.
if (NLAT & 1) { // odd NLAT : adjust weigth of middle point.
shtns->wg[NLAT_2-1] *= 0.5;
}
for (it=NLAT_2; it < NLAT_2 +overflow; it++) shtns->wg[it] = 0.0; // padding for multi-way algorithm.
#if SHT_VERBOSE > 1
if (verbose>1) {
printf(" NLAT=%d, NLAT_2=%d\n",NLAT,NLAT_2);
// TEST if gauss points are ok.
double tmax = 0.0;
for (it = 0; it<NLAT_2; it++) {
double t = legendre_Pl(NLAT, shtns->ct[it]);
if (t>tmax) tmax = t;
// printf("i=%d, x=%12.12g, p=%12.12g\n",it,ct[it],t);
}
printf(" max zero at Gauss nodes for Pl[l=NLAT] : %g\n",tmax);
if (NLAT_2 < 100) {
printf(" Gauss nodes :");
for (it=0;it<NLAT_2; it++)
printf(" %g",shtns->ct[it]);
printf("\n");
}
}
#endif
}
#ifdef SHTNS_DCT
/// \internal Generate an equi-spaced theta grid (Chebychev points, excluding poles) for Féjer-DCT SHT.
static void grid_dct(shtns_cfg shtns, double latdir)
{
long int it;
shtns->grid = GRID_REGULAR;
#if SHT_VERBOSE > 0
if (verbose) {
printf(" => using equaly spaced nodes with DCT acceleration\n");
if (NLAT <= SHT_NL_ORDER *LMAX) printf(" !! Warning : DCT anti-aliasing condition Nlat > %d*Lmax is not met.\n",SHT_NL_ORDER);
if (NLAT != fft_int(NLAT,7)) printf(" !! Warning : Nlat is not optimal for FFTW !\n");
}
#endif
if (NLAT & 1) shtns_runerr("NLAT must be even (DCT)");
if (NLAT <= LMAX+1) shtns_runerr("NLAT should be at least LMAX+2 (DCT)");
for (it=0; it<NLAT; it++) { // Chebychev points : equaly spaced but skipping poles.
real th = M_PIl; th = (th*(2*it+1))/(2*NLAT);
shtns->ct[it] = latdir * COS(th);
shtns->st[it] = SIN(th);
shtns->st_1[it] = 1.0/SIN(th);
}
#if SHT_VERBOSE > 1
if (verbose>1) {
printf(" NLAT=%d, NLAT_2=%d\n",NLAT,NLAT_2);
double tmax = 0.0;
for (it=0;it<NLAT_2; it++) {
double ct = shtns->ct[it]; double st = shtns->st[it];
double t = fabs((ct*ct + st*st) -1.0);
if (t > tmax) tmax=t;
}
printf(" max st^2 + ct^2 -1 = %g\n",tmax);
if (NLAT_2 < 100) {
printf(" DCT nodes :");
for (it=0; it<NLAT_2; it++)
printf(" %g",shtns->ct[it]);
printf("\n");
}
}
#endif
}
#endif /* SHTNS_DCT */
/// \internal Generate an equi-spaced theta grid including the poles, for synthesis only.
static void grid_equal_polar(shtns_cfg shtns, double latdir)
{
long int j;
shtns->grid = GRID_POLES;
#if SHT_VERBOSE > 0
if (verbose) printf(" => using Equaly Spaced Nodes including poles\n");
#endif
// cos theta of latidunal points (equaly spaced in theta)
double f = M_PIl/(NLAT-1);
for (j=0; j<NLAT; j++) {
shtns->ct[j] = latdir * cos(f*j);
shtns->st[j] = sin(f*j);
shtns->st_1[j] = 1.0/sin(f*j);
}
#if SHT_VERBOSE > 0
if (verbose) printf(" !! Warning : only synthesis (inverse transform) supported for this grid !\n");
#endif
}
/* TEST AND TIMING FUNCTIONS */
/// \internal return the max error for a back-and-forth SHT transform.
/// this function is used to internally measure the accuracy.
double SHT_error(shtns_cfg shtns, int vector)
{
cplx *Tlm0=0, *Slm0=0, *Tlm=0, *Slm=0;
double *Sh=0, *Th=0;
double t, tmax, n2, err;
long int i, jj, nlm_cplx;
srand( time(NULL) ); // init random numbers.
Slm0 = (cplx *) VMALLOC(sizeof(cplx)* NLM);
Slm = (cplx *) VMALLOC(sizeof(cplx)* NLM);
Sh = (double *) VMALLOC( NSPAT_ALLOC(shtns) * sizeof(double) );
if ((Sh==0) || (Slm==0) || (Slm0==0)) shtns_runerr("not enough memory.");
if (vector) {
Tlm0 = (cplx *) VMALLOC(sizeof(cplx)* NLM);
Tlm = (cplx *) VMALLOC(sizeof(cplx)* NLM);
Th = (double *) VMALLOC( NSPAT_ALLOC(shtns) * sizeof(double) );
if ((Th==0) || (Tlm==0) || (Tlm0==0)) vector=0;
}
// m = nphi/2 is also real if nphi is even.
nlm_cplx = ( MMAX*2 == NPHI ) ? LiM(shtns, MRES*MMAX,MMAX) : NLM;
t = 1.0 / (RAND_MAX/2);
for (i=0; i<NLM; i++) {
if ((i<=LMAX)||(i>=nlm_cplx)) { // m=0 or m*2=nphi : real random data
Slm0[i] = t*((double) (rand() - RAND_MAX/2));
if (vector) Tlm0[i] = t*((double) (rand() - RAND_MAX/2));
} else { // m>0 : complex random data
Slm0[i] = t*((double) (rand() - RAND_MAX/2)) + I*t*((double) (rand() - RAND_MAX/2));
if (vector) Tlm0[i] = t*((double) (rand() - RAND_MAX/2)) + I*t*((double) (rand() - RAND_MAX/2));
}
}
SH_to_spat(shtns, Slm0,Sh); // scalar SHT
spat_to_SH(shtns, Sh, Slm);
for (i=0, tmax=0., n2=0., jj=0; i<NLM; i++) { // compute error
t = cabs(Slm[i] - Slm0[i]);
n2 += t*t;
if (t>tmax) { tmax = t; jj = i; }
}
err = tmax;
#if SHT_VERBOSE > 1
if (verbose>1) printf(" scalar SH - poloidal rms error = %.3g max error = %.3g for l=%hu,lm=%ld\n",sqrt(n2/NLM),tmax,shtns->li[jj],jj);
#endif
if (vector) {
Slm0[0] = 0.0; Tlm0[0] = 0.0; // l=0, m=0 n'a pas de signification sph/tor
SHsphtor_to_spat(shtns, Slm0, Tlm0, Sh, Th); // vector SHT
spat_to_SHsphtor(shtns, Sh, Th, Slm, Tlm);
for (i=0, tmax=0., n2=0., jj=0; i<NLM; i++) { // compute error
t = cabs(Slm[i] - Slm0[i]);
n2 += t*t;
if (t>tmax) { tmax = t; jj = i; }
}
if (tmax > err) err = tmax;
#if SHT_VERBOSE > 1
if (verbose>1) printf(" vector SH - spheroidal rms error = %.3g max error = %.3g for l=%hu,lm=%ld\n",sqrt(n2/NLM),tmax,shtns->li[jj],jj);
#endif
for (i=0, tmax=0., n2=0., jj=0; i<NLM; i++) { // compute error
t = cabs(Tlm[i] - Tlm0[i]);
n2 += t*t;
if (t>tmax) { tmax = t; jj = i; }
}
if (tmax > err) err = tmax;
#if SHT_VERBOSE > 1
if (verbose>1) printf(" - toroidal rms error = %.3g max error = %.3g for l=%hu,lm=%ld\n",sqrt(n2/NLM),tmax,shtns->li[jj],jj);
#endif
}
if (Th) VFREE(Th); if (Tlm) VFREE(Tlm); if (Tlm0) VFREE(Tlm0);
VFREE(Sh); VFREE(Slm); VFREE(Slm0);
return(err); // return max error.
}
#if SHT_VERBOSE == 1
#define PRINT_DOT if (verbose>=1) { printf("."); fflush(stdout); }
#else
#define PRINT_DOT (0);
#endif
/// \internal measure time used for a transform function
static double get_time(shtns_cfg shtns, int nloop, int npar, char* name, void *fptr, void *i1, void *i2, void *i3, void *o1, void *o2, void *o3, int l)
{
double t;
int i;
ticks tik0, tik1;
if (fptr == NULL) return(0.0);
tik1 = getticks();
for (i=0; i<nloop; i++) {
switch(npar) {
case 2: (*(pf2l)fptr)(shtns, i1,o1, l); break; // l may be discarded.
case 3: (*(pf3l)fptr)(shtns, i1,o1,o2, l); break;
case 4: (*(pf4l)fptr)(shtns, i1,i2,o1,o2, l); break;
default: (*(pf6l)fptr)(shtns, i1,i2,i3, o1,o2,o3, l); break;
}
if (i==0) tik0 = getticks();
}
if (nloop == 1) {
t = elapsed(tik0, tik1);
} else {
tik1 = getticks();
t = elapsed(tik1, tik0)/(nloop-1); // discard first iteration.
}
#if SHT_VERBOSE > 1
if (verbose>1) { printf(" t(%s) = %.3g",name,t); fflush(stdout); }
#endif
return t;
}
/// \internal choose fastest between on-the-fly and gauss algorithms.
/// *nlp is the number of loops. If zero, it is set to a good value.
/// on_the_fly : 1 = skip all memory algorithm. 0 = include memory and on-the-fly. -1 = test only DCT.
/// returns time without dct / best time with dct (or 0 if no dct available).
static double choose_best_sht(shtns_cfg shtns, int* nlp, int vector, int dct_mtr)
{
cplx *Qlm=0, *Slm=0, *Tlm=0;
double *Qh=0, *Sh=0, *Th=0;
int m, i, i0, minc, nloop, alg_end;
int typ_lim = SHT_NTYP; // time every type.
double t0, t, tt, r;
double tdct, tnodct;
clock_t tcpu;
int on_the_fly_only = (shtns->ylm == NULL); // only on-the-fly.
int otf_analys = (shtns->wg != NULL); // on-the-fly analysis supported.
if (NLAT < VSIZE2*4) return(0.0); // on-the-fly not possible for NLAT_2 < 2*NWAY (overflow) and DCT not efficient for low NLAT.
if ((dct_mtr != 0) && (shtns->ykm_dct == NULL)) return(0.0); // no dct available : do nothing.
size_t nspat = sizeof(double) * NSPAT_ALLOC(shtns);
size_t nspec = sizeof(cplx)* NLM;
if (nspec>nspat) nspat=nspec;
Sh = (double *) VMALLOC(nspat); Slm = (cplx *) VMALLOC(nspec);
if ((Sh==0) || (Slm==0)) shtns_runerr("not enough memory.");
if (vector) {
Th = (double *) VMALLOC(nspat); Qh = (double *) VMALLOC(nspat);
Tlm = (cplx *) VMALLOC(nspec); Qlm = (cplx *) VMALLOC(nspec);
if ( (Th==0) || (Qh==0) || (Tlm==0) || (Qlm==0) ) vector = 0;
}
for (i=0;i<NLM;i++) {
int l = shtns->li[i];
Slm[i] = shtns->l_2[l] + 0.5*I*shtns->l_2[l];
if (vector) {
Tlm[i] = 0.5*shtns->l_2[l] + I*shtns->l_2[l];
Qlm[i] = 3*shtns->l_2[l] + 2*I*shtns->l_2[l];
}
}
#if SHT_VERBOSE > 0
if (verbose) {
if (dct_mtr != 0) printf(" finding optimal m-truncation for DCT synthesis");
else printf(" finding optimal algorithm");
fflush(stdout);
}
#endif
if (*nlp <= 0) {
// find good nloop by requiring less than 3% difference between 2 consecutive timings.
m=0; nloop = 1; // number of loops to get timings.
r = 0.0; tt = 1.0;
do {
if ((r > 0.03)||(tt<0.1)) {
m = 0; nloop *= 3;
} else m++;
tcpu = clock();
t0 = get_time(shtns, nloop, 2, "", sht_func[SHT_STD][SHT_FLY2][SHT_TYP_SSY], Slm, Tlm, Qlm, Sh, Th, Qh, LMAX);
tcpu = clock() - tcpu; tt = 1.e-6 * tcpu;
if (tt >= SHT_TIME_LIMIT) break; // we should not exceed 1 second
t = get_time(shtns, nloop, 2, "", sht_func[SHT_STD][SHT_FLY2][SHT_TYP_SSY], Slm, Tlm, Qlm, Sh, Th, Qh, LMAX);
r = fabs(2.0*(t-t0)/(t+t0));
#if SHT_VERBOSE > 1
if (verbose>1) printf(", nloop=%d, r=%g, m=%d (real time = %g s)\n",nloop,r,m,tt);
if (tt >= 0.01) break; // faster timing in debug mode.
#endif
PRINT_DOT
} while((nloop<10000)&&(m < 3));
*nlp = nloop;
} else {
nloop = *nlp;
}
#if SHT_VERBOSE > 1
if (verbose>1) printf(" => nloop=%d (takes %g s)\n",nloop, tt);
#endif
if (vector == 0) typ_lim = SHT_TYP_VSY; // time only scalar transforms.
// if (tt > 3.0) typ_lim = SHT_TYP_VSY; // time only scalar transforms.
// if (tt > 10.0) goto done; // timing this will be too slow...
int ityp = 0; do {
if ((dct_mtr != 0) && (ityp >= 4)) break; // dct !=0 : only scalar and vector.
if (ityp == 2) nloop = (nloop+1)/2; // scalar ar done.
t0 = 1e100;
i0 = 0;
if (MTR_DCT < 0) i0 = SHT_MEM; // skip dct.
if (on_the_fly_only) i0 = SHT_SV; // only on-the-fly (SV is then also on-the-fly)
alg_end = SHT_NALG;
if (shtns->nthreads <= 1) alg_end = SHT_OMP1; // no OpenMP with 1 thread.
if ((ityp&1) && (otf_analys == 0)) alg_end = SHT_FLY1; // no on-the-fly analysis for regular grid.
for (i=i0, m=0; i<alg_end; i++) {
if (sht_func[0][i][ityp] != NULL) m++; // count number of algos
}
if (m >= 2) { // don't time if there is only 1 algo !
#if SHT_VERBOSE > 1
if (verbose>1) { printf("finding best %s ...",sht_type[ityp]); fflush(stdout); }
#endif
i = i0-1; i0 = -1;
while (++i < alg_end) {
void *pf = sht_func[0][i][ityp];
if (pf != NULL) {
if (ityp&1) { // analysis
t = get_time(shtns, nloop, sht_npar[ityp], sht_name[i], pf, Sh, Th, Qh, Slm, Tlm, Qlm, LMAX);
} else {
t = get_time(shtns, nloop, sht_npar[ityp], sht_name[i], pf, Slm, Tlm, Qlm, Sh, Th, Qh, LMAX);
}
if (i < SHT_FLY1) t *= 1.03; // 3% penality for memory based transforms.
#ifdef _OPENMP
if ((i >= SHT_OMP1)||(i == SHT_SV)) t *= 1.3; // 30% penality for openmp transforms.
#endif
if (t < t0) { i0 = i; t0 = t; PRINT_VERB("*"); }
}
}
if (i0 >= 0) {
for (int iv=0; iv<SHT_NVAR; iv++) {
if (sht_func[iv][i0][ityp]) shtns->ftable[iv][ityp] = sht_func[iv][i0][ityp];
if (ityp == 4) { // only one timing for both gradients variants.
if (sht_func[iv][i0][ityp+1]) shtns->ftable[iv][ityp+1] = sht_func[iv][i0][ityp+1];
}
}
PRINT_DOT
#if SHT_VERBOSE > 1
if (verbose>1) printf(" => %s\n",sht_name[i0]);
#endif
}
}
if (ityp == 4) ityp++; // skip second gradient
} while(++ityp < typ_lim);
#ifdef SHTNS_DCT
if (dct_mtr != 0) { // find the best DCT timings...
#if SHT_VERBOSE > 1
if (verbose>1) { printf("finding best mtr_dct ..."); fflush(stdout); }
#endif
minc = MMAX/20 + 1; // don't test every single m.
m = -1; i = -1; t0 = 0.0; // reference = no dct.
if (sht_func[SHT_STD][SHT_DCT][SHT_TYP_SSY] != NULL)
t0 += get_time(shtns, *nlp, 2, "s", shtns->ftable[SHT_STD][SHT_TYP_SSY], Slm, Tlm, Qlm, Sh, Th, Qh, LMAX);
if ( (sht_func[SHT_STD][SHT_DCT][SHT_TYP_VSY] != NULL) && (vector) )
t0 += get_time(shtns, nloop, 4, "v", shtns->ftable[SHT_STD][SHT_TYP_VSY], Slm, Tlm, Qlm, Sh, Th, Qh, LMAX);
tnodct = t0;
for (m=0; m<=MMAX; m+=minc) {
#if SHT_VERBOSE > 1
if (verbose>1) printf("\n\tm=%d :",m);
#endif
if (Set_MTR_DCT(shtns, m) >= 0) {
t = get_time(shtns, *nlp, 2, "sdct", sht_func[SHT_STD][SHT_DCT][SHT_TYP_SSY], Slm, Tlm, Qlm, Sh, Th, Qh, LMAX);
if (vector)
t += get_time(shtns, nloop, 4, "vdct", sht_func[SHT_STD][SHT_DCT][SHT_TYP_VSY], Slm, Tlm, Qlm, Sh, Th, Qh, LMAX);
if (t < t0) { t0 = t; i = m; PRINT_VERB("*"); }
PRINT_DOT
}
}
tdct = t0;
Set_MTR_DCT(shtns, i); // the best DCT is chosen.
#if SHT_VERBOSE > 0
if (verbose) printf(" mtr_dct=%d (%.1f%% performance gain)", MTR_DCT*MRES, 100.*(tnodct/tdct-1.));
#endif
}
#endif
done:
#if SHT_VERBOSE > 0
if (verbose) printf("\n");
#endif
if (Qlm) VFREE(Qlm); if (Tlm) VFREE(Tlm);
if (Qh) VFREE(Qh); if (Th) VFREE(Th);
if (Slm) VFREE(Slm); if (Sh) VFREE(Sh);
if (dct_mtr > 0) {
return(tnodct/tdct);
} else return(0.0);
}
void shtns_print_version() {
printf("[" PACKAGE_STRING "] built " __DATE__ ", " __TIME__ ", id: " _SIMD_NAME_ "\n");
}
void fprint_ftable(FILE* fp, void* ftable[SHT_NVAR][SHT_NTYP])
{
for (int iv=0; iv<SHT_NVAR; iv++) {
fprintf(fp, "\n %4s:",sht_var[iv]);
void** f = ftable[iv];
for (int it=0; it<SHT_NTYP; it++) {
if (f[it] != NULL) {
for (int ia=0; ia<SHT_NALG; ia++)
if (sht_func[iv][ia][it] == f[it]) {
fprintf(fp, "%5s ",sht_name[ia]); break;
}
} else fprintf(fp, " none ");
}
}
}
void shtns_print_cfg(shtns_cfg shtns)
{
printf("Lmax=%d, Mmax*Mres=%d, Mres=%d, Nlm=%d [%d threads, ",LMAX, MMAX*MRES, MRES, NLM, shtns->nthreads);
if (shtns->norm & SHT_REAL_NORM) printf("'real' norm, ");
if (shtns->norm & SHT_NO_CS_PHASE) printf("no Condon-Shortley phase, ");
if (SHT_NORM == sht_fourpi) printf("4.pi normalized]\n");
else if (SHT_NORM == sht_schmidt) printf("Schmidt semi-normalized]\n");
else printf("orthonormalized]\n");
if (shtns->ct == NULL) return; // no grid is set
switch(shtns->grid) {
case GRID_GAUSS : printf("Gauss grid"); break;
case GRID_REGULAR : printf("Regular grid (mtr_dct=%d)",shtns->mtr_dct); break;
case GRID_POLES : printf("Regular grid including poles"); break;
default : printf("Unknown grid");
}
printf(" : Nlat=%d, Nphi=%d\n", NLAT, NPHI);
printf(" ");
for (int it=0; it<SHT_NTYP; it++)
printf("%5s ",sht_type[it]);
fprint_ftable(stdout, shtns->ftable);
printf("\n");
}
/// \internal saves config to a file for later restart.
int config_save(shtns_cfg shtns, int req_flags)
{
int err = 0;
if (shtns->ct == NULL) return -1; // no grid set
if ((shtns->nphi > 1)||(shtns->mtr_dct >= 0)) {
FILE* f = fopen("shtns_cfg_fftw","w");
if (f != NULL) {
fftw_export_wisdom_to_file(f);
fclose(f);
} else err -= 2;
}
FILE *fcfg = fopen("shtns_cfg","a");
if (fcfg != NULL) {
fprintf(fcfg, "%s %s %d %d %d %d %d %d %d %d %d %d",PACKAGE_VERSION, _SIMD_NAME_, shtns->lmax, shtns->mmax, shtns->mres, shtns->nphi, shtns->nlat, shtns->grid, shtns->nthreads, req_flags, shtns->nlorder, shtns->mtr_dct);
fprint_ftable(fcfg, shtns->ftable);
fprintf(fcfg,"\n");
fclose(fcfg);
} else err -= 4;
#if SHT_VERBOSE > 0
if (err < 0) fprintf(stderr,"! Warning ! SHTns could not save config\n");
#endif
return err;
}
/// \internal try to load config from a file
int config_load(shtns_cfg shtns, int req_flags)
{
void* ft2[SHT_NVAR][SHT_NTYP]; // pointers to transform functions.
int lmax2, mmax2, mres2, nphi2, nlat2, grid2, nthreads2, req_flags2, nlorder2, mtr_dct2;
int found = 0;
char version[32], simd[8], alg[8];
if (shtns->ct == NULL) return -1; // no grid set
if ((req_flags & 255) == sht_quick_init) req_flags += sht_gauss - sht_quick_init; // quick_init uses gauss.
FILE *fcfg = fopen("shtns_cfg","r");
if (fcfg != NULL) {
int i=0;
while(1) {
fscanf(fcfg, "%30s %8s %d %d %d %d %d %d %d %d %d %d",version, simd, &lmax2, &mmax2, &mres2, &nphi2, &nlat2, &grid2, &nthreads2, &req_flags2, &nlorder2, &mtr_dct2);
for (int iv=0; iv<SHT_NVAR; iv++) {
fscanf(fcfg, "%7s", alg);
for (int it=0; it<SHT_NTYP; it++) {
fscanf(fcfg, "%7s", alg),
ft2[iv][it] = 0;
for (int ia=0; ia<SHT_NALG; ia++) {
if (strcmp(alg, sht_name[ia]) == 0) {
ft2[iv][it] = sht_func[iv][ia][it];
break;
}
}
}
}
if (feof(fcfg)) break;
#ifndef SHTNS_DCT
if (mtr_dct2 <= 0)
#endif
if ((shtns->lmax == lmax2) && (shtns->mmax == mmax2) && (shtns->mres == mres2) && (shtns->nthreads == nthreads2) &&
(shtns->nphi == nphi2) && (shtns->nlat == nlat2) && (shtns->grid == grid2) && (req_flags == req_flags2) &&
(shtns->nlorder == nlorder2) && (strcmp(simd, _SIMD_NAME_)==0)) {
#if SHT_VERBOSE > 0
if (verbose > 0) printf(" + using saved config\n");
#endif
#if SHT_VERBOSE > 1
if (verbose > 1) {
fprint_ftable(stdout, ft2);
printf("\n");
}
#endif
#ifdef SHTNS_DCT
Set_MTR_DCT(shtns, mtr_dct2); // use loaded mtr_dct
#endif
for (int iv=0; iv<SHT_NVAR; iv++)
for (int it=0; it<SHT_NTYP; it++)
if (ft2[iv][it]) shtns->ftable[iv][it] = ft2[iv][it]; // accept only non-null pointer
found = 1;
break;
}
}
fclose(fcfg);
return found;
} else {
#if SHT_VERBOSE > 0
if (verbose) fprintf(stderr,"! Warning ! SHTns could not load config\n");
#endif
return -2; // file not found
}
}
/// \internal returns 1 if val cannot fit in dest (unsigned)
#define IS_TOO_LARGE(val, dest) (sizeof(dest) >= sizeof(val)) ? 0 : ( ( val >= (1<<(8*sizeof(dest))) ) ? 1 : 0 )
/// \internal returns the size that must be allocated for an shtns_info.
#define SIZEOF_SHTNS_INFO(mmax) ( sizeof(struct shtns_info) + (mmax+1)*( sizeof(int)+sizeof(unsigned short) ) )
/* PUBLIC INITIALIZATION & DESTRUCTION */
/** \addtogroup init Initialization functions.
*/
//@{
/*! This sets the description of spherical harmonic coefficients.
* It tells SHTns how to interpret spherical harmonic coefficient arrays, and it sets usefull arrays.
* Returns the configuration to be passed to subsequent transform functions, which is basicaly a pointer to a \ref shtns_info struct.
* \param lmax : maximum SH degree that we want to describe.
* \param mmax : number of azimutal wave numbers.
* \param mres : \c 2.pi/mres is the azimutal periodicity. \c mmax*mres is the maximum SH order.
* \param norm : define the normalization of the spherical harmonics (\ref shtns_norm)
* + optionaly disable Condon-Shortley phase (ex: \ref sht_schmidt | \ref SHT_NO_CS_PHASE)
* + optionaly use a 'real' normalization (ex: \ref sht_fourpi | \ref SHT_REAL_NORM)
*/
shtns_cfg shtns_create(int lmax, int mmax, int mres, enum shtns_norm norm)
{
shtns_cfg shtns, s2;
int im, m, l, lm;
int with_cs_phase = 1; /// Condon-Shortley phase (-1)^m is used by default.
double mpos_renorm = 1.0; /// renormalization of m>0.
int larrays_ok = 0;
int legendre_ok = 0;
int l_2_ok = 0;
// if (lmax < 1) shtns_runerr("lmax must be larger than 1");
if (lmax < 2) shtns_runerr("lmax must be at least 2");
if (IS_TOO_LARGE(lmax, shtns->lmax)) shtns_runerr("lmax too large");
if (mmax*mres > lmax) shtns_runerr("MMAX*MRES should not exceed LMAX");
if (mres <= 0) shtns_runerr("MRES must be > 0");
// allocate new setup and initialize some variables (used as flags) :
shtns = malloc( SIZEOF_SHTNS_INFO(mmax) );
if (shtns == NULL) return shtns; // FAIL
{
void **p0 = (void**) &shtns->tm; // first pointer in struct.
void **p1 = (void**) &shtns->Y00_1; // first non-pointer.
while(p0 < p1) *p0++ = NULL; // write NULL to every pointer.
shtns->lmidx = (int*) (shtns + 1); // lmidx is stored at the end of the struct...
shtns->tm = (unsigned short*) (shtns->lmidx + (mmax+1)); // and tm just after.
shtns->ct = NULL; shtns->st = NULL;
shtns->nphi = 0; shtns->nlat = 0; shtns->nlat_2 = 0; shtns->nspat = 0; // public data
}
// copy sizes.
shtns->norm = norm;
if (norm & SHT_NO_CS_PHASE)
with_cs_phase = 0;
if (norm & SHT_REAL_NORM)
mpos_renorm = 0.5; // normalization for 'real' spherical harmonics.
shtns->mmax = mmax; shtns->mres = mres; shtns->lmax = lmax;
shtns->nlm = nlm_calc(lmax, mmax, mres);
shtns->nthreads = omp_threads;
if (omp_threads > mmax+1) shtns->nthreads = mmax+1; // limit the number of threads to mmax+1
#if SHT_VERBOSE > 0
if (verbose) {
shtns_print_version();
printf(" "); shtns_print_cfg(shtns);
}
#endif
s2 = sht_data; // check if some data can be shared ...
while(s2 != NULL) {
if ((s2->mmax >= mmax) && (s2->mres == mres)) {
if (s2->lmax == lmax) { // we can reuse the l-related arrays (li + copy lmidx)
shtns->li = s2->li; shtns->mi = s2->mi;
for (im=0; im<=mmax; im++) shtns->lmidx[im] = s2->lmidx[im];
larrays_ok = 1;
}
if ( (s2->lmax >= lmax) && (s2->norm == norm) ) { // we can reuse the legendre tables.
shtns->alm = s2->alm; shtns->blm = s2->blm;
legendre_ok = 1;
}
}
if (s2->lmax >= lmax) { // we can reuse l_2
shtns->l_2 = s2->l_2;
l_2_ok = 1;
}
s2 = s2->next;
}
if (larrays_ok == 0) {
// alloc spectral arrays
shtns->li = (unsigned short *) malloc( 2*NLM*sizeof(unsigned short) ); // NLM defined at runtime.
shtns->mi = shtns->li + NLM;
for (im=0, lm=0; im<=MMAX; im++) { // init l-related arrays.
m = im*MRES;
shtns->lmidx[im] = lm -m; // virtual pointer for l=0
for (l=im*MRES;l<=LMAX;l++) {
shtns->li[lm] = l; shtns->mi[lm] = m;
lm++;
}
}
if (lm != NLM) shtns_runerr("unexpected error");
}
if (legendre_ok == 0) { // this quickly precomputes some values for the legendre recursion.
legendre_precomp(shtns, SHT_NORM, with_cs_phase, mpos_renorm);
}
if (l_2_ok == 0) {
shtns->l_2 = (double *) malloc( (LMAX+1)*sizeof(double) );
shtns->l_2[0] = 0.0; // undefined for l=0 => replace with 0.
real one = 1.0;
for (l=1; l<=LMAX; l++) shtns->l_2[l] = one/(l*(l+1));
}
switch(SHT_NORM) {
case sht_schmidt:
shtns->Y00_1 = 1.0; shtns->Y10_ct = 1.0;
break;
case sht_fourpi:
shtns->Y00_1 = 1.0; shtns->Y10_ct = sqrt(1./3.);
break;
case sht_orthonormal:
default:
shtns->Y00_1 = sqrt(4.*M_PI); shtns->Y10_ct = sqrt(4.*M_PI/3.);
// Y11_st = sqrt(2.*M_PI/3.); // orthonormal : \f$ \sin\theta\cos\phi/(Y_1^1 + Y_1^{-1}) = -\sqrt{2 \pi /3} \f$
}
shtns->Y11_st = shtns->Y10_ct * sqrt(0.5/mpos_renorm);
if (with_cs_phase) shtns->Y11_st *= -1.0; // correct Condon-Shortley phase
// save a pointer to this setup and return.
shtns->next = sht_data; // reference of previous setup (may be NULL).
sht_data = shtns; // keep track of new setup.
return(shtns);
}
/// Copy a given config but allow a different (smaller) mmax and the possibility to enable/disable fft (beta).
shtns_cfg shtns_create_with_grid(shtns_cfg base, int mmax, int nofft)
{
shtns_cfg shtns;
if (mmax > base->mmax) return (NULL); // fail if mmax larger than source config.
shtns = malloc( SIZEOF_SHTNS_INFO(mmax) );
memcpy(shtns, base, SIZEOF_SHTNS_INFO(mmax) ); // copy all
shtns->lmidx = (int*) shtns+1; // lmidx is stored at the end of the struct...
shtns->tm = (unsigned short*) (shtns->lmidx + (mmax+1)); // ...and tm just after.
if (mmax != shtns->mmax) {
shtns->mmax = mmax;
for (int im=0; im<=mmax; im++) {
shtns->lmidx[im] = base->lmidx[im];
shtns->tm[im] = base->tm[im];
}
#ifdef SHTNS_DCT
if (mmax < shtns->mtr_dct) {
shtns->idct = NULL; // do not destroy the plan of the source.
Set_MTR_DCT(shtns, mmax); // adjut mtr_dct if required.
}
#endif
if (mmax == 0) {
// TODO we may disable fft and replace with a phi-averaging function ...
// ... then switch to axisymmetric functions :
// init_sht_array_func(shtns);
// choose_best_sht(shtns, &nloop, 0);
}
}
if (nofft != 0) {
shtns->ncplx_fft = -1; // fft disabled.
}
// save a pointer to this setup and return.
shtns->next = sht_data; // reference of previous setup (may be NULL).
sht_data = shtns; // keep track of new setup.
return(shtns);
}
/// release all resources allocated by a grid.
void shtns_unset_grid(shtns_cfg shtns)
{
if (ref_count(shtns, &shtns->wg) == 1) VFREE(shtns->wg);
shtns->wg = NULL;
free_SH_dct(shtns);
free_SHTarrays(shtns);
shtns->nlat = 0; shtns->nlat_2 = 0;
shtns->nphi = 0; shtns->nspat = 0;
}
/// release all resources allocated by a given shtns_cfg.
void shtns_destroy(shtns_cfg shtns)
{
free_unused(shtns, &shtns->l_2);
if (shtns->blm != shtns->alm)
free_unused(shtns, &shtns->blm);
free_unused(shtns, &shtns->alm);
free_unused(shtns, &shtns->li);
shtns_unset_grid(shtns);
if (sht_data == shtns) {
sht_data = shtns->next; // forget shtns
} else {
shtns_cfg s2 = sht_data;
while (s2 != NULL) {
if (s2->next == shtns) {
s2->next = shtns->next; // forget shtns
break;
}
s2 = s2->next;
}
}
free(shtns);
}
/// clear all allocated memory (hopefully) and go back to 0 state.
void shtns_reset()
{
while (sht_data != NULL) {
shtns_destroy(sht_data);
}
}
/*! Initialization of Spherical Harmonic transforms (backward and forward, vector and scalar, ...) of given size.
* <b>This function must be called after \ref shtns_create and before any SH transform.</b> and sets all global variables and internal data.
* returns the required number of doubles to be allocated for a spatial field.
* \param shtns is the config created by \ref shtns_create for which the grid will be set.
* \param nlat,nphi pointers to the number of latitudinal and longitudinal grid points respectively. If 0, they are set to optimal values.
* \param nl_order defines the maximum SH degree to be resolved by analysis : lmax_analysis = lmax*nl_order. It is used to set an optimal and anti-aliasing nlat. If 0, the default SHT_DEFAULT_NL_ORDER is used.
* \param flags allows to choose the type of transform (see \ref shtns_type) and the spatial data layout (see \ref spat)
* \param eps polar optimization threshold : polar values of Legendre Polynomials below that threshold are neglected (for high m), leading to increased performance (a few percents)
* 0 = no polar optimization; 1.e-14 = VERY safe; 1.e-10 = safe; 1.e-6 = aggresive, but still good accuracy.
*/
int shtns_set_grid_auto(shtns_cfg shtns, enum shtns_type flags, double eps, int nl_order, int *nlat, int *nphi)
{
double t, mem;
int im,m;
int layout;
int nloop = 0;
int n_gauss = 0;
int on_the_fly = 0;
int quick_init = 0;
int vector = !(flags & SHT_SCALAR_ONLY);
int latdir = (flags & SHT_SOUTH_POLE_FIRST) ? -1 : 1; // choose latitudinal direction (change sign of ct)
int cfg_loaded = 0;
int analys = 1;
const int req_flags = flags; // requested flags.
#if _GCC_VEC_
if (*nlat & 1) shtns_runerr("Nlat must be even\n");
#ifdef __MIC__
if (*nlat % VSIZE2) shtns_runerr("Nlat must be a multiple of 8 for the MIC\n");
#endif
#endif
shtns_unset_grid(shtns); // release grid if previously allocated.
if (nl_order <= 0) nl_order = SHT_DEFAULT_NL_ORDER;
/* shtns.lshift = 0;
if (nl_order == 0) nl_order = SHT_DEFAULT_NL_ORDER;
if (nl_order < 0) { shtns.lshift = -nl_order; nl_order = 1; } // linear with a shift in l.
*/
shtns->nspat = 0;
shtns->nlorder = nl_order;
shtns->mtr_dct = -1; // dct switched off completely.
layout = flags & 0xFFFF00;
flags = flags & 255; // clear higher bits.
switch (flags) {
#ifndef SHTNS_DCT
case sht_auto : flags = sht_gauss; break; // only gauss available.
case sht_reg_fast:
case sht_reg_dct: shtns_runerr("regular grid not available (DCT required)."); break;
#endif
case sht_gauss_fly : flags = sht_gauss; on_the_fly = 1; break;
case sht_quick_init : flags = sht_gauss; quick_init = 1; break;
case sht_reg_poles : analys = 0; quick_init = 1; break;
default : break;
}
#ifndef SHTNS_MEM
on_the_fly = 1;
#endif
if (*nphi == 0) {
*nphi = fft_int((nl_order+1)*MMAX+1, 7); // required fft nodes
}
if (*nlat == 0) {
n_gauss = ((nl_order+1)*LMAX)/2 +1; // required gauss nodes
n_gauss += (n_gauss&1); // even is better.
n_gauss = ((n_gauss+(VSIZE2-1))/VSIZE2) * VSIZE2; // multiple of vector size
if (flags != sht_gauss) {
m = fft_int(nl_order*LMAX+2, 7); // required dct nodes
*nlat = m + (m&1); // even is better.
} else *nlat = n_gauss;
}
mem = sht_mem_size(shtns->lmax, shtns->mmax, shtns->mres, *nlat);
t=mem; if (analys) t*=2; if (vector) t*=3;
#if SHT_VERBOSE > 1
if (verbose>1) printf("Memory required for precomputed matrices (estimate) : %.3f Mb\n",t);
#endif
if ( t > SHTNS_MAX_MEMORY ) { // huge transform has been requested
on_the_fly = 1;
if ( (flags == sht_reg_dct) || (flags == sht_reg_fast) ) shtns_runerr("Memory limit exceeded, try using sht_gauss or increase SHTNS_MAX_MEMORY in sht_config.h");
if (flags != sht_reg_poles) {
flags = sht_gauss;
if (n_gauss > 0) *nlat = n_gauss;
}
// if (t > 10*SHTNS_MAX_MEMORY) quick_init =1; // do not time such large transforms.
}
if (quick_init == 0) { // do not waste too much time finding optimal fftw.
shtns->fftw_plan_mode = FFTW_EXHAUSTIVE; // defines the default FFTW planner mode.
// fftw_set_timelimit(60.0); // do not search plans for more than 1 minute (does it work well ???)
if (*nphi > 512) shtns->fftw_plan_mode = FFTW_PATIENT;
if (*nphi > 1024) shtns->fftw_plan_mode = FFTW_MEASURE;
} else {
shtns->fftw_plan_mode = FFTW_ESTIMATE;
if ((mem < 1.0) && (SHT_VERBOSE < 2)) shtns->nthreads = 1; // disable threads for small transforms (in quickinit mode).
if ((VSIZE2 >= 4) && (*nlat >= VSIZE2*4)) on_the_fly = 1; // with AVX, on-the-fly should be the default (faster).
if ((shtns->nthreads > 1) && (*nlat >= VSIZE2*16)) on_the_fly = 1; // force multi-thread transforms
}
if (flags == sht_auto) {
if ( ((nl_order>=2)&&(MMAX*MRES > LMAX/2)) || (*nlat < SHT_MIN_NLAT_DCT) || (*nlat & 1) || (*nlat <= LMAX+1) ) {
flags = sht_gauss; // avoid computing DCT stuff when it is not expected to be faster.
if (n_gauss > 0) *nlat = n_gauss;
}
}
if (*nlat <= shtns->lmax) shtns_runerr("Nlat must be larger than Lmax");
if (IS_TOO_LARGE(*nlat, shtns->nlat)) shtns_runerr("Nlat too large");
if (IS_TOO_LARGE(*nphi, shtns->nphi)) shtns_runerr("Nphi too large");
// copy to global variables.
shtns->nphi = *nphi;
shtns->nlat_2 = (*nlat+1)/2; shtns->nlat = *nlat;
if (layout & SHT_LOAD_SAVE_CFG) {
FILE* f = fopen("shtns_cfg_fftw","r");
if (f) {
fftw_import_wisdom_from_file(f); // load fftw wisdom.
fclose(f);
}
}
planFFT(shtns, layout, on_the_fly); // initialize fftw
shtns->zlm_dct0 = NULL; // used as a flag.
init_sht_array_func(shtns); // array of SHT functions is now set.
#ifdef SHTNS_DCT
if (flags == sht_reg_dct) { // pure dct.
alloc_SHTarrays(shtns, on_the_fly, vector, analys); // allocate dynamic arrays
grid_dct(shtns, latdir); init_SH_dct(shtns, 1);
OptimizeMatrices(shtns, eps);
Set_MTR_DCT(shtns, MMAX);
if (MTR_DCT != MMAX) shtns_runerr("DCT planning failed.");
}
if ((flags == sht_auto)||(flags == sht_reg_fast))
{
alloc_SHTarrays(shtns, on_the_fly, vector, analys); // allocate dynamic arrays
grid_dct(shtns, latdir); init_SH_dct(shtns, 1);
OptimizeMatrices(shtns, eps);
if (NLAT >= SHT_MIN_NLAT_DCT) { // dct requires large NLAT to perform well.
if ((layout & SHT_LOAD_SAVE_CFG) && (flags == sht_reg_fast))
cfg_loaded = (config_load(shtns, req_flags) > 0);
if (!cfg_loaded) {
t = choose_best_sht(shtns, &nloop, vector, 1); // find optimal MTR_DCT.
if ((n_gauss > 0)&&(flags == sht_auto)) t *= ((double) n_gauss)/NLAT; // we can revert to gauss with a smaller nlat.
if (t < MIN_PERF_IMPROVE_DCT) {
Set_MTR_DCT(shtns, -1); // turn off DCT.
} else {
t = SHT_error(shtns, vector);
if (t > MIN_ACCURACY_DCT) {
#if SHT_VERBOSE > 0
if (verbose) printf(" !! Not enough accuracy (%.3g) => DCT disabled.\n",t);
#endif
#if SHT_VERBOSE < 2
Set_MTR_DCT(shtns, -1); // turn off DCT.
#endif
}
}
}
}
if (MTR_DCT < 0) { // free memory used by DCT and disables DCT.
free_SH_dct(shtns); // free now useless arrays.
if (flags == sht_auto) {
flags = sht_gauss; // switch to gauss grid, even better accuracy.
#if SHT_VERBOSE > 0
if (verbose) printf(" => switching back to Gauss Grid\n");
#endif
for (im=1; im<=MMAX; im++) { // im >= 1
m = im*MRES;
shtns->ylm[im] -= shtns->tm[im]*(LMAX-m+1); // restore pointers altered by OptimizeMatrices().
if (vector) shtns->dylm[im] -= shtns->tm[im]*(LMAX-m+1);
}
if (n_gauss > 0) { // we should use the optimal size for gauss-legendre
free_SHTarrays(shtns);
*nlat = n_gauss;
shtns->nlat_2 = (*nlat+1)/2; shtns->nlat = *nlat;
planFFT(shtns, layout, on_the_fly); // fft must be replanned because NLAT has changed.
}
}
}
}
#endif /* SHTNS_DCT */
if (flags == sht_gauss)
{
alloc_SHTarrays(shtns, on_the_fly, vector, analys); // allocate dynamic arrays
grid_gauss(shtns, latdir);
#ifdef SHTNS_MEM
if (on_the_fly == 0) {
init_SH_gauss(shtns); // precompute matrices
OptimizeMatrices(shtns, eps);
}
#endif
}
if (flags == sht_reg_poles)
{
alloc_SHTarrays(shtns, on_the_fly, vector, 0); // allocate dynamic arrays (no analysis)
grid_equal_polar(shtns, latdir);
#ifdef SHTNS_MEM
if (on_the_fly == 0) {
init_SH_synth(shtns);
for (im=0; im<=MMAX; im++) shtns->tm[im] = 0; // avoid problems with tm[im] modified ????
}
#endif
}
if (on_the_fly == 1) {
#if SHT_VERBOSE > 0
if (verbose) printf(" + using on-the-fly transforms.\n");
#endif
if (NLAT < VSIZE2*4) shtns_runerr("on-the-fly only available for nlat>=32"); // avoid overflow with NLAT_2 < VSIZE2*2
PolarOptimize(shtns, eps);
set_sht_fly(shtns, 0); // switch function pointers to "on-the-fly" functions.
}
if ((layout & SHT_LOAD_SAVE_CFG) && (!cfg_loaded)) cfg_loaded = (config_load(shtns, req_flags) > 0);
if (quick_init == 0) {
if (!cfg_loaded) {
choose_best_sht(shtns, &nloop, vector, 0);
if (layout & SHT_LOAD_SAVE_CFG) config_save(shtns, req_flags);
}
#ifdef SHTNS_MEM
if (on_the_fly == 0) free_unused_matrices(shtns);
#endif
t = SHT_error(shtns, vector); // compute SHT accuracy.
#if SHT_VERBOSE > 0
if (verbose) printf(" + SHT accuracy = %.3g\n",t);
#endif
#if SHT_VERBOSE < 2
if (t > 1.e-3) {
shtns_print_cfg(shtns);
shtns_runerr("bad SHT accuracy"); // stop if something went wrong (but not in debug mode)
}
#endif
}
// set_sht_fly(shtns, SHT_TYP_VAN);
#if SHT_VERBOSE > 1
if ((omp_threads > 1)&&(verbose>1)) printf(" nthreads = %d\n",shtns->nthreads);
#endif
#if SHT_VERBOSE > 0
if (verbose) printf(" => " PACKAGE_NAME " is ready.\n");
#endif
return(shtns->nspat); // returns the number of doubles to be allocated for a spatial field.
}
/*! Initialization of Spherical Harmonic transforms (backward and forward, vector and scalar, ...) of given size.
* <b>This function must be called after \ref shtns_create and before any SH transform.</b> and sets all global variables.
* returns the required number of doubles to be allocated for a spatial field.
* \param shtns is the config created by shtns_create for which the grid will be set.
* \param flags allows to choose the type of transform (see \ref shtns_type) and the spatial data layout (see \ref spat)
* \param eps polar optimization threshold : polar values of Legendre Polynomials below that threshold are neglected (for high m), leading to increased performance (a few percents)
* \param nlat,nphi respectively the number of latitudinal and longitudinal grid points.
* 0 = no polar optimization; 1.e-14 = VERY safe; 1.e-10 = safe; 1.e-6 = aggresive, but still good accuracy.
*/
int shtns_set_grid(shtns_cfg shtns, enum shtns_type flags, double eps, int nlat, int nphi)
{
if ((nlat == 0)||(nphi == 0)) shtns_runerr("nlat or nphi is zero !");
return( shtns_set_grid_auto(shtns, flags, eps, 0, &nlat, &nphi) );
}
/*! Simple initialization of Spherical Harmonic transforms (backward and forward, vector and scalar, ...) of given size.
* This function sets all global variables by calling \ref shtns_create followed by \ref shtns_set_grid, with the
* default normalization and the default polar optimization (see \ref sht_config.h).
* Returns the configuration to be passed to subsequent transform functions, which is basicaly a pointer to a \ref shtns_info struct.
* \param lmax : maximum SH degree that we want to describe.
* \param mmax : number of azimutal wave numbers.
* \param mres : \c 2.pi/mres is the azimutal periodicity. \c mmax*mres is the maximum SH order.
* \param nlat,nphi : respectively the number of latitudinal and longitudinal grid points.
* \param flags allows to choose the type of transform (see \ref shtns_type) and the spatial data layout (see \ref spat)
*/
shtns_cfg shtns_init(enum shtns_type flags, int lmax, int mmax, int mres, int nlat, int nphi)
{
shtns_cfg shtns = shtns_create(lmax, mmax, mres, SHT_DEFAULT_NORM);
if (shtns != NULL)
shtns_set_grid(shtns, flags, SHT_DEFAULT_POLAR_OPT, nlat, nphi);
return shtns;
}
/** Enables OpenMP parallel transforms, if available (see \ref compil).
Call before any initialization of shtns to use mutliple threads. Returns the actual number of threads.
\li If num_threads > 0, specifies the maximum number of threads that should be used.
\li If num_threads <= 0, maximum number of threads is automatically set to the number of processors.
\li If num_threads == 1, openmp will be disabled. */
int shtns_use_threads(int num_threads)
{
#ifdef _OPENMP
int procs = omp_get_num_procs();
if (num_threads <= 0) num_threads = omp_get_max_threads();
else if (num_threads > 4*procs) num_threads = 4*procs; // limit the number of threads
omp_threads = num_threads;
#endif
#ifdef OMP_FFTW
fftw_init_threads(); // enable threads for FFTW.
#endif
return omp_threads;
}
/// fill the given array with Gauss weights. returns the number of weights written, which
/// may be zero if the grid is not a Gauss grid.
int shtns_gauss_wts(shtns_cfg shtns, double *wts)
{
int i = 0;
if (shtns->wg) {
double rescale = 2*NPHI; // weights are stored with a rescaling that depends on SHT_NORM.
if ((SHT_NORM != sht_fourpi)&&(SHT_NORM != sht_schmidt)) rescale *= 0.25/M_PI;
do {
wts[i] = shtns->wg[i] * rescale;
} while(++i < shtns->nlat_2);
}
return i;
}
//@}
#ifdef SHT_F77_API
/* FORTRAN API */
/** \addtogroup fortapi Fortran API.
* Call from fortran without the trailing '_'.
* see the \link SHT_example.f Fortran example \endlink for a simple usage of SHTns from Fortran language.
*/
//@{
/// Set verbosity level
void shtns_verbose_(int *v)
{
shtns_verbose(*v);
}
/// Enable threads
void shtns_use_threads_(int *num_threads)
{
shtns_use_threads(*num_threads);
}
/// Print info
void shtns_print_cfg_()
{
shtns_print_version();
if (sht_data) shtns_print_cfg(sht_data);
}
/// Initializes spherical harmonic transforms of given size using Gauss algorithm with default polar optimization.
void shtns_init_sh_gauss_(int *layout, int *lmax, int *mmax, int *mres, int *nlat, int *nphi)
{
shtns_reset();
shtns_cfg shtns = shtns_create(*lmax, *mmax, *mres, SHT_DEFAULT_NORM);
shtns_set_grid(shtns, sht_gauss | *layout, SHT_DEFAULT_POLAR_OPT, *nlat, *nphi);
}
/// Initializes spherical harmonic transforms of given size using Fastest available algorithm and polar optimization.
void shtns_init_sh_auto_(int *layout, int *lmax, int *mmax, int *mres, int *nlat, int *nphi)
{
shtns_reset();
shtns_cfg shtns = shtns_create(*lmax, *mmax, *mres, SHT_DEFAULT_NORM);
shtns_set_grid(shtns, sht_auto | *layout, SHT_DEFAULT_POLAR_OPT, *nlat, *nphi);
}
/// Initializes spherical harmonic transforms of given size using a regular grid and agressive optimizations.
void shtns_init_sh_reg_fast_(int *layout, int *lmax, int *mmax, int *mres, int *nlat, int *nphi)
{
shtns_reset();
shtns_cfg shtns = shtns_create(*lmax, *mmax, *mres, SHT_DEFAULT_NORM);
shtns_set_grid(shtns, sht_reg_fast | *layout, 1.e-6, *nlat, *nphi);
}
/// Initializes spherical harmonic transform SYNTHESIS ONLY of given size using a regular grid including poles.
void shtns_init_sh_poles_(int *layout, int *lmax, int *mmax, int *mres, int *nlat, int *nphi)
{
shtns_reset();
shtns_cfg shtns = shtns_create(*lmax, *mmax, *mres, SHT_DEFAULT_NORM);
shtns_set_grid(shtns, sht_reg_poles | *layout, 0, *nlat, *nphi);
}
/// Defines the size and convention of the transform.
/// Allow to choose the normalization and whether or not to include the Condon-Shortley phase.
/// \see shtns_create
void shtns_set_size_(int *lmax, int *mmax, int *mres, int *norm)
{
shtns_reset();
shtns_create(*lmax, *mmax, *mres, *norm);
}
/// Precompute matrices for synthesis and analysis.
/// Allow to choose polar optimization threshold and algorithm type.
/// \see shtns_set_grid
void shtns_precompute_(int *type, int *layout, double *eps, int *nlat, int *nphi)
{
shtns_set_grid(sht_data, *type | *layout, *eps, *nlat, *nphi);
}
/// Same as shtns_precompute_ but choose optimal nlat and/or nphi.
/// \see shtns_set_grid_auto
void shtns_precompute_auto_(int *type, int *layout, double *eps, int *nl_order, int *nlat, int *nphi)
{
shtns_set_grid_auto(sht_data, *type | *layout, *eps, *nl_order, nlat, nphi);
}
/// Clear everything
void shtns_reset_() {
shtns_reset();
}
/// returns nlm, the number of complex*16 elements in an SH array.
/// call from fortran using \code call shtns_calc_nlm(nlm, lmax, mmax, mres) \endcode
void shtns_calc_nlm_(int *nlm, const int *const lmax, const int *const mmax, const int *const mres)
{
*nlm = nlm_calc(*lmax, *mmax, *mres);
}
/// returns lm, the index in an SH array of mode (l,m).
/// call from fortran using \code call shtns_lmidx(lm, l, m) \endcode
void shtns_lmidx_(int *lm, const int *const l, const int *const m)
{
unsigned im = *m;
unsigned mres = sht_data->mres;
if (mres > 1) {
unsigned k = im % mres;
im = im / mres;
if (k) printf("wrong m");
}
*lm = LiM(sht_data, *l, im) + 1; // convert to fortran convention index.
}
/// returns l and m, degree and order of an index in SH array lm.
/// call from fortran using \code call shtns_l_m(l, m, lm) \endcode
void shtns_l_m_(int *l, int *m, const int *const lm)
{
*l = sht_data->li[*lm -1]; // convert from fortran convention index.
*m = sht_data->mi[*lm -1];
}
/// fills the given array with the cosine of the co-latitude angle (NLAT real*8)
/// if no grid has been set, the first element will be set to zero.
void shtns_cos_array_(double *costh)
{
if (sht_data->ct) {
for (int i=0; i<sht_data->nlat; i++)
costh[i] = sht_data->ct[i];
} else costh[0] = 0.0; // mark as invalid.
}
/// fills the given array with the gaussian quadrature weights ((NLAT+1)/2 real*8).
/// when there is no gaussian grid, the first element is set to zero.
void shtns_gauss_wts_(double *wts)
{
int i = shtns_gauss_wts(sht_data, wts);
if (i==0) wts[0] = 0; // mark as invalid.
}
/** \name Point evaluation of Spherical Harmonics
Evaluate at a given point (\f$cos(\theta)\f$ and \f$\phi\f$) a spherical harmonic representation.
*/
//@{
/// \see SH_to_point for argument description
void shtns_sh_to_point_(double *spat, cplx *Qlm, double *cost, double *phi)
{
*spat = SH_to_point(sht_data, Qlm, *cost, *phi);
}
/// \see SHqst_to_point for argument description
void shtns_qst_to_point_(double *vr, double *vt, double *vp,
cplx *Qlm, cplx *Slm, cplx *Tlm, double *cost, double *phi)
{
SHqst_to_point(sht_data, Qlm, Slm, Tlm, *cost, *phi, vr, vt, vp);
}
//@}
//@}
#endif
| 35.168801 | 222 | 0.619331 |
9fa7355d71a0f764fc825db085c3db05ccab42f2 | 217 | c | C | semana1/URI/URI-1011.c | ThiagoOliveiraCordeiro/c-ITP | 54fed21ef232db4d393a84d57190561d346d5919 | [
"MIT"
] | null | null | null | semana1/URI/URI-1011.c | ThiagoOliveiraCordeiro/c-ITP | 54fed21ef232db4d393a84d57190561d346d5919 | [
"MIT"
] | null | null | null | semana1/URI/URI-1011.c | ThiagoOliveiraCordeiro/c-ITP | 54fed21ef232db4d393a84d57190561d346d5919 | [
"MIT"
] | null | null | null | #include <stdio.h>
int main() {
int raio;
double volume;
scanf("%i", &raio);
volume = (4.0 / 3) * 3.14159 * raio * raio * raio;
printf("VOLUME = %.3lf\n", volume);
return 0;
} | 16.692308 | 55 | 0.483871 |
e5fea68ea94d03c67cf98c73024e21443e8e2aa5 | 806 | h | C | aimp_dlna/IUnknownInterfaceImpl.h | MoshiMoshi0/aimp_dlna | cc71f366cecbb85e30867b7ac66c145956501e17 | [
"MIT"
] | 3 | 2020-05-18T22:11:30.000Z | 2022-01-21T15:01:03.000Z | aimp_dlna/IUnknownInterfaceImpl.h | MoshiMoshi0/aimp_dlna | cc71f366cecbb85e30867b7ac66c145956501e17 | [
"MIT"
] | null | null | null | aimp_dlna/IUnknownInterfaceImpl.h | MoshiMoshi0/aimp_dlna | cc71f366cecbb85e30867b7ac66c145956501e17 | [
"MIT"
] | null | null | null | #pragma once
template <typename TInterface, REFIID TIID = IID_IUnknown>
class IUnknownInterfaceImpl : public TInterface {
protected:
typedef IUnknownInterfaceImpl<TInterface, TIID> Base;
ULONG reference_count_;
public:
IUnknownInterfaceImpl()
: reference_count_(0) {
AddRef();
}
virtual ~IUnknownInterfaceImpl() {}
virtual HRESULT WINAPI QueryInterface(REFIID riid, LPVOID* ppvObj) {
if (!ppvObj) {
return E_POINTER;
}
if (riid == TIID || riid == IID_IUnknown) {
*ppvObj = this;
AddRef();
return S_OK;
}
return E_NOINTERFACE;
}
virtual ULONG WINAPI AddRef(void) {
return ++reference_count_;
}
virtual ULONG WINAPI Release(void) {
ULONG reference_count = --reference_count_;
if (reference_count == 0) {
delete this;
}
return reference_count;
}
}; | 17.911111 | 69 | 0.704715 |
b23788701c312dc2420023839d95106bdb649a17 | 660,674 | c | C | py_ecc/cython_src/c_src/optimized_field_elements.c | Mikerah/py_ecc.js | b470d692ca8b1e4942b896ae1e4d1ddf20d4ff69 | [
"MIT"
] | 1 | 2018-07-12T14:12:06.000Z | 2018-07-12T14:12:06.000Z | py_ecc/cython_src/c_src/optimized_field_elements.c | Mikerah/py_ecc.js | b470d692ca8b1e4942b896ae1e4d1ddf20d4ff69 | [
"MIT"
] | null | null | null | py_ecc/cython_src/c_src/optimized_field_elements.c | Mikerah/py_ecc.js | b470d692ca8b1e4942b896ae1e4d1ddf20d4ff69 | [
"MIT"
] | null | null | null | /* Generated by Cython 0.28.4 */
/* BEGIN: Cython Metadata
{
"distutils": {
"name": "optimized_field_elements",
"sources": [
"py_ecc/cython_src/optimized_field_elements.pyx"
]
},
"module_name": "optimized_field_elements"
}
END: Cython Metadata */
#define PY_SSIZE_T_CLEAN
#include "Python.h"
#ifndef Py_PYTHON_H
#error Python headers needed to compile C extensions, please install development version of Python.
#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000)
#error Cython requires Python 2.6+ or Python 3.3+.
#else
#define CYTHON_ABI "0_28_4"
#define CYTHON_FUTURE_DIVISION 0
#include <stddef.h>
#ifndef offsetof
#define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
#endif
#if !defined(WIN32) && !defined(MS_WINDOWS)
#ifndef __stdcall
#define __stdcall
#endif
#ifndef __cdecl
#define __cdecl
#endif
#ifndef __fastcall
#define __fastcall
#endif
#endif
#ifndef DL_IMPORT
#define DL_IMPORT(t) t
#endif
#ifndef DL_EXPORT
#define DL_EXPORT(t) t
#endif
#define __PYX_COMMA ,
#ifndef HAVE_LONG_LONG
#if PY_VERSION_HEX >= 0x02070000
#define HAVE_LONG_LONG
#endif
#endif
#ifndef PY_LONG_LONG
#define PY_LONG_LONG LONG_LONG
#endif
#ifndef Py_HUGE_VAL
#define Py_HUGE_VAL HUGE_VAL
#endif
#ifdef PYPY_VERSION
#define CYTHON_COMPILING_IN_PYPY 1
#define CYTHON_COMPILING_IN_PYSTON 0
#define CYTHON_COMPILING_IN_CPYTHON 0
#undef CYTHON_USE_TYPE_SLOTS
#define CYTHON_USE_TYPE_SLOTS 0
#undef CYTHON_USE_PYTYPE_LOOKUP
#define CYTHON_USE_PYTYPE_LOOKUP 0
#if PY_VERSION_HEX < 0x03050000
#undef CYTHON_USE_ASYNC_SLOTS
#define CYTHON_USE_ASYNC_SLOTS 0
#elif !defined(CYTHON_USE_ASYNC_SLOTS)
#define CYTHON_USE_ASYNC_SLOTS 1
#endif
#undef CYTHON_USE_PYLIST_INTERNALS
#define CYTHON_USE_PYLIST_INTERNALS 0
#undef CYTHON_USE_UNICODE_INTERNALS
#define CYTHON_USE_UNICODE_INTERNALS 0
#undef CYTHON_USE_UNICODE_WRITER
#define CYTHON_USE_UNICODE_WRITER 0
#undef CYTHON_USE_PYLONG_INTERNALS
#define CYTHON_USE_PYLONG_INTERNALS 0
#undef CYTHON_AVOID_BORROWED_REFS
#define CYTHON_AVOID_BORROWED_REFS 1
#undef CYTHON_ASSUME_SAFE_MACROS
#define CYTHON_ASSUME_SAFE_MACROS 0
#undef CYTHON_UNPACK_METHODS
#define CYTHON_UNPACK_METHODS 0
#undef CYTHON_FAST_THREAD_STATE
#define CYTHON_FAST_THREAD_STATE 0
#undef CYTHON_FAST_PYCALL
#define CYTHON_FAST_PYCALL 0
#undef CYTHON_PEP489_MULTI_PHASE_INIT
#define CYTHON_PEP489_MULTI_PHASE_INIT 0
#undef CYTHON_USE_TP_FINALIZE
#define CYTHON_USE_TP_FINALIZE 0
#elif defined(PYSTON_VERSION)
#define CYTHON_COMPILING_IN_PYPY 0
#define CYTHON_COMPILING_IN_PYSTON 1
#define CYTHON_COMPILING_IN_CPYTHON 0
#ifndef CYTHON_USE_TYPE_SLOTS
#define CYTHON_USE_TYPE_SLOTS 1
#endif
#undef CYTHON_USE_PYTYPE_LOOKUP
#define CYTHON_USE_PYTYPE_LOOKUP 0
#undef CYTHON_USE_ASYNC_SLOTS
#define CYTHON_USE_ASYNC_SLOTS 0
#undef CYTHON_USE_PYLIST_INTERNALS
#define CYTHON_USE_PYLIST_INTERNALS 0
#ifndef CYTHON_USE_UNICODE_INTERNALS
#define CYTHON_USE_UNICODE_INTERNALS 1
#endif
#undef CYTHON_USE_UNICODE_WRITER
#define CYTHON_USE_UNICODE_WRITER 0
#undef CYTHON_USE_PYLONG_INTERNALS
#define CYTHON_USE_PYLONG_INTERNALS 0
#ifndef CYTHON_AVOID_BORROWED_REFS
#define CYTHON_AVOID_BORROWED_REFS 0
#endif
#ifndef CYTHON_ASSUME_SAFE_MACROS
#define CYTHON_ASSUME_SAFE_MACROS 1
#endif
#ifndef CYTHON_UNPACK_METHODS
#define CYTHON_UNPACK_METHODS 1
#endif
#undef CYTHON_FAST_THREAD_STATE
#define CYTHON_FAST_THREAD_STATE 0
#undef CYTHON_FAST_PYCALL
#define CYTHON_FAST_PYCALL 0
#undef CYTHON_PEP489_MULTI_PHASE_INIT
#define CYTHON_PEP489_MULTI_PHASE_INIT 0
#undef CYTHON_USE_TP_FINALIZE
#define CYTHON_USE_TP_FINALIZE 0
#else
#define CYTHON_COMPILING_IN_PYPY 0
#define CYTHON_COMPILING_IN_PYSTON 0
#define CYTHON_COMPILING_IN_CPYTHON 1
#ifndef CYTHON_USE_TYPE_SLOTS
#define CYTHON_USE_TYPE_SLOTS 1
#endif
#if PY_VERSION_HEX < 0x02070000
#undef CYTHON_USE_PYTYPE_LOOKUP
#define CYTHON_USE_PYTYPE_LOOKUP 0
#elif !defined(CYTHON_USE_PYTYPE_LOOKUP)
#define CYTHON_USE_PYTYPE_LOOKUP 1
#endif
#if PY_MAJOR_VERSION < 3
#undef CYTHON_USE_ASYNC_SLOTS
#define CYTHON_USE_ASYNC_SLOTS 0
#elif !defined(CYTHON_USE_ASYNC_SLOTS)
#define CYTHON_USE_ASYNC_SLOTS 1
#endif
#if PY_VERSION_HEX < 0x02070000
#undef CYTHON_USE_PYLONG_INTERNALS
#define CYTHON_USE_PYLONG_INTERNALS 0
#elif !defined(CYTHON_USE_PYLONG_INTERNALS)
#define CYTHON_USE_PYLONG_INTERNALS 1
#endif
#ifndef CYTHON_USE_PYLIST_INTERNALS
#define CYTHON_USE_PYLIST_INTERNALS 1
#endif
#ifndef CYTHON_USE_UNICODE_INTERNALS
#define CYTHON_USE_UNICODE_INTERNALS 1
#endif
#if PY_VERSION_HEX < 0x030300F0
#undef CYTHON_USE_UNICODE_WRITER
#define CYTHON_USE_UNICODE_WRITER 0
#elif !defined(CYTHON_USE_UNICODE_WRITER)
#define CYTHON_USE_UNICODE_WRITER 1
#endif
#ifndef CYTHON_AVOID_BORROWED_REFS
#define CYTHON_AVOID_BORROWED_REFS 0
#endif
#ifndef CYTHON_ASSUME_SAFE_MACROS
#define CYTHON_ASSUME_SAFE_MACROS 1
#endif
#ifndef CYTHON_UNPACK_METHODS
#define CYTHON_UNPACK_METHODS 1
#endif
#ifndef CYTHON_FAST_THREAD_STATE
#define CYTHON_FAST_THREAD_STATE 1
#endif
#ifndef CYTHON_FAST_PYCALL
#define CYTHON_FAST_PYCALL 1
#endif
#ifndef CYTHON_PEP489_MULTI_PHASE_INIT
#define CYTHON_PEP489_MULTI_PHASE_INIT (0 && PY_VERSION_HEX >= 0x03050000)
#endif
#ifndef CYTHON_USE_TP_FINALIZE
#define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1)
#endif
#endif
#if !defined(CYTHON_FAST_PYCCALL)
#define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
#endif
#if CYTHON_USE_PYLONG_INTERNALS
#include "longintrepr.h"
#undef SHIFT
#undef BASE
#undef MASK
#endif
#ifndef __has_attribute
#define __has_attribute(x) 0
#endif
#ifndef __has_cpp_attribute
#define __has_cpp_attribute(x) 0
#endif
#ifndef CYTHON_RESTRICT
#if defined(__GNUC__)
#define CYTHON_RESTRICT __restrict__
#elif defined(_MSC_VER) && _MSC_VER >= 1400
#define CYTHON_RESTRICT __restrict
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#define CYTHON_RESTRICT restrict
#else
#define CYTHON_RESTRICT
#endif
#endif
#ifndef CYTHON_UNUSED
# if defined(__GNUC__)
# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
# define CYTHON_UNUSED __attribute__ ((__unused__))
# else
# define CYTHON_UNUSED
# endif
# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
# define CYTHON_UNUSED __attribute__ ((__unused__))
# else
# define CYTHON_UNUSED
# endif
#endif
#ifndef CYTHON_MAYBE_UNUSED_VAR
# if defined(__cplusplus)
template<class T> void CYTHON_MAYBE_UNUSED_VAR( const T& ) { }
# else
# define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x)
# endif
#endif
#ifndef CYTHON_NCP_UNUSED
# if CYTHON_COMPILING_IN_CPYTHON
# define CYTHON_NCP_UNUSED
# else
# define CYTHON_NCP_UNUSED CYTHON_UNUSED
# endif
#endif
#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)
#ifdef _MSC_VER
#ifndef _MSC_STDINT_H_
#if _MSC_VER < 1300
typedef unsigned char uint8_t;
typedef unsigned int uint32_t;
#else
typedef unsigned __int8 uint8_t;
typedef unsigned __int32 uint32_t;
#endif
#endif
#else
#include <stdint.h>
#endif
#ifndef CYTHON_FALLTHROUGH
#if defined(__cplusplus) && __cplusplus >= 201103L
#if __has_cpp_attribute(fallthrough)
#define CYTHON_FALLTHROUGH [[fallthrough]]
#elif __has_cpp_attribute(clang::fallthrough)
#define CYTHON_FALLTHROUGH [[clang::fallthrough]]
#elif __has_cpp_attribute(gnu::fallthrough)
#define CYTHON_FALLTHROUGH [[gnu::fallthrough]]
#endif
#endif
#ifndef CYTHON_FALLTHROUGH
#if __has_attribute(fallthrough)
#define CYTHON_FALLTHROUGH __attribute__((fallthrough))
#else
#define CYTHON_FALLTHROUGH
#endif
#endif
#if defined(__clang__ ) && defined(__apple_build_version__)
#if __apple_build_version__ < 7000000
#undef CYTHON_FALLTHROUGH
#define CYTHON_FALLTHROUGH
#endif
#endif
#endif
#ifndef CYTHON_INLINE
#if defined(__clang__)
#define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
#elif defined(__GNUC__)
#define CYTHON_INLINE __inline__
#elif defined(_MSC_VER)
#define CYTHON_INLINE __inline
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#define CYTHON_INLINE inline
#else
#define CYTHON_INLINE
#endif
#endif
#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
#define Py_OptimizeFlag 0
#endif
#define __PYX_BUILD_PY_SSIZE_T "n"
#define CYTHON_FORMAT_SSIZE_T "z"
#if PY_MAJOR_VERSION < 3
#define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
#define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
#define __Pyx_DefaultClassType PyClass_Type
#else
#define __Pyx_BUILTIN_MODULE_NAME "builtins"
#define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
#define __Pyx_DefaultClassType PyType_Type
#endif
#ifndef Py_TPFLAGS_CHECKTYPES
#define Py_TPFLAGS_CHECKTYPES 0
#endif
#ifndef Py_TPFLAGS_HAVE_INDEX
#define Py_TPFLAGS_HAVE_INDEX 0
#endif
#ifndef Py_TPFLAGS_HAVE_NEWBUFFER
#define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#ifndef Py_TPFLAGS_HAVE_FINALIZE
#define Py_TPFLAGS_HAVE_FINALIZE 0
#endif
#if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL)
#ifndef METH_FASTCALL
#define METH_FASTCALL 0x80
#endif
typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs);
typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args,
Py_ssize_t nargs, PyObject *kwnames);
#else
#define __Pyx_PyCFunctionFast _PyCFunctionFast
#define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords
#endif
#if CYTHON_FAST_PYCCALL
#define __Pyx_PyFastCFunction_Check(func)\
((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS)))))
#else
#define __Pyx_PyFastCFunction_Check(func) 0
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
#define PyObject_Malloc(s) PyMem_Malloc(s)
#define PyObject_Free(p) PyMem_Free(p)
#define PyObject_Realloc(p) PyMem_Realloc(p)
#endif
#if CYTHON_COMPILING_IN_PYSTON
#define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co)
#define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno)
#else
#define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0)
#define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno)
#endif
#if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000
#define __Pyx_PyThreadState_Current PyThreadState_GET()
#elif PY_VERSION_HEX >= 0x03060000
#define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
#elif PY_VERSION_HEX >= 0x03000000
#define __Pyx_PyThreadState_Current PyThreadState_GET()
#else
#define __Pyx_PyThreadState_Current _PyThreadState_Current
#endif
#if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT)
#include "pythread.h"
#define Py_tss_NEEDS_INIT 0
typedef int Py_tss_t;
static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) {
*key = PyThread_create_key();
return 0; // PyThread_create_key reports success always
}
static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) {
Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t));
*key = Py_tss_NEEDS_INIT;
return key;
}
static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) {
PyObject_Free(key);
}
static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) {
return *key != Py_tss_NEEDS_INIT;
}
static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) {
PyThread_delete_key(*key);
*key = Py_tss_NEEDS_INIT;
}
static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) {
return PyThread_set_key_value(*key, value);
}
static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
return PyThread_get_key_value(*key);
}
#endif // TSS (Thread Specific Storage) API
#if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized)
#define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n))
#else
#define __Pyx_PyDict_NewPresized(n) PyDict_New()
#endif
#if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION
#define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)
#define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)
#else
#define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y)
#define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y)
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS
#define __Pyx_PyDict_GetItemStr(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash)
#else
#define __Pyx_PyDict_GetItemStr(dict, name) PyDict_GetItem(dict, name)
#endif
#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
#define CYTHON_PEP393_ENABLED 1
#define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\
0 : _PyUnicode_Ready((PyObject *)(op)))
#define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u)
#define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
#define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u)
#define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u)
#define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u)
#define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i)
#define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch)
#define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
#else
#define CYTHON_PEP393_ENABLED 0
#define PyUnicode_1BYTE_KIND 1
#define PyUnicode_2BYTE_KIND 2
#define PyUnicode_4BYTE_KIND 4
#define __Pyx_PyUnicode_READY(op) (0)
#define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u)
#define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
#define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111)
#define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE))
#define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u))
#define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
#define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = ch)
#define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u))
#endif
#if CYTHON_COMPILING_IN_PYPY
#define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b)
#define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b)
#else
#define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b)
#define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
#define PyUnicode_Contains(u, s) PySequence_Contains(u, s)
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check)
#define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type)
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
#define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt)
#endif
#define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b)
#else
#define __Pyx_PyString_Format(a, b) PyString_Format(a, b)
#endif
#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
#define PyObject_ASCII(o) PyObject_Repr(o)
#endif
#if PY_MAJOR_VERSION >= 3
#define PyBaseString_Type PyUnicode_Type
#define PyStringObject PyUnicodeObject
#define PyString_Type PyUnicode_Type
#define PyString_Check PyUnicode_Check
#define PyString_CheckExact PyUnicode_CheckExact
#define PyObject_Unicode PyObject_Str
#endif
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
#define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
#else
#define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
#define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
#endif
#ifndef PySet_CheckExact
#define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
#endif
#if CYTHON_ASSUME_SAFE_MACROS
#define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq)
#else
#define __Pyx_PySequence_SIZE(seq) PySequence_Size(seq)
#endif
#if PY_MAJOR_VERSION >= 3
#define PyIntObject PyLongObject
#define PyInt_Type PyLong_Type
#define PyInt_Check(op) PyLong_Check(op)
#define PyInt_CheckExact(op) PyLong_CheckExact(op)
#define PyInt_FromString PyLong_FromString
#define PyInt_FromUnicode PyLong_FromUnicode
#define PyInt_FromLong PyLong_FromLong
#define PyInt_FromSize_t PyLong_FromSize_t
#define PyInt_FromSsize_t PyLong_FromSsize_t
#define PyInt_AsLong PyLong_AsLong
#define PyInt_AS_LONG PyLong_AS_LONG
#define PyInt_AsSsize_t PyLong_AsSsize_t
#define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
#define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
#define PyNumber_Int PyNumber_Long
#endif
#if PY_MAJOR_VERSION >= 3
#define PyBoolObject PyLongObject
#endif
#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
#ifndef PyUnicode_InternFromString
#define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
#endif
#endif
#if PY_VERSION_HEX < 0x030200A4
typedef long Py_hash_t;
#define __Pyx_PyInt_FromHash_t PyInt_FromLong
#define __Pyx_PyInt_AsHash_t PyInt_AsLong
#else
#define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
#define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t
#endif
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : (Py_INCREF(func), func))
#else
#define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
#endif
#if CYTHON_USE_ASYNC_SLOTS
#if PY_VERSION_HEX >= 0x030500B1
#define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
#define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
#else
#define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
#endif
#else
#define __Pyx_PyType_AsAsync(obj) NULL
#endif
#ifndef __Pyx_PyAsyncMethodsStruct
typedef struct {
unaryfunc am_await;
unaryfunc am_aiter;
unaryfunc am_anext;
} __Pyx_PyAsyncMethodsStruct;
#endif
#if defined(WIN32) || defined(MS_WINDOWS)
#define _USE_MATH_DEFINES
#endif
#include <math.h>
#ifdef NAN
#define __PYX_NAN() ((float) NAN)
#else
static CYTHON_INLINE float __PYX_NAN() {
float value;
memset(&value, 0xFF, sizeof(value));
return value;
}
#endif
#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL)
#define __Pyx_truncl trunc
#else
#define __Pyx_truncl truncl
#endif
#define __PYX_ERR(f_index, lineno, Ln_error) \
{ \
__pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \
}
#ifndef __PYX_EXTERN_C
#ifdef __cplusplus
#define __PYX_EXTERN_C extern "C"
#else
#define __PYX_EXTERN_C extern
#endif
#endif
#define __PYX_HAVE__optimized_field_elements
#define __PYX_HAVE_API__optimized_field_elements
/* Early includes */
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */
#if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS)
#define CYTHON_WITHOUT_ASSERTIONS
#endif
typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;
#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0
#define __PYX_DEFAULT_STRING_ENCODING ""
#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#define __Pyx_uchar_cast(c) ((unsigned char)c)
#define __Pyx_long_cast(x) ((long)x)
#define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\
(sizeof(type) < sizeof(Py_ssize_t)) ||\
(sizeof(type) > sizeof(Py_ssize_t) &&\
likely(v < (type)PY_SSIZE_T_MAX ||\
v == (type)PY_SSIZE_T_MAX) &&\
(!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
v == (type)PY_SSIZE_T_MIN))) ||\
(sizeof(type) == sizeof(Py_ssize_t) &&\
(is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
v == (type)PY_SSIZE_T_MAX))) )
#if defined (__cplusplus) && __cplusplus >= 201103L
#include <cstdlib>
#define __Pyx_sst_abs(value) std::abs(value)
#elif SIZEOF_INT >= SIZEOF_SIZE_T
#define __Pyx_sst_abs(value) abs(value)
#elif SIZEOF_LONG >= SIZEOF_SIZE_T
#define __Pyx_sst_abs(value) labs(value)
#elif defined (_MSC_VER)
#define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value))
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#define __Pyx_sst_abs(value) llabs(value)
#elif defined (__GNUC__)
#define __Pyx_sst_abs(value) __builtin_llabs(value)
#else
#define __Pyx_sst_abs(value) ((value<0) ? -value : value)
#endif
static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*);
static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
#define __Pyx_PyBytes_FromString PyBytes_FromString
#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
#if PY_MAJOR_VERSION < 3
#define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString
#define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#else
#define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString
#define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
#endif
#define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AS_STRING(s))
#define __Pyx_PyObject_AsWritableString(s) ((char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsWritableSString(s) ((signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s)
#define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s)
#define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s)
#define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s)
#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) {
const Py_UNICODE *u_end = u;
while (*u_end++) ;
return (size_t)(u_end - u - 1);
}
#define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
#define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode
#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b);
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
#define __Pyx_PySequence_Tuple(obj)\
(likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj))
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
#if CYTHON_ASSUME_SAFE_MACROS
#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
#else
#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
#endif
#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
#else
#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
#endif
#define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x))
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
static int __Pyx_sys_getdefaultencoding_not_ascii;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
PyObject* sys;
PyObject* default_encoding = NULL;
PyObject* ascii_chars_u = NULL;
PyObject* ascii_chars_b = NULL;
const char* default_encoding_c;
sys = PyImport_ImportModule("sys");
if (!sys) goto bad;
default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
Py_DECREF(sys);
if (!default_encoding) goto bad;
default_encoding_c = PyBytes_AsString(default_encoding);
if (!default_encoding_c) goto bad;
if (strcmp(default_encoding_c, "ascii") == 0) {
__Pyx_sys_getdefaultencoding_not_ascii = 0;
} else {
char ascii_chars[128];
int c;
for (c = 0; c < 128; c++) {
ascii_chars[c] = c;
}
__Pyx_sys_getdefaultencoding_not_ascii = 1;
ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
if (!ascii_chars_u) goto bad;
ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
PyErr_Format(
PyExc_ValueError,
"This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
default_encoding_c);
goto bad;
}
Py_DECREF(ascii_chars_u);
Py_DECREF(ascii_chars_b);
}
Py_DECREF(default_encoding);
return 0;
bad:
Py_XDECREF(default_encoding);
Py_XDECREF(ascii_chars_u);
Py_XDECREF(ascii_chars_b);
return -1;
}
#endif
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
#else
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
static char* __PYX_DEFAULT_STRING_ENCODING;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
PyObject* sys;
PyObject* default_encoding = NULL;
char* default_encoding_c;
sys = PyImport_ImportModule("sys");
if (!sys) goto bad;
default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
Py_DECREF(sys);
if (!default_encoding) goto bad;
default_encoding_c = PyBytes_AsString(default_encoding);
if (!default_encoding_c) goto bad;
__PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c));
if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
Py_DECREF(default_encoding);
return 0;
bad:
Py_XDECREF(default_encoding);
return -1;
}
#endif
#endif
/* Test for GCC > 2.95 */
#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else /* !__GNUC__ or GCC < 2.95 */
#define likely(x) (x)
#define unlikely(x) (x)
#endif /* __GNUC__ */
static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; }
static PyObject *__pyx_m = NULL;
static PyObject *__pyx_d;
static PyObject *__pyx_b;
static PyObject *__pyx_cython_runtime = NULL;
static PyObject *__pyx_empty_tuple;
static PyObject *__pyx_empty_bytes;
static PyObject *__pyx_empty_unicode;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;
static const char *__pyx_f[] = {
"py_ecc/cython_src/optimized_field_elements.pyx",
};
/*--- Type declarations ---*/
/* --- Runtime support code (head) --- */
/* Refnanny.proto */
#ifndef CYTHON_REFNANNY
#define CYTHON_REFNANNY 0
#endif
#if CYTHON_REFNANNY
typedef struct {
void (*INCREF)(void*, PyObject*, int);
void (*DECREF)(void*, PyObject*, int);
void (*GOTREF)(void*, PyObject*, int);
void (*GIVEREF)(void*, PyObject*, int);
void* (*SetupContext)(const char*, int, const char*);
void (*FinishContext)(void**);
} __Pyx_RefNannyAPIStruct;
static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
#define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
#ifdef WITH_THREAD
#define __Pyx_RefNannySetupContext(name, acquire_gil)\
if (acquire_gil) {\
PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
PyGILState_Release(__pyx_gilstate_save);\
} else {\
__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
}
#else
#define __Pyx_RefNannySetupContext(name, acquire_gil)\
__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
#endif
#define __Pyx_RefNannyFinishContext()\
__Pyx_RefNanny->FinishContext(&__pyx_refnanny)
#define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
#define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
#define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
#define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
#define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
#define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
#define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
#define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
#else
#define __Pyx_RefNannyDeclarations
#define __Pyx_RefNannySetupContext(name, acquire_gil)
#define __Pyx_RefNannyFinishContext()
#define __Pyx_INCREF(r) Py_INCREF(r)
#define __Pyx_DECREF(r) Py_DECREF(r)
#define __Pyx_GOTREF(r)
#define __Pyx_GIVEREF(r)
#define __Pyx_XINCREF(r) Py_XINCREF(r)
#define __Pyx_XDECREF(r) Py_XDECREF(r)
#define __Pyx_XGOTREF(r)
#define __Pyx_XGIVEREF(r)
#endif
#define __Pyx_XDECREF_SET(r, v) do {\
PyObject *tmp = (PyObject *) r;\
r = v; __Pyx_XDECREF(tmp);\
} while (0)
#define __Pyx_DECREF_SET(r, v) do {\
PyObject *tmp = (PyObject *) r;\
r = v; __Pyx_DECREF(tmp);\
} while (0)
#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)
/* PyObjectGetAttrStr.proto */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name);
#else
#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
#endif
/* GetBuiltinName.proto */
static PyObject *__Pyx_GetBuiltinName(PyObject *name);
/* RaiseArgTupleInvalid.proto */
static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found);
/* RaiseDoubleKeywords.proto */
static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);
/* ParseKeywords.proto */
static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\
PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\
const char* function_name);
/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_EqObjC(op1, op2, intval, inplace)\
PyObject_RichCompare(op1, op2, Py_EQ)
#endif
/* PyObjectSetAttrStr.proto */
#if CYTHON_USE_TYPE_SLOTS
#define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o, n, NULL)
static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value);
#else
#define __Pyx_PyObject_DelAttrStr(o,n) PyObject_DelAttr(o,n)
#define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v)
#endif
/* GetModuleGlobalName.proto */
static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name);
/* PyCFunctionFastCall.proto */
#if CYTHON_FAST_PYCCALL
static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs);
#else
#define __Pyx_PyCFunction_FastCall(func, args, nargs) (assert(0), NULL)
#endif
/* PyFunctionFastCall.proto */
#if CYTHON_FAST_PYCALL
#define __Pyx_PyFunction_FastCall(func, args, nargs)\
__Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL)
#if 1 || PY_VERSION_HEX < 0x030600B1
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs);
#else
#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs)
#endif
#endif
/* PyObjectCall.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw);
#else
#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
#endif
/* PyObjectCallMethO.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
#endif
/* PyObjectCallOneArg.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);
/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_RemainderObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_RemainderObjC(op1, op2, intval, inplace)\
(inplace ? PyNumber_InPlaceRemainder(op1, op2) : PyNumber_Remainder(op1, op2))
#endif
/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_FloorDivideObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_FloorDivideObjC(op1, op2, intval, inplace)\
(inplace ? PyNumber_InPlaceFloorDivide(op1, op2) : PyNumber_FloorDivide(op1, op2))
#endif
/* GetItemInt.proto */
#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
(__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
__Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\
(is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\
__Pyx_GetItemInt_Generic(o, to_py_func(i))))
#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
(__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
__Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
(PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
int wraparound, int boundscheck);
#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
(__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
__Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
(PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
int wraparound, int boundscheck);
static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j);
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
int is_list, int wraparound, int boundscheck);
/* ObjectGetItem.proto */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key);
#else
#define __Pyx_PyObject_GetItem(obj, key) PyObject_GetItem(obj, key)
#endif
/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_SubtractObjC(op1, op2, intval, inplace)\
(inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2))
#endif
/* ListCompAppend.proto */
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) {
PyListObject* L = (PyListObject*) list;
Py_ssize_t len = Py_SIZE(list);
if (likely(L->allocated > len)) {
Py_INCREF(x);
PyList_SET_ITEM(list, len, x);
Py_SIZE(list) = len+1;
return 0;
}
return PyList_Append(list, x);
}
#else
#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x)
#endif
/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace)\
(inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
#endif
/* SliceTupleAndList.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyList_GetSlice(PyObject* src, Py_ssize_t start, Py_ssize_t stop);
static CYTHON_INLINE PyObject* __Pyx_PyTuple_GetSlice(PyObject* src, Py_ssize_t start, Py_ssize_t stop);
#else
#define __Pyx_PyList_GetSlice(seq, start, stop) PySequence_GetSlice(seq, start, stop)
#define __Pyx_PyTuple_GetSlice(seq, start, stop) PySequence_GetSlice(seq, start, stop)
#endif
/* RaiseTooManyValuesToUnpack.proto */
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);
/* RaiseNeedMoreValuesToUnpack.proto */
static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);
/* IterFinish.proto */
static CYTHON_INLINE int __Pyx_IterFinish(void);
/* UnpackItemEndCheck.proto */
static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected);
/* PyObjectCallNoArg.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func);
#else
#define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL)
#endif
/* PyObjectCallMethod0.proto */
static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name);
/* pop.proto */
static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L);
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
static CYTHON_INLINE PyObject* __Pyx_PyList_Pop(PyObject* L);
#define __Pyx_PyObject_Pop(L) (likely(PyList_CheckExact(L)) ?\
__Pyx_PyList_Pop(L) : __Pyx__PyObject_Pop(L))
#else
#define __Pyx_PyList_Pop(L) __Pyx__PyObject_Pop(L)
#define __Pyx_PyObject_Pop(L) __Pyx__PyObject_Pop(L)
#endif
/* UnpackUnboundCMethod.proto */
typedef struct {
PyObject *type;
PyObject **method_name;
PyCFunction func;
PyObject *method;
int flag;
} __Pyx_CachedCFunction;
/* CallUnboundCMethod0.proto */
static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self);
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_CallUnboundCMethod0(cfunc, self)\
(likely((cfunc)->func) ?\
(likely((cfunc)->flag == METH_NOARGS) ? (*((cfunc)->func))(self, NULL) :\
(PY_VERSION_HEX >= 0x030600B1 && likely((cfunc)->flag == METH_FASTCALL) ?\
(PY_VERSION_HEX >= 0x030700A0 ?\
(*(__Pyx_PyCFunctionFast)(cfunc)->func)(self, &__pyx_empty_tuple, 0) :\
(*(__Pyx_PyCFunctionFastWithKeywords)(cfunc)->func)(self, &__pyx_empty_tuple, 0, NULL)) :\
(PY_VERSION_HEX >= 0x030700A0 && (cfunc)->flag == (METH_FASTCALL | METH_KEYWORDS) ?\
(*(__Pyx_PyCFunctionFastWithKeywords)(cfunc)->func)(self, &__pyx_empty_tuple, 0, NULL) :\
(likely((cfunc)->flag == (METH_VARARGS | METH_KEYWORDS)) ? ((*(PyCFunctionWithKeywords)(cfunc)->func)(self, __pyx_empty_tuple, NULL)) :\
((cfunc)->flag == METH_VARARGS ? (*((cfunc)->func))(self, __pyx_empty_tuple) :\
__Pyx__CallUnboundCMethod0(cfunc, self)))))) :\
__Pyx__CallUnboundCMethod0(cfunc, self))
#else
#define __Pyx_CallUnboundCMethod0(cfunc, self) __Pyx__CallUnboundCMethod0(cfunc, self)
#endif
/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AndObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_AndObjC(op1, op2, intval, inplace)\
(inplace ? PyNumber_InPlaceAnd(op1, op2) : PyNumber_And(op1, op2))
#endif
/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_RshiftObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_RshiftObjC(op1, op2, intval, inplace)\
(inplace ? PyNumber_InPlaceRshift(op1, op2) : PyNumber_Rshift(op1, op2))
#endif
/* Import.proto */
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);
/* CalculateMetaclass.proto */
static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases);
/* FetchCommonType.proto */
static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type);
/* CythonFunction.proto */
#define __Pyx_CyFunction_USED 1
#define __Pyx_CYFUNCTION_STATICMETHOD 0x01
#define __Pyx_CYFUNCTION_CLASSMETHOD 0x02
#define __Pyx_CYFUNCTION_CCLASS 0x04
#define __Pyx_CyFunction_GetClosure(f)\
(((__pyx_CyFunctionObject *) (f))->func_closure)
#define __Pyx_CyFunction_GetClassObj(f)\
(((__pyx_CyFunctionObject *) (f))->func_classobj)
#define __Pyx_CyFunction_Defaults(type, f)\
((type *)(((__pyx_CyFunctionObject *) (f))->defaults))
#define __Pyx_CyFunction_SetDefaultsGetter(f, g)\
((__pyx_CyFunctionObject *) (f))->defaults_getter = (g)
typedef struct {
PyCFunctionObject func;
#if PY_VERSION_HEX < 0x030500A0
PyObject *func_weakreflist;
#endif
PyObject *func_dict;
PyObject *func_name;
PyObject *func_qualname;
PyObject *func_doc;
PyObject *func_globals;
PyObject *func_code;
PyObject *func_closure;
PyObject *func_classobj;
void *defaults;
int defaults_pyobjects;
int flags;
PyObject *defaults_tuple;
PyObject *defaults_kwdict;
PyObject *(*defaults_getter)(PyObject *);
PyObject *func_annotations;
} __pyx_CyFunctionObject;
static PyTypeObject *__pyx_CyFunctionType = 0;
#define __Pyx_CyFunction_NewEx(ml, flags, qualname, self, module, globals, code)\
__Pyx_CyFunction_New(__pyx_CyFunctionType, ml, flags, qualname, self, module, globals, code)
static PyObject *__Pyx_CyFunction_New(PyTypeObject *, PyMethodDef *ml,
int flags, PyObject* qualname,
PyObject *self,
PyObject *module, PyObject *globals,
PyObject* code);
static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *m,
size_t size,
int pyobjects);
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *m,
PyObject *tuple);
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *m,
PyObject *dict);
static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *m,
PyObject *dict);
static int __pyx_CyFunction_init(void);
/* SetNameInClass.proto */
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1
#define __Pyx_SetNameInClass(ns, name, value)\
(likely(PyDict_CheckExact(ns)) ? _PyDict_SetItem_KnownHash(ns, name, value, ((PyASCIIObject *) name)->hash) : PyObject_SetItem(ns, name, value))
#elif CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_SetNameInClass(ns, name, value)\
(likely(PyDict_CheckExact(ns)) ? PyDict_SetItem(ns, name, value) : PyObject_SetItem(ns, name, value))
#else
#define __Pyx_SetNameInClass(ns, name, value) PyObject_SetItem(ns, name, value)
#endif
/* ClassMethod.proto */
#include "descrobject.h"
static PyObject* __Pyx_Method_ClassMethod(PyObject *method);
/* Py3ClassCreate.proto */
static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name, PyObject *qualname,
PyObject *mkw, PyObject *modname, PyObject *doc);
static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases, PyObject *dict,
PyObject *mkw, int calculate_metaclass, int allow_py2_metaclass);
/* PyThreadStateGet.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate;
#define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current;
#define __Pyx_PyErr_Occurred() __pyx_tstate->curexc_type
#else
#define __Pyx_PyThreadState_declare
#define __Pyx_PyThreadState_assign
#define __Pyx_PyErr_Occurred() PyErr_Occurred()
#endif
/* PyErrFetchRestore.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL)
#define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
#define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL))
#else
#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
#endif
#else
#define __Pyx_PyErr_Clear() PyErr_Clear()
#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
#define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb)
#define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb)
#define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb)
#endif
/* CLineInTraceback.proto */
#ifdef CYTHON_CLINE_IN_TRACEBACK
#define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0)
#else
static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line);
#endif
/* CodeObjectCache.proto */
typedef struct {
PyCodeObject* code_object;
int code_line;
} __Pyx_CodeObjectCacheEntry;
struct __Pyx_CodeObjectCache {
int count;
int max_count;
__Pyx_CodeObjectCacheEntry* entries;
};
static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
static PyCodeObject *__pyx_find_code_object(int code_line);
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
/* AddTraceback.proto */
static void __Pyx_AddTraceback(const char *funcname, int c_line,
int py_line, const char *filename);
/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);
/* CIntFromPy.proto */
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);
/* CIntFromPy.proto */
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);
/* FastTypeChecks.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type)
static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b);
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type);
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2);
#else
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type)
#define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2))
#endif
#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)
/* CheckBinaryVersion.proto */
static int __Pyx_check_binary_version(void);
/* InitStrings.proto */
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);
/* Module declarations from 'optimized_field_elements' */
#define __Pyx_MODULE_NAME "optimized_field_elements"
extern int __pyx_module_is_main_optimized_field_elements;
int __pyx_module_is_main_optimized_field_elements = 0;
/* Implementation of 'optimized_field_elements' */
static PyObject *__pyx_builtin_enumerate;
static PyObject *__pyx_builtin_object;
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_builtin_zip;
static const char __pyx_k_a[] = "a";
static const char __pyx_k_b[] = "b";
static const char __pyx_k_c[] = "c";
static const char __pyx_k_d[] = "d";
static const char __pyx_k_i[] = "i";
static const char __pyx_k_j[] = "j";
static const char __pyx_k_n[] = "n";
static const char __pyx_k_o[] = "o";
static const char __pyx_k_p[] = "p";
static const char __pyx_k_r[] = "r";
static const char __pyx_k_t[] = "t";
static const char __pyx_k_x[] = "x";
static const char __pyx_k_y[] = "y";
static const char __pyx_k_FQ[] = "FQ";
static const char __pyx_k_c1[] = "c1";
static const char __pyx_k_c2[] = "c2";
static const char __pyx_k_eq[] = "__eq__";
static const char __pyx_k_hm[] = "hm";
static const char __pyx_k_lm[] = "lm";
static const char __pyx_k_ne[] = "__ne__";
static const char __pyx_k_nm[] = "nm";
static const char __pyx_k_on[] = "on";
static const char __pyx_k_FQ2[] = "FQ2";
static const char __pyx_k_FQP[] = "FQP";
static const char __pyx_k_add[] = "__add__";
static const char __pyx_k_cls[] = "cls";
static const char __pyx_k_deg[] = "deg";
static const char __pyx_k_div[] = "__div__";
static const char __pyx_k_doc[] = "__doc__";
static const char __pyx_k_eli[] = "eli";
static const char __pyx_k_elj[] = "elj";
static const char __pyx_k_exp[] = "exp";
static const char __pyx_k_inv[] = "inv";
static const char __pyx_k_low[] = "low";
static const char __pyx_k_mul[] = "__mul__";
static const char __pyx_k_neg[] = "__neg__";
static const char __pyx_k_new[] = "new";
static const char __pyx_k_one[] = "one";
static const char __pyx_k_pop[] = "pop";
static const char __pyx_k_pow[] = "__pow__";
static const char __pyx_k_sub[] = "__sub__";
static const char __pyx_k_sys[] = "sys";
static const char __pyx_k_top[] = "top";
static const char __pyx_k_zip[] = "zip";
static const char __pyx_k_FQ12[] = "FQ12";
static const char __pyx_k_dega[] = "dega";
static const char __pyx_k_degb[] = "degb";
static const char __pyx_k_high[] = "high";
static const char __pyx_k_init[] = "__init__";
static const char __pyx_k_main[] = "__main__";
static const char __pyx_k_radd[] = "__radd__";
static const char __pyx_k_rdiv[] = "__rdiv__";
static const char __pyx_k_repr[] = "__repr__";
static const char __pyx_k_rmul[] = "__rmul__";
static const char __pyx_k_rsub[] = "__rsub__";
static const char __pyx_k_self[] = "self";
static const char __pyx_k_temp[] = "temp";
static const char __pyx_k_test[] = "__test__";
static const char __pyx_k_zero[] = "zero";
static const char __pyx_k_class[] = "__class__";
static const char __pyx_k_major[] = "major";
static const char __pyx_k_other[] = "other";
static const char __pyx_k_range[] = "range";
static const char __pyx_k_FQ_one[] = "FQ.one";
static const char __pyx_k_coeffs[] = "coeffs";
static const char __pyx_k_degree[] = "degree";
static const char __pyx_k_import[] = "__import__";
static const char __pyx_k_module[] = "__module__";
static const char __pyx_k_object[] = "object";
static const char __pyx_k_FQP_inv[] = "FQP.inv";
static const char __pyx_k_FQP_one[] = "FQP.one";
static const char __pyx_k_FQ___eq[] = "FQ.__eq__";
static const char __pyx_k_FQ___ne[] = "FQ.__ne__";
static const char __pyx_k_FQ_zero[] = "FQ.zero";
static const char __pyx_k_prepare[] = "__prepare__";
static const char __pyx_k_truediv[] = "__truediv__";
static const char __pyx_k_FQP___eq[] = "FQP.__eq__";
static const char __pyx_k_FQP___ne[] = "FQP.__ne__";
static const char __pyx_k_FQP_zero[] = "FQP.zero";
static const char __pyx_k_FQ___add[] = "FQ.__add__";
static const char __pyx_k_FQ___div[] = "FQ.__div__";
static const char __pyx_k_FQ___mul[] = "FQ.__mul__";
static const char __pyx_k_FQ___neg[] = "FQ.__neg__";
static const char __pyx_k_FQ___pow[] = "FQ.__pow__";
static const char __pyx_k_FQ___sub[] = "FQ.__sub__";
static const char __pyx_k_qualname[] = "__qualname__";
static const char __pyx_k_rtruediv[] = "__rtruediv__";
static const char __pyx_k_FQP___add[] = "FQP.__add__";
static const char __pyx_k_FQP___div[] = "FQP.__div__";
static const char __pyx_k_FQP___mul[] = "FQP.__mul__";
static const char __pyx_k_FQP___neg[] = "FQP.__neg__";
static const char __pyx_k_FQP___pow[] = "FQP.__pow__";
static const char __pyx_k_FQP___sub[] = "FQP.__sub__";
static const char __pyx_k_FQ___init[] = "FQ.__init__";
static const char __pyx_k_FQ___radd[] = "FQ.__radd__";
static const char __pyx_k_FQ___rdiv[] = "FQ.__rdiv__";
static const char __pyx_k_FQ___repr[] = "FQ.__repr__";
static const char __pyx_k_FQ___rmul[] = "FQ.__rmul__";
static const char __pyx_k_FQ___rsub[] = "FQ.__rsub__";
static const char __pyx_k_enumerate[] = "enumerate";
static const char __pyx_k_int_types[] = "int_types";
static const char __pyx_k_mc_tuples[] = "mc_tuples";
static const char __pyx_k_metaclass[] = "__metaclass__";
static const char __pyx_k_FQ2___init[] = "FQ2.__init__";
static const char __pyx_k_FQP___init[] = "FQP.__init__";
static const char __pyx_k_FQP___repr[] = "FQP.__repr__";
static const char __pyx_k_FQP___rmul[] = "FQP.__rmul__";
static const char __pyx_k_FQ12___init[] = "FQ12.__init__";
static const char __pyx_k_FQ___truediv[] = "FQ.__truediv__";
static const char __pyx_k_version_info[] = "version_info";
static const char __pyx_k_FQP___truediv[] = "FQP.__truediv__";
static const char __pyx_k_FQ___rtruediv[] = "FQ.__rtruediv__";
static const char __pyx_k_field_modulus[] = "field_modulus";
static const char __pyx_k_FQ12_mc_tuples[] = "FQ12_mc_tuples";
static const char __pyx_k_modulus_coeffs[] = "modulus_coeffs";
static const char __pyx_k_inner_enumerate[] = "inner_enumerate";
static const char __pyx_k_prime_field_inv[] = "prime_field_inv";
static const char __pyx_k_poly_rounded_div[] = "poly_rounded_div";
static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
static const char __pyx_k_FQ12_modulus_coeffs[] = "FQ12_modulus_coeffs";
static const char __pyx_k_optimized_field_elements[] = "optimized_field_elements";
static const char __pyx_k_py_ecc_cython_src_optimized_fiel[] = "py_ecc/cython_src/optimized_field_elements.pyx";
static PyObject *__pyx_n_s_FQ;
static PyObject *__pyx_n_s_FQ12;
static PyObject *__pyx_n_s_FQ12___init;
static PyObject *__pyx_n_s_FQ12_mc_tuples;
static PyObject *__pyx_n_s_FQ12_modulus_coeffs;
static PyObject *__pyx_n_s_FQ2;
static PyObject *__pyx_n_s_FQ2___init;
static PyObject *__pyx_n_s_FQP;
static PyObject *__pyx_n_s_FQP___add;
static PyObject *__pyx_n_s_FQP___div;
static PyObject *__pyx_n_s_FQP___eq;
static PyObject *__pyx_n_s_FQP___init;
static PyObject *__pyx_n_s_FQP___mul;
static PyObject *__pyx_n_s_FQP___ne;
static PyObject *__pyx_n_s_FQP___neg;
static PyObject *__pyx_n_s_FQP___pow;
static PyObject *__pyx_n_s_FQP___repr;
static PyObject *__pyx_n_s_FQP___rmul;
static PyObject *__pyx_n_s_FQP___sub;
static PyObject *__pyx_n_s_FQP___truediv;
static PyObject *__pyx_n_s_FQP_inv;
static PyObject *__pyx_n_s_FQP_one;
static PyObject *__pyx_n_s_FQP_zero;
static PyObject *__pyx_n_s_FQ___add;
static PyObject *__pyx_n_s_FQ___div;
static PyObject *__pyx_n_s_FQ___eq;
static PyObject *__pyx_n_s_FQ___init;
static PyObject *__pyx_n_s_FQ___mul;
static PyObject *__pyx_n_s_FQ___ne;
static PyObject *__pyx_n_s_FQ___neg;
static PyObject *__pyx_n_s_FQ___pow;
static PyObject *__pyx_n_s_FQ___radd;
static PyObject *__pyx_n_s_FQ___rdiv;
static PyObject *__pyx_n_s_FQ___repr;
static PyObject *__pyx_n_s_FQ___rmul;
static PyObject *__pyx_n_s_FQ___rsub;
static PyObject *__pyx_n_s_FQ___rtruediv;
static PyObject *__pyx_n_s_FQ___sub;
static PyObject *__pyx_n_s_FQ___truediv;
static PyObject *__pyx_n_s_FQ_one;
static PyObject *__pyx_n_s_FQ_zero;
static PyObject *__pyx_n_s_a;
static PyObject *__pyx_n_s_add;
static PyObject *__pyx_n_s_b;
static PyObject *__pyx_n_s_c;
static PyObject *__pyx_n_s_c1;
static PyObject *__pyx_n_s_c2;
static PyObject *__pyx_n_s_class;
static PyObject *__pyx_n_s_cline_in_traceback;
static PyObject *__pyx_n_s_cls;
static PyObject *__pyx_n_s_coeffs;
static PyObject *__pyx_n_s_d;
static PyObject *__pyx_n_s_deg;
static PyObject *__pyx_n_s_dega;
static PyObject *__pyx_n_s_degb;
static PyObject *__pyx_n_s_degree;
static PyObject *__pyx_n_s_div;
static PyObject *__pyx_n_s_doc;
static PyObject *__pyx_n_s_eli;
static PyObject *__pyx_n_s_elj;
static PyObject *__pyx_n_s_enumerate;
static PyObject *__pyx_n_s_eq;
static PyObject *__pyx_n_s_exp;
static PyObject *__pyx_n_s_field_modulus;
static PyObject *__pyx_n_s_high;
static PyObject *__pyx_n_s_hm;
static PyObject *__pyx_n_s_i;
static PyObject *__pyx_n_s_import;
static PyObject *__pyx_n_s_init;
static PyObject *__pyx_n_s_inner_enumerate;
static PyObject *__pyx_n_s_int_types;
static PyObject *__pyx_n_s_inv;
static PyObject *__pyx_n_s_j;
static PyObject *__pyx_n_s_lm;
static PyObject *__pyx_n_s_low;
static PyObject *__pyx_n_s_main;
static PyObject *__pyx_n_s_major;
static PyObject *__pyx_n_s_mc_tuples;
static PyObject *__pyx_n_s_metaclass;
static PyObject *__pyx_n_s_module;
static PyObject *__pyx_n_s_modulus_coeffs;
static PyObject *__pyx_n_s_mul;
static PyObject *__pyx_n_s_n;
static PyObject *__pyx_n_s_ne;
static PyObject *__pyx_n_s_neg;
static PyObject *__pyx_n_s_new;
static PyObject *__pyx_n_s_nm;
static PyObject *__pyx_n_s_o;
static PyObject *__pyx_n_s_object;
static PyObject *__pyx_n_s_on;
static PyObject *__pyx_n_s_one;
static PyObject *__pyx_n_s_optimized_field_elements;
static PyObject *__pyx_n_s_other;
static PyObject *__pyx_n_s_p;
static PyObject *__pyx_n_s_poly_rounded_div;
static PyObject *__pyx_n_s_pop;
static PyObject *__pyx_n_s_pow;
static PyObject *__pyx_n_s_prepare;
static PyObject *__pyx_n_s_prime_field_inv;
static PyObject *__pyx_kp_s_py_ecc_cython_src_optimized_fiel;
static PyObject *__pyx_n_s_qualname;
static PyObject *__pyx_n_s_r;
static PyObject *__pyx_n_s_radd;
static PyObject *__pyx_n_s_range;
static PyObject *__pyx_n_s_rdiv;
static PyObject *__pyx_n_s_repr;
static PyObject *__pyx_n_s_rmul;
static PyObject *__pyx_n_s_rsub;
static PyObject *__pyx_n_s_rtruediv;
static PyObject *__pyx_n_s_self;
static PyObject *__pyx_n_s_sub;
static PyObject *__pyx_n_s_sys;
static PyObject *__pyx_n_s_t;
static PyObject *__pyx_n_s_temp;
static PyObject *__pyx_n_s_test;
static PyObject *__pyx_n_s_top;
static PyObject *__pyx_n_s_truediv;
static PyObject *__pyx_n_s_version_info;
static PyObject *__pyx_n_s_x;
static PyObject *__pyx_n_s_y;
static PyObject *__pyx_n_s_zero;
static PyObject *__pyx_n_s_zip;
static PyObject *__pyx_pf_24optimized_field_elements_prime_field_inv(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_a, PyObject *__pyx_v_n); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_2FQ___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_n); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_2__add__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_4__mul__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_6__rmul__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_8__radd__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_10__rsub__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_12__sub__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_14__div__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_16__truediv__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_18__rdiv__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_20__rtruediv__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_22__pow__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_24__eq__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_26__ne__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_28__neg__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_30__repr__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_32one(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_cls); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_34zero(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_cls); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_2deg(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_p); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_4poly_rounded_div(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_a, PyObject *__pyx_v_b); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_3FQP___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_coeffs, PyObject *__pyx_v_modulus_coeffs); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_2__add__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_4__sub__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_6__mul__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_8__rmul__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_10__div__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_12__truediv__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_14__pow__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_16inv(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_18__repr__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_20__eq__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_22__ne__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_24__neg__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_26one(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_cls); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_28zero(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_cls); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_3FQ2___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_coeffs); /* proto */
static PyObject *__pyx_pf_24optimized_field_elements_4FQ12___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_coeffs); /* proto */
static __Pyx_CachedCFunction __pyx_umethod_PyList_Type_pop = {0, &__pyx_n_s_pop, 0, 0, 0};
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_2;
static PyObject *__pyx_int_12;
static PyObject *__pyx_int_82;
static PyObject *__pyx_int_21888242871839275222246405745257275088696311157297823662689037894645226208583;
static PyObject *__pyx_int_neg_1;
static PyObject *__pyx_int_neg_18;
static PyObject *__pyx_tuple_;
static PyObject *__pyx_tuple__2;
static PyObject *__pyx_tuple__3;
static PyObject *__pyx_tuple__4;
static PyObject *__pyx_tuple__5;
static PyObject *__pyx_tuple__7;
static PyObject *__pyx_tuple__8;
static PyObject *__pyx_tuple__10;
static PyObject *__pyx_tuple__12;
static PyObject *__pyx_tuple__14;
static PyObject *__pyx_tuple__16;
static PyObject *__pyx_tuple__18;
static PyObject *__pyx_tuple__20;
static PyObject *__pyx_tuple__22;
static PyObject *__pyx_tuple__24;
static PyObject *__pyx_tuple__26;
static PyObject *__pyx_tuple__28;
static PyObject *__pyx_tuple__30;
static PyObject *__pyx_tuple__32;
static PyObject *__pyx_tuple__34;
static PyObject *__pyx_tuple__36;
static PyObject *__pyx_tuple__38;
static PyObject *__pyx_tuple__40;
static PyObject *__pyx_tuple__42;
static PyObject *__pyx_tuple__44;
static PyObject *__pyx_tuple__46;
static PyObject *__pyx_tuple__48;
static PyObject *__pyx_tuple__49;
static PyObject *__pyx_tuple__51;
static PyObject *__pyx_tuple__53;
static PyObject *__pyx_tuple__55;
static PyObject *__pyx_tuple__57;
static PyObject *__pyx_tuple__59;
static PyObject *__pyx_tuple__61;
static PyObject *__pyx_tuple__63;
static PyObject *__pyx_tuple__65;
static PyObject *__pyx_tuple__67;
static PyObject *__pyx_tuple__69;
static PyObject *__pyx_tuple__71;
static PyObject *__pyx_tuple__73;
static PyObject *__pyx_tuple__75;
static PyObject *__pyx_tuple__77;
static PyObject *__pyx_tuple__79;
static PyObject *__pyx_tuple__81;
static PyObject *__pyx_codeobj__6;
static PyObject *__pyx_codeobj__9;
static PyObject *__pyx_codeobj__11;
static PyObject *__pyx_codeobj__13;
static PyObject *__pyx_codeobj__15;
static PyObject *__pyx_codeobj__17;
static PyObject *__pyx_codeobj__19;
static PyObject *__pyx_codeobj__21;
static PyObject *__pyx_codeobj__23;
static PyObject *__pyx_codeobj__25;
static PyObject *__pyx_codeobj__27;
static PyObject *__pyx_codeobj__29;
static PyObject *__pyx_codeobj__31;
static PyObject *__pyx_codeobj__33;
static PyObject *__pyx_codeobj__35;
static PyObject *__pyx_codeobj__37;
static PyObject *__pyx_codeobj__39;
static PyObject *__pyx_codeobj__41;
static PyObject *__pyx_codeobj__43;
static PyObject *__pyx_codeobj__45;
static PyObject *__pyx_codeobj__47;
static PyObject *__pyx_codeobj__50;
static PyObject *__pyx_codeobj__52;
static PyObject *__pyx_codeobj__54;
static PyObject *__pyx_codeobj__56;
static PyObject *__pyx_codeobj__58;
static PyObject *__pyx_codeobj__60;
static PyObject *__pyx_codeobj__62;
static PyObject *__pyx_codeobj__64;
static PyObject *__pyx_codeobj__66;
static PyObject *__pyx_codeobj__68;
static PyObject *__pyx_codeobj__70;
static PyObject *__pyx_codeobj__72;
static PyObject *__pyx_codeobj__74;
static PyObject *__pyx_codeobj__76;
static PyObject *__pyx_codeobj__78;
static PyObject *__pyx_codeobj__80;
static PyObject *__pyx_codeobj__82;
/* Late includes */
/* "optimized_field_elements.pyx":19
* # Extended euclidean algorithm to find modular inverses for
* # integers
* def prime_field_inv(a, n): # <<<<<<<<<<<<<<
* if a == 0:
* return 0
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_1prime_field_inv(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_1prime_field_inv = {"prime_field_inv", (PyCFunction)__pyx_pw_24optimized_field_elements_1prime_field_inv, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_1prime_field_inv(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_a = 0;
PyObject *__pyx_v_n = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("prime_field_inv (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_a,&__pyx_n_s_n,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_a)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("prime_field_inv", 1, 2, 2, 1); __PYX_ERR(0, 19, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "prime_field_inv") < 0)) __PYX_ERR(0, 19, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_a = values[0];
__pyx_v_n = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("prime_field_inv", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 19, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.prime_field_inv", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_prime_field_inv(__pyx_self, __pyx_v_a, __pyx_v_n);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_prime_field_inv(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_a, PyObject *__pyx_v_n) {
PyObject *__pyx_v_lm = NULL;
PyObject *__pyx_v_hm = NULL;
PyObject *__pyx_v_low = NULL;
PyObject *__pyx_v_high = NULL;
PyObject *__pyx_v_r = NULL;
PyObject *__pyx_v_nm = NULL;
PyObject *__pyx_v_new = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
int __pyx_t_2;
PyObject *__pyx_t_3 = NULL;
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
__Pyx_RefNannySetupContext("prime_field_inv", 0);
/* "optimized_field_elements.pyx":20
* # integers
* def prime_field_inv(a, n):
* if a == 0: # <<<<<<<<<<<<<<
* return 0
* lm, hm = 1, 0
*/
__pyx_t_1 = __Pyx_PyInt_EqObjC(__pyx_v_a, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 20, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 20, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (__pyx_t_2) {
/* "optimized_field_elements.pyx":21
* def prime_field_inv(a, n):
* if a == 0:
* return 0 # <<<<<<<<<<<<<<
* lm, hm = 1, 0
* low, high = a % n, n
*/
__Pyx_XDECREF(__pyx_r);
__Pyx_INCREF(__pyx_int_0);
__pyx_r = __pyx_int_0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":20
* # integers
* def prime_field_inv(a, n):
* if a == 0: # <<<<<<<<<<<<<<
* return 0
* lm, hm = 1, 0
*/
}
/* "optimized_field_elements.pyx":22
* if a == 0:
* return 0
* lm, hm = 1, 0 # <<<<<<<<<<<<<<
* low, high = a % n, n
* while low > 1:
*/
__pyx_t_1 = __pyx_int_1;
__Pyx_INCREF(__pyx_t_1);
__pyx_t_3 = __pyx_int_0;
__Pyx_INCREF(__pyx_t_3);
__pyx_v_lm = __pyx_t_1;
__pyx_t_1 = 0;
__pyx_v_hm = __pyx_t_3;
__pyx_t_3 = 0;
/* "optimized_field_elements.pyx":23
* return 0
* lm, hm = 1, 0
* low, high = a % n, n # <<<<<<<<<<<<<<
* while low > 1:
* r = high // low
*/
__pyx_t_3 = PyNumber_Remainder(__pyx_v_a, __pyx_v_n); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 23, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_1 = __pyx_v_n;
__Pyx_INCREF(__pyx_t_1);
__pyx_v_low = __pyx_t_3;
__pyx_t_3 = 0;
__pyx_v_high = __pyx_t_1;
__pyx_t_1 = 0;
/* "optimized_field_elements.pyx":24
* lm, hm = 1, 0
* low, high = a % n, n
* while low > 1: # <<<<<<<<<<<<<<
* r = high // low
* nm, new = hm - lm * r, high - low * r
*/
while (1) {
__pyx_t_1 = PyObject_RichCompare(__pyx_v_low, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 24, __pyx_L1_error)
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 24, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (!__pyx_t_2) break;
/* "optimized_field_elements.pyx":25
* low, high = a % n, n
* while low > 1:
* r = high // low # <<<<<<<<<<<<<<
* nm, new = hm - lm * r, high - low * r
* lm, low, hm, high = nm, new, lm, low
*/
__pyx_t_1 = PyNumber_FloorDivide(__pyx_v_high, __pyx_v_low); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 25, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_XDECREF_SET(__pyx_v_r, __pyx_t_1);
__pyx_t_1 = 0;
/* "optimized_field_elements.pyx":26
* while low > 1:
* r = high // low
* nm, new = hm - lm * r, high - low * r # <<<<<<<<<<<<<<
* lm, low, hm, high = nm, new, lm, low
* return lm % n
*/
__pyx_t_1 = PyNumber_Multiply(__pyx_v_lm, __pyx_v_r); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 26, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_3 = PyNumber_Subtract(__pyx_v_hm, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 26, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_1 = PyNumber_Multiply(__pyx_v_low, __pyx_v_r); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 26, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_4 = PyNumber_Subtract(__pyx_v_high, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 26, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_XDECREF_SET(__pyx_v_nm, __pyx_t_3);
__pyx_t_3 = 0;
__Pyx_XDECREF_SET(__pyx_v_new, __pyx_t_4);
__pyx_t_4 = 0;
/* "optimized_field_elements.pyx":27
* r = high // low
* nm, new = hm - lm * r, high - low * r
* lm, low, hm, high = nm, new, lm, low # <<<<<<<<<<<<<<
* return lm % n
*
*/
__pyx_t_4 = __pyx_v_nm;
__Pyx_INCREF(__pyx_t_4);
__pyx_t_3 = __pyx_v_new;
__Pyx_INCREF(__pyx_t_3);
__pyx_t_1 = __pyx_v_lm;
__Pyx_INCREF(__pyx_t_1);
__pyx_t_5 = __pyx_v_low;
__Pyx_INCREF(__pyx_t_5);
__Pyx_DECREF_SET(__pyx_v_lm, __pyx_t_4);
__pyx_t_4 = 0;
__Pyx_DECREF_SET(__pyx_v_low, __pyx_t_3);
__pyx_t_3 = 0;
__Pyx_DECREF_SET(__pyx_v_hm, __pyx_t_1);
__pyx_t_1 = 0;
__Pyx_DECREF_SET(__pyx_v_high, __pyx_t_5);
__pyx_t_5 = 0;
}
/* "optimized_field_elements.pyx":28
* nm, new = hm - lm * r, high - low * r
* lm, low, hm, high = nm, new, lm, low
* return lm % n # <<<<<<<<<<<<<<
*
*
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_5 = PyNumber_Remainder(__pyx_v_lm, __pyx_v_n); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 28, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_r = __pyx_t_5;
__pyx_t_5 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":19
* # Extended euclidean algorithm to find modular inverses for
* # integers
* def prime_field_inv(a, n): # <<<<<<<<<<<<<<
* if a == 0:
* return 0
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_AddTraceback("optimized_field_elements.prime_field_inv", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_lm);
__Pyx_XDECREF(__pyx_v_hm);
__Pyx_XDECREF(__pyx_v_low);
__Pyx_XDECREF(__pyx_v_high);
__Pyx_XDECREF(__pyx_v_r);
__Pyx_XDECREF(__pyx_v_nm);
__Pyx_XDECREF(__pyx_v_new);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":34
* # and it becomes a field element.
* class FQ(object):
* def __init__(self, n): # <<<<<<<<<<<<<<
* if isinstance(n, self.__class__):
* self.n = n.n
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_2FQ_1__init__ = {"__init__", (PyCFunction)__pyx_pw_24optimized_field_elements_2FQ_1__init__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_n = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_n,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_n)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, 1); __PYX_ERR(0, 34, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 34, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_n = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 34, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQ.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_2FQ___init__(__pyx_self, __pyx_v_self, __pyx_v_n);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_2FQ___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_n) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
int __pyx_t_2;
int __pyx_t_3;
PyObject *__pyx_t_4 = NULL;
__Pyx_RefNannySetupContext("__init__", 0);
/* "optimized_field_elements.pyx":35
* class FQ(object):
* def __init__(self, n):
* if isinstance(n, self.__class__): # <<<<<<<<<<<<<<
* self.n = n.n
* else:
*/
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_class); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 35, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PyObject_IsInstance(__pyx_v_n, __pyx_t_1); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 35, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_3 = (__pyx_t_2 != 0);
if (__pyx_t_3) {
/* "optimized_field_elements.pyx":36
* def __init__(self, n):
* if isinstance(n, self.__class__):
* self.n = n.n # <<<<<<<<<<<<<<
* else:
* self.n = n % field_modulus
*/
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_n, __pyx_n_s_n); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 36, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_n, __pyx_t_1) < 0) __PYX_ERR(0, 36, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/* "optimized_field_elements.pyx":35
* class FQ(object):
* def __init__(self, n):
* if isinstance(n, self.__class__): # <<<<<<<<<<<<<<
* self.n = n.n
* else:
*/
goto __pyx_L3;
}
/* "optimized_field_elements.pyx":38
* self.n = n.n
* else:
* self.n = n % field_modulus # <<<<<<<<<<<<<<
* assert isinstance(self.n, int_types)
*
*/
/*else*/ {
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_field_modulus); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 38, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_4 = PyNumber_Remainder(__pyx_v_n, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 38, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_n, __pyx_t_4) < 0) __PYX_ERR(0, 38, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
}
__pyx_L3:;
/* "optimized_field_elements.pyx":39
* else:
* self.n = n % field_modulus
* assert isinstance(self.n, int_types) # <<<<<<<<<<<<<<
*
* def __add__(self, other):
*/
#ifndef CYTHON_WITHOUT_ASSERTIONS
if (unlikely(!Py_OptimizeFlag)) {
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_n); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 39, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_int_types); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 39, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_3 = PyObject_IsInstance(__pyx_t_4, __pyx_t_1); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 39, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (unlikely(!(__pyx_t_3 != 0))) {
PyErr_SetNone(PyExc_AssertionError);
__PYX_ERR(0, 39, __pyx_L1_error)
}
}
#endif
/* "optimized_field_elements.pyx":34
* # and it becomes a field element.
* class FQ(object):
* def __init__(self, n): # <<<<<<<<<<<<<<
* if isinstance(n, self.__class__):
* self.n = n.n
*/
/* function exit code */
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_AddTraceback("optimized_field_elements.FQ.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":41
* assert isinstance(self.n, int_types)
*
* def __add__(self, other): # <<<<<<<<<<<<<<
* on = other.n if isinstance(other, FQ) else other
* return FQ((self.n + on) % field_modulus)
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_3__add__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_2FQ_3__add__ = {"__add__", (PyCFunction)__pyx_pw_24optimized_field_elements_2FQ_3__add__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_3__add__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_other = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__add__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__add__", 1, 2, 2, 1); __PYX_ERR(0, 41, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__add__") < 0)) __PYX_ERR(0, 41, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_other = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__add__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 41, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQ.__add__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_2FQ_2__add__(__pyx_self, __pyx_v_self, __pyx_v_other);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_2__add__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
PyObject *__pyx_v_on = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
int __pyx_t_3;
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
PyObject *__pyx_t_6 = NULL;
__Pyx_RefNannySetupContext("__add__", 0);
/* "optimized_field_elements.pyx":42
*
* def __add__(self, other):
* on = other.n if isinstance(other, FQ) else other # <<<<<<<<<<<<<<
* return FQ((self.n + on) % field_modulus)
*
*/
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_FQ); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 42, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = PyObject_IsInstance(__pyx_v_other, __pyx_t_2); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 42, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if ((__pyx_t_3 != 0)) {
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_n); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 42, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_1 = __pyx_t_2;
__pyx_t_2 = 0;
} else {
__Pyx_INCREF(__pyx_v_other);
__pyx_t_1 = __pyx_v_other;
}
__pyx_v_on = __pyx_t_1;
__pyx_t_1 = 0;
/* "optimized_field_elements.pyx":43
* def __add__(self, other):
* on = other.n if isinstance(other, FQ) else other
* return FQ((self.n + on) % field_modulus) # <<<<<<<<<<<<<<
*
* def __mul__(self, other):
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_FQ); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 43, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_n); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 43, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_5 = PyNumber_Add(__pyx_t_4, __pyx_v_on); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 43, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_field_modulus); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 43, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_6 = PyNumber_Remainder(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 43, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = NULL;
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
if (likely(__pyx_t_4)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
__Pyx_INCREF(__pyx_t_4);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_2, function);
}
}
if (!__pyx_t_4) {
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_6};
__pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_6};
__pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
} else
#endif
{
__pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 43, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
__Pyx_GIVEREF(__pyx_t_6);
PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_6);
__pyx_t_6 = 0;
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
}
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":41
* assert isinstance(self.n, int_types)
*
* def __add__(self, other): # <<<<<<<<<<<<<<
* on = other.n if isinstance(other, FQ) else other
* return FQ((self.n + on) % field_modulus)
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_AddTraceback("optimized_field_elements.FQ.__add__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_on);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":45
* return FQ((self.n + on) % field_modulus)
*
* def __mul__(self, other): # <<<<<<<<<<<<<<
* on = other.n if isinstance(other, FQ) else other
* return FQ((self.n * on) % field_modulus)
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_5__mul__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_2FQ_5__mul__ = {"__mul__", (PyCFunction)__pyx_pw_24optimized_field_elements_2FQ_5__mul__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_5__mul__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_other = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__mul__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__mul__", 1, 2, 2, 1); __PYX_ERR(0, 45, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__mul__") < 0)) __PYX_ERR(0, 45, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_other = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__mul__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 45, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQ.__mul__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_2FQ_4__mul__(__pyx_self, __pyx_v_self, __pyx_v_other);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_4__mul__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
PyObject *__pyx_v_on = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
int __pyx_t_3;
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
PyObject *__pyx_t_6 = NULL;
__Pyx_RefNannySetupContext("__mul__", 0);
/* "optimized_field_elements.pyx":46
*
* def __mul__(self, other):
* on = other.n if isinstance(other, FQ) else other # <<<<<<<<<<<<<<
* return FQ((self.n * on) % field_modulus)
*
*/
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_FQ); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 46, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = PyObject_IsInstance(__pyx_v_other, __pyx_t_2); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 46, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if ((__pyx_t_3 != 0)) {
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_n); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 46, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_1 = __pyx_t_2;
__pyx_t_2 = 0;
} else {
__Pyx_INCREF(__pyx_v_other);
__pyx_t_1 = __pyx_v_other;
}
__pyx_v_on = __pyx_t_1;
__pyx_t_1 = 0;
/* "optimized_field_elements.pyx":47
* def __mul__(self, other):
* on = other.n if isinstance(other, FQ) else other
* return FQ((self.n * on) % field_modulus) # <<<<<<<<<<<<<<
*
* def __rmul__(self, other):
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_FQ); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 47, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_n); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 47, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_5 = PyNumber_Multiply(__pyx_t_4, __pyx_v_on); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 47, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_field_modulus); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 47, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_6 = PyNumber_Remainder(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 47, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = NULL;
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
if (likely(__pyx_t_4)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
__Pyx_INCREF(__pyx_t_4);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_2, function);
}
}
if (!__pyx_t_4) {
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 47, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_6};
__pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 47, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_6};
__pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 47, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
} else
#endif
{
__pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 47, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
__Pyx_GIVEREF(__pyx_t_6);
PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_6);
__pyx_t_6 = 0;
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 47, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
}
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":45
* return FQ((self.n + on) % field_modulus)
*
* def __mul__(self, other): # <<<<<<<<<<<<<<
* on = other.n if isinstance(other, FQ) else other
* return FQ((self.n * on) % field_modulus)
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_AddTraceback("optimized_field_elements.FQ.__mul__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_on);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":49
* return FQ((self.n * on) % field_modulus)
*
* def __rmul__(self, other): # <<<<<<<<<<<<<<
* return self * other
*
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_7__rmul__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_2FQ_7__rmul__ = {"__rmul__", (PyCFunction)__pyx_pw_24optimized_field_elements_2FQ_7__rmul__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_7__rmul__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_other = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__rmul__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__rmul__", 1, 2, 2, 1); __PYX_ERR(0, 49, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__rmul__") < 0)) __PYX_ERR(0, 49, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_other = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__rmul__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 49, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQ.__rmul__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_2FQ_6__rmul__(__pyx_self, __pyx_v_self, __pyx_v_other);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_6__rmul__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
__Pyx_RefNannySetupContext("__rmul__", 0);
/* "optimized_field_elements.pyx":50
*
* def __rmul__(self, other):
* return self * other # <<<<<<<<<<<<<<
*
* def __radd__(self, other):
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = PyNumber_Multiply(__pyx_v_self, __pyx_v_other); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 50, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":49
* return FQ((self.n * on) % field_modulus)
*
* def __rmul__(self, other): # <<<<<<<<<<<<<<
* return self * other
*
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("optimized_field_elements.FQ.__rmul__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":52
* return self * other
*
* def __radd__(self, other): # <<<<<<<<<<<<<<
* return self + other
*
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_9__radd__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_2FQ_9__radd__ = {"__radd__", (PyCFunction)__pyx_pw_24optimized_field_elements_2FQ_9__radd__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_9__radd__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_other = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__radd__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__radd__", 1, 2, 2, 1); __PYX_ERR(0, 52, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__radd__") < 0)) __PYX_ERR(0, 52, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_other = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__radd__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 52, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQ.__radd__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_2FQ_8__radd__(__pyx_self, __pyx_v_self, __pyx_v_other);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_8__radd__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
__Pyx_RefNannySetupContext("__radd__", 0);
/* "optimized_field_elements.pyx":53
*
* def __radd__(self, other):
* return self + other # <<<<<<<<<<<<<<
*
* def __rsub__(self, other):
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = PyNumber_Add(__pyx_v_self, __pyx_v_other); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 53, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":52
* return self * other
*
* def __radd__(self, other): # <<<<<<<<<<<<<<
* return self + other
*
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("optimized_field_elements.FQ.__radd__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":55
* return self + other
*
* def __rsub__(self, other): # <<<<<<<<<<<<<<
* on = other.n if isinstance(other, FQ) else other
* return FQ((on - self.n) % field_modulus)
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_11__rsub__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_2FQ_11__rsub__ = {"__rsub__", (PyCFunction)__pyx_pw_24optimized_field_elements_2FQ_11__rsub__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_11__rsub__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_other = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__rsub__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__rsub__", 1, 2, 2, 1); __PYX_ERR(0, 55, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__rsub__") < 0)) __PYX_ERR(0, 55, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_other = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__rsub__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 55, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQ.__rsub__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_2FQ_10__rsub__(__pyx_self, __pyx_v_self, __pyx_v_other);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_10__rsub__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
PyObject *__pyx_v_on = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
int __pyx_t_3;
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
PyObject *__pyx_t_6 = NULL;
__Pyx_RefNannySetupContext("__rsub__", 0);
/* "optimized_field_elements.pyx":56
*
* def __rsub__(self, other):
* on = other.n if isinstance(other, FQ) else other # <<<<<<<<<<<<<<
* return FQ((on - self.n) % field_modulus)
*
*/
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_FQ); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 56, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = PyObject_IsInstance(__pyx_v_other, __pyx_t_2); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 56, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if ((__pyx_t_3 != 0)) {
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_n); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 56, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_1 = __pyx_t_2;
__pyx_t_2 = 0;
} else {
__Pyx_INCREF(__pyx_v_other);
__pyx_t_1 = __pyx_v_other;
}
__pyx_v_on = __pyx_t_1;
__pyx_t_1 = 0;
/* "optimized_field_elements.pyx":57
* def __rsub__(self, other):
* on = other.n if isinstance(other, FQ) else other
* return FQ((on - self.n) % field_modulus) # <<<<<<<<<<<<<<
*
* def __sub__(self, other):
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_FQ); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 57, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_n); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 57, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_5 = PyNumber_Subtract(__pyx_v_on, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 57, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_field_modulus); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 57, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_6 = PyNumber_Remainder(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 57, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = NULL;
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
if (likely(__pyx_t_4)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
__Pyx_INCREF(__pyx_t_4);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_2, function);
}
}
if (!__pyx_t_4) {
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 57, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_6};
__pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 57, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_6};
__pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 57, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
} else
#endif
{
__pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 57, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
__Pyx_GIVEREF(__pyx_t_6);
PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_6);
__pyx_t_6 = 0;
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 57, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
}
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":55
* return self + other
*
* def __rsub__(self, other): # <<<<<<<<<<<<<<
* on = other.n if isinstance(other, FQ) else other
* return FQ((on - self.n) % field_modulus)
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_AddTraceback("optimized_field_elements.FQ.__rsub__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_on);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":59
* return FQ((on - self.n) % field_modulus)
*
* def __sub__(self, other): # <<<<<<<<<<<<<<
* on = other.n if isinstance(other, FQ) else other
* return FQ((self.n - on) % field_modulus)
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_13__sub__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_2FQ_13__sub__ = {"__sub__", (PyCFunction)__pyx_pw_24optimized_field_elements_2FQ_13__sub__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_13__sub__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_other = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__sub__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__sub__", 1, 2, 2, 1); __PYX_ERR(0, 59, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__sub__") < 0)) __PYX_ERR(0, 59, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_other = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__sub__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 59, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQ.__sub__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_2FQ_12__sub__(__pyx_self, __pyx_v_self, __pyx_v_other);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_12__sub__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
PyObject *__pyx_v_on = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
int __pyx_t_3;
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
PyObject *__pyx_t_6 = NULL;
__Pyx_RefNannySetupContext("__sub__", 0);
/* "optimized_field_elements.pyx":60
*
* def __sub__(self, other):
* on = other.n if isinstance(other, FQ) else other # <<<<<<<<<<<<<<
* return FQ((self.n - on) % field_modulus)
*
*/
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_FQ); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 60, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = PyObject_IsInstance(__pyx_v_other, __pyx_t_2); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 60, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if ((__pyx_t_3 != 0)) {
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_n); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 60, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_1 = __pyx_t_2;
__pyx_t_2 = 0;
} else {
__Pyx_INCREF(__pyx_v_other);
__pyx_t_1 = __pyx_v_other;
}
__pyx_v_on = __pyx_t_1;
__pyx_t_1 = 0;
/* "optimized_field_elements.pyx":61
* def __sub__(self, other):
* on = other.n if isinstance(other, FQ) else other
* return FQ((self.n - on) % field_modulus) # <<<<<<<<<<<<<<
*
* def __div__(self, other):
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_FQ); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 61, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_n); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 61, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_5 = PyNumber_Subtract(__pyx_t_4, __pyx_v_on); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 61, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_field_modulus); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 61, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_6 = PyNumber_Remainder(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 61, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = NULL;
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
if (likely(__pyx_t_4)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
__Pyx_INCREF(__pyx_t_4);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_2, function);
}
}
if (!__pyx_t_4) {
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 61, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_6};
__pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 61, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_6};
__pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 61, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
} else
#endif
{
__pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 61, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
__Pyx_GIVEREF(__pyx_t_6);
PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_6);
__pyx_t_6 = 0;
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 61, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
}
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":59
* return FQ((on - self.n) % field_modulus)
*
* def __sub__(self, other): # <<<<<<<<<<<<<<
* on = other.n if isinstance(other, FQ) else other
* return FQ((self.n - on) % field_modulus)
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_AddTraceback("optimized_field_elements.FQ.__sub__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_on);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":63
* return FQ((self.n - on) % field_modulus)
*
* def __div__(self, other): # <<<<<<<<<<<<<<
* on = other.n if isinstance(other, FQ) else other
* assert isinstance(on, int_types)
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_15__div__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_2FQ_15__div__ = {"__div__", (PyCFunction)__pyx_pw_24optimized_field_elements_2FQ_15__div__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_15__div__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_other = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__div__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__div__", 1, 2, 2, 1); __PYX_ERR(0, 63, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__div__") < 0)) __PYX_ERR(0, 63, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_other = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__div__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 63, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQ.__div__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_2FQ_14__div__(__pyx_self, __pyx_v_self, __pyx_v_other);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_14__div__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
PyObject *__pyx_v_on = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
int __pyx_t_3;
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
PyObject *__pyx_t_6 = NULL;
PyObject *__pyx_t_7 = NULL;
PyObject *__pyx_t_8 = NULL;
int __pyx_t_9;
PyObject *__pyx_t_10 = NULL;
__Pyx_RefNannySetupContext("__div__", 0);
/* "optimized_field_elements.pyx":64
*
* def __div__(self, other):
* on = other.n if isinstance(other, FQ) else other # <<<<<<<<<<<<<<
* assert isinstance(on, int_types)
* return FQ(self.n * prime_field_inv(on, field_modulus) % field_modulus)
*/
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_FQ); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 64, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = PyObject_IsInstance(__pyx_v_other, __pyx_t_2); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 64, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if ((__pyx_t_3 != 0)) {
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_n); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 64, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_1 = __pyx_t_2;
__pyx_t_2 = 0;
} else {
__Pyx_INCREF(__pyx_v_other);
__pyx_t_1 = __pyx_v_other;
}
__pyx_v_on = __pyx_t_1;
__pyx_t_1 = 0;
/* "optimized_field_elements.pyx":65
* def __div__(self, other):
* on = other.n if isinstance(other, FQ) else other
* assert isinstance(on, int_types) # <<<<<<<<<<<<<<
* return FQ(self.n * prime_field_inv(on, field_modulus) % field_modulus)
*
*/
#ifndef CYTHON_WITHOUT_ASSERTIONS
if (unlikely(!Py_OptimizeFlag)) {
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_int_types); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 65, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_3 = PyObject_IsInstance(__pyx_v_on, __pyx_t_1); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 65, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (unlikely(!(__pyx_t_3 != 0))) {
PyErr_SetNone(PyExc_AssertionError);
__PYX_ERR(0, 65, __pyx_L1_error)
}
}
#endif
/* "optimized_field_elements.pyx":66
* on = other.n if isinstance(other, FQ) else other
* assert isinstance(on, int_types)
* return FQ(self.n * prime_field_inv(on, field_modulus) % field_modulus) # <<<<<<<<<<<<<<
*
* def __truediv__(self, other):
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_FQ); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 66, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_n); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 66, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_prime_field_inv); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 66, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_field_modulus); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 66, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_8 = NULL;
__pyx_t_9 = 0;
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
__pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
if (likely(__pyx_t_8)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
__Pyx_INCREF(__pyx_t_8);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_6, function);
__pyx_t_9 = 1;
}
}
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_6)) {
PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_v_on, __pyx_t_7};
__pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 66, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_v_on, __pyx_t_7};
__pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 66, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
} else
#endif
{
__pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 66, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_10);
if (__pyx_t_8) {
__Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __pyx_t_8 = NULL;
}
__Pyx_INCREF(__pyx_v_on);
__Pyx_GIVEREF(__pyx_v_on);
PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_v_on);
__Pyx_GIVEREF(__pyx_t_7);
PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_t_7);
__pyx_t_7 = 0;
__pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_10, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 66, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
}
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__pyx_t_6 = PyNumber_Multiply(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 66, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_field_modulus); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 66, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_4 = PyNumber_Remainder(__pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 66, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_t_5 = NULL;
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
__pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
if (likely(__pyx_t_5)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
__Pyx_INCREF(__pyx_t_5);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_2, function);
}
}
if (!__pyx_t_5) {
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 66, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4};
__pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 66, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4};
__pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 66, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
} else
#endif
{
__pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 66, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL;
__Pyx_GIVEREF(__pyx_t_4);
PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4);
__pyx_t_4 = 0;
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 66, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
}
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":63
* return FQ((self.n - on) % field_modulus)
*
* def __div__(self, other): # <<<<<<<<<<<<<<
* on = other.n if isinstance(other, FQ) else other
* assert isinstance(on, int_types)
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_XDECREF(__pyx_t_8);
__Pyx_XDECREF(__pyx_t_10);
__Pyx_AddTraceback("optimized_field_elements.FQ.__div__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_on);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":68
* return FQ(self.n * prime_field_inv(on, field_modulus) % field_modulus)
*
* def __truediv__(self, other): # <<<<<<<<<<<<<<
* return self.__div__(other)
*
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_17__truediv__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_2FQ_17__truediv__ = {"__truediv__", (PyCFunction)__pyx_pw_24optimized_field_elements_2FQ_17__truediv__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_17__truediv__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_other = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__truediv__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__truediv__", 1, 2, 2, 1); __PYX_ERR(0, 68, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__truediv__") < 0)) __PYX_ERR(0, 68, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_other = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__truediv__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 68, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQ.__truediv__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_2FQ_16__truediv__(__pyx_self, __pyx_v_self, __pyx_v_other);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_16__truediv__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
PyObject *__pyx_t_3 = NULL;
PyObject *__pyx_t_4 = NULL;
__Pyx_RefNannySetupContext("__truediv__", 0);
/* "optimized_field_elements.pyx":69
*
* def __truediv__(self, other):
* return self.__div__(other) # <<<<<<<<<<<<<<
*
* def __rdiv__(self, other):
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_div); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 69, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
__pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
if (likely(__pyx_t_3)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
__Pyx_INCREF(__pyx_t_3);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_2, function);
}
}
if (!__pyx_t_3) {
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_other); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 69, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_other};
__pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 69, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_other};
__pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 69, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else
#endif
{
__pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 69, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL;
__Pyx_INCREF(__pyx_v_other);
__Pyx_GIVEREF(__pyx_v_other);
PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_other);
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 69, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
}
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":68
* return FQ(self.n * prime_field_inv(on, field_modulus) % field_modulus)
*
* def __truediv__(self, other): # <<<<<<<<<<<<<<
* return self.__div__(other)
*
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_AddTraceback("optimized_field_elements.FQ.__truediv__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":71
* return self.__div__(other)
*
* def __rdiv__(self, other): # <<<<<<<<<<<<<<
* on = other.n if isinstance(other, FQ) else other
* assert isinstance(on, int_types), on
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_19__rdiv__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_2FQ_19__rdiv__ = {"__rdiv__", (PyCFunction)__pyx_pw_24optimized_field_elements_2FQ_19__rdiv__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_19__rdiv__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_other = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__rdiv__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__rdiv__", 1, 2, 2, 1); __PYX_ERR(0, 71, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__rdiv__") < 0)) __PYX_ERR(0, 71, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_other = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__rdiv__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 71, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQ.__rdiv__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_2FQ_18__rdiv__(__pyx_self, __pyx_v_self, __pyx_v_other);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_18__rdiv__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
PyObject *__pyx_v_on = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
int __pyx_t_3;
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
PyObject *__pyx_t_6 = NULL;
PyObject *__pyx_t_7 = NULL;
PyObject *__pyx_t_8 = NULL;
int __pyx_t_9;
PyObject *__pyx_t_10 = NULL;
__Pyx_RefNannySetupContext("__rdiv__", 0);
/* "optimized_field_elements.pyx":72
*
* def __rdiv__(self, other):
* on = other.n if isinstance(other, FQ) else other # <<<<<<<<<<<<<<
* assert isinstance(on, int_types), on
* return FQ(prime_field_inv(self.n, field_modulus) * on % field_modulus)
*/
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_FQ); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 72, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = PyObject_IsInstance(__pyx_v_other, __pyx_t_2); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 72, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if ((__pyx_t_3 != 0)) {
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_n); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 72, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_1 = __pyx_t_2;
__pyx_t_2 = 0;
} else {
__Pyx_INCREF(__pyx_v_other);
__pyx_t_1 = __pyx_v_other;
}
__pyx_v_on = __pyx_t_1;
__pyx_t_1 = 0;
/* "optimized_field_elements.pyx":73
* def __rdiv__(self, other):
* on = other.n if isinstance(other, FQ) else other
* assert isinstance(on, int_types), on # <<<<<<<<<<<<<<
* return FQ(prime_field_inv(self.n, field_modulus) * on % field_modulus)
*
*/
#ifndef CYTHON_WITHOUT_ASSERTIONS
if (unlikely(!Py_OptimizeFlag)) {
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_int_types); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 73, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_3 = PyObject_IsInstance(__pyx_v_on, __pyx_t_1); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 73, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (unlikely(!(__pyx_t_3 != 0))) {
__pyx_t_1 = PyTuple_Pack(1, __pyx_v_on); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 73, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
PyErr_SetObject(PyExc_AssertionError, __pyx_t_1);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__PYX_ERR(0, 73, __pyx_L1_error)
}
}
#endif
/* "optimized_field_elements.pyx":74
* on = other.n if isinstance(other, FQ) else other
* assert isinstance(on, int_types), on
* return FQ(prime_field_inv(self.n, field_modulus) * on % field_modulus) # <<<<<<<<<<<<<<
*
* def __rtruediv__(self, other):
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_FQ); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 74, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_prime_field_inv); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 74, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_n); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 74, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_field_modulus); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 74, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_8 = NULL;
__pyx_t_9 = 0;
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
__pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
if (likely(__pyx_t_8)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
__Pyx_INCREF(__pyx_t_8);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_5, function);
__pyx_t_9 = 1;
}
}
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_5)) {
PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_6, __pyx_t_7};
__pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 74, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_t_6, __pyx_t_7};
__pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 74, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
} else
#endif
{
__pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 74, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_10);
if (__pyx_t_8) {
__Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __pyx_t_8 = NULL;
}
__Pyx_GIVEREF(__pyx_t_6);
PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_t_6);
__Pyx_GIVEREF(__pyx_t_7);
PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_t_7);
__pyx_t_6 = 0;
__pyx_t_7 = 0;
__pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_10, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 74, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
}
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_t_5 = PyNumber_Multiply(__pyx_t_4, __pyx_v_on); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 74, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_field_modulus); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 74, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_10 = PyNumber_Remainder(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 74, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_10);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = NULL;
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
if (likely(__pyx_t_4)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
__Pyx_INCREF(__pyx_t_4);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_2, function);
}
}
if (!__pyx_t_4) {
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 74, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_10};
__pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 74, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_10};
__pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 74, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
} else
#endif
{
__pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 74, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
__Pyx_GIVEREF(__pyx_t_10);
PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_10);
__pyx_t_10 = 0;
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 74, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
}
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":71
* return self.__div__(other)
*
* def __rdiv__(self, other): # <<<<<<<<<<<<<<
* on = other.n if isinstance(other, FQ) else other
* assert isinstance(on, int_types), on
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_XDECREF(__pyx_t_8);
__Pyx_XDECREF(__pyx_t_10);
__Pyx_AddTraceback("optimized_field_elements.FQ.__rdiv__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_on);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":76
* return FQ(prime_field_inv(self.n, field_modulus) * on % field_modulus)
*
* def __rtruediv__(self, other): # <<<<<<<<<<<<<<
* return self.__rdiv__(other)
*
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_21__rtruediv__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_2FQ_21__rtruediv__ = {"__rtruediv__", (PyCFunction)__pyx_pw_24optimized_field_elements_2FQ_21__rtruediv__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_21__rtruediv__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_other = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__rtruediv__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__rtruediv__", 1, 2, 2, 1); __PYX_ERR(0, 76, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__rtruediv__") < 0)) __PYX_ERR(0, 76, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_other = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__rtruediv__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 76, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQ.__rtruediv__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_2FQ_20__rtruediv__(__pyx_self, __pyx_v_self, __pyx_v_other);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_20__rtruediv__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
PyObject *__pyx_t_3 = NULL;
PyObject *__pyx_t_4 = NULL;
__Pyx_RefNannySetupContext("__rtruediv__", 0);
/* "optimized_field_elements.pyx":77
*
* def __rtruediv__(self, other):
* return self.__rdiv__(other) # <<<<<<<<<<<<<<
*
* def __pow__(self, other):
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_rdiv); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 77, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
__pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
if (likely(__pyx_t_3)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
__Pyx_INCREF(__pyx_t_3);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_2, function);
}
}
if (!__pyx_t_3) {
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_other); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 77, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_other};
__pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 77, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_other};
__pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 77, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else
#endif
{
__pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 77, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL;
__Pyx_INCREF(__pyx_v_other);
__Pyx_GIVEREF(__pyx_v_other);
PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_other);
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 77, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
}
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":76
* return FQ(prime_field_inv(self.n, field_modulus) * on % field_modulus)
*
* def __rtruediv__(self, other): # <<<<<<<<<<<<<<
* return self.__rdiv__(other)
*
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_AddTraceback("optimized_field_elements.FQ.__rtruediv__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":79
* return self.__rdiv__(other)
*
* def __pow__(self, other): # <<<<<<<<<<<<<<
* if other == 0:
* return FQ(1)
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_23__pow__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_2FQ_23__pow__ = {"__pow__", (PyCFunction)__pyx_pw_24optimized_field_elements_2FQ_23__pow__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_23__pow__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_other = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__pow__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__pow__", 1, 2, 2, 1); __PYX_ERR(0, 79, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pow__") < 0)) __PYX_ERR(0, 79, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_other = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__pow__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 79, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQ.__pow__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_2FQ_22__pow__(__pyx_self, __pyx_v_self, __pyx_v_other);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_22__pow__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
int __pyx_t_2;
PyObject *__pyx_t_3 = NULL;
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
PyObject *__pyx_t_6 = NULL;
__Pyx_RefNannySetupContext("__pow__", 0);
/* "optimized_field_elements.pyx":80
*
* def __pow__(self, other):
* if other == 0: # <<<<<<<<<<<<<<
* return FQ(1)
* elif other == 1:
*/
__pyx_t_1 = __Pyx_PyInt_EqObjC(__pyx_v_other, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 80, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (__pyx_t_2) {
/* "optimized_field_elements.pyx":81
* def __pow__(self, other):
* if other == 0:
* return FQ(1) # <<<<<<<<<<<<<<
* elif other == 1:
* return FQ(self.n)
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_FQ); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 81, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 81, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_r = __pyx_t_3;
__pyx_t_3 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":80
*
* def __pow__(self, other):
* if other == 0: # <<<<<<<<<<<<<<
* return FQ(1)
* elif other == 1:
*/
}
/* "optimized_field_elements.pyx":82
* if other == 0:
* return FQ(1)
* elif other == 1: # <<<<<<<<<<<<<<
* return FQ(self.n)
* elif other % 2 == 0:
*/
__pyx_t_3 = __Pyx_PyInt_EqObjC(__pyx_v_other, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 82, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 82, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
if (__pyx_t_2) {
/* "optimized_field_elements.pyx":83
* return FQ(1)
* elif other == 1:
* return FQ(self.n) # <<<<<<<<<<<<<<
* elif other % 2 == 0:
* return (self * self) ** (other // 2)
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_FQ); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 83, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_n); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 83, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_5 = NULL;
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
__pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1);
if (likely(__pyx_t_5)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
__Pyx_INCREF(__pyx_t_5);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_1, function);
}
}
if (!__pyx_t_5) {
__pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 83, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_GOTREF(__pyx_t_3);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_1)) {
PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4};
__pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 83, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4};
__pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 83, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
} else
#endif
{
__pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 83, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL;
__Pyx_GIVEREF(__pyx_t_4);
PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4);
__pyx_t_4 = 0;
__pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 83, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
}
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_r = __pyx_t_3;
__pyx_t_3 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":82
* if other == 0:
* return FQ(1)
* elif other == 1: # <<<<<<<<<<<<<<
* return FQ(self.n)
* elif other % 2 == 0:
*/
}
/* "optimized_field_elements.pyx":84
* elif other == 1:
* return FQ(self.n)
* elif other % 2 == 0: # <<<<<<<<<<<<<<
* return (self * self) ** (other // 2)
* else:
*/
__pyx_t_3 = __Pyx_PyInt_RemainderObjC(__pyx_v_other, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 84, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_1 = __Pyx_PyInt_EqObjC(__pyx_t_3, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 84, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 84, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (__pyx_t_2) {
/* "optimized_field_elements.pyx":85
* return FQ(self.n)
* elif other % 2 == 0:
* return (self * self) ** (other // 2) # <<<<<<<<<<<<<<
* else:
* return ((self * self) ** int(other // 2)) * self
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = PyNumber_Multiply(__pyx_v_self, __pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 85, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_3 = __Pyx_PyInt_FloorDivideObjC(__pyx_v_other, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 85, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_6 = PyNumber_Power(__pyx_t_1, __pyx_t_3, Py_None); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 85, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_r = __pyx_t_6;
__pyx_t_6 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":84
* elif other == 1:
* return FQ(self.n)
* elif other % 2 == 0: # <<<<<<<<<<<<<<
* return (self * self) ** (other // 2)
* else:
*/
}
/* "optimized_field_elements.pyx":87
* return (self * self) ** (other // 2)
* else:
* return ((self * self) ** int(other // 2)) * self # <<<<<<<<<<<<<<
*
* def __eq__(self, other):
*/
/*else*/ {
__Pyx_XDECREF(__pyx_r);
__pyx_t_6 = PyNumber_Multiply(__pyx_v_self, __pyx_v_self); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 87, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_3 = __Pyx_PyInt_FloorDivideObjC(__pyx_v_other, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 87, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_1 = __Pyx_PyNumber_Int(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 87, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_3 = PyNumber_Power(__pyx_t_6, __pyx_t_1, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 87, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_1 = PyNumber_Multiply(__pyx_t_3, __pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 87, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
}
/* "optimized_field_elements.pyx":79
* return self.__rdiv__(other)
*
* def __pow__(self, other): # <<<<<<<<<<<<<<
* if other == 0:
* return FQ(1)
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_AddTraceback("optimized_field_elements.FQ.__pow__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":89
* return ((self * self) ** int(other // 2)) * self
*
* def __eq__(self, other): # <<<<<<<<<<<<<<
* if isinstance(other, FQ):
* return self.n == other.n
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_25__eq__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_2FQ_25__eq__ = {"__eq__", (PyCFunction)__pyx_pw_24optimized_field_elements_2FQ_25__eq__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_25__eq__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_other = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__eq__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__eq__", 1, 2, 2, 1); __PYX_ERR(0, 89, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__eq__") < 0)) __PYX_ERR(0, 89, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_other = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__eq__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 89, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQ.__eq__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_2FQ_24__eq__(__pyx_self, __pyx_v_self, __pyx_v_other);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_24__eq__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
int __pyx_t_2;
int __pyx_t_3;
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
__Pyx_RefNannySetupContext("__eq__", 0);
/* "optimized_field_elements.pyx":90
*
* def __eq__(self, other):
* if isinstance(other, FQ): # <<<<<<<<<<<<<<
* return self.n == other.n
* else:
*/
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_FQ); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 90, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PyObject_IsInstance(__pyx_v_other, __pyx_t_1); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 90, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_3 = (__pyx_t_2 != 0);
if (__pyx_t_3) {
/* "optimized_field_elements.pyx":91
* def __eq__(self, other):
* if isinstance(other, FQ):
* return self.n == other.n # <<<<<<<<<<<<<<
* else:
* return self.n == other
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_n); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 91, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_n); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 91, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_5 = PyObject_RichCompare(__pyx_t_1, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 91, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_r = __pyx_t_5;
__pyx_t_5 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":90
*
* def __eq__(self, other):
* if isinstance(other, FQ): # <<<<<<<<<<<<<<
* return self.n == other.n
* else:
*/
}
/* "optimized_field_elements.pyx":93
* return self.n == other.n
* else:
* return self.n == other # <<<<<<<<<<<<<<
*
* def __ne__(self, other):
*/
/*else*/ {
__Pyx_XDECREF(__pyx_r);
__pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_n); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 93, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_4 = PyObject_RichCompare(__pyx_t_5, __pyx_v_other, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 93, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_r = __pyx_t_4;
__pyx_t_4 = 0;
goto __pyx_L0;
}
/* "optimized_field_elements.pyx":89
* return ((self * self) ** int(other // 2)) * self
*
* def __eq__(self, other): # <<<<<<<<<<<<<<
* if isinstance(other, FQ):
* return self.n == other.n
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_AddTraceback("optimized_field_elements.FQ.__eq__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":95
* return self.n == other
*
* def __ne__(self, other): # <<<<<<<<<<<<<<
* return not self == other
*
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_27__ne__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_2FQ_27__ne__ = {"__ne__", (PyCFunction)__pyx_pw_24optimized_field_elements_2FQ_27__ne__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_27__ne__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_other = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__ne__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__ne__", 1, 2, 2, 1); __PYX_ERR(0, 95, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__ne__") < 0)) __PYX_ERR(0, 95, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_other = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__ne__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 95, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQ.__ne__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_2FQ_26__ne__(__pyx_self, __pyx_v_self, __pyx_v_other);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_26__ne__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
int __pyx_t_2;
__Pyx_RefNannySetupContext("__ne__", 0);
/* "optimized_field_elements.pyx":96
*
* def __ne__(self, other):
* return not self == other # <<<<<<<<<<<<<<
*
* def __neg__(self):
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = PyObject_RichCompare(__pyx_v_self, __pyx_v_other, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 96, __pyx_L1_error)
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 96, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_1 = __Pyx_PyBool_FromLong((!__pyx_t_2)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 96, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":95
* return self.n == other
*
* def __ne__(self, other): # <<<<<<<<<<<<<<
* return not self == other
*
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("optimized_field_elements.FQ.__ne__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":98
* return not self == other
*
* def __neg__(self): # <<<<<<<<<<<<<<
* return FQ(-self.n)
*
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_29__neg__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_2FQ_29__neg__ = {"__neg__", (PyCFunction)__pyx_pw_24optimized_field_elements_2FQ_29__neg__, METH_O, 0};
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_29__neg__(PyObject *__pyx_self, PyObject *__pyx_v_self) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__neg__ (wrapper)", 0);
__pyx_r = __pyx_pf_24optimized_field_elements_2FQ_28__neg__(__pyx_self, ((PyObject *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_28__neg__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
PyObject *__pyx_t_3 = NULL;
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
__Pyx_RefNannySetupContext("__neg__", 0);
/* "optimized_field_elements.pyx":99
*
* def __neg__(self):
* return FQ(-self.n) # <<<<<<<<<<<<<<
*
* def __repr__(self):
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_FQ); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 99, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_n); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 99, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_4 = PyNumber_Negative(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 99, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_3 = NULL;
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
__pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
if (likely(__pyx_t_3)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
__Pyx_INCREF(__pyx_t_3);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_2, function);
}
}
if (!__pyx_t_3) {
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 99, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_4};
__pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 99, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_4};
__pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 99, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
} else
#endif
{
__pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 99, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL;
__Pyx_GIVEREF(__pyx_t_4);
PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_4);
__pyx_t_4 = 0;
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 99, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
}
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":98
* return not self == other
*
* def __neg__(self): # <<<<<<<<<<<<<<
* return FQ(-self.n)
*
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_AddTraceback("optimized_field_elements.FQ.__neg__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":101
* return FQ(-self.n)
*
* def __repr__(self): # <<<<<<<<<<<<<<
* return repr(self.n)
*
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_31__repr__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_2FQ_31__repr__ = {"__repr__", (PyCFunction)__pyx_pw_24optimized_field_elements_2FQ_31__repr__, METH_O, 0};
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_31__repr__(PyObject *__pyx_self, PyObject *__pyx_v_self) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__repr__ (wrapper)", 0);
__pyx_r = __pyx_pf_24optimized_field_elements_2FQ_30__repr__(__pyx_self, ((PyObject *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_30__repr__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
__Pyx_RefNannySetupContext("__repr__", 0);
/* "optimized_field_elements.pyx":102
*
* def __repr__(self):
* return repr(self.n) # <<<<<<<<<<<<<<
*
* @classmethod
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_n); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 102, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PyObject_Repr(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 102, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_r = __pyx_t_2;
__pyx_t_2 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":101
* return FQ(-self.n)
*
* def __repr__(self): # <<<<<<<<<<<<<<
* return repr(self.n)
*
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_AddTraceback("optimized_field_elements.FQ.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":105
*
* @classmethod
* def one(cls): # <<<<<<<<<<<<<<
* return cls(1)
*
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_33one(PyObject *__pyx_self, PyObject *__pyx_v_cls); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_2FQ_33one = {"one", (PyCFunction)__pyx_pw_24optimized_field_elements_2FQ_33one, METH_O, 0};
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_33one(PyObject *__pyx_self, PyObject *__pyx_v_cls) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("one (wrapper)", 0);
__pyx_r = __pyx_pf_24optimized_field_elements_2FQ_32one(__pyx_self, ((PyObject *)__pyx_v_cls));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_32one(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_cls) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
__Pyx_RefNannySetupContext("one", 0);
/* "optimized_field_elements.pyx":106
* @classmethod
* def one(cls):
* return cls(1) # <<<<<<<<<<<<<<
*
* @classmethod
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_v_cls, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 106, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":105
*
* @classmethod
* def one(cls): # <<<<<<<<<<<<<<
* return cls(1)
*
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("optimized_field_elements.FQ.one", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":109
*
* @classmethod
* def zero(cls): # <<<<<<<<<<<<<<
* return cls(0)
*
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_35zero(PyObject *__pyx_self, PyObject *__pyx_v_cls); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_2FQ_35zero = {"zero", (PyCFunction)__pyx_pw_24optimized_field_elements_2FQ_35zero, METH_O, 0};
static PyObject *__pyx_pw_24optimized_field_elements_2FQ_35zero(PyObject *__pyx_self, PyObject *__pyx_v_cls) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("zero (wrapper)", 0);
__pyx_r = __pyx_pf_24optimized_field_elements_2FQ_34zero(__pyx_self, ((PyObject *)__pyx_v_cls));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_2FQ_34zero(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_cls) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
__Pyx_RefNannySetupContext("zero", 0);
/* "optimized_field_elements.pyx":110
* @classmethod
* def zero(cls):
* return cls(0) # <<<<<<<<<<<<<<
*
*
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_v_cls, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 110, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":109
*
* @classmethod
* def zero(cls): # <<<<<<<<<<<<<<
* return cls(0)
*
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("optimized_field_elements.FQ.zero", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":114
*
* # Utility methods for polynomial math
* def deg(p): # <<<<<<<<<<<<<<
* d = len(p) - 1
* while p[d] == 0 and d:
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_3deg(PyObject *__pyx_self, PyObject *__pyx_v_p); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_3deg = {"deg", (PyCFunction)__pyx_pw_24optimized_field_elements_3deg, METH_O, 0};
static PyObject *__pyx_pw_24optimized_field_elements_3deg(PyObject *__pyx_self, PyObject *__pyx_v_p) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("deg (wrapper)", 0);
__pyx_r = __pyx_pf_24optimized_field_elements_2deg(__pyx_self, ((PyObject *)__pyx_v_p));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_2deg(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_p) {
PyObject *__pyx_v_d = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
Py_ssize_t __pyx_t_1;
PyObject *__pyx_t_2 = NULL;
int __pyx_t_3;
PyObject *__pyx_t_4 = NULL;
int __pyx_t_5;
__Pyx_RefNannySetupContext("deg", 0);
/* "optimized_field_elements.pyx":115
* # Utility methods for polynomial math
* def deg(p):
* d = len(p) - 1 # <<<<<<<<<<<<<<
* while p[d] == 0 and d:
* d -= 1
*/
__pyx_t_1 = PyObject_Length(__pyx_v_p); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 115, __pyx_L1_error)
__pyx_t_2 = PyInt_FromSsize_t((__pyx_t_1 - 1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 115, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_v_d = __pyx_t_2;
__pyx_t_2 = 0;
/* "optimized_field_elements.pyx":116
* def deg(p):
* d = len(p) - 1
* while p[d] == 0 and d: # <<<<<<<<<<<<<<
* d -= 1
* return d
*/
while (1) {
__pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_p, __pyx_v_d); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 116, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_4 = __Pyx_PyInt_EqObjC(__pyx_t_2, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 116, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 116, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
if (__pyx_t_5) {
} else {
__pyx_t_3 = __pyx_t_5;
goto __pyx_L5_bool_binop_done;
}
__pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_d); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 116, __pyx_L1_error)
__pyx_t_3 = __pyx_t_5;
__pyx_L5_bool_binop_done:;
if (!__pyx_t_3) break;
/* "optimized_field_elements.pyx":117
* d = len(p) - 1
* while p[d] == 0 and d:
* d -= 1 # <<<<<<<<<<<<<<
* return d
*
*/
__pyx_t_4 = __Pyx_PyInt_SubtractObjC(__pyx_v_d, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 117, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF_SET(__pyx_v_d, __pyx_t_4);
__pyx_t_4 = 0;
}
/* "optimized_field_elements.pyx":118
* while p[d] == 0 and d:
* d -= 1
* return d # <<<<<<<<<<<<<<
*
*
*/
__Pyx_XDECREF(__pyx_r);
__Pyx_INCREF(__pyx_v_d);
__pyx_r = __pyx_v_d;
goto __pyx_L0;
/* "optimized_field_elements.pyx":114
*
* # Utility methods for polynomial math
* def deg(p): # <<<<<<<<<<<<<<
* d = len(p) - 1
* while p[d] == 0 and d:
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_AddTraceback("optimized_field_elements.deg", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_d);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":121
*
*
* def poly_rounded_div(a, b): # <<<<<<<<<<<<<<
* dega = deg(a)
* degb = deg(b)
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_5poly_rounded_div(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_5poly_rounded_div = {"poly_rounded_div", (PyCFunction)__pyx_pw_24optimized_field_elements_5poly_rounded_div, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_5poly_rounded_div(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_a = 0;
PyObject *__pyx_v_b = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("poly_rounded_div (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_a,&__pyx_n_s_b,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_a)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_b)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("poly_rounded_div", 1, 2, 2, 1); __PYX_ERR(0, 121, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "poly_rounded_div") < 0)) __PYX_ERR(0, 121, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_a = values[0];
__pyx_v_b = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("poly_rounded_div", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 121, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.poly_rounded_div", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_4poly_rounded_div(__pyx_self, __pyx_v_a, __pyx_v_b);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_4poly_rounded_div(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_a, PyObject *__pyx_v_b) {
PyObject *__pyx_v_dega = NULL;
PyObject *__pyx_v_degb = NULL;
PyObject *__pyx_v_temp = NULL;
PyObject *__pyx_v_o = NULL;
PyObject *__pyx_v_i = NULL;
PyObject *__pyx_v_c = NULL;
PyObject *__pyx_v_x = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
PyObject *__pyx_t_3 = NULL;
PyObject *__pyx_t_4 = NULL;
Py_ssize_t __pyx_t_5;
PyObject *(*__pyx_t_6)(PyObject *);
PyObject *__pyx_t_7 = NULL;
PyObject *__pyx_t_8 = NULL;
PyObject *__pyx_t_9 = NULL;
PyObject *__pyx_t_10 = NULL;
int __pyx_t_11;
PyObject *__pyx_t_12 = NULL;
Py_ssize_t __pyx_t_13;
PyObject *(*__pyx_t_14)(PyObject *);
__Pyx_RefNannySetupContext("poly_rounded_div", 0);
/* "optimized_field_elements.pyx":122
*
* def poly_rounded_div(a, b):
* dega = deg(a) # <<<<<<<<<<<<<<
* degb = deg(b)
* temp = [x for x in a]
*/
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_deg); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 122, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = NULL;
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
__pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
if (likely(__pyx_t_3)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
__Pyx_INCREF(__pyx_t_3);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_2, function);
}
}
if (!__pyx_t_3) {
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_a); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 122, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_a};
__pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 122, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_a};
__pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 122, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else
#endif
{
__pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 122, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL;
__Pyx_INCREF(__pyx_v_a);
__Pyx_GIVEREF(__pyx_v_a);
PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_a);
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 122, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
}
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_v_dega = __pyx_t_1;
__pyx_t_1 = 0;
/* "optimized_field_elements.pyx":123
* def poly_rounded_div(a, b):
* dega = deg(a)
* degb = deg(b) # <<<<<<<<<<<<<<
* temp = [x for x in a]
* o = [0 for x in a]
*/
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_deg); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 123, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_4 = NULL;
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
if (likely(__pyx_t_4)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
__Pyx_INCREF(__pyx_t_4);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_2, function);
}
}
if (!__pyx_t_4) {
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_b); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 123, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_b};
__pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 123, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_b};
__pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 123, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else
#endif
{
__pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 123, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = NULL;
__Pyx_INCREF(__pyx_v_b);
__Pyx_GIVEREF(__pyx_v_b);
PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_v_b);
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 123, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
}
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_v_degb = __pyx_t_1;
__pyx_t_1 = 0;
/* "optimized_field_elements.pyx":124
* dega = deg(a)
* degb = deg(b)
* temp = [x for x in a] # <<<<<<<<<<<<<<
* o = [0 for x in a]
* for i in range(dega - degb, -1, -1):
*/
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 124, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
if (likely(PyList_CheckExact(__pyx_v_a)) || PyTuple_CheckExact(__pyx_v_a)) {
__pyx_t_2 = __pyx_v_a; __Pyx_INCREF(__pyx_t_2); __pyx_t_5 = 0;
__pyx_t_6 = NULL;
} else {
__pyx_t_5 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_a); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 124, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_6 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 124, __pyx_L1_error)
}
for (;;) {
if (likely(!__pyx_t_6)) {
if (likely(PyList_CheckExact(__pyx_t_2))) {
if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_2)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 124, __pyx_L1_error)
#else
__pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 124, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
#endif
} else {
if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 124, __pyx_L1_error)
#else
__pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 124, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
#endif
}
} else {
__pyx_t_3 = __pyx_t_6(__pyx_t_2);
if (unlikely(!__pyx_t_3)) {
PyObject* exc_type = PyErr_Occurred();
if (exc_type) {
if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
else __PYX_ERR(0, 124, __pyx_L1_error)
}
break;
}
__Pyx_GOTREF(__pyx_t_3);
}
__Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_3);
__pyx_t_3 = 0;
if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_v_x))) __PYX_ERR(0, 124, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_v_temp = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;
/* "optimized_field_elements.pyx":125
* degb = deg(b)
* temp = [x for x in a]
* o = [0 for x in a] # <<<<<<<<<<<<<<
* for i in range(dega - degb, -1, -1):
* o[i] = (o[i] + temp[degb + i] * prime_field_inv(b[degb], field_modulus))
*/
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 125, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
if (likely(PyList_CheckExact(__pyx_v_a)) || PyTuple_CheckExact(__pyx_v_a)) {
__pyx_t_2 = __pyx_v_a; __Pyx_INCREF(__pyx_t_2); __pyx_t_5 = 0;
__pyx_t_6 = NULL;
} else {
__pyx_t_5 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_a); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 125, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_6 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 125, __pyx_L1_error)
}
for (;;) {
if (likely(!__pyx_t_6)) {
if (likely(PyList_CheckExact(__pyx_t_2))) {
if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_2)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 125, __pyx_L1_error)
#else
__pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 125, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
#endif
} else {
if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 125, __pyx_L1_error)
#else
__pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 125, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
#endif
}
} else {
__pyx_t_3 = __pyx_t_6(__pyx_t_2);
if (unlikely(!__pyx_t_3)) {
PyObject* exc_type = PyErr_Occurred();
if (exc_type) {
if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
else __PYX_ERR(0, 125, __pyx_L1_error)
}
break;
}
__Pyx_GOTREF(__pyx_t_3);
}
__Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_3);
__pyx_t_3 = 0;
if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_int_0))) __PYX_ERR(0, 125, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_v_o = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;
/* "optimized_field_elements.pyx":126
* temp = [x for x in a]
* o = [0 for x in a]
* for i in range(dega - degb, -1, -1): # <<<<<<<<<<<<<<
* o[i] = (o[i] + temp[degb + i] * prime_field_inv(b[degb], field_modulus))
* for c in range(degb + 1):
*/
__pyx_t_1 = PyNumber_Subtract(__pyx_v_dega, __pyx_v_degb); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 126, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 126, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_GIVEREF(__pyx_t_1);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
__Pyx_INCREF(__pyx_int_neg_1);
__Pyx_GIVEREF(__pyx_int_neg_1);
PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_neg_1);
__Pyx_INCREF(__pyx_int_neg_1);
__Pyx_GIVEREF(__pyx_int_neg_1);
PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_int_neg_1);
__pyx_t_1 = 0;
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 126, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
__pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_5 = 0;
__pyx_t_6 = NULL;
} else {
__pyx_t_5 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 126, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_6 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 126, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
for (;;) {
if (likely(!__pyx_t_6)) {
if (likely(PyList_CheckExact(__pyx_t_2))) {
if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_2)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 126, __pyx_L1_error)
#else
__pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 126, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
#endif
} else {
if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 126, __pyx_L1_error)
#else
__pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 126, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
#endif
}
} else {
__pyx_t_1 = __pyx_t_6(__pyx_t_2);
if (unlikely(!__pyx_t_1)) {
PyObject* exc_type = PyErr_Occurred();
if (exc_type) {
if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
else __PYX_ERR(0, 126, __pyx_L1_error)
}
break;
}
__Pyx_GOTREF(__pyx_t_1);
}
__Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_1);
__pyx_t_1 = 0;
/* "optimized_field_elements.pyx":127
* o = [0 for x in a]
* for i in range(dega - degb, -1, -1):
* o[i] = (o[i] + temp[degb + i] * prime_field_inv(b[degb], field_modulus)) # <<<<<<<<<<<<<<
* for c in range(degb + 1):
* temp[c + i] = (temp[c + i] - o[c])
*/
__pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_o, __pyx_v_i); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 127, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_3 = PyNumber_Add(__pyx_v_degb, __pyx_v_i); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 127, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_4 = __Pyx_PyObject_GetItem(__pyx_v_temp, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 127, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_prime_field_inv); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 127, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_v_b, __pyx_v_degb); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 127, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_field_modulus); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 127, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_9);
__pyx_t_10 = NULL;
__pyx_t_11 = 0;
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
__pyx_t_10 = PyMethod_GET_SELF(__pyx_t_7);
if (likely(__pyx_t_10)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
__Pyx_INCREF(__pyx_t_10);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_7, function);
__pyx_t_11 = 1;
}
}
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_7)) {
PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_t_8, __pyx_t_9};
__pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 127, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_t_8, __pyx_t_9};
__pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 127, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
} else
#endif
{
__pyx_t_12 = PyTuple_New(2+__pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 127, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_12);
if (__pyx_t_10) {
__Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_10); __pyx_t_10 = NULL;
}
__Pyx_GIVEREF(__pyx_t_8);
PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_11, __pyx_t_8);
__Pyx_GIVEREF(__pyx_t_9);
PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_11, __pyx_t_9);
__pyx_t_8 = 0;
__pyx_t_9 = 0;
__pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_12, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 127, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
}
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_7 = PyNumber_Multiply(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 127, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_3 = PyNumber_Add(__pyx_t_1, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 127, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
if (unlikely(PyObject_SetItem(__pyx_v_o, __pyx_v_i, __pyx_t_3) < 0)) __PYX_ERR(0, 127, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
/* "optimized_field_elements.pyx":128
* for i in range(dega - degb, -1, -1):
* o[i] = (o[i] + temp[degb + i] * prime_field_inv(b[degb], field_modulus))
* for c in range(degb + 1): # <<<<<<<<<<<<<<
* temp[c + i] = (temp[c + i] - o[c])
* return [x % field_modulus for x in o[:deg(o) + 1]]
*/
__pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_v_degb, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 128, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 128, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
if (likely(PyList_CheckExact(__pyx_t_7)) || PyTuple_CheckExact(__pyx_t_7)) {
__pyx_t_3 = __pyx_t_7; __Pyx_INCREF(__pyx_t_3); __pyx_t_13 = 0;
__pyx_t_14 = NULL;
} else {
__pyx_t_13 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 128, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_14 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 128, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
for (;;) {
if (likely(!__pyx_t_14)) {
if (likely(PyList_CheckExact(__pyx_t_3))) {
if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_3)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_7 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_13); __Pyx_INCREF(__pyx_t_7); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 128, __pyx_L1_error)
#else
__pyx_t_7 = PySequence_ITEM(__pyx_t_3, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 128, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
#endif
} else {
if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_13); __Pyx_INCREF(__pyx_t_7); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 128, __pyx_L1_error)
#else
__pyx_t_7 = PySequence_ITEM(__pyx_t_3, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 128, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
#endif
}
} else {
__pyx_t_7 = __pyx_t_14(__pyx_t_3);
if (unlikely(!__pyx_t_7)) {
PyObject* exc_type = PyErr_Occurred();
if (exc_type) {
if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
else __PYX_ERR(0, 128, __pyx_L1_error)
}
break;
}
__Pyx_GOTREF(__pyx_t_7);
}
__Pyx_XDECREF_SET(__pyx_v_c, __pyx_t_7);
__pyx_t_7 = 0;
/* "optimized_field_elements.pyx":129
* o[i] = (o[i] + temp[degb + i] * prime_field_inv(b[degb], field_modulus))
* for c in range(degb + 1):
* temp[c + i] = (temp[c + i] - o[c]) # <<<<<<<<<<<<<<
* return [x % field_modulus for x in o[:deg(o) + 1]]
*
*/
__pyx_t_7 = PyNumber_Add(__pyx_v_c, __pyx_v_i); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 129, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_temp, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 129, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_o, __pyx_v_c); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 129, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_4 = PyNumber_Subtract(__pyx_t_1, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 129, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_7 = PyNumber_Add(__pyx_v_c, __pyx_v_i); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 129, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
if (unlikely(PyObject_SetItem(__pyx_v_temp, __pyx_t_7, __pyx_t_4) < 0)) __PYX_ERR(0, 129, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":128
* for i in range(dega - degb, -1, -1):
* o[i] = (o[i] + temp[degb + i] * prime_field_inv(b[degb], field_modulus))
* for c in range(degb + 1): # <<<<<<<<<<<<<<
* temp[c + i] = (temp[c + i] - o[c])
* return [x % field_modulus for x in o[:deg(o) + 1]]
*/
}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
/* "optimized_field_elements.pyx":126
* temp = [x for x in a]
* o = [0 for x in a]
* for i in range(dega - degb, -1, -1): # <<<<<<<<<<<<<<
* o[i] = (o[i] + temp[degb + i] * prime_field_inv(b[degb], field_modulus))
* for c in range(degb + 1):
*/
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
/* "optimized_field_elements.pyx":130
* for c in range(degb + 1):
* temp[c + i] = (temp[c + i] - o[c])
* return [x % field_modulus for x in o[:deg(o) + 1]] # <<<<<<<<<<<<<<
*
*
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 130, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_deg); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 130, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_7 = NULL;
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
__pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4);
if (likely(__pyx_t_7)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
__Pyx_INCREF(__pyx_t_7);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_4, function);
}
}
if (!__pyx_t_7) {
__pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_o); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 130, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_4)) {
PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_o};
__pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 130, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
__Pyx_GOTREF(__pyx_t_3);
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_o};
__pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 130, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
__Pyx_GOTREF(__pyx_t_3);
} else
#endif
{
__pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 130, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7); __pyx_t_7 = NULL;
__Pyx_INCREF(__pyx_v_o);
__Pyx_GIVEREF(__pyx_v_o);
PyTuple_SET_ITEM(__pyx_t_1, 0+1, __pyx_v_o);
__pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 130, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 130, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 130, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = __Pyx_PyList_GetSlice(__pyx_v_o, 0, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 130, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_3 = __pyx_t_4; __Pyx_INCREF(__pyx_t_3); __pyx_t_5 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
for (;;) {
if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_3)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_4 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 130, __pyx_L1_error)
#else
__pyx_t_4 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 130, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
#endif
__Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_4);
__pyx_t_4 = 0;
__pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_field_modulus); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 130, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_1 = PyNumber_Remainder(__pyx_v_x, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 130, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_1))) __PYX_ERR(0, 130, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_r = __pyx_t_2;
__pyx_t_2 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":121
*
*
* def poly_rounded_div(a, b): # <<<<<<<<<<<<<<
* dega = deg(a)
* degb = deg(b)
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_XDECREF(__pyx_t_8);
__Pyx_XDECREF(__pyx_t_9);
__Pyx_XDECREF(__pyx_t_10);
__Pyx_XDECREF(__pyx_t_12);
__Pyx_AddTraceback("optimized_field_elements.poly_rounded_div", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_dega);
__Pyx_XDECREF(__pyx_v_degb);
__Pyx_XDECREF(__pyx_v_temp);
__Pyx_XDECREF(__pyx_v_o);
__Pyx_XDECREF(__pyx_v_i);
__Pyx_XDECREF(__pyx_v_c);
__Pyx_XDECREF(__pyx_v_x);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":135
* # A class for elements in polynomial extension fields
* class FQP(object):
* def __init__(self, coeffs, modulus_coeffs): # <<<<<<<<<<<<<<
* assert len(coeffs) == len(modulus_coeffs)
* self.coeffs = coeffs
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_3FQP_1__init__ = {"__init__", (PyCFunction)__pyx_pw_24optimized_field_elements_3FQP_1__init__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_coeffs = 0;
PyObject *__pyx_v_modulus_coeffs = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_coeffs,&__pyx_n_s_modulus_coeffs,0};
PyObject* values[3] = {0,0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_coeffs)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, 1); __PYX_ERR(0, 135, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 2:
if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_modulus_coeffs)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, 2); __PYX_ERR(0, 135, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 135, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
}
__pyx_v_self = values[0];
__pyx_v_coeffs = values[1];
__pyx_v_modulus_coeffs = values[2];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 135, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQP.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_3FQP___init__(__pyx_self, __pyx_v_self, __pyx_v_coeffs, __pyx_v_modulus_coeffs);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_3FQP___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_coeffs, PyObject *__pyx_v_modulus_coeffs) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
Py_ssize_t __pyx_t_1;
Py_ssize_t __pyx_t_2;
PyObject *__pyx_t_3 = NULL;
__Pyx_RefNannySetupContext("__init__", 0);
/* "optimized_field_elements.pyx":136
* class FQP(object):
* def __init__(self, coeffs, modulus_coeffs):
* assert len(coeffs) == len(modulus_coeffs) # <<<<<<<<<<<<<<
* self.coeffs = coeffs
* # The coefficients of the modulus, without the leading [1]
*/
#ifndef CYTHON_WITHOUT_ASSERTIONS
if (unlikely(!Py_OptimizeFlag)) {
__pyx_t_1 = PyObject_Length(__pyx_v_coeffs); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 136, __pyx_L1_error)
__pyx_t_2 = PyObject_Length(__pyx_v_modulus_coeffs); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 136, __pyx_L1_error)
if (unlikely(!((__pyx_t_1 == __pyx_t_2) != 0))) {
PyErr_SetNone(PyExc_AssertionError);
__PYX_ERR(0, 136, __pyx_L1_error)
}
}
#endif
/* "optimized_field_elements.pyx":137
* def __init__(self, coeffs, modulus_coeffs):
* assert len(coeffs) == len(modulus_coeffs)
* self.coeffs = coeffs # <<<<<<<<<<<<<<
* # The coefficients of the modulus, without the leading [1]
* self.modulus_coeffs = modulus_coeffs
*/
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_coeffs, __pyx_v_coeffs) < 0) __PYX_ERR(0, 137, __pyx_L1_error)
/* "optimized_field_elements.pyx":139
* self.coeffs = coeffs
* # The coefficients of the modulus, without the leading [1]
* self.modulus_coeffs = modulus_coeffs # <<<<<<<<<<<<<<
* # The degree of the extension field
* self.degree = len(self.modulus_coeffs)
*/
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_modulus_coeffs, __pyx_v_modulus_coeffs) < 0) __PYX_ERR(0, 139, __pyx_L1_error)
/* "optimized_field_elements.pyx":141
* self.modulus_coeffs = modulus_coeffs
* # The degree of the extension field
* self.degree = len(self.modulus_coeffs) # <<<<<<<<<<<<<<
*
* def __add__(self, other):
*/
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_modulus_coeffs); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 141, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_2 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 141, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_3 = PyInt_FromSsize_t(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 141, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_degree, __pyx_t_3) < 0) __PYX_ERR(0, 141, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
/* "optimized_field_elements.pyx":135
* # A class for elements in polynomial extension fields
* class FQP(object):
* def __init__(self, coeffs, modulus_coeffs): # <<<<<<<<<<<<<<
* assert len(coeffs) == len(modulus_coeffs)
* self.coeffs = coeffs
*/
/* function exit code */
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_3);
__Pyx_AddTraceback("optimized_field_elements.FQP.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":143
* self.degree = len(self.modulus_coeffs)
*
* def __add__(self, other): # <<<<<<<<<<<<<<
* assert isinstance(other, self.__class__)
* return self.__class__([
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_3__add__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_3FQP_3__add__ = {"__add__", (PyCFunction)__pyx_pw_24optimized_field_elements_3FQP_3__add__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_3__add__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_other = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__add__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__add__", 1, 2, 2, 1); __PYX_ERR(0, 143, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__add__") < 0)) __PYX_ERR(0, 143, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_other = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__add__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 143, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQP.__add__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_3FQP_2__add__(__pyx_self, __pyx_v_self, __pyx_v_other);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_2__add__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
PyObject *__pyx_v_x = NULL;
PyObject *__pyx_v_y = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
int __pyx_t_2;
PyObject *__pyx_t_3 = NULL;
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
PyObject *__pyx_t_6 = NULL;
PyObject *__pyx_t_7 = NULL;
Py_ssize_t __pyx_t_8;
PyObject *(*__pyx_t_9)(PyObject *);
PyObject *__pyx_t_10 = NULL;
PyObject *__pyx_t_11 = NULL;
PyObject *(*__pyx_t_12)(PyObject *);
__Pyx_RefNannySetupContext("__add__", 0);
/* "optimized_field_elements.pyx":144
*
* def __add__(self, other):
* assert isinstance(other, self.__class__) # <<<<<<<<<<<<<<
* return self.__class__([
* (x + y) % field_modulus
*/
#ifndef CYTHON_WITHOUT_ASSERTIONS
if (unlikely(!Py_OptimizeFlag)) {
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_class); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 144, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PyObject_IsInstance(__pyx_v_other, __pyx_t_1); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 144, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (unlikely(!(__pyx_t_2 != 0))) {
PyErr_SetNone(PyExc_AssertionError);
__PYX_ERR(0, 144, __pyx_L1_error)
}
}
#endif
/* "optimized_field_elements.pyx":145
* def __add__(self, other):
* assert isinstance(other, self.__class__)
* return self.__class__([ # <<<<<<<<<<<<<<
* (x + y) % field_modulus
* for x, y
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_class); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 145, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 145, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
/* "optimized_field_elements.pyx":148
* (x + y) % field_modulus
* for x, y
* in zip(self.coeffs, other.coeffs) # <<<<<<<<<<<<<<
* ])
*
*/
__pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_coeffs); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 148, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_coeffs); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 148, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 148, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_GIVEREF(__pyx_t_5);
PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5);
__Pyx_GIVEREF(__pyx_t_6);
PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
__pyx_t_5 = 0;
__pyx_t_6 = 0;
__pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_7, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 148, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
if (likely(PyList_CheckExact(__pyx_t_6)) || PyTuple_CheckExact(__pyx_t_6)) {
__pyx_t_7 = __pyx_t_6; __Pyx_INCREF(__pyx_t_7); __pyx_t_8 = 0;
__pyx_t_9 = NULL;
} else {
__pyx_t_8 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 148, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_9 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 148, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
for (;;) {
if (likely(!__pyx_t_9)) {
if (likely(PyList_CheckExact(__pyx_t_7))) {
if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_7)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_6 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_8); __Pyx_INCREF(__pyx_t_6); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 148, __pyx_L1_error)
#else
__pyx_t_6 = PySequence_ITEM(__pyx_t_7, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 148, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
#endif
} else {
if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_8); __Pyx_INCREF(__pyx_t_6); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 148, __pyx_L1_error)
#else
__pyx_t_6 = PySequence_ITEM(__pyx_t_7, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 148, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
#endif
}
} else {
__pyx_t_6 = __pyx_t_9(__pyx_t_7);
if (unlikely(!__pyx_t_6)) {
PyObject* exc_type = PyErr_Occurred();
if (exc_type) {
if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
else __PYX_ERR(0, 148, __pyx_L1_error)
}
break;
}
__Pyx_GOTREF(__pyx_t_6);
}
if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) {
PyObject* sequence = __pyx_t_6;
Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
if (unlikely(size != 2)) {
if (size > 2) __Pyx_RaiseTooManyValuesError(2);
else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
__PYX_ERR(0, 147, __pyx_L1_error)
}
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
if (likely(PyTuple_CheckExact(sequence))) {
__pyx_t_5 = PyTuple_GET_ITEM(sequence, 0);
__pyx_t_10 = PyTuple_GET_ITEM(sequence, 1);
} else {
__pyx_t_5 = PyList_GET_ITEM(sequence, 0);
__pyx_t_10 = PyList_GET_ITEM(sequence, 1);
}
__Pyx_INCREF(__pyx_t_5);
__Pyx_INCREF(__pyx_t_10);
#else
__pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 147, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 147, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_10);
#endif
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
} else {
Py_ssize_t index = -1;
__pyx_t_11 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 147, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_11);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext;
index = 0; __pyx_t_5 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_5)) goto __pyx_L5_unpacking_failed;
__Pyx_GOTREF(__pyx_t_5);
index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L5_unpacking_failed;
__Pyx_GOTREF(__pyx_t_10);
if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) __PYX_ERR(0, 147, __pyx_L1_error)
__pyx_t_12 = NULL;
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
goto __pyx_L6_unpacking_done;
__pyx_L5_unpacking_failed:;
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
__pyx_t_12 = NULL;
if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
__PYX_ERR(0, 147, __pyx_L1_error)
__pyx_L6_unpacking_done:;
}
/* "optimized_field_elements.pyx":147
* return self.__class__([
* (x + y) % field_modulus
* for x, y # <<<<<<<<<<<<<<
* in zip(self.coeffs, other.coeffs)
* ])
*/
__Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_5);
__pyx_t_5 = 0;
__Pyx_XDECREF_SET(__pyx_v_y, __pyx_t_10);
__pyx_t_10 = 0;
/* "optimized_field_elements.pyx":146
* assert isinstance(other, self.__class__)
* return self.__class__([
* (x + y) % field_modulus # <<<<<<<<<<<<<<
* for x, y
* in zip(self.coeffs, other.coeffs)
*/
__pyx_t_6 = PyNumber_Add(__pyx_v_x, __pyx_v_y); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 146, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_field_modulus); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 146, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_10);
__pyx_t_5 = PyNumber_Remainder(__pyx_t_6, __pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 146, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
if (unlikely(__Pyx_ListComp_Append(__pyx_t_4, (PyObject*)__pyx_t_5))) __PYX_ERR(0, 145, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
/* "optimized_field_elements.pyx":147
* return self.__class__([
* (x + y) % field_modulus
* for x, y # <<<<<<<<<<<<<<
* in zip(self.coeffs, other.coeffs)
* ])
*/
}
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_7 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
__pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3);
if (likely(__pyx_t_7)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
__Pyx_INCREF(__pyx_t_7);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_3, function);
}
}
if (!__pyx_t_7) {
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 145, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_3)) {
PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_4};
__pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 145, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_4};
__pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 145, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
} else
#endif
{
__pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 145, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7); __pyx_t_7 = NULL;
__Pyx_GIVEREF(__pyx_t_4);
PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_4);
__pyx_t_4 = 0;
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 145, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
}
}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":143
* self.degree = len(self.modulus_coeffs)
*
* def __add__(self, other): # <<<<<<<<<<<<<<
* assert isinstance(other, self.__class__)
* return self.__class__([
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_XDECREF(__pyx_t_10);
__Pyx_XDECREF(__pyx_t_11);
__Pyx_AddTraceback("optimized_field_elements.FQP.__add__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_x);
__Pyx_XDECREF(__pyx_v_y);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":151
* ])
*
* def __sub__(self, other): # <<<<<<<<<<<<<<
* assert isinstance(other, self.__class__)
* return self.__class__([
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_5__sub__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_3FQP_5__sub__ = {"__sub__", (PyCFunction)__pyx_pw_24optimized_field_elements_3FQP_5__sub__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_5__sub__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_other = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__sub__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__sub__", 1, 2, 2, 1); __PYX_ERR(0, 151, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__sub__") < 0)) __PYX_ERR(0, 151, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_other = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__sub__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 151, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQP.__sub__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_3FQP_4__sub__(__pyx_self, __pyx_v_self, __pyx_v_other);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_4__sub__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
PyObject *__pyx_v_x = NULL;
PyObject *__pyx_v_y = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
int __pyx_t_2;
PyObject *__pyx_t_3 = NULL;
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
PyObject *__pyx_t_6 = NULL;
PyObject *__pyx_t_7 = NULL;
Py_ssize_t __pyx_t_8;
PyObject *(*__pyx_t_9)(PyObject *);
PyObject *__pyx_t_10 = NULL;
PyObject *__pyx_t_11 = NULL;
PyObject *(*__pyx_t_12)(PyObject *);
__Pyx_RefNannySetupContext("__sub__", 0);
/* "optimized_field_elements.pyx":152
*
* def __sub__(self, other):
* assert isinstance(other, self.__class__) # <<<<<<<<<<<<<<
* return self.__class__([
* (x - y) % field_modulus
*/
#ifndef CYTHON_WITHOUT_ASSERTIONS
if (unlikely(!Py_OptimizeFlag)) {
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_class); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 152, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PyObject_IsInstance(__pyx_v_other, __pyx_t_1); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 152, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (unlikely(!(__pyx_t_2 != 0))) {
PyErr_SetNone(PyExc_AssertionError);
__PYX_ERR(0, 152, __pyx_L1_error)
}
}
#endif
/* "optimized_field_elements.pyx":153
* def __sub__(self, other):
* assert isinstance(other, self.__class__)
* return self.__class__([ # <<<<<<<<<<<<<<
* (x - y) % field_modulus
* for x, y
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_class); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 153, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 153, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
/* "optimized_field_elements.pyx":156
* (x - y) % field_modulus
* for x, y
* in zip(self.coeffs, other.coeffs) # <<<<<<<<<<<<<<
* ])
*
*/
__pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_coeffs); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 156, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_coeffs); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 156, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 156, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_GIVEREF(__pyx_t_5);
PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5);
__Pyx_GIVEREF(__pyx_t_6);
PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
__pyx_t_5 = 0;
__pyx_t_6 = 0;
__pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_7, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 156, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
if (likely(PyList_CheckExact(__pyx_t_6)) || PyTuple_CheckExact(__pyx_t_6)) {
__pyx_t_7 = __pyx_t_6; __Pyx_INCREF(__pyx_t_7); __pyx_t_8 = 0;
__pyx_t_9 = NULL;
} else {
__pyx_t_8 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 156, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_9 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 156, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
for (;;) {
if (likely(!__pyx_t_9)) {
if (likely(PyList_CheckExact(__pyx_t_7))) {
if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_7)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_6 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_8); __Pyx_INCREF(__pyx_t_6); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 156, __pyx_L1_error)
#else
__pyx_t_6 = PySequence_ITEM(__pyx_t_7, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 156, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
#endif
} else {
if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_8); __Pyx_INCREF(__pyx_t_6); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 156, __pyx_L1_error)
#else
__pyx_t_6 = PySequence_ITEM(__pyx_t_7, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 156, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
#endif
}
} else {
__pyx_t_6 = __pyx_t_9(__pyx_t_7);
if (unlikely(!__pyx_t_6)) {
PyObject* exc_type = PyErr_Occurred();
if (exc_type) {
if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
else __PYX_ERR(0, 156, __pyx_L1_error)
}
break;
}
__Pyx_GOTREF(__pyx_t_6);
}
if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) {
PyObject* sequence = __pyx_t_6;
Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
if (unlikely(size != 2)) {
if (size > 2) __Pyx_RaiseTooManyValuesError(2);
else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
__PYX_ERR(0, 155, __pyx_L1_error)
}
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
if (likely(PyTuple_CheckExact(sequence))) {
__pyx_t_5 = PyTuple_GET_ITEM(sequence, 0);
__pyx_t_10 = PyTuple_GET_ITEM(sequence, 1);
} else {
__pyx_t_5 = PyList_GET_ITEM(sequence, 0);
__pyx_t_10 = PyList_GET_ITEM(sequence, 1);
}
__Pyx_INCREF(__pyx_t_5);
__Pyx_INCREF(__pyx_t_10);
#else
__pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 155, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 155, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_10);
#endif
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
} else {
Py_ssize_t index = -1;
__pyx_t_11 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 155, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_11);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext;
index = 0; __pyx_t_5 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_5)) goto __pyx_L5_unpacking_failed;
__Pyx_GOTREF(__pyx_t_5);
index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L5_unpacking_failed;
__Pyx_GOTREF(__pyx_t_10);
if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) __PYX_ERR(0, 155, __pyx_L1_error)
__pyx_t_12 = NULL;
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
goto __pyx_L6_unpacking_done;
__pyx_L5_unpacking_failed:;
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
__pyx_t_12 = NULL;
if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
__PYX_ERR(0, 155, __pyx_L1_error)
__pyx_L6_unpacking_done:;
}
/* "optimized_field_elements.pyx":155
* return self.__class__([
* (x - y) % field_modulus
* for x, y # <<<<<<<<<<<<<<
* in zip(self.coeffs, other.coeffs)
* ])
*/
__Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_5);
__pyx_t_5 = 0;
__Pyx_XDECREF_SET(__pyx_v_y, __pyx_t_10);
__pyx_t_10 = 0;
/* "optimized_field_elements.pyx":154
* assert isinstance(other, self.__class__)
* return self.__class__([
* (x - y) % field_modulus # <<<<<<<<<<<<<<
* for x, y
* in zip(self.coeffs, other.coeffs)
*/
__pyx_t_6 = PyNumber_Subtract(__pyx_v_x, __pyx_v_y); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 154, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_field_modulus); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 154, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_10);
__pyx_t_5 = PyNumber_Remainder(__pyx_t_6, __pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 154, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
if (unlikely(__Pyx_ListComp_Append(__pyx_t_4, (PyObject*)__pyx_t_5))) __PYX_ERR(0, 153, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
/* "optimized_field_elements.pyx":155
* return self.__class__([
* (x - y) % field_modulus
* for x, y # <<<<<<<<<<<<<<
* in zip(self.coeffs, other.coeffs)
* ])
*/
}
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_7 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
__pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3);
if (likely(__pyx_t_7)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
__Pyx_INCREF(__pyx_t_7);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_3, function);
}
}
if (!__pyx_t_7) {
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 153, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_3)) {
PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_4};
__pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 153, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_4};
__pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 153, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
} else
#endif
{
__pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 153, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7); __pyx_t_7 = NULL;
__Pyx_GIVEREF(__pyx_t_4);
PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_4);
__pyx_t_4 = 0;
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 153, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
}
}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":151
* ])
*
* def __sub__(self, other): # <<<<<<<<<<<<<<
* assert isinstance(other, self.__class__)
* return self.__class__([
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_XDECREF(__pyx_t_10);
__Pyx_XDECREF(__pyx_t_11);
__Pyx_AddTraceback("optimized_field_elements.FQP.__sub__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_x);
__Pyx_XDECREF(__pyx_v_y);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":159
* ])
*
* def __mul__(self, other): # <<<<<<<<<<<<<<
* if isinstance(other, int_types):
* return self.__class__([c * other % field_modulus for c in self.coeffs])
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_7__mul__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_3FQP_7__mul__ = {"__mul__", (PyCFunction)__pyx_pw_24optimized_field_elements_3FQP_7__mul__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_7__mul__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_other = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__mul__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__mul__", 1, 2, 2, 1); __PYX_ERR(0, 159, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__mul__") < 0)) __PYX_ERR(0, 159, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_other = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__mul__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 159, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQP.__mul__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_3FQP_6__mul__(__pyx_self, __pyx_v_self, __pyx_v_other);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_6__mul__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
PyObject *__pyx_v_b = NULL;
PyObject *__pyx_v_inner_enumerate = NULL;
PyObject *__pyx_v_i = NULL;
PyObject *__pyx_v_eli = NULL;
PyObject *__pyx_v_j = NULL;
PyObject *__pyx_v_elj = NULL;
PyObject *__pyx_v_exp = NULL;
PyObject *__pyx_v_top = NULL;
PyObject *__pyx_v_c = NULL;
PyObject *__pyx_v_x = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
int __pyx_t_2;
int __pyx_t_3;
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
PyObject *__pyx_t_6 = NULL;
PyObject *__pyx_t_7 = NULL;
Py_ssize_t __pyx_t_8;
PyObject *(*__pyx_t_9)(PyObject *);
PyObject *__pyx_t_10 = NULL;
PyObject *__pyx_t_11 = NULL;
Py_ssize_t __pyx_t_12;
PyObject *(*__pyx_t_13)(PyObject *);
PyObject *(*__pyx_t_14)(PyObject *);
__Pyx_RefNannySetupContext("__mul__", 0);
/* "optimized_field_elements.pyx":160
*
* def __mul__(self, other):
* if isinstance(other, int_types): # <<<<<<<<<<<<<<
* return self.__class__([c * other % field_modulus for c in self.coeffs])
* else:
*/
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_int_types); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 160, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PyObject_IsInstance(__pyx_v_other, __pyx_t_1); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 160, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_3 = (__pyx_t_2 != 0);
if (__pyx_t_3) {
/* "optimized_field_elements.pyx":161
* def __mul__(self, other):
* if isinstance(other, int_types):
* return self.__class__([c * other % field_modulus for c in self.coeffs]) # <<<<<<<<<<<<<<
* else:
* # assert isinstance(other, self.__class__)
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_class); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 161, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 161, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_coeffs); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 161, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
if (likely(PyList_CheckExact(__pyx_t_6)) || PyTuple_CheckExact(__pyx_t_6)) {
__pyx_t_7 = __pyx_t_6; __Pyx_INCREF(__pyx_t_7); __pyx_t_8 = 0;
__pyx_t_9 = NULL;
} else {
__pyx_t_8 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 161, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_9 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 161, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
for (;;) {
if (likely(!__pyx_t_9)) {
if (likely(PyList_CheckExact(__pyx_t_7))) {
if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_7)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_6 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_8); __Pyx_INCREF(__pyx_t_6); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 161, __pyx_L1_error)
#else
__pyx_t_6 = PySequence_ITEM(__pyx_t_7, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 161, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
#endif
} else {
if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_8); __Pyx_INCREF(__pyx_t_6); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 161, __pyx_L1_error)
#else
__pyx_t_6 = PySequence_ITEM(__pyx_t_7, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 161, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
#endif
}
} else {
__pyx_t_6 = __pyx_t_9(__pyx_t_7);
if (unlikely(!__pyx_t_6)) {
PyObject* exc_type = PyErr_Occurred();
if (exc_type) {
if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
else __PYX_ERR(0, 161, __pyx_L1_error)
}
break;
}
__Pyx_GOTREF(__pyx_t_6);
}
__Pyx_XDECREF_SET(__pyx_v_c, __pyx_t_6);
__pyx_t_6 = 0;
__pyx_t_6 = PyNumber_Multiply(__pyx_v_c, __pyx_v_other); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 161, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_field_modulus); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 161, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_10);
__pyx_t_11 = PyNumber_Remainder(__pyx_t_6, __pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 161, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_11);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
if (unlikely(__Pyx_ListComp_Append(__pyx_t_5, (PyObject*)__pyx_t_11))) __PYX_ERR(0, 161, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
}
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_7 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
__pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4);
if (likely(__pyx_t_7)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
__Pyx_INCREF(__pyx_t_7);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_4, function);
}
}
if (!__pyx_t_7) {
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 161, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_4)) {
PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_5};
__pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 161, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_5};
__pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 161, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
} else
#endif
{
__pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 161, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_11);
__Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_7); __pyx_t_7 = NULL;
__Pyx_GIVEREF(__pyx_t_5);
PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_t_5);
__pyx_t_5 = 0;
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_11, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 161, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
}
}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":160
*
* def __mul__(self, other):
* if isinstance(other, int_types): # <<<<<<<<<<<<<<
* return self.__class__([c * other % field_modulus for c in self.coeffs])
* else:
*/
}
/* "optimized_field_elements.pyx":164
* else:
* # assert isinstance(other, self.__class__)
* b = [0] * (self.degree * 2 - 1) # <<<<<<<<<<<<<<
* inner_enumerate = list(enumerate(other.coeffs))
* for i, eli in enumerate(self.coeffs):
*/
/*else*/ {
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_degree); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 164, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_4 = PyNumber_Multiply(__pyx_t_1, __pyx_int_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 164, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_1 = __Pyx_PyInt_SubtractObjC(__pyx_t_4, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 164, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 164, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_INCREF(__pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
PyList_SET_ITEM(__pyx_t_4, 0, __pyx_int_0);
{ PyObject* __pyx_temp = PyNumber_InPlaceMultiply(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_temp)) __PYX_ERR(0, 164, __pyx_L1_error)
__Pyx_GOTREF(__pyx_temp);
__Pyx_DECREF(__pyx_t_4);
__pyx_t_4 = __pyx_temp;
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_b = ((PyObject*)__pyx_t_4);
__pyx_t_4 = 0;
/* "optimized_field_elements.pyx":165
* # assert isinstance(other, self.__class__)
* b = [0] * (self.degree * 2 - 1)
* inner_enumerate = list(enumerate(other.coeffs)) # <<<<<<<<<<<<<<
* for i, eli in enumerate(self.coeffs):
* for j, elj in inner_enumerate:
*/
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_coeffs); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 165, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_enumerate, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 165, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 165, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_inner_enumerate = ((PyObject*)__pyx_t_4);
__pyx_t_4 = 0;
/* "optimized_field_elements.pyx":166
* b = [0] * (self.degree * 2 - 1)
* inner_enumerate = list(enumerate(other.coeffs))
* for i, eli in enumerate(self.coeffs): # <<<<<<<<<<<<<<
* for j, elj in inner_enumerate:
* b[i + j] += eli * elj
*/
__Pyx_INCREF(__pyx_int_0);
__pyx_t_4 = __pyx_int_0;
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_coeffs); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 166, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
__pyx_t_11 = __pyx_t_1; __Pyx_INCREF(__pyx_t_11); __pyx_t_8 = 0;
__pyx_t_9 = NULL;
} else {
__pyx_t_8 = -1; __pyx_t_11 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 166, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_11);
__pyx_t_9 = Py_TYPE(__pyx_t_11)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 166, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
for (;;) {
if (likely(!__pyx_t_9)) {
if (likely(PyList_CheckExact(__pyx_t_11))) {
if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_11)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_1 = PyList_GET_ITEM(__pyx_t_11, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 166, __pyx_L1_error)
#else
__pyx_t_1 = PySequence_ITEM(__pyx_t_11, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 166, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
#endif
} else {
if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_11)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_11, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 166, __pyx_L1_error)
#else
__pyx_t_1 = PySequence_ITEM(__pyx_t_11, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 166, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
#endif
}
} else {
__pyx_t_1 = __pyx_t_9(__pyx_t_11);
if (unlikely(!__pyx_t_1)) {
PyObject* exc_type = PyErr_Occurred();
if (exc_type) {
if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
else __PYX_ERR(0, 166, __pyx_L1_error)
}
break;
}
__Pyx_GOTREF(__pyx_t_1);
}
__Pyx_XDECREF_SET(__pyx_v_eli, __pyx_t_1);
__pyx_t_1 = 0;
__Pyx_INCREF(__pyx_t_4);
__Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_4);
__pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_t_4, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 166, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_4);
__pyx_t_4 = __pyx_t_1;
__pyx_t_1 = 0;
/* "optimized_field_elements.pyx":167
* inner_enumerate = list(enumerate(other.coeffs))
* for i, eli in enumerate(self.coeffs):
* for j, elj in inner_enumerate: # <<<<<<<<<<<<<<
* b[i + j] += eli * elj
* # MID = len(self.coeffs) // 2
*/
__pyx_t_1 = __pyx_v_inner_enumerate; __Pyx_INCREF(__pyx_t_1); __pyx_t_12 = 0;
for (;;) {
if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_1)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_12); __Pyx_INCREF(__pyx_t_5); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 167, __pyx_L1_error)
#else
__pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 167, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
#endif
if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) {
PyObject* sequence = __pyx_t_5;
Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
if (unlikely(size != 2)) {
if (size > 2) __Pyx_RaiseTooManyValuesError(2);
else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
__PYX_ERR(0, 167, __pyx_L1_error)
}
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
if (likely(PyTuple_CheckExact(sequence))) {
__pyx_t_7 = PyTuple_GET_ITEM(sequence, 0);
__pyx_t_10 = PyTuple_GET_ITEM(sequence, 1);
} else {
__pyx_t_7 = PyList_GET_ITEM(sequence, 0);
__pyx_t_10 = PyList_GET_ITEM(sequence, 1);
}
__Pyx_INCREF(__pyx_t_7);
__Pyx_INCREF(__pyx_t_10);
#else
__pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 167, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 167, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_10);
#endif
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
} else {
Py_ssize_t index = -1;
__pyx_t_6 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 167, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_t_13 = Py_TYPE(__pyx_t_6)->tp_iternext;
index = 0; __pyx_t_7 = __pyx_t_13(__pyx_t_6); if (unlikely(!__pyx_t_7)) goto __pyx_L10_unpacking_failed;
__Pyx_GOTREF(__pyx_t_7);
index = 1; __pyx_t_10 = __pyx_t_13(__pyx_t_6); if (unlikely(!__pyx_t_10)) goto __pyx_L10_unpacking_failed;
__Pyx_GOTREF(__pyx_t_10);
if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_6), 2) < 0) __PYX_ERR(0, 167, __pyx_L1_error)
__pyx_t_13 = NULL;
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
goto __pyx_L11_unpacking_done;
__pyx_L10_unpacking_failed:;
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__pyx_t_13 = NULL;
if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
__PYX_ERR(0, 167, __pyx_L1_error)
__pyx_L11_unpacking_done:;
}
__Pyx_XDECREF_SET(__pyx_v_j, __pyx_t_7);
__pyx_t_7 = 0;
__Pyx_XDECREF_SET(__pyx_v_elj, __pyx_t_10);
__pyx_t_10 = 0;
/* "optimized_field_elements.pyx":168
* for i, eli in enumerate(self.coeffs):
* for j, elj in inner_enumerate:
* b[i + j] += eli * elj # <<<<<<<<<<<<<<
* # MID = len(self.coeffs) // 2
* for exp in range(self.degree - 2, -1, -1):
*/
__pyx_t_5 = PyNumber_Add(__pyx_v_i, __pyx_v_j); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 168, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_10 = __Pyx_PyObject_GetItem(__pyx_v_b, __pyx_t_5); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 168, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_10);
__pyx_t_7 = PyNumber_Multiply(__pyx_v_eli, __pyx_v_elj); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 168, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_6 = PyNumber_InPlaceAdd(__pyx_t_10, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 168, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
if (unlikely(PyObject_SetItem(__pyx_v_b, __pyx_t_5, __pyx_t_6) < 0)) __PYX_ERR(0, 168, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
/* "optimized_field_elements.pyx":167
* inner_enumerate = list(enumerate(other.coeffs))
* for i, eli in enumerate(self.coeffs):
* for j, elj in inner_enumerate: # <<<<<<<<<<<<<<
* b[i + j] += eli * elj
* # MID = len(self.coeffs) // 2
*/
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/* "optimized_field_elements.pyx":166
* b = [0] * (self.degree * 2 - 1)
* inner_enumerate = list(enumerate(other.coeffs))
* for i, eli in enumerate(self.coeffs): # <<<<<<<<<<<<<<
* for j, elj in inner_enumerate:
* b[i + j] += eli * elj
*/
}
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":170
* b[i + j] += eli * elj
* # MID = len(self.coeffs) // 2
* for exp in range(self.degree - 2, -1, -1): # <<<<<<<<<<<<<<
* top = b.pop()
* for i, c in self.mc_tuples:
*/
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_degree); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 170, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_11 = __Pyx_PyInt_SubtractObjC(__pyx_t_4, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 170, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_11);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 170, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_GIVEREF(__pyx_t_11);
PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_11);
__Pyx_INCREF(__pyx_int_neg_1);
__Pyx_GIVEREF(__pyx_int_neg_1);
PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_neg_1);
__Pyx_INCREF(__pyx_int_neg_1);
__Pyx_GIVEREF(__pyx_int_neg_1);
PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_int_neg_1);
__pyx_t_11 = 0;
__pyx_t_11 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_4, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 170, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_11);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
if (likely(PyList_CheckExact(__pyx_t_11)) || PyTuple_CheckExact(__pyx_t_11)) {
__pyx_t_4 = __pyx_t_11; __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0;
__pyx_t_9 = NULL;
} else {
__pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 170, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 170, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
for (;;) {
if (likely(!__pyx_t_9)) {
if (likely(PyList_CheckExact(__pyx_t_4))) {
if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_11 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_11); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 170, __pyx_L1_error)
#else
__pyx_t_11 = PySequence_ITEM(__pyx_t_4, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 170, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_11);
#endif
} else {
if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_11 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_11); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 170, __pyx_L1_error)
#else
__pyx_t_11 = PySequence_ITEM(__pyx_t_4, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 170, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_11);
#endif
}
} else {
__pyx_t_11 = __pyx_t_9(__pyx_t_4);
if (unlikely(!__pyx_t_11)) {
PyObject* exc_type = PyErr_Occurred();
if (exc_type) {
if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
else __PYX_ERR(0, 170, __pyx_L1_error)
}
break;
}
__Pyx_GOTREF(__pyx_t_11);
}
__Pyx_XDECREF_SET(__pyx_v_exp, __pyx_t_11);
__pyx_t_11 = 0;
/* "optimized_field_elements.pyx":171
* # MID = len(self.coeffs) // 2
* for exp in range(self.degree - 2, -1, -1):
* top = b.pop() # <<<<<<<<<<<<<<
* for i, c in self.mc_tuples:
* b[exp + i] -= top * c
*/
__pyx_t_11 = __Pyx_PyList_Pop(__pyx_v_b); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 171, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_11);
__Pyx_XDECREF_SET(__pyx_v_top, __pyx_t_11);
__pyx_t_11 = 0;
/* "optimized_field_elements.pyx":172
* for exp in range(self.degree - 2, -1, -1):
* top = b.pop()
* for i, c in self.mc_tuples: # <<<<<<<<<<<<<<
* b[exp + i] -= top * c
* return self.__class__([x % field_modulus for x in b])
*/
__pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_mc_tuples); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 172, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_11);
if (likely(PyList_CheckExact(__pyx_t_11)) || PyTuple_CheckExact(__pyx_t_11)) {
__pyx_t_1 = __pyx_t_11; __Pyx_INCREF(__pyx_t_1); __pyx_t_12 = 0;
__pyx_t_14 = NULL;
} else {
__pyx_t_12 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 172, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_14 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 172, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
for (;;) {
if (likely(!__pyx_t_14)) {
if (likely(PyList_CheckExact(__pyx_t_1))) {
if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_1)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_11 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_12); __Pyx_INCREF(__pyx_t_11); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 172, __pyx_L1_error)
#else
__pyx_t_11 = PySequence_ITEM(__pyx_t_1, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 172, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_11);
#endif
} else {
if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_11 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_12); __Pyx_INCREF(__pyx_t_11); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 172, __pyx_L1_error)
#else
__pyx_t_11 = PySequence_ITEM(__pyx_t_1, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 172, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_11);
#endif
}
} else {
__pyx_t_11 = __pyx_t_14(__pyx_t_1);
if (unlikely(!__pyx_t_11)) {
PyObject* exc_type = PyErr_Occurred();
if (exc_type) {
if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
else __PYX_ERR(0, 172, __pyx_L1_error)
}
break;
}
__Pyx_GOTREF(__pyx_t_11);
}
if ((likely(PyTuple_CheckExact(__pyx_t_11))) || (PyList_CheckExact(__pyx_t_11))) {
PyObject* sequence = __pyx_t_11;
Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
if (unlikely(size != 2)) {
if (size > 2) __Pyx_RaiseTooManyValuesError(2);
else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
__PYX_ERR(0, 172, __pyx_L1_error)
}
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
if (likely(PyTuple_CheckExact(sequence))) {
__pyx_t_5 = PyTuple_GET_ITEM(sequence, 0);
__pyx_t_6 = PyTuple_GET_ITEM(sequence, 1);
} else {
__pyx_t_5 = PyList_GET_ITEM(sequence, 0);
__pyx_t_6 = PyList_GET_ITEM(sequence, 1);
}
__Pyx_INCREF(__pyx_t_5);
__Pyx_INCREF(__pyx_t_6);
#else
__pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 172, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 172, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
#endif
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
} else {
Py_ssize_t index = -1;
__pyx_t_7 = PyObject_GetIter(__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 172, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
__pyx_t_13 = Py_TYPE(__pyx_t_7)->tp_iternext;
index = 0; __pyx_t_5 = __pyx_t_13(__pyx_t_7); if (unlikely(!__pyx_t_5)) goto __pyx_L16_unpacking_failed;
__Pyx_GOTREF(__pyx_t_5);
index = 1; __pyx_t_6 = __pyx_t_13(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L16_unpacking_failed;
__Pyx_GOTREF(__pyx_t_6);
if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_7), 2) < 0) __PYX_ERR(0, 172, __pyx_L1_error)
__pyx_t_13 = NULL;
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
goto __pyx_L17_unpacking_done;
__pyx_L16_unpacking_failed:;
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_13 = NULL;
if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
__PYX_ERR(0, 172, __pyx_L1_error)
__pyx_L17_unpacking_done:;
}
__Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_5);
__pyx_t_5 = 0;
__Pyx_XDECREF_SET(__pyx_v_c, __pyx_t_6);
__pyx_t_6 = 0;
/* "optimized_field_elements.pyx":173
* top = b.pop()
* for i, c in self.mc_tuples:
* b[exp + i] -= top * c # <<<<<<<<<<<<<<
* return self.__class__([x % field_modulus for x in b])
*
*/
__pyx_t_11 = PyNumber_Add(__pyx_v_exp, __pyx_v_i); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 173, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_11);
__pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_v_b, __pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 173, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_5 = PyNumber_Multiply(__pyx_v_top, __pyx_v_c); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 173, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_7 = PyNumber_InPlaceSubtract(__pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 173, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
if (unlikely(PyObject_SetItem(__pyx_v_b, __pyx_t_11, __pyx_t_7) < 0)) __PYX_ERR(0, 173, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
/* "optimized_field_elements.pyx":172
* for exp in range(self.degree - 2, -1, -1):
* top = b.pop()
* for i, c in self.mc_tuples: # <<<<<<<<<<<<<<
* b[exp + i] -= top * c
* return self.__class__([x % field_modulus for x in b])
*/
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/* "optimized_field_elements.pyx":170
* b[i + j] += eli * elj
* # MID = len(self.coeffs) // 2
* for exp in range(self.degree - 2, -1, -1): # <<<<<<<<<<<<<<
* top = b.pop()
* for i, c in self.mc_tuples:
*/
}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":174
* for i, c in self.mc_tuples:
* b[exp + i] -= top * c
* return self.__class__([x % field_modulus for x in b]) # <<<<<<<<<<<<<<
*
* def __rmul__(self, other):
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_class); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 174, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_11 = PyList_New(0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 174, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_11);
__pyx_t_7 = __pyx_v_b; __Pyx_INCREF(__pyx_t_7); __pyx_t_8 = 0;
for (;;) {
if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_7)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_5 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_8); __Pyx_INCREF(__pyx_t_5); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 174, __pyx_L1_error)
#else
__pyx_t_5 = PySequence_ITEM(__pyx_t_7, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 174, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
#endif
__Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_5);
__pyx_t_5 = 0;
__pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_field_modulus); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 174, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_6 = PyNumber_Remainder(__pyx_v_x, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 174, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
if (unlikely(__Pyx_ListComp_Append(__pyx_t_11, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 174, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
}
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_7 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
__pyx_t_7 = PyMethod_GET_SELF(__pyx_t_1);
if (likely(__pyx_t_7)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
__Pyx_INCREF(__pyx_t_7);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_1, function);
}
}
if (!__pyx_t_7) {
__pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 174, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
__Pyx_GOTREF(__pyx_t_4);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_1)) {
PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_11};
__pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 174, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_11};
__pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 174, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
} else
#endif
{
__pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 174, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7); __pyx_t_7 = NULL;
__Pyx_GIVEREF(__pyx_t_11);
PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_11);
__pyx_t_11 = 0;
__pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 174, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
}
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_r = __pyx_t_4;
__pyx_t_4 = 0;
goto __pyx_L0;
}
/* "optimized_field_elements.pyx":159
* ])
*
* def __mul__(self, other): # <<<<<<<<<<<<<<
* if isinstance(other, int_types):
* return self.__class__([c * other % field_modulus for c in self.coeffs])
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_XDECREF(__pyx_t_10);
__Pyx_XDECREF(__pyx_t_11);
__Pyx_AddTraceback("optimized_field_elements.FQP.__mul__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_b);
__Pyx_XDECREF(__pyx_v_inner_enumerate);
__Pyx_XDECREF(__pyx_v_i);
__Pyx_XDECREF(__pyx_v_eli);
__Pyx_XDECREF(__pyx_v_j);
__Pyx_XDECREF(__pyx_v_elj);
__Pyx_XDECREF(__pyx_v_exp);
__Pyx_XDECREF(__pyx_v_top);
__Pyx_XDECREF(__pyx_v_c);
__Pyx_XDECREF(__pyx_v_x);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":176
* return self.__class__([x % field_modulus for x in b])
*
* def __rmul__(self, other): # <<<<<<<<<<<<<<
* return self * other
*
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_9__rmul__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_3FQP_9__rmul__ = {"__rmul__", (PyCFunction)__pyx_pw_24optimized_field_elements_3FQP_9__rmul__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_9__rmul__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_other = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__rmul__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__rmul__", 1, 2, 2, 1); __PYX_ERR(0, 176, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__rmul__") < 0)) __PYX_ERR(0, 176, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_other = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__rmul__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 176, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQP.__rmul__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_3FQP_8__rmul__(__pyx_self, __pyx_v_self, __pyx_v_other);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_8__rmul__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
__Pyx_RefNannySetupContext("__rmul__", 0);
/* "optimized_field_elements.pyx":177
*
* def __rmul__(self, other):
* return self * other # <<<<<<<<<<<<<<
*
* def __div__(self, other):
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = PyNumber_Multiply(__pyx_v_self, __pyx_v_other); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 177, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":176
* return self.__class__([x % field_modulus for x in b])
*
* def __rmul__(self, other): # <<<<<<<<<<<<<<
* return self * other
*
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("optimized_field_elements.FQP.__rmul__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":179
* return self * other
*
* def __div__(self, other): # <<<<<<<<<<<<<<
* if isinstance(other, int_types):
* return self.__class__([
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_11__div__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_3FQP_11__div__ = {"__div__", (PyCFunction)__pyx_pw_24optimized_field_elements_3FQP_11__div__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_11__div__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_other = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__div__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__div__", 1, 2, 2, 1); __PYX_ERR(0, 179, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__div__") < 0)) __PYX_ERR(0, 179, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_other = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__div__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 179, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQP.__div__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_3FQP_10__div__(__pyx_self, __pyx_v_self, __pyx_v_other);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_10__div__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
PyObject *__pyx_v_c = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
int __pyx_t_2;
int __pyx_t_3;
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
PyObject *__pyx_t_6 = NULL;
PyObject *__pyx_t_7 = NULL;
Py_ssize_t __pyx_t_8;
PyObject *(*__pyx_t_9)(PyObject *);
PyObject *__pyx_t_10 = NULL;
PyObject *__pyx_t_11 = NULL;
PyObject *__pyx_t_12 = NULL;
int __pyx_t_13;
PyObject *__pyx_t_14 = NULL;
__Pyx_RefNannySetupContext("__div__", 0);
/* "optimized_field_elements.pyx":180
*
* def __div__(self, other):
* if isinstance(other, int_types): # <<<<<<<<<<<<<<
* return self.__class__([
* c * prime_field_inv(other, field_modulus) % field_modulus
*/
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_int_types); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 180, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PyObject_IsInstance(__pyx_v_other, __pyx_t_1); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 180, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_3 = (__pyx_t_2 != 0);
if (__pyx_t_3) {
/* "optimized_field_elements.pyx":181
* def __div__(self, other):
* if isinstance(other, int_types):
* return self.__class__([ # <<<<<<<<<<<<<<
* c * prime_field_inv(other, field_modulus) % field_modulus
* for c
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_class); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 181, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 181, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
/* "optimized_field_elements.pyx":184
* c * prime_field_inv(other, field_modulus) % field_modulus
* for c
* in self.coeffs # <<<<<<<<<<<<<<
* ])
* else:
*/
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_coeffs); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 184, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
if (likely(PyList_CheckExact(__pyx_t_6)) || PyTuple_CheckExact(__pyx_t_6)) {
__pyx_t_7 = __pyx_t_6; __Pyx_INCREF(__pyx_t_7); __pyx_t_8 = 0;
__pyx_t_9 = NULL;
} else {
__pyx_t_8 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 184, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_9 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 184, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
for (;;) {
if (likely(!__pyx_t_9)) {
if (likely(PyList_CheckExact(__pyx_t_7))) {
if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_7)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_6 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_8); __Pyx_INCREF(__pyx_t_6); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 184, __pyx_L1_error)
#else
__pyx_t_6 = PySequence_ITEM(__pyx_t_7, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 184, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
#endif
} else {
if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_8); __Pyx_INCREF(__pyx_t_6); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 184, __pyx_L1_error)
#else
__pyx_t_6 = PySequence_ITEM(__pyx_t_7, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 184, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
#endif
}
} else {
__pyx_t_6 = __pyx_t_9(__pyx_t_7);
if (unlikely(!__pyx_t_6)) {
PyObject* exc_type = PyErr_Occurred();
if (exc_type) {
if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
else __PYX_ERR(0, 184, __pyx_L1_error)
}
break;
}
__Pyx_GOTREF(__pyx_t_6);
}
__Pyx_XDECREF_SET(__pyx_v_c, __pyx_t_6);
__pyx_t_6 = 0;
/* "optimized_field_elements.pyx":182
* if isinstance(other, int_types):
* return self.__class__([
* c * prime_field_inv(other, field_modulus) % field_modulus # <<<<<<<<<<<<<<
* for c
* in self.coeffs
*/
__pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_prime_field_inv); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 182, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_10);
__pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_field_modulus); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 182, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_11);
__pyx_t_12 = NULL;
__pyx_t_13 = 0;
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) {
__pyx_t_12 = PyMethod_GET_SELF(__pyx_t_10);
if (likely(__pyx_t_12)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
__Pyx_INCREF(__pyx_t_12);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_10, function);
__pyx_t_13 = 1;
}
}
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_10)) {
PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_v_other, __pyx_t_11};
__pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 182, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) {
PyObject *__pyx_temp[3] = {__pyx_t_12, __pyx_v_other, __pyx_t_11};
__pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_13, 2+__pyx_t_13); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 182, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
} else
#endif
{
__pyx_t_14 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 182, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_14);
if (__pyx_t_12) {
__Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_12); __pyx_t_12 = NULL;
}
__Pyx_INCREF(__pyx_v_other);
__Pyx_GIVEREF(__pyx_v_other);
PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_13, __pyx_v_other);
__Pyx_GIVEREF(__pyx_t_11);
PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_13, __pyx_t_11);
__pyx_t_11 = 0;
__pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_14, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 182, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
}
__Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
__pyx_t_10 = PyNumber_Multiply(__pyx_v_c, __pyx_t_6); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 182, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_10);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_field_modulus); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 182, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_14 = PyNumber_Remainder(__pyx_t_10, __pyx_t_6); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 182, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_14);
__Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
if (unlikely(__Pyx_ListComp_Append(__pyx_t_5, (PyObject*)__pyx_t_14))) __PYX_ERR(0, 181, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
/* "optimized_field_elements.pyx":183
* return self.__class__([
* c * prime_field_inv(other, field_modulus) % field_modulus
* for c # <<<<<<<<<<<<<<
* in self.coeffs
* ])
*/
}
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_7 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
__pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4);
if (likely(__pyx_t_7)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
__Pyx_INCREF(__pyx_t_7);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_4, function);
}
}
if (!__pyx_t_7) {
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 181, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_4)) {
PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_5};
__pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 181, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_5};
__pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 181, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
} else
#endif
{
__pyx_t_14 = PyTuple_New(1+1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 181, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_14);
__Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_7); __pyx_t_7 = NULL;
__Pyx_GIVEREF(__pyx_t_5);
PyTuple_SET_ITEM(__pyx_t_14, 0+1, __pyx_t_5);
__pyx_t_5 = 0;
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_14, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 181, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
}
}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":180
*
* def __div__(self, other):
* if isinstance(other, int_types): # <<<<<<<<<<<<<<
* return self.__class__([
* c * prime_field_inv(other, field_modulus) % field_modulus
*/
}
/* "optimized_field_elements.pyx":187
* ])
* else:
* assert isinstance(other, self.__class__) # <<<<<<<<<<<<<<
* return self * other.inv()
*
*/
/*else*/ {
#ifndef CYTHON_WITHOUT_ASSERTIONS
if (unlikely(!Py_OptimizeFlag)) {
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_class); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 187, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_3 = PyObject_IsInstance(__pyx_v_other, __pyx_t_1); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 187, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (unlikely(!(__pyx_t_3 != 0))) {
PyErr_SetNone(PyExc_AssertionError);
__PYX_ERR(0, 187, __pyx_L1_error)
}
}
#endif
/* "optimized_field_elements.pyx":188
* else:
* assert isinstance(other, self.__class__)
* return self * other.inv() # <<<<<<<<<<<<<<
*
* def __truediv__(self, other):
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_inv); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 188, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_14 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
__pyx_t_14 = PyMethod_GET_SELF(__pyx_t_4);
if (likely(__pyx_t_14)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
__Pyx_INCREF(__pyx_t_14);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_4, function);
}
}
if (__pyx_t_14) {
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_14); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 188, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
} else {
__pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 188, __pyx_L1_error)
}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = PyNumber_Multiply(__pyx_v_self, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 188, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_r = __pyx_t_4;
__pyx_t_4 = 0;
goto __pyx_L0;
}
/* "optimized_field_elements.pyx":179
* return self * other
*
* def __div__(self, other): # <<<<<<<<<<<<<<
* if isinstance(other, int_types):
* return self.__class__([
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_XDECREF(__pyx_t_10);
__Pyx_XDECREF(__pyx_t_11);
__Pyx_XDECREF(__pyx_t_12);
__Pyx_XDECREF(__pyx_t_14);
__Pyx_AddTraceback("optimized_field_elements.FQP.__div__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_c);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":190
* return self * other.inv()
*
* def __truediv__(self, other): # <<<<<<<<<<<<<<
* return self.__div__(other)
*
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_13__truediv__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_3FQP_13__truediv__ = {"__truediv__", (PyCFunction)__pyx_pw_24optimized_field_elements_3FQP_13__truediv__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_13__truediv__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_other = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__truediv__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__truediv__", 1, 2, 2, 1); __PYX_ERR(0, 190, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__truediv__") < 0)) __PYX_ERR(0, 190, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_other = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__truediv__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 190, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQP.__truediv__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_3FQP_12__truediv__(__pyx_self, __pyx_v_self, __pyx_v_other);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_12__truediv__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
PyObject *__pyx_t_3 = NULL;
PyObject *__pyx_t_4 = NULL;
__Pyx_RefNannySetupContext("__truediv__", 0);
/* "optimized_field_elements.pyx":191
*
* def __truediv__(self, other):
* return self.__div__(other) # <<<<<<<<<<<<<<
*
* def __pow__(self, other):
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_div); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 191, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
__pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
if (likely(__pyx_t_3)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
__Pyx_INCREF(__pyx_t_3);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_2, function);
}
}
if (!__pyx_t_3) {
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_other); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 191, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_other};
__pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 191, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_other};
__pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 191, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else
#endif
{
__pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 191, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL;
__Pyx_INCREF(__pyx_v_other);
__Pyx_GIVEREF(__pyx_v_other);
PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_other);
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 191, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
}
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":190
* return self * other.inv()
*
* def __truediv__(self, other): # <<<<<<<<<<<<<<
* return self.__div__(other)
*
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_AddTraceback("optimized_field_elements.FQP.__truediv__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":193
* return self.__div__(other)
*
* def __pow__(self, other): # <<<<<<<<<<<<<<
* o = self.__class__([1] + [0] * (self.degree - 1))
* t = self
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_15__pow__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_3FQP_15__pow__ = {"__pow__", (PyCFunction)__pyx_pw_24optimized_field_elements_3FQP_15__pow__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_15__pow__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_other = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__pow__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__pow__", 1, 2, 2, 1); __PYX_ERR(0, 193, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__pow__") < 0)) __PYX_ERR(0, 193, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_other = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__pow__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 193, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQP.__pow__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_3FQP_14__pow__(__pyx_self, __pyx_v_self, __pyx_v_other);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_14__pow__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
PyObject *__pyx_v_o = NULL;
PyObject *__pyx_v_t = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
PyObject *__pyx_t_3 = NULL;
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
int __pyx_t_6;
__Pyx_RefNannySetupContext("__pow__", 0);
__Pyx_INCREF(__pyx_v_other);
/* "optimized_field_elements.pyx":194
*
* def __pow__(self, other):
* o = self.__class__([1] + [0] * (self.degree - 1)) # <<<<<<<<<<<<<<
* t = self
* while other > 0:
*/
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_class); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 194, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 194, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_INCREF(__pyx_int_1);
__Pyx_GIVEREF(__pyx_int_1);
PyList_SET_ITEM(__pyx_t_3, 0, __pyx_int_1);
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_degree); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 194, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_5 = __Pyx_PyInt_SubtractObjC(__pyx_t_4, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 194, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 194, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_INCREF(__pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
PyList_SET_ITEM(__pyx_t_4, 0, __pyx_int_0);
{ PyObject* __pyx_temp = PyNumber_InPlaceMultiply(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_temp)) __PYX_ERR(0, 194, __pyx_L1_error)
__Pyx_GOTREF(__pyx_temp);
__Pyx_DECREF(__pyx_t_4);
__pyx_t_4 = __pyx_temp;
}
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_t_5 = PyNumber_Add(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 194, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
if (likely(__pyx_t_4)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
__Pyx_INCREF(__pyx_t_4);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_2, function);
}
}
if (!__pyx_t_4) {
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 194, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_5};
__pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 194, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_5};
__pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 194, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
} else
#endif
{
__pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 194, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = NULL;
__Pyx_GIVEREF(__pyx_t_5);
PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_t_5);
__pyx_t_5 = 0;
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 194, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
}
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_v_o = __pyx_t_1;
__pyx_t_1 = 0;
/* "optimized_field_elements.pyx":195
* def __pow__(self, other):
* o = self.__class__([1] + [0] * (self.degree - 1))
* t = self # <<<<<<<<<<<<<<
* while other > 0:
* if other & 1:
*/
__Pyx_INCREF(__pyx_v_self);
__pyx_v_t = __pyx_v_self;
/* "optimized_field_elements.pyx":196
* o = self.__class__([1] + [0] * (self.degree - 1))
* t = self
* while other > 0: # <<<<<<<<<<<<<<
* if other & 1:
* o = o * t
*/
while (1) {
__pyx_t_1 = PyObject_RichCompare(__pyx_v_other, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 196, __pyx_L1_error)
__pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 196, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (!__pyx_t_6) break;
/* "optimized_field_elements.pyx":197
* t = self
* while other > 0:
* if other & 1: # <<<<<<<<<<<<<<
* o = o * t
* other >>= 1
*/
__pyx_t_1 = __Pyx_PyInt_AndObjC(__pyx_v_other, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 197, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 197, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (__pyx_t_6) {
/* "optimized_field_elements.pyx":198
* while other > 0:
* if other & 1:
* o = o * t # <<<<<<<<<<<<<<
* other >>= 1
* t = t * t
*/
__pyx_t_1 = PyNumber_Multiply(__pyx_v_o, __pyx_v_t); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 198, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF_SET(__pyx_v_o, __pyx_t_1);
__pyx_t_1 = 0;
/* "optimized_field_elements.pyx":197
* t = self
* while other > 0:
* if other & 1: # <<<<<<<<<<<<<<
* o = o * t
* other >>= 1
*/
}
/* "optimized_field_elements.pyx":199
* if other & 1:
* o = o * t
* other >>= 1 # <<<<<<<<<<<<<<
* t = t * t
* return o
*/
__pyx_t_1 = __Pyx_PyInt_RshiftObjC(__pyx_v_other, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 199, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF_SET(__pyx_v_other, __pyx_t_1);
__pyx_t_1 = 0;
/* "optimized_field_elements.pyx":200
* o = o * t
* other >>= 1
* t = t * t # <<<<<<<<<<<<<<
* return o
*
*/
__pyx_t_1 = PyNumber_Multiply(__pyx_v_t, __pyx_v_t); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 200, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF_SET(__pyx_v_t, __pyx_t_1);
__pyx_t_1 = 0;
}
/* "optimized_field_elements.pyx":201
* other >>= 1
* t = t * t
* return o # <<<<<<<<<<<<<<
*
* # Extended euclidean algorithm used to find the modular inverse
*/
__Pyx_XDECREF(__pyx_r);
__Pyx_INCREF(__pyx_v_o);
__pyx_r = __pyx_v_o;
goto __pyx_L0;
/* "optimized_field_elements.pyx":193
* return self.__div__(other)
*
* def __pow__(self, other): # <<<<<<<<<<<<<<
* o = self.__class__([1] + [0] * (self.degree - 1))
* t = self
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_AddTraceback("optimized_field_elements.FQP.__pow__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_o);
__Pyx_XDECREF(__pyx_v_t);
__Pyx_XDECREF(__pyx_v_other);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":204
*
* # Extended euclidean algorithm used to find the modular inverse
* def inv(self): # <<<<<<<<<<<<<<
* lm, hm = [1] + [0] * self.degree, [0] * (self.degree + 1)
* low, high = self.coeffs + [0], self.modulus_coeffs + [1]
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_17inv(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_3FQP_17inv = {"inv", (PyCFunction)__pyx_pw_24optimized_field_elements_3FQP_17inv, METH_O, 0};
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_17inv(PyObject *__pyx_self, PyObject *__pyx_v_self) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("inv (wrapper)", 0);
__pyx_r = __pyx_pf_24optimized_field_elements_3FQP_16inv(__pyx_self, ((PyObject *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_16inv(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
PyObject *__pyx_v_lm = NULL;
PyObject *__pyx_v_hm = NULL;
PyObject *__pyx_v_low = NULL;
PyObject *__pyx_v_high = NULL;
PyObject *__pyx_v_r = NULL;
PyObject *__pyx_v_nm = NULL;
PyObject *__pyx_v_new = NULL;
PyObject *__pyx_v_i = NULL;
PyObject *__pyx_v_j = NULL;
PyObject *__pyx_v_x = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
PyObject *__pyx_t_3 = NULL;
PyObject *__pyx_t_4 = NULL;
int __pyx_t_5;
int __pyx_t_6;
Py_ssize_t __pyx_t_7;
PyObject *(*__pyx_t_8)(PyObject *);
Py_ssize_t __pyx_t_9;
PyObject *(*__pyx_t_10)(PyObject *);
PyObject *__pyx_t_11 = NULL;
PyObject *__pyx_t_12 = NULL;
PyObject *__pyx_t_13 = NULL;
__Pyx_RefNannySetupContext("inv", 0);
/* "optimized_field_elements.pyx":205
* # Extended euclidean algorithm used to find the modular inverse
* def inv(self):
* lm, hm = [1] + [0] * self.degree, [0] * (self.degree + 1) # <<<<<<<<<<<<<<
* low, high = self.coeffs + [0], self.modulus_coeffs + [1]
* while deg(low):
*/
__pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 205, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_INCREF(__pyx_int_1);
__Pyx_GIVEREF(__pyx_int_1);
PyList_SET_ITEM(__pyx_t_1, 0, __pyx_int_1);
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_degree); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 205, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 205, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_INCREF(__pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
PyList_SET_ITEM(__pyx_t_3, 0, __pyx_int_0);
{ PyObject* __pyx_temp = PyNumber_InPlaceMultiply(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_temp)) __PYX_ERR(0, 205, __pyx_L1_error)
__Pyx_GOTREF(__pyx_temp);
__Pyx_DECREF(__pyx_t_3);
__pyx_t_3 = __pyx_temp;
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 205, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_degree); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 205, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 205, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 205, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_INCREF(__pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
PyList_SET_ITEM(__pyx_t_3, 0, __pyx_int_0);
{ PyObject* __pyx_temp = PyNumber_InPlaceMultiply(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_temp)) __PYX_ERR(0, 205, __pyx_L1_error)
__Pyx_GOTREF(__pyx_temp);
__Pyx_DECREF(__pyx_t_3);
__pyx_t_3 = __pyx_temp;
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_lm = ((PyObject*)__pyx_t_2);
__pyx_t_2 = 0;
__pyx_v_hm = ((PyObject*)__pyx_t_3);
__pyx_t_3 = 0;
/* "optimized_field_elements.pyx":206
* def inv(self):
* lm, hm = [1] + [0] * self.degree, [0] * (self.degree + 1)
* low, high = self.coeffs + [0], self.modulus_coeffs + [1] # <<<<<<<<<<<<<<
* while deg(low):
* r = poly_rounded_div(high, low)
*/
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_coeffs); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 206, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 206, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(__pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
PyList_SET_ITEM(__pyx_t_2, 0, __pyx_int_0);
__pyx_t_1 = PyNumber_Add(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 206, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_modulus_coeffs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 206, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 206, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_INCREF(__pyx_int_1);
__Pyx_GIVEREF(__pyx_int_1);
PyList_SET_ITEM(__pyx_t_3, 0, __pyx_int_1);
__pyx_t_4 = PyNumber_Add(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 206, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_v_low = __pyx_t_1;
__pyx_t_1 = 0;
__pyx_v_high = __pyx_t_4;
__pyx_t_4 = 0;
/* "optimized_field_elements.pyx":207
* lm, hm = [1] + [0] * self.degree, [0] * (self.degree + 1)
* low, high = self.coeffs + [0], self.modulus_coeffs + [1]
* while deg(low): # <<<<<<<<<<<<<<
* r = poly_rounded_div(high, low)
* r += [0] * (self.degree + 1 - len(r))
*/
while (1) {
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_deg); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 207, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_3 = NULL;
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
__pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1);
if (likely(__pyx_t_3)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
__Pyx_INCREF(__pyx_t_3);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_1, function);
}
}
if (!__pyx_t_3) {
__pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_low); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 207, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_1)) {
PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_low};
__pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 207, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_GOTREF(__pyx_t_4);
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_low};
__pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 207, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_GOTREF(__pyx_t_4);
} else
#endif
{
__pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 207, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __pyx_t_3 = NULL;
__Pyx_INCREF(__pyx_v_low);
__Pyx_GIVEREF(__pyx_v_low);
PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_v_low);
__pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 207, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
}
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 207, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
if (!__pyx_t_5) break;
/* "optimized_field_elements.pyx":208
* low, high = self.coeffs + [0], self.modulus_coeffs + [1]
* while deg(low):
* r = poly_rounded_div(high, low) # <<<<<<<<<<<<<<
* r += [0] * (self.degree + 1 - len(r))
* nm = [x for x in hm]
*/
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_poly_rounded_div); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 208, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = NULL;
__pyx_t_6 = 0;
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
__pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1);
if (likely(__pyx_t_2)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
__Pyx_INCREF(__pyx_t_2);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_1, function);
__pyx_t_6 = 1;
}
}
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_1)) {
PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_high, __pyx_v_low};
__pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 208, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_GOTREF(__pyx_t_4);
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_high, __pyx_v_low};
__pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 208, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_GOTREF(__pyx_t_4);
} else
#endif
{
__pyx_t_3 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 208, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
if (__pyx_t_2) {
__Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __pyx_t_2 = NULL;
}
__Pyx_INCREF(__pyx_v_high);
__Pyx_GIVEREF(__pyx_v_high);
PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_6, __pyx_v_high);
__Pyx_INCREF(__pyx_v_low);
__Pyx_GIVEREF(__pyx_v_low);
PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_6, __pyx_v_low);
__pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 208, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_XDECREF_SET(__pyx_v_r, __pyx_t_4);
__pyx_t_4 = 0;
/* "optimized_field_elements.pyx":209
* while deg(low):
* r = poly_rounded_div(high, low)
* r += [0] * (self.degree + 1 - len(r)) # <<<<<<<<<<<<<<
* nm = [x for x in hm]
* new = [x for x in high]
*/
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_degree); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 209, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_t_4, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 209, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_7 = PyObject_Length(__pyx_v_r); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 209, __pyx_L1_error)
__pyx_t_4 = PyInt_FromSsize_t(__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 209, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_3 = PyNumber_Subtract(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 209, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 209, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_INCREF(__pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
PyList_SET_ITEM(__pyx_t_4, 0, __pyx_int_0);
{ PyObject* __pyx_temp = PyNumber_InPlaceMultiply(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_temp)) __PYX_ERR(0, 209, __pyx_L1_error)
__Pyx_GOTREF(__pyx_temp);
__Pyx_DECREF(__pyx_t_4);
__pyx_t_4 = __pyx_temp;
}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_3 = PyNumber_InPlaceAdd(__pyx_v_r, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 209, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_DECREF_SET(__pyx_v_r, __pyx_t_3);
__pyx_t_3 = 0;
/* "optimized_field_elements.pyx":210
* r = poly_rounded_div(high, low)
* r += [0] * (self.degree + 1 - len(r))
* nm = [x for x in hm] # <<<<<<<<<<<<<<
* new = [x for x in high]
* # assert len(lm) == len(hm) == len(low) == len(high) == len(nm) == len(new) == self.degree + 1 # noqa: E501
*/
__pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 210, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_4 = __pyx_v_hm; __Pyx_INCREF(__pyx_t_4); __pyx_t_7 = 0;
for (;;) {
if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_4)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_7); __Pyx_INCREF(__pyx_t_1); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 210, __pyx_L1_error)
#else
__pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 210, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
#endif
__Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_1);
__pyx_t_1 = 0;
if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_v_x))) __PYX_ERR(0, 210, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_XDECREF_SET(__pyx_v_nm, ((PyObject*)__pyx_t_3));
__pyx_t_3 = 0;
/* "optimized_field_elements.pyx":211
* r += [0] * (self.degree + 1 - len(r))
* nm = [x for x in hm]
* new = [x for x in high] # <<<<<<<<<<<<<<
* # assert len(lm) == len(hm) == len(low) == len(high) == len(nm) == len(new) == self.degree + 1 # noqa: E501
* for i in range(self.degree + 1):
*/
__pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 211, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
if (likely(PyList_CheckExact(__pyx_v_high)) || PyTuple_CheckExact(__pyx_v_high)) {
__pyx_t_4 = __pyx_v_high; __Pyx_INCREF(__pyx_t_4); __pyx_t_7 = 0;
__pyx_t_8 = NULL;
} else {
__pyx_t_7 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_high); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 211, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_8 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 211, __pyx_L1_error)
}
for (;;) {
if (likely(!__pyx_t_8)) {
if (likely(PyList_CheckExact(__pyx_t_4))) {
if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_4)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_7); __Pyx_INCREF(__pyx_t_1); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 211, __pyx_L1_error)
#else
__pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 211, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
#endif
} else {
if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_7); __Pyx_INCREF(__pyx_t_1); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 211, __pyx_L1_error)
#else
__pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 211, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
#endif
}
} else {
__pyx_t_1 = __pyx_t_8(__pyx_t_4);
if (unlikely(!__pyx_t_1)) {
PyObject* exc_type = PyErr_Occurred();
if (exc_type) {
if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
else __PYX_ERR(0, 211, __pyx_L1_error)
}
break;
}
__Pyx_GOTREF(__pyx_t_1);
}
__Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_1);
__pyx_t_1 = 0;
if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_v_x))) __PYX_ERR(0, 211, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_XDECREF_SET(__pyx_v_new, ((PyObject*)__pyx_t_3));
__pyx_t_3 = 0;
/* "optimized_field_elements.pyx":213
* new = [x for x in high]
* # assert len(lm) == len(hm) == len(low) == len(high) == len(nm) == len(new) == self.degree + 1 # noqa: E501
* for i in range(self.degree + 1): # <<<<<<<<<<<<<<
* for j in range(self.degree + 1 - i):
* nm[i + j] -= lm[i] * r[j]
*/
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_degree); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 213, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 213, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 213, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
__pyx_t_4 = __pyx_t_3; __Pyx_INCREF(__pyx_t_4); __pyx_t_7 = 0;
__pyx_t_8 = NULL;
} else {
__pyx_t_7 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 213, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_8 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 213, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
for (;;) {
if (likely(!__pyx_t_8)) {
if (likely(PyList_CheckExact(__pyx_t_4))) {
if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_4)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_3 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_7); __Pyx_INCREF(__pyx_t_3); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 213, __pyx_L1_error)
#else
__pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 213, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
#endif
} else {
if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_7); __Pyx_INCREF(__pyx_t_3); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 213, __pyx_L1_error)
#else
__pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 213, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
#endif
}
} else {
__pyx_t_3 = __pyx_t_8(__pyx_t_4);
if (unlikely(!__pyx_t_3)) {
PyObject* exc_type = PyErr_Occurred();
if (exc_type) {
if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
else __PYX_ERR(0, 213, __pyx_L1_error)
}
break;
}
__Pyx_GOTREF(__pyx_t_3);
}
__Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_3);
__pyx_t_3 = 0;
/* "optimized_field_elements.pyx":214
* # assert len(lm) == len(hm) == len(low) == len(high) == len(nm) == len(new) == self.degree + 1 # noqa: E501
* for i in range(self.degree + 1):
* for j in range(self.degree + 1 - i): # <<<<<<<<<<<<<<
* nm[i + j] -= lm[i] * r[j]
* new[i + j] -= low[i] * r[j]
*/
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_degree); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 214, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 214, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_3 = PyNumber_Subtract(__pyx_t_1, __pyx_v_i); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 214, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 214, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
__pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_9 = 0;
__pyx_t_10 = NULL;
} else {
__pyx_t_9 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 214, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_10 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 214, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
for (;;) {
if (likely(!__pyx_t_10)) {
if (likely(PyList_CheckExact(__pyx_t_3))) {
if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_3)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_9); __Pyx_INCREF(__pyx_t_1); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 214, __pyx_L1_error)
#else
__pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 214, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
#endif
} else {
if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_9); __Pyx_INCREF(__pyx_t_1); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 214, __pyx_L1_error)
#else
__pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 214, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
#endif
}
} else {
__pyx_t_1 = __pyx_t_10(__pyx_t_3);
if (unlikely(!__pyx_t_1)) {
PyObject* exc_type = PyErr_Occurred();
if (exc_type) {
if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
else __PYX_ERR(0, 214, __pyx_L1_error)
}
break;
}
__Pyx_GOTREF(__pyx_t_1);
}
__Pyx_XDECREF_SET(__pyx_v_j, __pyx_t_1);
__pyx_t_1 = 0;
/* "optimized_field_elements.pyx":215
* for i in range(self.degree + 1):
* for j in range(self.degree + 1 - i):
* nm[i + j] -= lm[i] * r[j] # <<<<<<<<<<<<<<
* new[i + j] -= low[i] * r[j]
* nm = [x % field_modulus for x in nm]
*/
__pyx_t_1 = PyNumber_Add(__pyx_v_i, __pyx_v_j); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 215, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_nm, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 215, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_11 = __Pyx_PyObject_GetItem(__pyx_v_lm, __pyx_v_i); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 215, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_11);
__pyx_t_12 = __Pyx_PyObject_GetItem(__pyx_v_r, __pyx_v_j); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 215, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_12);
__pyx_t_13 = PyNumber_Multiply(__pyx_t_11, __pyx_t_12); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 215, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_13);
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
__Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
__pyx_t_12 = PyNumber_InPlaceSubtract(__pyx_t_2, __pyx_t_13); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 215, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_12);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
if (unlikely(PyObject_SetItem(__pyx_v_nm, __pyx_t_1, __pyx_t_12) < 0)) __PYX_ERR(0, 215, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/* "optimized_field_elements.pyx":216
* for j in range(self.degree + 1 - i):
* nm[i + j] -= lm[i] * r[j]
* new[i + j] -= low[i] * r[j] # <<<<<<<<<<<<<<
* nm = [x % field_modulus for x in nm]
* new = [x % field_modulus for x in new]
*/
__pyx_t_1 = PyNumber_Add(__pyx_v_i, __pyx_v_j); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 216, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_12 = __Pyx_PyObject_GetItem(__pyx_v_new, __pyx_t_1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 216, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_12);
__pyx_t_13 = __Pyx_PyObject_GetItem(__pyx_v_low, __pyx_v_i); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 216, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_13);
__pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_r, __pyx_v_j); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 216, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_11 = PyNumber_Multiply(__pyx_t_13, __pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 216, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_11);
__Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_2 = PyNumber_InPlaceSubtract(__pyx_t_12, __pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 216, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
if (unlikely(PyObject_SetItem(__pyx_v_new, __pyx_t_1, __pyx_t_2) < 0)) __PYX_ERR(0, 216, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/* "optimized_field_elements.pyx":214
* # assert len(lm) == len(hm) == len(low) == len(high) == len(nm) == len(new) == self.degree + 1 # noqa: E501
* for i in range(self.degree + 1):
* for j in range(self.degree + 1 - i): # <<<<<<<<<<<<<<
* nm[i + j] -= lm[i] * r[j]
* new[i + j] -= low[i] * r[j]
*/
}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
/* "optimized_field_elements.pyx":213
* new = [x for x in high]
* # assert len(lm) == len(hm) == len(low) == len(high) == len(nm) == len(new) == self.degree + 1 # noqa: E501
* for i in range(self.degree + 1): # <<<<<<<<<<<<<<
* for j in range(self.degree + 1 - i):
* nm[i + j] -= lm[i] * r[j]
*/
}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":217
* nm[i + j] -= lm[i] * r[j]
* new[i + j] -= low[i] * r[j]
* nm = [x % field_modulus for x in nm] # <<<<<<<<<<<<<<
* new = [x % field_modulus for x in new]
* lm, low, hm, high = nm, new, lm, low
*/
__pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 217, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_3 = __pyx_v_nm; __Pyx_INCREF(__pyx_t_3); __pyx_t_7 = 0;
for (;;) {
if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_3)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_1); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 217, __pyx_L1_error)
#else
__pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 217, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
#endif
__Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_1);
__pyx_t_1 = 0;
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_field_modulus); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 217, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PyNumber_Remainder(__pyx_v_x, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 217, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (unlikely(__Pyx_ListComp_Append(__pyx_t_4, (PyObject*)__pyx_t_2))) __PYX_ERR(0, 217, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_DECREF_SET(__pyx_v_nm, ((PyObject*)__pyx_t_4));
__pyx_t_4 = 0;
/* "optimized_field_elements.pyx":218
* new[i + j] -= low[i] * r[j]
* nm = [x % field_modulus for x in nm]
* new = [x % field_modulus for x in new] # <<<<<<<<<<<<<<
* lm, low, hm, high = nm, new, lm, low
* return self.__class__(lm[:self.degree]) / low[0]
*/
__pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 218, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_3 = __pyx_v_new; __Pyx_INCREF(__pyx_t_3); __pyx_t_7 = 0;
for (;;) {
if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_3)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_2); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 218, __pyx_L1_error)
#else
__pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 218, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
#endif
__Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_2);
__pyx_t_2 = 0;
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_field_modulus); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 218, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_1 = PyNumber_Remainder(__pyx_v_x, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 218, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (unlikely(__Pyx_ListComp_Append(__pyx_t_4, (PyObject*)__pyx_t_1))) __PYX_ERR(0, 218, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_DECREF_SET(__pyx_v_new, ((PyObject*)__pyx_t_4));
__pyx_t_4 = 0;
/* "optimized_field_elements.pyx":219
* nm = [x % field_modulus for x in nm]
* new = [x % field_modulus for x in new]
* lm, low, hm, high = nm, new, lm, low # <<<<<<<<<<<<<<
* return self.__class__(lm[:self.degree]) / low[0]
*
*/
__pyx_t_4 = __pyx_v_nm;
__Pyx_INCREF(__pyx_t_4);
__pyx_t_3 = __pyx_v_new;
__Pyx_INCREF(__pyx_t_3);
__pyx_t_1 = __pyx_v_lm;
__Pyx_INCREF(__pyx_t_1);
__pyx_t_2 = __pyx_v_low;
__Pyx_INCREF(__pyx_t_2);
__Pyx_DECREF_SET(__pyx_v_lm, ((PyObject*)__pyx_t_4));
__pyx_t_4 = 0;
__Pyx_DECREF_SET(__pyx_v_low, __pyx_t_3);
__pyx_t_3 = 0;
__Pyx_DECREF_SET(__pyx_v_hm, ((PyObject*)__pyx_t_1));
__pyx_t_1 = 0;
__Pyx_DECREF_SET(__pyx_v_high, __pyx_t_2);
__pyx_t_2 = 0;
}
/* "optimized_field_elements.pyx":220
* new = [x % field_modulus for x in new]
* lm, low, hm, high = nm, new, lm, low
* return self.__class__(lm[:self.degree]) / low[0] # <<<<<<<<<<<<<<
*
* def __repr__(self):
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_class); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 220, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_degree); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 220, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_7 = __Pyx_PyIndex_AsSsize_t(__pyx_t_3); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 220, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_3 = __Pyx_PyList_GetSlice(__pyx_v_lm, 0, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 220, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_4 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_1);
if (likely(__pyx_t_4)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
__Pyx_INCREF(__pyx_t_4);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_1, function);
}
}
if (!__pyx_t_4) {
__pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 220, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_GOTREF(__pyx_t_2);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_1)) {
PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_3};
__pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 220, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_3};
__pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 220, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
} else
#endif
{
__pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 220, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_11);
__Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_4); __pyx_t_4 = NULL;
__Pyx_GIVEREF(__pyx_t_3);
PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_t_3);
__pyx_t_3 = 0;
__pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_11, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 220, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
}
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_1 = __Pyx_GetItemInt(__pyx_v_low, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 220, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_11 = __Pyx_PyNumber_Divide(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 220, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_11);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_r = __pyx_t_11;
__pyx_t_11 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":204
*
* # Extended euclidean algorithm used to find the modular inverse
* def inv(self): # <<<<<<<<<<<<<<
* lm, hm = [1] + [0] * self.degree, [0] * (self.degree + 1)
* low, high = self.coeffs + [0], self.modulus_coeffs + [1]
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_11);
__Pyx_XDECREF(__pyx_t_12);
__Pyx_XDECREF(__pyx_t_13);
__Pyx_AddTraceback("optimized_field_elements.FQP.inv", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_lm);
__Pyx_XDECREF(__pyx_v_hm);
__Pyx_XDECREF(__pyx_v_low);
__Pyx_XDECREF(__pyx_v_high);
__Pyx_XDECREF(__pyx_v_r);
__Pyx_XDECREF(__pyx_v_nm);
__Pyx_XDECREF(__pyx_v_new);
__Pyx_XDECREF(__pyx_v_i);
__Pyx_XDECREF(__pyx_v_j);
__Pyx_XDECREF(__pyx_v_x);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":222
* return self.__class__(lm[:self.degree]) / low[0]
*
* def __repr__(self): # <<<<<<<<<<<<<<
* return repr(self.coeffs)
*
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_19__repr__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_3FQP_19__repr__ = {"__repr__", (PyCFunction)__pyx_pw_24optimized_field_elements_3FQP_19__repr__, METH_O, 0};
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_19__repr__(PyObject *__pyx_self, PyObject *__pyx_v_self) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__repr__ (wrapper)", 0);
__pyx_r = __pyx_pf_24optimized_field_elements_3FQP_18__repr__(__pyx_self, ((PyObject *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_18__repr__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
__Pyx_RefNannySetupContext("__repr__", 0);
/* "optimized_field_elements.pyx":223
*
* def __repr__(self):
* return repr(self.coeffs) # <<<<<<<<<<<<<<
*
* def __eq__(self, other):
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_coeffs); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 223, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PyObject_Repr(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 223, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_r = __pyx_t_2;
__pyx_t_2 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":222
* return self.__class__(lm[:self.degree]) / low[0]
*
* def __repr__(self): # <<<<<<<<<<<<<<
* return repr(self.coeffs)
*
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_AddTraceback("optimized_field_elements.FQP.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":225
* return repr(self.coeffs)
*
* def __eq__(self, other): # <<<<<<<<<<<<<<
* assert isinstance(other, self.__class__)
* for c1, c2 in zip(self.coeffs, other.coeffs):
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_21__eq__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_3FQP_21__eq__ = {"__eq__", (PyCFunction)__pyx_pw_24optimized_field_elements_3FQP_21__eq__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_21__eq__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_other = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__eq__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__eq__", 1, 2, 2, 1); __PYX_ERR(0, 225, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__eq__") < 0)) __PYX_ERR(0, 225, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_other = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__eq__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 225, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQP.__eq__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_3FQP_20__eq__(__pyx_self, __pyx_v_self, __pyx_v_other);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_20__eq__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
PyObject *__pyx_v_c1 = NULL;
PyObject *__pyx_v_c2 = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
int __pyx_t_2;
PyObject *__pyx_t_3 = NULL;
PyObject *__pyx_t_4 = NULL;
Py_ssize_t __pyx_t_5;
PyObject *(*__pyx_t_6)(PyObject *);
PyObject *__pyx_t_7 = NULL;
PyObject *__pyx_t_8 = NULL;
PyObject *(*__pyx_t_9)(PyObject *);
__Pyx_RefNannySetupContext("__eq__", 0);
/* "optimized_field_elements.pyx":226
*
* def __eq__(self, other):
* assert isinstance(other, self.__class__) # <<<<<<<<<<<<<<
* for c1, c2 in zip(self.coeffs, other.coeffs):
* if c1 != c2:
*/
#ifndef CYTHON_WITHOUT_ASSERTIONS
if (unlikely(!Py_OptimizeFlag)) {
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_class); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 226, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PyObject_IsInstance(__pyx_v_other, __pyx_t_1); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 226, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (unlikely(!(__pyx_t_2 != 0))) {
PyErr_SetNone(PyExc_AssertionError);
__PYX_ERR(0, 226, __pyx_L1_error)
}
}
#endif
/* "optimized_field_elements.pyx":227
* def __eq__(self, other):
* assert isinstance(other, self.__class__)
* for c1, c2 in zip(self.coeffs, other.coeffs): # <<<<<<<<<<<<<<
* if c1 != c2:
* return False
*/
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_coeffs); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 227, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_coeffs); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 227, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 227, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_GIVEREF(__pyx_t_1);
PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
__Pyx_GIVEREF(__pyx_t_3);
PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
__pyx_t_1 = 0;
__pyx_t_3 = 0;
__pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 227, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
__pyx_t_4 = __pyx_t_3; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
__pyx_t_6 = NULL;
} else {
__pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 227, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 227, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
for (;;) {
if (likely(!__pyx_t_6)) {
if (likely(PyList_CheckExact(__pyx_t_4))) {
if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_3 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 227, __pyx_L1_error)
#else
__pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 227, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
#endif
} else {
if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 227, __pyx_L1_error)
#else
__pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 227, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
#endif
}
} else {
__pyx_t_3 = __pyx_t_6(__pyx_t_4);
if (unlikely(!__pyx_t_3)) {
PyObject* exc_type = PyErr_Occurred();
if (exc_type) {
if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
else __PYX_ERR(0, 227, __pyx_L1_error)
}
break;
}
__Pyx_GOTREF(__pyx_t_3);
}
if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
PyObject* sequence = __pyx_t_3;
Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
if (unlikely(size != 2)) {
if (size > 2) __Pyx_RaiseTooManyValuesError(2);
else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
__PYX_ERR(0, 227, __pyx_L1_error)
}
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
if (likely(PyTuple_CheckExact(sequence))) {
__pyx_t_1 = PyTuple_GET_ITEM(sequence, 0);
__pyx_t_7 = PyTuple_GET_ITEM(sequence, 1);
} else {
__pyx_t_1 = PyList_GET_ITEM(sequence, 0);
__pyx_t_7 = PyList_GET_ITEM(sequence, 1);
}
__Pyx_INCREF(__pyx_t_1);
__Pyx_INCREF(__pyx_t_7);
#else
__pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 227, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 227, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
#endif
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
} else {
Py_ssize_t index = -1;
__pyx_t_8 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 227, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
index = 0; __pyx_t_1 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_1)) goto __pyx_L5_unpacking_failed;
__Pyx_GOTREF(__pyx_t_1);
index = 1; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L5_unpacking_failed;
__Pyx_GOTREF(__pyx_t_7);
if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) __PYX_ERR(0, 227, __pyx_L1_error)
__pyx_t_9 = NULL;
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
goto __pyx_L6_unpacking_done;
__pyx_L5_unpacking_failed:;
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
__pyx_t_9 = NULL;
if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
__PYX_ERR(0, 227, __pyx_L1_error)
__pyx_L6_unpacking_done:;
}
__Pyx_XDECREF_SET(__pyx_v_c1, __pyx_t_1);
__pyx_t_1 = 0;
__Pyx_XDECREF_SET(__pyx_v_c2, __pyx_t_7);
__pyx_t_7 = 0;
/* "optimized_field_elements.pyx":228
* assert isinstance(other, self.__class__)
* for c1, c2 in zip(self.coeffs, other.coeffs):
* if c1 != c2: # <<<<<<<<<<<<<<
* return False
* return True
*/
__pyx_t_3 = PyObject_RichCompare(__pyx_v_c1, __pyx_v_c2, Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 228, __pyx_L1_error)
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 228, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
if (__pyx_t_2) {
/* "optimized_field_elements.pyx":229
* for c1, c2 in zip(self.coeffs, other.coeffs):
* if c1 != c2:
* return False # <<<<<<<<<<<<<<
* return True
*
*/
__Pyx_XDECREF(__pyx_r);
__Pyx_INCREF(Py_False);
__pyx_r = Py_False;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":228
* assert isinstance(other, self.__class__)
* for c1, c2 in zip(self.coeffs, other.coeffs):
* if c1 != c2: # <<<<<<<<<<<<<<
* return False
* return True
*/
}
/* "optimized_field_elements.pyx":227
* def __eq__(self, other):
* assert isinstance(other, self.__class__)
* for c1, c2 in zip(self.coeffs, other.coeffs): # <<<<<<<<<<<<<<
* if c1 != c2:
* return False
*/
}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":230
* if c1 != c2:
* return False
* return True # <<<<<<<<<<<<<<
*
* def __ne__(self, other):
*/
__Pyx_XDECREF(__pyx_r);
__Pyx_INCREF(Py_True);
__pyx_r = Py_True;
goto __pyx_L0;
/* "optimized_field_elements.pyx":225
* return repr(self.coeffs)
*
* def __eq__(self, other): # <<<<<<<<<<<<<<
* assert isinstance(other, self.__class__)
* for c1, c2 in zip(self.coeffs, other.coeffs):
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_XDECREF(__pyx_t_8);
__Pyx_AddTraceback("optimized_field_elements.FQP.__eq__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_c1);
__Pyx_XDECREF(__pyx_v_c2);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":232
* return True
*
* def __ne__(self, other): # <<<<<<<<<<<<<<
* return not self == other
*
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_23__ne__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_3FQP_23__ne__ = {"__ne__", (PyCFunction)__pyx_pw_24optimized_field_elements_3FQP_23__ne__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_23__ne__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_other = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__ne__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_other,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_other)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__ne__", 1, 2, 2, 1); __PYX_ERR(0, 232, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__ne__") < 0)) __PYX_ERR(0, 232, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_other = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__ne__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 232, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQP.__ne__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_3FQP_22__ne__(__pyx_self, __pyx_v_self, __pyx_v_other);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_22__ne__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
int __pyx_t_2;
__Pyx_RefNannySetupContext("__ne__", 0);
/* "optimized_field_elements.pyx":233
*
* def __ne__(self, other):
* return not self == other # <<<<<<<<<<<<<<
*
* def __neg__(self):
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = PyObject_RichCompare(__pyx_v_self, __pyx_v_other, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 233, __pyx_L1_error)
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 233, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_1 = __Pyx_PyBool_FromLong((!__pyx_t_2)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 233, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":232
* return True
*
* def __ne__(self, other): # <<<<<<<<<<<<<<
* return not self == other
*
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("optimized_field_elements.FQP.__ne__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":235
* return not self == other
*
* def __neg__(self): # <<<<<<<<<<<<<<
* return self.__class__([-c for c in self.coeffs])
*
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_25__neg__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_3FQP_25__neg__ = {"__neg__", (PyCFunction)__pyx_pw_24optimized_field_elements_3FQP_25__neg__, METH_O, 0};
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_25__neg__(PyObject *__pyx_self, PyObject *__pyx_v_self) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__neg__ (wrapper)", 0);
__pyx_r = __pyx_pf_24optimized_field_elements_3FQP_24__neg__(__pyx_self, ((PyObject *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_24__neg__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
PyObject *__pyx_v_c = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
PyObject *__pyx_t_3 = NULL;
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
Py_ssize_t __pyx_t_6;
PyObject *(*__pyx_t_7)(PyObject *);
__Pyx_RefNannySetupContext("__neg__", 0);
/* "optimized_field_elements.pyx":236
*
* def __neg__(self):
* return self.__class__([-c for c in self.coeffs]) # <<<<<<<<<<<<<<
*
* @classmethod
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_class); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 236, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 236, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_coeffs); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 236, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) {
__pyx_t_5 = __pyx_t_4; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0;
__pyx_t_7 = NULL;
} else {
__pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 236, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_7 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 236, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
for (;;) {
if (likely(!__pyx_t_7)) {
if (likely(PyList_CheckExact(__pyx_t_5))) {
if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_4 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 236, __pyx_L1_error)
#else
__pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 236, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
#endif
} else {
if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_4); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 236, __pyx_L1_error)
#else
__pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 236, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
#endif
}
} else {
__pyx_t_4 = __pyx_t_7(__pyx_t_5);
if (unlikely(!__pyx_t_4)) {
PyObject* exc_type = PyErr_Occurred();
if (exc_type) {
if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
else __PYX_ERR(0, 236, __pyx_L1_error)
}
break;
}
__Pyx_GOTREF(__pyx_t_4);
}
__Pyx_XDECREF_SET(__pyx_v_c, __pyx_t_4);
__pyx_t_4 = 0;
__pyx_t_4 = PyNumber_Negative(__pyx_v_c); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 236, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_4))) __PYX_ERR(0, 236, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
}
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_t_5 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
__pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
if (likely(__pyx_t_5)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
__Pyx_INCREF(__pyx_t_5);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_2, function);
}
}
if (!__pyx_t_5) {
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 236, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_3};
__pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 236, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_3};
__pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 236, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
} else
#endif
{
__pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 236, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); __pyx_t_5 = NULL;
__Pyx_GIVEREF(__pyx_t_3);
PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_3);
__pyx_t_3 = 0;
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 236, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
}
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":235
* return not self == other
*
* def __neg__(self): # <<<<<<<<<<<<<<
* return self.__class__([-c for c in self.coeffs])
*
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_AddTraceback("optimized_field_elements.FQP.__neg__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_c);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":239
*
* @classmethod
* def one(cls): # <<<<<<<<<<<<<<
* return cls([1] + [0] * (cls.degree - 1))
*
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_27one(PyObject *__pyx_self, PyObject *__pyx_v_cls); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_3FQP_27one = {"one", (PyCFunction)__pyx_pw_24optimized_field_elements_3FQP_27one, METH_O, 0};
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_27one(PyObject *__pyx_self, PyObject *__pyx_v_cls) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("one (wrapper)", 0);
__pyx_r = __pyx_pf_24optimized_field_elements_3FQP_26one(__pyx_self, ((PyObject *)__pyx_v_cls));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_26one(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_cls) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
PyObject *__pyx_t_3 = NULL;
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
__Pyx_RefNannySetupContext("one", 0);
/* "optimized_field_elements.pyx":240
* @classmethod
* def one(cls):
* return cls([1] + [0] * (cls.degree - 1)) # <<<<<<<<<<<<<<
*
* @classmethod
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 240, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(__pyx_int_1);
__Pyx_GIVEREF(__pyx_int_1);
PyList_SET_ITEM(__pyx_t_2, 0, __pyx_int_1);
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_cls, __pyx_n_s_degree); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 240, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_4 = __Pyx_PyInt_SubtractObjC(__pyx_t_3, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 240, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 240, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_INCREF(__pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
PyList_SET_ITEM(__pyx_t_3, 0, __pyx_int_0);
{ PyObject* __pyx_temp = PyNumber_InPlaceMultiply(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_temp)) __PYX_ERR(0, 240, __pyx_L1_error)
__Pyx_GOTREF(__pyx_temp);
__Pyx_DECREF(__pyx_t_3);
__pyx_t_3 = __pyx_temp;
}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = PyNumber_Add(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 240, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_INCREF(__pyx_v_cls);
__pyx_t_3 = __pyx_v_cls; __pyx_t_2 = NULL;
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
__pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
if (likely(__pyx_t_2)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
__Pyx_INCREF(__pyx_t_2);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_3, function);
}
}
if (!__pyx_t_2) {
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 240, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_3)) {
PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_4};
__pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 240, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_4};
__pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 240, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
} else
#endif
{
__pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 240, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __pyx_t_2 = NULL;
__Pyx_GIVEREF(__pyx_t_4);
PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_4);
__pyx_t_4 = 0;
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 240, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
}
}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":239
*
* @classmethod
* def one(cls): # <<<<<<<<<<<<<<
* return cls([1] + [0] * (cls.degree - 1))
*
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_AddTraceback("optimized_field_elements.FQP.one", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":243
*
* @classmethod
* def zero(cls): # <<<<<<<<<<<<<<
* return cls([0] * cls.degree)
*
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_29zero(PyObject *__pyx_self, PyObject *__pyx_v_cls); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_3FQP_29zero = {"zero", (PyCFunction)__pyx_pw_24optimized_field_elements_3FQP_29zero, METH_O, 0};
static PyObject *__pyx_pw_24optimized_field_elements_3FQP_29zero(PyObject *__pyx_self, PyObject *__pyx_v_cls) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("zero (wrapper)", 0);
__pyx_r = __pyx_pf_24optimized_field_elements_3FQP_28zero(__pyx_self, ((PyObject *)__pyx_v_cls));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_3FQP_28zero(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_cls) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
PyObject *__pyx_t_3 = NULL;
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
__Pyx_RefNannySetupContext("zero", 0);
/* "optimized_field_elements.pyx":244
* @classmethod
* def zero(cls):
* return cls([0] * cls.degree) # <<<<<<<<<<<<<<
*
*
*/
__Pyx_XDECREF(__pyx_r);
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_cls, __pyx_n_s_degree); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 244, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 244, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_INCREF(__pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
PyList_SET_ITEM(__pyx_t_3, 0, __pyx_int_0);
{ PyObject* __pyx_temp = PyNumber_InPlaceMultiply(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_temp)) __PYX_ERR(0, 244, __pyx_L1_error)
__Pyx_GOTREF(__pyx_temp);
__Pyx_DECREF(__pyx_t_3);
__pyx_t_3 = __pyx_temp;
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_INCREF(__pyx_v_cls);
__pyx_t_2 = __pyx_v_cls; __pyx_t_4 = NULL;
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
if (likely(__pyx_t_4)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
__Pyx_INCREF(__pyx_t_4);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_2, function);
}
}
if (!__pyx_t_4) {
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 244, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_GOTREF(__pyx_t_1);
} else {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_3};
__pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 244, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_3};
__pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 244, __pyx_L1_error)
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
} else
#endif
{
__pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 244, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
__Pyx_GIVEREF(__pyx_t_3);
PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_3);
__pyx_t_3 = 0;
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 244, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
}
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
/* "optimized_field_elements.pyx":243
*
* @classmethod
* def zero(cls): # <<<<<<<<<<<<<<
* return cls([0] * cls.degree)
*
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_AddTraceback("optimized_field_elements.FQP.zero", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":249
* # The quadratic extension field
* class FQ2(FQP):
* def __init__(self, coeffs): # <<<<<<<<<<<<<<
* self.coeffs = coeffs
* self.modulus_coeffs = [1, 0]
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_3FQ2_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_3FQ2_1__init__ = {"__init__", (PyCFunction)__pyx_pw_24optimized_field_elements_3FQ2_1__init__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_3FQ2_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_coeffs = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_coeffs,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_coeffs)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, 1); __PYX_ERR(0, 249, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 249, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_coeffs = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 249, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQ2.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_3FQ2___init__(__pyx_self, __pyx_v_self, __pyx_v_coeffs);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_3FQ2___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_coeffs) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
__Pyx_RefNannySetupContext("__init__", 0);
/* "optimized_field_elements.pyx":250
* class FQ2(FQP):
* def __init__(self, coeffs):
* self.coeffs = coeffs # <<<<<<<<<<<<<<
* self.modulus_coeffs = [1, 0]
* self.mc_tuples = [(0, 1)]
*/
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_coeffs, __pyx_v_coeffs) < 0) __PYX_ERR(0, 250, __pyx_L1_error)
/* "optimized_field_elements.pyx":251
* def __init__(self, coeffs):
* self.coeffs = coeffs
* self.modulus_coeffs = [1, 0] # <<<<<<<<<<<<<<
* self.mc_tuples = [(0, 1)]
* self.degree = 2
*/
__pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 251, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_INCREF(__pyx_int_1);
__Pyx_GIVEREF(__pyx_int_1);
PyList_SET_ITEM(__pyx_t_1, 0, __pyx_int_1);
__Pyx_INCREF(__pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
PyList_SET_ITEM(__pyx_t_1, 1, __pyx_int_0);
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_modulus_coeffs, __pyx_t_1) < 0) __PYX_ERR(0, 251, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/* "optimized_field_elements.pyx":252
* self.coeffs = coeffs
* self.modulus_coeffs = [1, 0]
* self.mc_tuples = [(0, 1)] # <<<<<<<<<<<<<<
* self.degree = 2
* self.__class__.degree = 2
*/
__pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 252, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_INCREF(__pyx_tuple__4);
__Pyx_GIVEREF(__pyx_tuple__4);
PyList_SET_ITEM(__pyx_t_1, 0, __pyx_tuple__4);
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_mc_tuples, __pyx_t_1) < 0) __PYX_ERR(0, 252, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/* "optimized_field_elements.pyx":253
* self.modulus_coeffs = [1, 0]
* self.mc_tuples = [(0, 1)]
* self.degree = 2 # <<<<<<<<<<<<<<
* self.__class__.degree = 2
*
*/
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_degree, __pyx_int_2) < 0) __PYX_ERR(0, 253, __pyx_L1_error)
/* "optimized_field_elements.pyx":254
* self.mc_tuples = [(0, 1)]
* self.degree = 2
* self.__class__.degree = 2 # <<<<<<<<<<<<<<
*
*
*/
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_class); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 254, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
if (__Pyx_PyObject_SetAttrStr(__pyx_t_1, __pyx_n_s_degree, __pyx_int_2) < 0) __PYX_ERR(0, 254, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/* "optimized_field_elements.pyx":249
* # The quadratic extension field
* class FQ2(FQP):
* def __init__(self, coeffs): # <<<<<<<<<<<<<<
* self.coeffs = coeffs
* self.modulus_coeffs = [1, 0]
*/
/* function exit code */
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("optimized_field_elements.FQ2.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* "optimized_field_elements.pyx":259
* # The 12th-degree extension field
* class FQ12(FQP):
* def __init__(self, coeffs): # <<<<<<<<<<<<<<
* self.coeffs = coeffs
* self.modulus_coeffs = FQ12_modulus_coeffs
*/
/* Python wrapper */
static PyObject *__pyx_pw_24optimized_field_elements_4FQ12_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_24optimized_field_elements_4FQ12_1__init__ = {"__init__", (PyCFunction)__pyx_pw_24optimized_field_elements_4FQ12_1__init__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_24optimized_field_elements_4FQ12_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_self = 0;
PyObject *__pyx_v_coeffs = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_coeffs,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_self)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_coeffs)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, 1); __PYX_ERR(0, 259, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 259, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_self = values[0];
__pyx_v_coeffs = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("__init__", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 259, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("optimized_field_elements.FQ12.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_24optimized_field_elements_4FQ12___init__(__pyx_self, __pyx_v_self, __pyx_v_coeffs);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_24optimized_field_elements_4FQ12___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_coeffs) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
__Pyx_RefNannySetupContext("__init__", 0);
/* "optimized_field_elements.pyx":260
* class FQ12(FQP):
* def __init__(self, coeffs):
* self.coeffs = coeffs # <<<<<<<<<<<<<<
* self.modulus_coeffs = FQ12_modulus_coeffs
* self.mc_tuples = FQ12_mc_tuples
*/
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_coeffs, __pyx_v_coeffs) < 0) __PYX_ERR(0, 260, __pyx_L1_error)
/* "optimized_field_elements.pyx":261
* def __init__(self, coeffs):
* self.coeffs = coeffs
* self.modulus_coeffs = FQ12_modulus_coeffs # <<<<<<<<<<<<<<
* self.mc_tuples = FQ12_mc_tuples
* self.degree = 12
*/
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_FQ12_modulus_coeffs); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 261, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_modulus_coeffs, __pyx_t_1) < 0) __PYX_ERR(0, 261, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/* "optimized_field_elements.pyx":262
* self.coeffs = coeffs
* self.modulus_coeffs = FQ12_modulus_coeffs
* self.mc_tuples = FQ12_mc_tuples # <<<<<<<<<<<<<<
* self.degree = 12
* self.__class__.degree = 12
*/
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_FQ12_mc_tuples); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 262, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_mc_tuples, __pyx_t_1) < 0) __PYX_ERR(0, 262, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/* "optimized_field_elements.pyx":263
* self.modulus_coeffs = FQ12_modulus_coeffs
* self.mc_tuples = FQ12_mc_tuples
* self.degree = 12 # <<<<<<<<<<<<<<
* self.__class__.degree = 12
*/
if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_degree, __pyx_int_12) < 0) __PYX_ERR(0, 263, __pyx_L1_error)
/* "optimized_field_elements.pyx":264
* self.mc_tuples = FQ12_mc_tuples
* self.degree = 12
* self.__class__.degree = 12 # <<<<<<<<<<<<<<
*/
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_class); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 264, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
if (__Pyx_PyObject_SetAttrStr(__pyx_t_1, __pyx_n_s_degree, __pyx_int_12) < 0) __PYX_ERR(0, 264, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/* "optimized_field_elements.pyx":259
* # The 12th-degree extension field
* class FQ12(FQP):
* def __init__(self, coeffs): # <<<<<<<<<<<<<<
* self.coeffs = coeffs
* self.modulus_coeffs = FQ12_modulus_coeffs
*/
/* function exit code */
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("optimized_field_elements.FQ12.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyMethodDef __pyx_methods[] = {
{0, 0, 0, 0}
};
#if PY_MAJOR_VERSION >= 3
#if CYTHON_PEP489_MULTI_PHASE_INIT
static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/
static int __pyx_pymod_exec_optimized_field_elements(PyObject* module); /*proto*/
static PyModuleDef_Slot __pyx_moduledef_slots[] = {
{Py_mod_create, (void*)__pyx_pymod_create},
{Py_mod_exec, (void*)__pyx_pymod_exec_optimized_field_elements},
{0, NULL}
};
#endif
static struct PyModuleDef __pyx_moduledef = {
PyModuleDef_HEAD_INIT,
"optimized_field_elements",
0, /* m_doc */
#if CYTHON_PEP489_MULTI_PHASE_INIT
0, /* m_size */
#else
-1, /* m_size */
#endif
__pyx_methods /* m_methods */,
#if CYTHON_PEP489_MULTI_PHASE_INIT
__pyx_moduledef_slots, /* m_slots */
#else
NULL, /* m_reload */
#endif
NULL, /* m_traverse */
NULL, /* m_clear */
NULL /* m_free */
};
#endif
static __Pyx_StringTabEntry __pyx_string_tab[] = {
{&__pyx_n_s_FQ, __pyx_k_FQ, sizeof(__pyx_k_FQ), 0, 0, 1, 1},
{&__pyx_n_s_FQ12, __pyx_k_FQ12, sizeof(__pyx_k_FQ12), 0, 0, 1, 1},
{&__pyx_n_s_FQ12___init, __pyx_k_FQ12___init, sizeof(__pyx_k_FQ12___init), 0, 0, 1, 1},
{&__pyx_n_s_FQ12_mc_tuples, __pyx_k_FQ12_mc_tuples, sizeof(__pyx_k_FQ12_mc_tuples), 0, 0, 1, 1},
{&__pyx_n_s_FQ12_modulus_coeffs, __pyx_k_FQ12_modulus_coeffs, sizeof(__pyx_k_FQ12_modulus_coeffs), 0, 0, 1, 1},
{&__pyx_n_s_FQ2, __pyx_k_FQ2, sizeof(__pyx_k_FQ2), 0, 0, 1, 1},
{&__pyx_n_s_FQ2___init, __pyx_k_FQ2___init, sizeof(__pyx_k_FQ2___init), 0, 0, 1, 1},
{&__pyx_n_s_FQP, __pyx_k_FQP, sizeof(__pyx_k_FQP), 0, 0, 1, 1},
{&__pyx_n_s_FQP___add, __pyx_k_FQP___add, sizeof(__pyx_k_FQP___add), 0, 0, 1, 1},
{&__pyx_n_s_FQP___div, __pyx_k_FQP___div, sizeof(__pyx_k_FQP___div), 0, 0, 1, 1},
{&__pyx_n_s_FQP___eq, __pyx_k_FQP___eq, sizeof(__pyx_k_FQP___eq), 0, 0, 1, 1},
{&__pyx_n_s_FQP___init, __pyx_k_FQP___init, sizeof(__pyx_k_FQP___init), 0, 0, 1, 1},
{&__pyx_n_s_FQP___mul, __pyx_k_FQP___mul, sizeof(__pyx_k_FQP___mul), 0, 0, 1, 1},
{&__pyx_n_s_FQP___ne, __pyx_k_FQP___ne, sizeof(__pyx_k_FQP___ne), 0, 0, 1, 1},
{&__pyx_n_s_FQP___neg, __pyx_k_FQP___neg, sizeof(__pyx_k_FQP___neg), 0, 0, 1, 1},
{&__pyx_n_s_FQP___pow, __pyx_k_FQP___pow, sizeof(__pyx_k_FQP___pow), 0, 0, 1, 1},
{&__pyx_n_s_FQP___repr, __pyx_k_FQP___repr, sizeof(__pyx_k_FQP___repr), 0, 0, 1, 1},
{&__pyx_n_s_FQP___rmul, __pyx_k_FQP___rmul, sizeof(__pyx_k_FQP___rmul), 0, 0, 1, 1},
{&__pyx_n_s_FQP___sub, __pyx_k_FQP___sub, sizeof(__pyx_k_FQP___sub), 0, 0, 1, 1},
{&__pyx_n_s_FQP___truediv, __pyx_k_FQP___truediv, sizeof(__pyx_k_FQP___truediv), 0, 0, 1, 1},
{&__pyx_n_s_FQP_inv, __pyx_k_FQP_inv, sizeof(__pyx_k_FQP_inv), 0, 0, 1, 1},
{&__pyx_n_s_FQP_one, __pyx_k_FQP_one, sizeof(__pyx_k_FQP_one), 0, 0, 1, 1},
{&__pyx_n_s_FQP_zero, __pyx_k_FQP_zero, sizeof(__pyx_k_FQP_zero), 0, 0, 1, 1},
{&__pyx_n_s_FQ___add, __pyx_k_FQ___add, sizeof(__pyx_k_FQ___add), 0, 0, 1, 1},
{&__pyx_n_s_FQ___div, __pyx_k_FQ___div, sizeof(__pyx_k_FQ___div), 0, 0, 1, 1},
{&__pyx_n_s_FQ___eq, __pyx_k_FQ___eq, sizeof(__pyx_k_FQ___eq), 0, 0, 1, 1},
{&__pyx_n_s_FQ___init, __pyx_k_FQ___init, sizeof(__pyx_k_FQ___init), 0, 0, 1, 1},
{&__pyx_n_s_FQ___mul, __pyx_k_FQ___mul, sizeof(__pyx_k_FQ___mul), 0, 0, 1, 1},
{&__pyx_n_s_FQ___ne, __pyx_k_FQ___ne, sizeof(__pyx_k_FQ___ne), 0, 0, 1, 1},
{&__pyx_n_s_FQ___neg, __pyx_k_FQ___neg, sizeof(__pyx_k_FQ___neg), 0, 0, 1, 1},
{&__pyx_n_s_FQ___pow, __pyx_k_FQ___pow, sizeof(__pyx_k_FQ___pow), 0, 0, 1, 1},
{&__pyx_n_s_FQ___radd, __pyx_k_FQ___radd, sizeof(__pyx_k_FQ___radd), 0, 0, 1, 1},
{&__pyx_n_s_FQ___rdiv, __pyx_k_FQ___rdiv, sizeof(__pyx_k_FQ___rdiv), 0, 0, 1, 1},
{&__pyx_n_s_FQ___repr, __pyx_k_FQ___repr, sizeof(__pyx_k_FQ___repr), 0, 0, 1, 1},
{&__pyx_n_s_FQ___rmul, __pyx_k_FQ___rmul, sizeof(__pyx_k_FQ___rmul), 0, 0, 1, 1},
{&__pyx_n_s_FQ___rsub, __pyx_k_FQ___rsub, sizeof(__pyx_k_FQ___rsub), 0, 0, 1, 1},
{&__pyx_n_s_FQ___rtruediv, __pyx_k_FQ___rtruediv, sizeof(__pyx_k_FQ___rtruediv), 0, 0, 1, 1},
{&__pyx_n_s_FQ___sub, __pyx_k_FQ___sub, sizeof(__pyx_k_FQ___sub), 0, 0, 1, 1},
{&__pyx_n_s_FQ___truediv, __pyx_k_FQ___truediv, sizeof(__pyx_k_FQ___truediv), 0, 0, 1, 1},
{&__pyx_n_s_FQ_one, __pyx_k_FQ_one, sizeof(__pyx_k_FQ_one), 0, 0, 1, 1},
{&__pyx_n_s_FQ_zero, __pyx_k_FQ_zero, sizeof(__pyx_k_FQ_zero), 0, 0, 1, 1},
{&__pyx_n_s_a, __pyx_k_a, sizeof(__pyx_k_a), 0, 0, 1, 1},
{&__pyx_n_s_add, __pyx_k_add, sizeof(__pyx_k_add), 0, 0, 1, 1},
{&__pyx_n_s_b, __pyx_k_b, sizeof(__pyx_k_b), 0, 0, 1, 1},
{&__pyx_n_s_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 0, 1, 1},
{&__pyx_n_s_c1, __pyx_k_c1, sizeof(__pyx_k_c1), 0, 0, 1, 1},
{&__pyx_n_s_c2, __pyx_k_c2, sizeof(__pyx_k_c2), 0, 0, 1, 1},
{&__pyx_n_s_class, __pyx_k_class, sizeof(__pyx_k_class), 0, 0, 1, 1},
{&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1},
{&__pyx_n_s_cls, __pyx_k_cls, sizeof(__pyx_k_cls), 0, 0, 1, 1},
{&__pyx_n_s_coeffs, __pyx_k_coeffs, sizeof(__pyx_k_coeffs), 0, 0, 1, 1},
{&__pyx_n_s_d, __pyx_k_d, sizeof(__pyx_k_d), 0, 0, 1, 1},
{&__pyx_n_s_deg, __pyx_k_deg, sizeof(__pyx_k_deg), 0, 0, 1, 1},
{&__pyx_n_s_dega, __pyx_k_dega, sizeof(__pyx_k_dega), 0, 0, 1, 1},
{&__pyx_n_s_degb, __pyx_k_degb, sizeof(__pyx_k_degb), 0, 0, 1, 1},
{&__pyx_n_s_degree, __pyx_k_degree, sizeof(__pyx_k_degree), 0, 0, 1, 1},
{&__pyx_n_s_div, __pyx_k_div, sizeof(__pyx_k_div), 0, 0, 1, 1},
{&__pyx_n_s_doc, __pyx_k_doc, sizeof(__pyx_k_doc), 0, 0, 1, 1},
{&__pyx_n_s_eli, __pyx_k_eli, sizeof(__pyx_k_eli), 0, 0, 1, 1},
{&__pyx_n_s_elj, __pyx_k_elj, sizeof(__pyx_k_elj), 0, 0, 1, 1},
{&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1},
{&__pyx_n_s_eq, __pyx_k_eq, sizeof(__pyx_k_eq), 0, 0, 1, 1},
{&__pyx_n_s_exp, __pyx_k_exp, sizeof(__pyx_k_exp), 0, 0, 1, 1},
{&__pyx_n_s_field_modulus, __pyx_k_field_modulus, sizeof(__pyx_k_field_modulus), 0, 0, 1, 1},
{&__pyx_n_s_high, __pyx_k_high, sizeof(__pyx_k_high), 0, 0, 1, 1},
{&__pyx_n_s_hm, __pyx_k_hm, sizeof(__pyx_k_hm), 0, 0, 1, 1},
{&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1},
{&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
{&__pyx_n_s_init, __pyx_k_init, sizeof(__pyx_k_init), 0, 0, 1, 1},
{&__pyx_n_s_inner_enumerate, __pyx_k_inner_enumerate, sizeof(__pyx_k_inner_enumerate), 0, 0, 1, 1},
{&__pyx_n_s_int_types, __pyx_k_int_types, sizeof(__pyx_k_int_types), 0, 0, 1, 1},
{&__pyx_n_s_inv, __pyx_k_inv, sizeof(__pyx_k_inv), 0, 0, 1, 1},
{&__pyx_n_s_j, __pyx_k_j, sizeof(__pyx_k_j), 0, 0, 1, 1},
{&__pyx_n_s_lm, __pyx_k_lm, sizeof(__pyx_k_lm), 0, 0, 1, 1},
{&__pyx_n_s_low, __pyx_k_low, sizeof(__pyx_k_low), 0, 0, 1, 1},
{&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
{&__pyx_n_s_major, __pyx_k_major, sizeof(__pyx_k_major), 0, 0, 1, 1},
{&__pyx_n_s_mc_tuples, __pyx_k_mc_tuples, sizeof(__pyx_k_mc_tuples), 0, 0, 1, 1},
{&__pyx_n_s_metaclass, __pyx_k_metaclass, sizeof(__pyx_k_metaclass), 0, 0, 1, 1},
{&__pyx_n_s_module, __pyx_k_module, sizeof(__pyx_k_module), 0, 0, 1, 1},
{&__pyx_n_s_modulus_coeffs, __pyx_k_modulus_coeffs, sizeof(__pyx_k_modulus_coeffs), 0, 0, 1, 1},
{&__pyx_n_s_mul, __pyx_k_mul, sizeof(__pyx_k_mul), 0, 0, 1, 1},
{&__pyx_n_s_n, __pyx_k_n, sizeof(__pyx_k_n), 0, 0, 1, 1},
{&__pyx_n_s_ne, __pyx_k_ne, sizeof(__pyx_k_ne), 0, 0, 1, 1},
{&__pyx_n_s_neg, __pyx_k_neg, sizeof(__pyx_k_neg), 0, 0, 1, 1},
{&__pyx_n_s_new, __pyx_k_new, sizeof(__pyx_k_new), 0, 0, 1, 1},
{&__pyx_n_s_nm, __pyx_k_nm, sizeof(__pyx_k_nm), 0, 0, 1, 1},
{&__pyx_n_s_o, __pyx_k_o, sizeof(__pyx_k_o), 0, 0, 1, 1},
{&__pyx_n_s_object, __pyx_k_object, sizeof(__pyx_k_object), 0, 0, 1, 1},
{&__pyx_n_s_on, __pyx_k_on, sizeof(__pyx_k_on), 0, 0, 1, 1},
{&__pyx_n_s_one, __pyx_k_one, sizeof(__pyx_k_one), 0, 0, 1, 1},
{&__pyx_n_s_optimized_field_elements, __pyx_k_optimized_field_elements, sizeof(__pyx_k_optimized_field_elements), 0, 0, 1, 1},
{&__pyx_n_s_other, __pyx_k_other, sizeof(__pyx_k_other), 0, 0, 1, 1},
{&__pyx_n_s_p, __pyx_k_p, sizeof(__pyx_k_p), 0, 0, 1, 1},
{&__pyx_n_s_poly_rounded_div, __pyx_k_poly_rounded_div, sizeof(__pyx_k_poly_rounded_div), 0, 0, 1, 1},
{&__pyx_n_s_pop, __pyx_k_pop, sizeof(__pyx_k_pop), 0, 0, 1, 1},
{&__pyx_n_s_pow, __pyx_k_pow, sizeof(__pyx_k_pow), 0, 0, 1, 1},
{&__pyx_n_s_prepare, __pyx_k_prepare, sizeof(__pyx_k_prepare), 0, 0, 1, 1},
{&__pyx_n_s_prime_field_inv, __pyx_k_prime_field_inv, sizeof(__pyx_k_prime_field_inv), 0, 0, 1, 1},
{&__pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_k_py_ecc_cython_src_optimized_fiel, sizeof(__pyx_k_py_ecc_cython_src_optimized_fiel), 0, 0, 1, 0},
{&__pyx_n_s_qualname, __pyx_k_qualname, sizeof(__pyx_k_qualname), 0, 0, 1, 1},
{&__pyx_n_s_r, __pyx_k_r, sizeof(__pyx_k_r), 0, 0, 1, 1},
{&__pyx_n_s_radd, __pyx_k_radd, sizeof(__pyx_k_radd), 0, 0, 1, 1},
{&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
{&__pyx_n_s_rdiv, __pyx_k_rdiv, sizeof(__pyx_k_rdiv), 0, 0, 1, 1},
{&__pyx_n_s_repr, __pyx_k_repr, sizeof(__pyx_k_repr), 0, 0, 1, 1},
{&__pyx_n_s_rmul, __pyx_k_rmul, sizeof(__pyx_k_rmul), 0, 0, 1, 1},
{&__pyx_n_s_rsub, __pyx_k_rsub, sizeof(__pyx_k_rsub), 0, 0, 1, 1},
{&__pyx_n_s_rtruediv, __pyx_k_rtruediv, sizeof(__pyx_k_rtruediv), 0, 0, 1, 1},
{&__pyx_n_s_self, __pyx_k_self, sizeof(__pyx_k_self), 0, 0, 1, 1},
{&__pyx_n_s_sub, __pyx_k_sub, sizeof(__pyx_k_sub), 0, 0, 1, 1},
{&__pyx_n_s_sys, __pyx_k_sys, sizeof(__pyx_k_sys), 0, 0, 1, 1},
{&__pyx_n_s_t, __pyx_k_t, sizeof(__pyx_k_t), 0, 0, 1, 1},
{&__pyx_n_s_temp, __pyx_k_temp, sizeof(__pyx_k_temp), 0, 0, 1, 1},
{&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
{&__pyx_n_s_top, __pyx_k_top, sizeof(__pyx_k_top), 0, 0, 1, 1},
{&__pyx_n_s_truediv, __pyx_k_truediv, sizeof(__pyx_k_truediv), 0, 0, 1, 1},
{&__pyx_n_s_version_info, __pyx_k_version_info, sizeof(__pyx_k_version_info), 0, 0, 1, 1},
{&__pyx_n_s_x, __pyx_k_x, sizeof(__pyx_k_x), 0, 0, 1, 1},
{&__pyx_n_s_y, __pyx_k_y, sizeof(__pyx_k_y), 0, 0, 1, 1},
{&__pyx_n_s_zero, __pyx_k_zero, sizeof(__pyx_k_zero), 0, 0, 1, 1},
{&__pyx_n_s_zip, __pyx_k_zip, sizeof(__pyx_k_zip), 0, 0, 1, 1},
{0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
__pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(0, 8, __pyx_L1_error)
__pyx_builtin_object = __Pyx_GetBuiltinName(__pyx_n_s_object); if (!__pyx_builtin_object) __PYX_ERR(0, 33, __pyx_L1_error)
__pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 126, __pyx_L1_error)
__pyx_builtin_zip = __Pyx_GetBuiltinName(__pyx_n_s_zip); if (!__pyx_builtin_zip) __PYX_ERR(0, 148, __pyx_L1_error)
return 0;
__pyx_L1_error:;
return -1;
}
static int __Pyx_InitCachedConstants(void) {
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
/* "optimized_field_elements.pyx":81
* def __pow__(self, other):
* if other == 0:
* return FQ(1) # <<<<<<<<<<<<<<
* elif other == 1:
* return FQ(self.n)
*/
__pyx_tuple_ = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 81, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple_);
__Pyx_GIVEREF(__pyx_tuple_);
/* "optimized_field_elements.pyx":106
* @classmethod
* def one(cls):
* return cls(1) # <<<<<<<<<<<<<<
*
* @classmethod
*/
__pyx_tuple__2 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 106, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__2);
__Pyx_GIVEREF(__pyx_tuple__2);
/* "optimized_field_elements.pyx":110
* @classmethod
* def zero(cls):
* return cls(0) # <<<<<<<<<<<<<<
*
*
*/
__pyx_tuple__3 = PyTuple_Pack(1, __pyx_int_0); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 110, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__3);
__Pyx_GIVEREF(__pyx_tuple__3);
/* "optimized_field_elements.pyx":252
* self.coeffs = coeffs
* self.modulus_coeffs = [1, 0]
* self.mc_tuples = [(0, 1)] # <<<<<<<<<<<<<<
* self.degree = 2
* self.__class__.degree = 2
*/
__pyx_tuple__4 = PyTuple_Pack(2, __pyx_int_0, __pyx_int_1); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 252, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__4);
__Pyx_GIVEREF(__pyx_tuple__4);
/* "optimized_field_elements.pyx":19
* # Extended euclidean algorithm to find modular inverses for
* # integers
* def prime_field_inv(a, n): # <<<<<<<<<<<<<<
* if a == 0:
* return 0
*/
__pyx_tuple__5 = PyTuple_Pack(9, __pyx_n_s_a, __pyx_n_s_n, __pyx_n_s_lm, __pyx_n_s_hm, __pyx_n_s_low, __pyx_n_s_high, __pyx_n_s_r, __pyx_n_s_nm, __pyx_n_s_new); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 19, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__5);
__Pyx_GIVEREF(__pyx_tuple__5);
__pyx_codeobj__6 = (PyObject*)__Pyx_PyCode_New(2, 0, 9, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__5, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_prime_field_inv, 19, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__6)) __PYX_ERR(0, 19, __pyx_L1_error)
/* "optimized_field_elements.pyx":33
* # A class for field elements in FQ. Wrap a number in this class,
* # and it becomes a field element.
* class FQ(object): # <<<<<<<<<<<<<<
* def __init__(self, n):
* if isinstance(n, self.__class__):
*/
__pyx_tuple__7 = PyTuple_Pack(1, __pyx_builtin_object); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 33, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__7);
__Pyx_GIVEREF(__pyx_tuple__7);
/* "optimized_field_elements.pyx":34
* # and it becomes a field element.
* class FQ(object):
* def __init__(self, n): # <<<<<<<<<<<<<<
* if isinstance(n, self.__class__):
* self.n = n.n
*/
__pyx_tuple__8 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_n); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 34, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__8);
__Pyx_GIVEREF(__pyx_tuple__8);
__pyx_codeobj__9 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__8, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_init, 34, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__9)) __PYX_ERR(0, 34, __pyx_L1_error)
/* "optimized_field_elements.pyx":41
* assert isinstance(self.n, int_types)
*
* def __add__(self, other): # <<<<<<<<<<<<<<
* on = other.n if isinstance(other, FQ) else other
* return FQ((self.n + on) % field_modulus)
*/
__pyx_tuple__10 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_other, __pyx_n_s_on); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 41, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__10);
__Pyx_GIVEREF(__pyx_tuple__10);
__pyx_codeobj__11 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__10, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_add, 41, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__11)) __PYX_ERR(0, 41, __pyx_L1_error)
/* "optimized_field_elements.pyx":45
* return FQ((self.n + on) % field_modulus)
*
* def __mul__(self, other): # <<<<<<<<<<<<<<
* on = other.n if isinstance(other, FQ) else other
* return FQ((self.n * on) % field_modulus)
*/
__pyx_tuple__12 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_other, __pyx_n_s_on); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 45, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__12);
__Pyx_GIVEREF(__pyx_tuple__12);
__pyx_codeobj__13 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__12, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_mul, 45, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__13)) __PYX_ERR(0, 45, __pyx_L1_error)
/* "optimized_field_elements.pyx":49
* return FQ((self.n * on) % field_modulus)
*
* def __rmul__(self, other): # <<<<<<<<<<<<<<
* return self * other
*
*/
__pyx_tuple__14 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_other); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 49, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__14);
__Pyx_GIVEREF(__pyx_tuple__14);
__pyx_codeobj__15 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__14, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_rmul, 49, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__15)) __PYX_ERR(0, 49, __pyx_L1_error)
/* "optimized_field_elements.pyx":52
* return self * other
*
* def __radd__(self, other): # <<<<<<<<<<<<<<
* return self + other
*
*/
__pyx_tuple__16 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_other); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(0, 52, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__16);
__Pyx_GIVEREF(__pyx_tuple__16);
__pyx_codeobj__17 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__16, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_radd, 52, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__17)) __PYX_ERR(0, 52, __pyx_L1_error)
/* "optimized_field_elements.pyx":55
* return self + other
*
* def __rsub__(self, other): # <<<<<<<<<<<<<<
* on = other.n if isinstance(other, FQ) else other
* return FQ((on - self.n) % field_modulus)
*/
__pyx_tuple__18 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_other, __pyx_n_s_on); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 55, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__18);
__Pyx_GIVEREF(__pyx_tuple__18);
__pyx_codeobj__19 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__18, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_rsub, 55, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__19)) __PYX_ERR(0, 55, __pyx_L1_error)
/* "optimized_field_elements.pyx":59
* return FQ((on - self.n) % field_modulus)
*
* def __sub__(self, other): # <<<<<<<<<<<<<<
* on = other.n if isinstance(other, FQ) else other
* return FQ((self.n - on) % field_modulus)
*/
__pyx_tuple__20 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_other, __pyx_n_s_on); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 59, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__20);
__Pyx_GIVEREF(__pyx_tuple__20);
__pyx_codeobj__21 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__20, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_sub, 59, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__21)) __PYX_ERR(0, 59, __pyx_L1_error)
/* "optimized_field_elements.pyx":63
* return FQ((self.n - on) % field_modulus)
*
* def __div__(self, other): # <<<<<<<<<<<<<<
* on = other.n if isinstance(other, FQ) else other
* assert isinstance(on, int_types)
*/
__pyx_tuple__22 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_other, __pyx_n_s_on); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 63, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__22);
__Pyx_GIVEREF(__pyx_tuple__22);
__pyx_codeobj__23 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__22, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_div, 63, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__23)) __PYX_ERR(0, 63, __pyx_L1_error)
/* "optimized_field_elements.pyx":68
* return FQ(self.n * prime_field_inv(on, field_modulus) % field_modulus)
*
* def __truediv__(self, other): # <<<<<<<<<<<<<<
* return self.__div__(other)
*
*/
__pyx_tuple__24 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_other); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 68, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__24);
__Pyx_GIVEREF(__pyx_tuple__24);
__pyx_codeobj__25 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__24, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_truediv, 68, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__25)) __PYX_ERR(0, 68, __pyx_L1_error)
/* "optimized_field_elements.pyx":71
* return self.__div__(other)
*
* def __rdiv__(self, other): # <<<<<<<<<<<<<<
* on = other.n if isinstance(other, FQ) else other
* assert isinstance(on, int_types), on
*/
__pyx_tuple__26 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_other, __pyx_n_s_on); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 71, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__26);
__Pyx_GIVEREF(__pyx_tuple__26);
__pyx_codeobj__27 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__26, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_rdiv, 71, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__27)) __PYX_ERR(0, 71, __pyx_L1_error)
/* "optimized_field_elements.pyx":76
* return FQ(prime_field_inv(self.n, field_modulus) * on % field_modulus)
*
* def __rtruediv__(self, other): # <<<<<<<<<<<<<<
* return self.__rdiv__(other)
*
*/
__pyx_tuple__28 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_other); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 76, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__28);
__Pyx_GIVEREF(__pyx_tuple__28);
__pyx_codeobj__29 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__28, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_rtruediv, 76, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__29)) __PYX_ERR(0, 76, __pyx_L1_error)
/* "optimized_field_elements.pyx":79
* return self.__rdiv__(other)
*
* def __pow__(self, other): # <<<<<<<<<<<<<<
* if other == 0:
* return FQ(1)
*/
__pyx_tuple__30 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_other); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 79, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__30);
__Pyx_GIVEREF(__pyx_tuple__30);
__pyx_codeobj__31 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__30, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_pow, 79, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__31)) __PYX_ERR(0, 79, __pyx_L1_error)
/* "optimized_field_elements.pyx":89
* return ((self * self) ** int(other // 2)) * self
*
* def __eq__(self, other): # <<<<<<<<<<<<<<
* if isinstance(other, FQ):
* return self.n == other.n
*/
__pyx_tuple__32 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_other); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 89, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__32);
__Pyx_GIVEREF(__pyx_tuple__32);
__pyx_codeobj__33 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__32, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_eq, 89, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__33)) __PYX_ERR(0, 89, __pyx_L1_error)
/* "optimized_field_elements.pyx":95
* return self.n == other
*
* def __ne__(self, other): # <<<<<<<<<<<<<<
* return not self == other
*
*/
__pyx_tuple__34 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_other); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(0, 95, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__34);
__Pyx_GIVEREF(__pyx_tuple__34);
__pyx_codeobj__35 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__34, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_ne, 95, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__35)) __PYX_ERR(0, 95, __pyx_L1_error)
/* "optimized_field_elements.pyx":98
* return not self == other
*
* def __neg__(self): # <<<<<<<<<<<<<<
* return FQ(-self.n)
*
*/
__pyx_tuple__36 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(0, 98, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__36);
__Pyx_GIVEREF(__pyx_tuple__36);
__pyx_codeobj__37 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__36, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_neg, 98, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__37)) __PYX_ERR(0, 98, __pyx_L1_error)
/* "optimized_field_elements.pyx":101
* return FQ(-self.n)
*
* def __repr__(self): # <<<<<<<<<<<<<<
* return repr(self.n)
*
*/
__pyx_tuple__38 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__38)) __PYX_ERR(0, 101, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__38);
__Pyx_GIVEREF(__pyx_tuple__38);
__pyx_codeobj__39 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__38, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_repr, 101, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__39)) __PYX_ERR(0, 101, __pyx_L1_error)
/* "optimized_field_elements.pyx":105
*
* @classmethod
* def one(cls): # <<<<<<<<<<<<<<
* return cls(1)
*
*/
__pyx_tuple__40 = PyTuple_Pack(1, __pyx_n_s_cls); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(0, 105, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__40);
__Pyx_GIVEREF(__pyx_tuple__40);
__pyx_codeobj__41 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__40, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_one, 105, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__41)) __PYX_ERR(0, 105, __pyx_L1_error)
/* "optimized_field_elements.pyx":109
*
* @classmethod
* def zero(cls): # <<<<<<<<<<<<<<
* return cls(0)
*
*/
__pyx_tuple__42 = PyTuple_Pack(1, __pyx_n_s_cls); if (unlikely(!__pyx_tuple__42)) __PYX_ERR(0, 109, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__42);
__Pyx_GIVEREF(__pyx_tuple__42);
__pyx_codeobj__43 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__42, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_zero, 109, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__43)) __PYX_ERR(0, 109, __pyx_L1_error)
/* "optimized_field_elements.pyx":114
*
* # Utility methods for polynomial math
* def deg(p): # <<<<<<<<<<<<<<
* d = len(p) - 1
* while p[d] == 0 and d:
*/
__pyx_tuple__44 = PyTuple_Pack(2, __pyx_n_s_p, __pyx_n_s_d); if (unlikely(!__pyx_tuple__44)) __PYX_ERR(0, 114, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__44);
__Pyx_GIVEREF(__pyx_tuple__44);
__pyx_codeobj__45 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__44, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_deg, 114, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__45)) __PYX_ERR(0, 114, __pyx_L1_error)
/* "optimized_field_elements.pyx":121
*
*
* def poly_rounded_div(a, b): # <<<<<<<<<<<<<<
* dega = deg(a)
* degb = deg(b)
*/
__pyx_tuple__46 = PyTuple_Pack(9, __pyx_n_s_a, __pyx_n_s_b, __pyx_n_s_dega, __pyx_n_s_degb, __pyx_n_s_temp, __pyx_n_s_o, __pyx_n_s_i, __pyx_n_s_c, __pyx_n_s_x); if (unlikely(!__pyx_tuple__46)) __PYX_ERR(0, 121, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__46);
__Pyx_GIVEREF(__pyx_tuple__46);
__pyx_codeobj__47 = (PyObject*)__Pyx_PyCode_New(2, 0, 9, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__46, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_poly_rounded_div, 121, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__47)) __PYX_ERR(0, 121, __pyx_L1_error)
/* "optimized_field_elements.pyx":134
*
* # A class for elements in polynomial extension fields
* class FQP(object): # <<<<<<<<<<<<<<
* def __init__(self, coeffs, modulus_coeffs):
* assert len(coeffs) == len(modulus_coeffs)
*/
__pyx_tuple__48 = PyTuple_Pack(1, __pyx_builtin_object); if (unlikely(!__pyx_tuple__48)) __PYX_ERR(0, 134, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__48);
__Pyx_GIVEREF(__pyx_tuple__48);
/* "optimized_field_elements.pyx":135
* # A class for elements in polynomial extension fields
* class FQP(object):
* def __init__(self, coeffs, modulus_coeffs): # <<<<<<<<<<<<<<
* assert len(coeffs) == len(modulus_coeffs)
* self.coeffs = coeffs
*/
__pyx_tuple__49 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_coeffs, __pyx_n_s_modulus_coeffs); if (unlikely(!__pyx_tuple__49)) __PYX_ERR(0, 135, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__49);
__Pyx_GIVEREF(__pyx_tuple__49);
__pyx_codeobj__50 = (PyObject*)__Pyx_PyCode_New(3, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__49, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_init, 135, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__50)) __PYX_ERR(0, 135, __pyx_L1_error)
/* "optimized_field_elements.pyx":143
* self.degree = len(self.modulus_coeffs)
*
* def __add__(self, other): # <<<<<<<<<<<<<<
* assert isinstance(other, self.__class__)
* return self.__class__([
*/
__pyx_tuple__51 = PyTuple_Pack(4, __pyx_n_s_self, __pyx_n_s_other, __pyx_n_s_x, __pyx_n_s_y); if (unlikely(!__pyx_tuple__51)) __PYX_ERR(0, 143, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__51);
__Pyx_GIVEREF(__pyx_tuple__51);
__pyx_codeobj__52 = (PyObject*)__Pyx_PyCode_New(2, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__51, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_add, 143, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__52)) __PYX_ERR(0, 143, __pyx_L1_error)
/* "optimized_field_elements.pyx":151
* ])
*
* def __sub__(self, other): # <<<<<<<<<<<<<<
* assert isinstance(other, self.__class__)
* return self.__class__([
*/
__pyx_tuple__53 = PyTuple_Pack(4, __pyx_n_s_self, __pyx_n_s_other, __pyx_n_s_x, __pyx_n_s_y); if (unlikely(!__pyx_tuple__53)) __PYX_ERR(0, 151, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__53);
__Pyx_GIVEREF(__pyx_tuple__53);
__pyx_codeobj__54 = (PyObject*)__Pyx_PyCode_New(2, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__53, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_sub, 151, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__54)) __PYX_ERR(0, 151, __pyx_L1_error)
/* "optimized_field_elements.pyx":159
* ])
*
* def __mul__(self, other): # <<<<<<<<<<<<<<
* if isinstance(other, int_types):
* return self.__class__([c * other % field_modulus for c in self.coeffs])
*/
__pyx_tuple__55 = PyTuple_Pack(12, __pyx_n_s_self, __pyx_n_s_other, __pyx_n_s_b, __pyx_n_s_inner_enumerate, __pyx_n_s_i, __pyx_n_s_eli, __pyx_n_s_j, __pyx_n_s_elj, __pyx_n_s_exp, __pyx_n_s_top, __pyx_n_s_c, __pyx_n_s_x); if (unlikely(!__pyx_tuple__55)) __PYX_ERR(0, 159, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__55);
__Pyx_GIVEREF(__pyx_tuple__55);
__pyx_codeobj__56 = (PyObject*)__Pyx_PyCode_New(2, 0, 12, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__55, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_mul, 159, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__56)) __PYX_ERR(0, 159, __pyx_L1_error)
/* "optimized_field_elements.pyx":176
* return self.__class__([x % field_modulus for x in b])
*
* def __rmul__(self, other): # <<<<<<<<<<<<<<
* return self * other
*
*/
__pyx_tuple__57 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_other); if (unlikely(!__pyx_tuple__57)) __PYX_ERR(0, 176, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__57);
__Pyx_GIVEREF(__pyx_tuple__57);
__pyx_codeobj__58 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__57, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_rmul, 176, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__58)) __PYX_ERR(0, 176, __pyx_L1_error)
/* "optimized_field_elements.pyx":179
* return self * other
*
* def __div__(self, other): # <<<<<<<<<<<<<<
* if isinstance(other, int_types):
* return self.__class__([
*/
__pyx_tuple__59 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_other, __pyx_n_s_c); if (unlikely(!__pyx_tuple__59)) __PYX_ERR(0, 179, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__59);
__Pyx_GIVEREF(__pyx_tuple__59);
__pyx_codeobj__60 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__59, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_div, 179, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__60)) __PYX_ERR(0, 179, __pyx_L1_error)
/* "optimized_field_elements.pyx":190
* return self * other.inv()
*
* def __truediv__(self, other): # <<<<<<<<<<<<<<
* return self.__div__(other)
*
*/
__pyx_tuple__61 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_other); if (unlikely(!__pyx_tuple__61)) __PYX_ERR(0, 190, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__61);
__Pyx_GIVEREF(__pyx_tuple__61);
__pyx_codeobj__62 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__61, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_truediv, 190, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__62)) __PYX_ERR(0, 190, __pyx_L1_error)
/* "optimized_field_elements.pyx":193
* return self.__div__(other)
*
* def __pow__(self, other): # <<<<<<<<<<<<<<
* o = self.__class__([1] + [0] * (self.degree - 1))
* t = self
*/
__pyx_tuple__63 = PyTuple_Pack(4, __pyx_n_s_self, __pyx_n_s_other, __pyx_n_s_o, __pyx_n_s_t); if (unlikely(!__pyx_tuple__63)) __PYX_ERR(0, 193, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__63);
__Pyx_GIVEREF(__pyx_tuple__63);
__pyx_codeobj__64 = (PyObject*)__Pyx_PyCode_New(2, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__63, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_pow, 193, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__64)) __PYX_ERR(0, 193, __pyx_L1_error)
/* "optimized_field_elements.pyx":204
*
* # Extended euclidean algorithm used to find the modular inverse
* def inv(self): # <<<<<<<<<<<<<<
* lm, hm = [1] + [0] * self.degree, [0] * (self.degree + 1)
* low, high = self.coeffs + [0], self.modulus_coeffs + [1]
*/
__pyx_tuple__65 = PyTuple_Pack(11, __pyx_n_s_self, __pyx_n_s_lm, __pyx_n_s_hm, __pyx_n_s_low, __pyx_n_s_high, __pyx_n_s_r, __pyx_n_s_nm, __pyx_n_s_new, __pyx_n_s_i, __pyx_n_s_j, __pyx_n_s_x); if (unlikely(!__pyx_tuple__65)) __PYX_ERR(0, 204, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__65);
__Pyx_GIVEREF(__pyx_tuple__65);
__pyx_codeobj__66 = (PyObject*)__Pyx_PyCode_New(1, 0, 11, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__65, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_inv, 204, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__66)) __PYX_ERR(0, 204, __pyx_L1_error)
/* "optimized_field_elements.pyx":222
* return self.__class__(lm[:self.degree]) / low[0]
*
* def __repr__(self): # <<<<<<<<<<<<<<
* return repr(self.coeffs)
*
*/
__pyx_tuple__67 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__67)) __PYX_ERR(0, 222, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__67);
__Pyx_GIVEREF(__pyx_tuple__67);
__pyx_codeobj__68 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__67, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_repr, 222, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__68)) __PYX_ERR(0, 222, __pyx_L1_error)
/* "optimized_field_elements.pyx":225
* return repr(self.coeffs)
*
* def __eq__(self, other): # <<<<<<<<<<<<<<
* assert isinstance(other, self.__class__)
* for c1, c2 in zip(self.coeffs, other.coeffs):
*/
__pyx_tuple__69 = PyTuple_Pack(4, __pyx_n_s_self, __pyx_n_s_other, __pyx_n_s_c1, __pyx_n_s_c2); if (unlikely(!__pyx_tuple__69)) __PYX_ERR(0, 225, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__69);
__Pyx_GIVEREF(__pyx_tuple__69);
__pyx_codeobj__70 = (PyObject*)__Pyx_PyCode_New(2, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__69, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_eq, 225, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__70)) __PYX_ERR(0, 225, __pyx_L1_error)
/* "optimized_field_elements.pyx":232
* return True
*
* def __ne__(self, other): # <<<<<<<<<<<<<<
* return not self == other
*
*/
__pyx_tuple__71 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_other); if (unlikely(!__pyx_tuple__71)) __PYX_ERR(0, 232, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__71);
__Pyx_GIVEREF(__pyx_tuple__71);
__pyx_codeobj__72 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__71, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_ne, 232, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__72)) __PYX_ERR(0, 232, __pyx_L1_error)
/* "optimized_field_elements.pyx":235
* return not self == other
*
* def __neg__(self): # <<<<<<<<<<<<<<
* return self.__class__([-c for c in self.coeffs])
*
*/
__pyx_tuple__73 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_c); if (unlikely(!__pyx_tuple__73)) __PYX_ERR(0, 235, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__73);
__Pyx_GIVEREF(__pyx_tuple__73);
__pyx_codeobj__74 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__73, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_neg, 235, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__74)) __PYX_ERR(0, 235, __pyx_L1_error)
/* "optimized_field_elements.pyx":239
*
* @classmethod
* def one(cls): # <<<<<<<<<<<<<<
* return cls([1] + [0] * (cls.degree - 1))
*
*/
__pyx_tuple__75 = PyTuple_Pack(1, __pyx_n_s_cls); if (unlikely(!__pyx_tuple__75)) __PYX_ERR(0, 239, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__75);
__Pyx_GIVEREF(__pyx_tuple__75);
__pyx_codeobj__76 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__75, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_one, 239, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__76)) __PYX_ERR(0, 239, __pyx_L1_error)
/* "optimized_field_elements.pyx":243
*
* @classmethod
* def zero(cls): # <<<<<<<<<<<<<<
* return cls([0] * cls.degree)
*
*/
__pyx_tuple__77 = PyTuple_Pack(1, __pyx_n_s_cls); if (unlikely(!__pyx_tuple__77)) __PYX_ERR(0, 243, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__77);
__Pyx_GIVEREF(__pyx_tuple__77);
__pyx_codeobj__78 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__77, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_zero, 243, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__78)) __PYX_ERR(0, 243, __pyx_L1_error)
/* "optimized_field_elements.pyx":249
* # The quadratic extension field
* class FQ2(FQP):
* def __init__(self, coeffs): # <<<<<<<<<<<<<<
* self.coeffs = coeffs
* self.modulus_coeffs = [1, 0]
*/
__pyx_tuple__79 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_coeffs); if (unlikely(!__pyx_tuple__79)) __PYX_ERR(0, 249, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__79);
__Pyx_GIVEREF(__pyx_tuple__79);
__pyx_codeobj__80 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__79, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_init, 249, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__80)) __PYX_ERR(0, 249, __pyx_L1_error)
/* "optimized_field_elements.pyx":259
* # The 12th-degree extension field
* class FQ12(FQP):
* def __init__(self, coeffs): # <<<<<<<<<<<<<<
* self.coeffs = coeffs
* self.modulus_coeffs = FQ12_modulus_coeffs
*/
__pyx_tuple__81 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_coeffs); if (unlikely(!__pyx_tuple__81)) __PYX_ERR(0, 259, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__81);
__Pyx_GIVEREF(__pyx_tuple__81);
__pyx_codeobj__82 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__81, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_py_ecc_cython_src_optimized_fiel, __pyx_n_s_init, 259, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__82)) __PYX_ERR(0, 259, __pyx_L1_error)
__Pyx_RefNannyFinishContext();
return 0;
__pyx_L1_error:;
__Pyx_RefNannyFinishContext();
return -1;
}
static int __Pyx_InitGlobals(void) {
__pyx_umethod_PyList_Type_pop.type = (PyObject*)&PyList_Type;
if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
__pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error)
__pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error)
__pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) __PYX_ERR(0, 1, __pyx_L1_error)
__pyx_int_12 = PyInt_FromLong(12); if (unlikely(!__pyx_int_12)) __PYX_ERR(0, 1, __pyx_L1_error)
__pyx_int_82 = PyInt_FromLong(82); if (unlikely(!__pyx_int_82)) __PYX_ERR(0, 1, __pyx_L1_error)
__pyx_int_21888242871839275222246405745257275088696311157297823662689037894645226208583 = PyInt_FromString((char *)"21888242871839275222246405745257275088696311157297823662689037894645226208583", 0, 0); if (unlikely(!__pyx_int_21888242871839275222246405745257275088696311157297823662689037894645226208583)) __PYX_ERR(0, 1, __pyx_L1_error)
__pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) __PYX_ERR(0, 1, __pyx_L1_error)
__pyx_int_neg_18 = PyInt_FromLong(-18); if (unlikely(!__pyx_int_neg_18)) __PYX_ERR(0, 1, __pyx_L1_error)
return 0;
__pyx_L1_error:;
return -1;
}
static int __Pyx_modinit_global_init_code(void); /*proto*/
static int __Pyx_modinit_variable_export_code(void); /*proto*/
static int __Pyx_modinit_function_export_code(void); /*proto*/
static int __Pyx_modinit_type_init_code(void); /*proto*/
static int __Pyx_modinit_type_import_code(void); /*proto*/
static int __Pyx_modinit_variable_import_code(void); /*proto*/
static int __Pyx_modinit_function_import_code(void); /*proto*/
static int __Pyx_modinit_global_init_code(void) {
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0);
/*--- Global init code ---*/
__Pyx_RefNannyFinishContext();
return 0;
}
static int __Pyx_modinit_variable_export_code(void) {
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0);
/*--- Variable export code ---*/
__Pyx_RefNannyFinishContext();
return 0;
}
static int __Pyx_modinit_function_export_code(void) {
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0);
/*--- Function export code ---*/
__Pyx_RefNannyFinishContext();
return 0;
}
static int __Pyx_modinit_type_init_code(void) {
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
/*--- Type init code ---*/
__Pyx_RefNannyFinishContext();
return 0;
}
static int __Pyx_modinit_type_import_code(void) {
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
/*--- Type import code ---*/
__Pyx_RefNannyFinishContext();
return 0;
}
static int __Pyx_modinit_variable_import_code(void) {
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0);
/*--- Variable import code ---*/
__Pyx_RefNannyFinishContext();
return 0;
}
static int __Pyx_modinit_function_import_code(void) {
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0);
/*--- Function import code ---*/
__Pyx_RefNannyFinishContext();
return 0;
}
#if PY_MAJOR_VERSION < 3
#ifdef CYTHON_NO_PYINIT_EXPORT
#define __Pyx_PyMODINIT_FUNC void
#else
#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
#endif
#else
#ifdef CYTHON_NO_PYINIT_EXPORT
#define __Pyx_PyMODINIT_FUNC PyObject *
#else
#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
#endif
#endif
#ifndef CYTHON_SMALL_CODE
#if defined(__clang__)
#define CYTHON_SMALL_CODE
#elif defined(__GNUC__) && (!(defined(__cplusplus)) || (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 4)))
#define CYTHON_SMALL_CODE __attribute__((optimize("Os")))
#else
#define CYTHON_SMALL_CODE
#endif
#endif
#if PY_MAJOR_VERSION < 3
__Pyx_PyMODINIT_FUNC initoptimized_field_elements(void) CYTHON_SMALL_CODE; /*proto*/
__Pyx_PyMODINIT_FUNC initoptimized_field_elements(void)
#else
__Pyx_PyMODINIT_FUNC PyInit_optimized_field_elements(void) CYTHON_SMALL_CODE; /*proto*/
__Pyx_PyMODINIT_FUNC PyInit_optimized_field_elements(void)
#if CYTHON_PEP489_MULTI_PHASE_INIT
{
return PyModuleDef_Init(&__pyx_moduledef);
}
static int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name) {
PyObject *value = PyObject_GetAttrString(spec, from_name);
int result = 0;
if (likely(value)) {
result = PyDict_SetItemString(moddict, to_name, value);
Py_DECREF(value);
} else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
PyErr_Clear();
} else {
result = -1;
}
return result;
}
static PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) {
PyObject *module = NULL, *moddict, *modname;
if (__pyx_m)
return __Pyx_NewRef(__pyx_m);
modname = PyObject_GetAttrString(spec, "name");
if (unlikely(!modname)) goto bad;
module = PyModule_NewObject(modname);
Py_DECREF(modname);
if (unlikely(!module)) goto bad;
moddict = PyModule_GetDict(module);
if (unlikely(!moddict)) goto bad;
if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__") < 0)) goto bad;
if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__") < 0)) goto bad;
if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__") < 0)) goto bad;
if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__") < 0)) goto bad;
return module;
bad:
Py_XDECREF(module);
return NULL;
}
static int __pyx_pymod_exec_optimized_field_elements(PyObject *__pyx_pyinit_module)
#endif
#endif
{
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
PyObject *__pyx_t_3 = NULL;
PyObject *__pyx_t_4 = NULL;
Py_ssize_t __pyx_t_5;
PyObject *(*__pyx_t_6)(PyObject *);
int __pyx_t_7;
PyObject *__pyx_t_8 = NULL;
PyObject *__pyx_t_9 = NULL;
__Pyx_RefNannyDeclarations
#if CYTHON_PEP489_MULTI_PHASE_INIT
if (__pyx_m && __pyx_m == __pyx_pyinit_module) return 0;
#elif PY_MAJOR_VERSION >= 3
if (__pyx_m) return __Pyx_NewRef(__pyx_m);
#endif
#if CYTHON_REFNANNY
__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
if (!__Pyx_RefNanny) {
PyErr_Clear();
__Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
if (!__Pyx_RefNanny)
Py_FatalError("failed to import 'refnanny' module");
}
#endif
__Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_optimized_field_elements(void)", 0);
if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
__pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error)
__pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error)
__pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error)
#ifdef __Pyx_CyFunction_USED
if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
#endif
#ifdef __Pyx_FusedFunction_USED
if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
#endif
#ifdef __Pyx_Coroutine_USED
if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
#endif
#ifdef __Pyx_Generator_USED
if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
#endif
#ifdef __Pyx_AsyncGen_USED
if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
#endif
#ifdef __Pyx_StopAsyncIteration_USED
if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
#endif
/*--- Library function declarations ---*/
/*--- Threads initialization code ---*/
#if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
#ifdef WITH_THREAD /* Python build with threading support? */
PyEval_InitThreads();
#endif
#endif
/*--- Module creation code ---*/
#if CYTHON_PEP489_MULTI_PHASE_INIT
__pyx_m = __pyx_pyinit_module;
Py_INCREF(__pyx_m);
#else
#if PY_MAJOR_VERSION < 3
__pyx_m = Py_InitModule4("optimized_field_elements", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
#else
__pyx_m = PyModule_Create(&__pyx_moduledef);
#endif
if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
#endif
__pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error)
Py_INCREF(__pyx_d);
__pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error)
__pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error)
#if CYTHON_COMPILING_IN_PYPY
Py_INCREF(__pyx_b);
#endif
if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
/*--- Initialize various global constants etc. ---*/
if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
#if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
#endif
if (__pyx_module_is_main_optimized_field_elements) {
if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
}
#if PY_MAJOR_VERSION >= 3
{
PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error)
if (!PyDict_GetItemString(modules, "optimized_field_elements")) {
if (unlikely(PyDict_SetItemString(modules, "optimized_field_elements", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
}
}
#endif
/*--- Builtin init code ---*/
if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
/*--- Constants init code ---*/
if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
/*--- Global type/function init code ---*/
(void)__Pyx_modinit_global_init_code();
(void)__Pyx_modinit_variable_export_code();
(void)__Pyx_modinit_function_export_code();
(void)__Pyx_modinit_type_init_code();
(void)__Pyx_modinit_type_import_code();
(void)__Pyx_modinit_variable_import_code();
(void)__Pyx_modinit_function_import_code();
/*--- Execution code ---*/
#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
#endif
/* "optimized_field_elements.pyx":3
* from __future__ import absolute_import
*
* import sys # <<<<<<<<<<<<<<
*
*
*/
__pyx_t_1 = __Pyx_Import(__pyx_n_s_sys, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) __PYX_ERR(0, 3, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/* "optimized_field_elements.pyx":6
*
*
* field_modulus = 21888242871839275222246405745257275088696311157297823662689037894645226208583 # <<<<<<<<<<<<<<
* FQ12_modulus_coeffs = [82, 0, 0, 0, 0, 0, -18, 0, 0, 0, 0, 0] # Implied + [1]
* FQ12_mc_tuples = [(i, c) for i, c in enumerate(FQ12_modulus_coeffs) if c]
*/
if (PyDict_SetItem(__pyx_d, __pyx_n_s_field_modulus, __pyx_int_21888242871839275222246405745257275088696311157297823662689037894645226208583) < 0) __PYX_ERR(0, 6, __pyx_L1_error)
/* "optimized_field_elements.pyx":7
*
* field_modulus = 21888242871839275222246405745257275088696311157297823662689037894645226208583
* FQ12_modulus_coeffs = [82, 0, 0, 0, 0, 0, -18, 0, 0, 0, 0, 0] # Implied + [1] # <<<<<<<<<<<<<<
* FQ12_mc_tuples = [(i, c) for i, c in enumerate(FQ12_modulus_coeffs) if c]
*
*/
__pyx_t_1 = PyList_New(12); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 7, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_INCREF(__pyx_int_82);
__Pyx_GIVEREF(__pyx_int_82);
PyList_SET_ITEM(__pyx_t_1, 0, __pyx_int_82);
__Pyx_INCREF(__pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
PyList_SET_ITEM(__pyx_t_1, 1, __pyx_int_0);
__Pyx_INCREF(__pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
PyList_SET_ITEM(__pyx_t_1, 2, __pyx_int_0);
__Pyx_INCREF(__pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
PyList_SET_ITEM(__pyx_t_1, 3, __pyx_int_0);
__Pyx_INCREF(__pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
PyList_SET_ITEM(__pyx_t_1, 4, __pyx_int_0);
__Pyx_INCREF(__pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
PyList_SET_ITEM(__pyx_t_1, 5, __pyx_int_0);
__Pyx_INCREF(__pyx_int_neg_18);
__Pyx_GIVEREF(__pyx_int_neg_18);
PyList_SET_ITEM(__pyx_t_1, 6, __pyx_int_neg_18);
__Pyx_INCREF(__pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
PyList_SET_ITEM(__pyx_t_1, 7, __pyx_int_0);
__Pyx_INCREF(__pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
PyList_SET_ITEM(__pyx_t_1, 8, __pyx_int_0);
__Pyx_INCREF(__pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
PyList_SET_ITEM(__pyx_t_1, 9, __pyx_int_0);
__Pyx_INCREF(__pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
PyList_SET_ITEM(__pyx_t_1, 10, __pyx_int_0);
__Pyx_INCREF(__pyx_int_0);
__Pyx_GIVEREF(__pyx_int_0);
PyList_SET_ITEM(__pyx_t_1, 11, __pyx_int_0);
if (PyDict_SetItem(__pyx_d, __pyx_n_s_FQ12_modulus_coeffs, __pyx_t_1) < 0) __PYX_ERR(0, 7, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/* "optimized_field_elements.pyx":8
* field_modulus = 21888242871839275222246405745257275088696311157297823662689037894645226208583
* FQ12_modulus_coeffs = [82, 0, 0, 0, 0, 0, -18, 0, 0, 0, 0, 0] # Implied + [1]
* FQ12_mc_tuples = [(i, c) for i, c in enumerate(FQ12_modulus_coeffs) if c] # <<<<<<<<<<<<<<
*
* # python3 compatibility
*/
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_INCREF(__pyx_int_0);
__pyx_t_2 = __pyx_int_0;
__pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_FQ12_modulus_coeffs); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
__pyx_t_4 = __pyx_t_3; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
__pyx_t_6 = NULL;
} else {
__pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 8, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
for (;;) {
if (likely(!__pyx_t_6)) {
if (likely(PyList_CheckExact(__pyx_t_4))) {
if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_3 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 8, __pyx_L1_error)
#else
__pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
#endif
} else {
if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 8, __pyx_L1_error)
#else
__pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
#endif
}
} else {
__pyx_t_3 = __pyx_t_6(__pyx_t_4);
if (unlikely(!__pyx_t_3)) {
PyObject* exc_type = PyErr_Occurred();
if (exc_type) {
if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
else __PYX_ERR(0, 8, __pyx_L1_error)
}
break;
}
__Pyx_GOTREF(__pyx_t_3);
}
if (PyDict_SetItem(__pyx_d, __pyx_n_s_c, __pyx_t_3) < 0) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
if (PyDict_SetItem(__pyx_d, __pyx_n_s_i, __pyx_t_2) < 0) __PYX_ERR(0, 8, __pyx_L1_error)
__pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_2);
__pyx_t_2 = __pyx_t_3;
__pyx_t_3 = 0;
__pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_c); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
if (__pyx_t_7) {
__pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_i); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_c); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_9);
__Pyx_GIVEREF(__pyx_t_3);
PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3);
__Pyx_GIVEREF(__pyx_t_8);
PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_8);
__pyx_t_3 = 0;
__pyx_t_8 = 0;
if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_9))) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
}
}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (PyDict_SetItem(__pyx_d, __pyx_n_s_FQ12_mc_tuples, __pyx_t_1) < 0) __PYX_ERR(0, 8, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/* "optimized_field_elements.pyx":11
*
* # python3 compatibility
* if sys.version_info.major == 2: # <<<<<<<<<<<<<<
* int_types = (int, long) # noqa: F821
* else:
*/
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 11, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_version_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 11, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_major); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 11, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 11, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 11, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_7) {
/* "optimized_field_elements.pyx":12
* # python3 compatibility
* if sys.version_info.major == 2:
* int_types = (int, long) # noqa: F821 # <<<<<<<<<<<<<<
* else:
* int_types = (int,)
*/
__pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 12, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(((PyObject *)(&PyInt_Type)));
__Pyx_GIVEREF(((PyObject *)(&PyInt_Type)));
PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)(&PyInt_Type)));
__Pyx_INCREF(((PyObject *)(&PyLong_Type)));
__Pyx_GIVEREF(((PyObject *)(&PyLong_Type)));
PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)(&PyLong_Type)));
if (PyDict_SetItem(__pyx_d, __pyx_n_s_int_types, __pyx_t_2) < 0) __PYX_ERR(0, 12, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
/* "optimized_field_elements.pyx":11
*
* # python3 compatibility
* if sys.version_info.major == 2: # <<<<<<<<<<<<<<
* int_types = (int, long) # noqa: F821
* else:
*/
goto __pyx_L5;
}
/* "optimized_field_elements.pyx":14
* int_types = (int, long) # noqa: F821
* else:
* int_types = (int,) # <<<<<<<<<<<<<<
*
*
*/
/*else*/ {
__pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 14, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(((PyObject *)(&PyInt_Type)));
__Pyx_GIVEREF(((PyObject *)(&PyInt_Type)));
PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)(&PyInt_Type)));
if (PyDict_SetItem(__pyx_d, __pyx_n_s_int_types, __pyx_t_2) < 0) __PYX_ERR(0, 14, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
}
__pyx_L5:;
/* "optimized_field_elements.pyx":19
* # Extended euclidean algorithm to find modular inverses for
* # integers
* def prime_field_inv(a, n): # <<<<<<<<<<<<<<
* if a == 0:
* return 0
*/
__pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_24optimized_field_elements_1prime_field_inv, NULL, __pyx_n_s_optimized_field_elements); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 19, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
if (PyDict_SetItem(__pyx_d, __pyx_n_s_prime_field_inv, __pyx_t_2) < 0) __PYX_ERR(0, 19, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
/* "optimized_field_elements.pyx":33
* # A class for field elements in FQ. Wrap a number in this class,
* # and it becomes a field element.
* class FQ(object): # <<<<<<<<<<<<<<
* def __init__(self, n):
* if isinstance(n, self.__class__):
*/
__pyx_t_2 = __Pyx_CalculateMetaclass(NULL, __pyx_tuple__7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 33, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_1 = __Pyx_Py3MetaclassPrepare(__pyx_t_2, __pyx_tuple__7, __pyx_n_s_FQ, __pyx_n_s_FQ, (PyObject *) NULL, __pyx_n_s_optimized_field_elements, (PyObject *) NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 33, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
/* "optimized_field_elements.pyx":34
* # and it becomes a field element.
* class FQ(object):
* def __init__(self, n): # <<<<<<<<<<<<<<
* if isinstance(n, self.__class__):
* self.n = n.n
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_2FQ_1__init__, 0, __pyx_n_s_FQ___init, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__9)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 34, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_init, __pyx_t_4) < 0) __PYX_ERR(0, 34, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":41
* assert isinstance(self.n, int_types)
*
* def __add__(self, other): # <<<<<<<<<<<<<<
* on = other.n if isinstance(other, FQ) else other
* return FQ((self.n + on) % field_modulus)
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_2FQ_3__add__, 0, __pyx_n_s_FQ___add, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__11)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 41, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_add, __pyx_t_4) < 0) __PYX_ERR(0, 41, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":45
* return FQ((self.n + on) % field_modulus)
*
* def __mul__(self, other): # <<<<<<<<<<<<<<
* on = other.n if isinstance(other, FQ) else other
* return FQ((self.n * on) % field_modulus)
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_2FQ_5__mul__, 0, __pyx_n_s_FQ___mul, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__13)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 45, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_mul, __pyx_t_4) < 0) __PYX_ERR(0, 45, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":49
* return FQ((self.n * on) % field_modulus)
*
* def __rmul__(self, other): # <<<<<<<<<<<<<<
* return self * other
*
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_2FQ_7__rmul__, 0, __pyx_n_s_FQ___rmul, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__15)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 49, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_rmul, __pyx_t_4) < 0) __PYX_ERR(0, 49, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":52
* return self * other
*
* def __radd__(self, other): # <<<<<<<<<<<<<<
* return self + other
*
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_2FQ_9__radd__, 0, __pyx_n_s_FQ___radd, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__17)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 52, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_radd, __pyx_t_4) < 0) __PYX_ERR(0, 52, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":55
* return self + other
*
* def __rsub__(self, other): # <<<<<<<<<<<<<<
* on = other.n if isinstance(other, FQ) else other
* return FQ((on - self.n) % field_modulus)
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_2FQ_11__rsub__, 0, __pyx_n_s_FQ___rsub, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__19)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 55, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_rsub, __pyx_t_4) < 0) __PYX_ERR(0, 55, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":59
* return FQ((on - self.n) % field_modulus)
*
* def __sub__(self, other): # <<<<<<<<<<<<<<
* on = other.n if isinstance(other, FQ) else other
* return FQ((self.n - on) % field_modulus)
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_2FQ_13__sub__, 0, __pyx_n_s_FQ___sub, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__21)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 59, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_sub, __pyx_t_4) < 0) __PYX_ERR(0, 59, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":63
* return FQ((self.n - on) % field_modulus)
*
* def __div__(self, other): # <<<<<<<<<<<<<<
* on = other.n if isinstance(other, FQ) else other
* assert isinstance(on, int_types)
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_2FQ_15__div__, 0, __pyx_n_s_FQ___div, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__23)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 63, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_div, __pyx_t_4) < 0) __PYX_ERR(0, 63, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":68
* return FQ(self.n * prime_field_inv(on, field_modulus) % field_modulus)
*
* def __truediv__(self, other): # <<<<<<<<<<<<<<
* return self.__div__(other)
*
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_2FQ_17__truediv__, 0, __pyx_n_s_FQ___truediv, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__25)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 68, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_truediv, __pyx_t_4) < 0) __PYX_ERR(0, 68, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":71
* return self.__div__(other)
*
* def __rdiv__(self, other): # <<<<<<<<<<<<<<
* on = other.n if isinstance(other, FQ) else other
* assert isinstance(on, int_types), on
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_2FQ_19__rdiv__, 0, __pyx_n_s_FQ___rdiv, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__27)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 71, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_rdiv, __pyx_t_4) < 0) __PYX_ERR(0, 71, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":76
* return FQ(prime_field_inv(self.n, field_modulus) * on % field_modulus)
*
* def __rtruediv__(self, other): # <<<<<<<<<<<<<<
* return self.__rdiv__(other)
*
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_2FQ_21__rtruediv__, 0, __pyx_n_s_FQ___rtruediv, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__29)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 76, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_rtruediv, __pyx_t_4) < 0) __PYX_ERR(0, 76, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":79
* return self.__rdiv__(other)
*
* def __pow__(self, other): # <<<<<<<<<<<<<<
* if other == 0:
* return FQ(1)
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_2FQ_23__pow__, 0, __pyx_n_s_FQ___pow, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__31)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 79, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_pow, __pyx_t_4) < 0) __PYX_ERR(0, 79, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":89
* return ((self * self) ** int(other // 2)) * self
*
* def __eq__(self, other): # <<<<<<<<<<<<<<
* if isinstance(other, FQ):
* return self.n == other.n
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_2FQ_25__eq__, 0, __pyx_n_s_FQ___eq, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__33)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 89, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_eq, __pyx_t_4) < 0) __PYX_ERR(0, 89, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":95
* return self.n == other
*
* def __ne__(self, other): # <<<<<<<<<<<<<<
* return not self == other
*
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_2FQ_27__ne__, 0, __pyx_n_s_FQ___ne, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__35)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 95, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_ne, __pyx_t_4) < 0) __PYX_ERR(0, 95, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":98
* return not self == other
*
* def __neg__(self): # <<<<<<<<<<<<<<
* return FQ(-self.n)
*
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_2FQ_29__neg__, 0, __pyx_n_s_FQ___neg, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__37)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 98, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_neg, __pyx_t_4) < 0) __PYX_ERR(0, 98, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":101
* return FQ(-self.n)
*
* def __repr__(self): # <<<<<<<<<<<<<<
* return repr(self.n)
*
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_2FQ_31__repr__, 0, __pyx_n_s_FQ___repr, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__39)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 101, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_repr, __pyx_t_4) < 0) __PYX_ERR(0, 101, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":105
*
* @classmethod
* def one(cls): # <<<<<<<<<<<<<<
* return cls(1)
*
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_2FQ_33one, __Pyx_CYFUNCTION_CLASSMETHOD, __pyx_n_s_FQ_one, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__41)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 105, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
/* "optimized_field_elements.pyx":104
* return repr(self.n)
*
* @classmethod # <<<<<<<<<<<<<<
* def one(cls):
* return cls(1)
*/
__pyx_t_9 = __Pyx_Method_ClassMethod(__pyx_t_4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 104, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_9);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_one, __pyx_t_9) < 0) __PYX_ERR(0, 105, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
/* "optimized_field_elements.pyx":109
*
* @classmethod
* def zero(cls): # <<<<<<<<<<<<<<
* return cls(0)
*
*/
__pyx_t_9 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_2FQ_35zero, __Pyx_CYFUNCTION_CLASSMETHOD, __pyx_n_s_FQ_zero, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__43)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 109, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_9);
/* "optimized_field_elements.pyx":108
* return cls(1)
*
* @classmethod # <<<<<<<<<<<<<<
* def zero(cls):
* return cls(0)
*/
__pyx_t_4 = __Pyx_Method_ClassMethod(__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 108, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_zero, __pyx_t_4) < 0) __PYX_ERR(0, 109, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":33
* # A class for field elements in FQ. Wrap a number in this class,
* # and it becomes a field element.
* class FQ(object): # <<<<<<<<<<<<<<
* def __init__(self, n):
* if isinstance(n, self.__class__):
*/
__pyx_t_4 = __Pyx_Py3ClassCreate(__pyx_t_2, __pyx_n_s_FQ, __pyx_tuple__7, __pyx_t_1, NULL, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 33, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (PyDict_SetItem(__pyx_d, __pyx_n_s_FQ, __pyx_t_4) < 0) __PYX_ERR(0, 33, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
/* "optimized_field_elements.pyx":114
*
* # Utility methods for polynomial math
* def deg(p): # <<<<<<<<<<<<<<
* d = len(p) - 1
* while p[d] == 0 and d:
*/
__pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_24optimized_field_elements_3deg, NULL, __pyx_n_s_optimized_field_elements); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 114, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
if (PyDict_SetItem(__pyx_d, __pyx_n_s_deg, __pyx_t_2) < 0) __PYX_ERR(0, 114, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
/* "optimized_field_elements.pyx":121
*
*
* def poly_rounded_div(a, b): # <<<<<<<<<<<<<<
* dega = deg(a)
* degb = deg(b)
*/
__pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_24optimized_field_elements_5poly_rounded_div, NULL, __pyx_n_s_optimized_field_elements); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 121, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
if (PyDict_SetItem(__pyx_d, __pyx_n_s_poly_rounded_div, __pyx_t_2) < 0) __PYX_ERR(0, 121, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
/* "optimized_field_elements.pyx":134
*
* # A class for elements in polynomial extension fields
* class FQP(object): # <<<<<<<<<<<<<<
* def __init__(self, coeffs, modulus_coeffs):
* assert len(coeffs) == len(modulus_coeffs)
*/
__pyx_t_2 = __Pyx_CalculateMetaclass(NULL, __pyx_tuple__48); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 134, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_1 = __Pyx_Py3MetaclassPrepare(__pyx_t_2, __pyx_tuple__48, __pyx_n_s_FQP, __pyx_n_s_FQP, (PyObject *) NULL, __pyx_n_s_optimized_field_elements, (PyObject *) NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 134, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
/* "optimized_field_elements.pyx":135
* # A class for elements in polynomial extension fields
* class FQP(object):
* def __init__(self, coeffs, modulus_coeffs): # <<<<<<<<<<<<<<
* assert len(coeffs) == len(modulus_coeffs)
* self.coeffs = coeffs
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_3FQP_1__init__, 0, __pyx_n_s_FQP___init, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__50)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 135, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_init, __pyx_t_4) < 0) __PYX_ERR(0, 135, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":143
* self.degree = len(self.modulus_coeffs)
*
* def __add__(self, other): # <<<<<<<<<<<<<<
* assert isinstance(other, self.__class__)
* return self.__class__([
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_3FQP_3__add__, 0, __pyx_n_s_FQP___add, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__52)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 143, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_add, __pyx_t_4) < 0) __PYX_ERR(0, 143, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":151
* ])
*
* def __sub__(self, other): # <<<<<<<<<<<<<<
* assert isinstance(other, self.__class__)
* return self.__class__([
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_3FQP_5__sub__, 0, __pyx_n_s_FQP___sub, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__54)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 151, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_sub, __pyx_t_4) < 0) __PYX_ERR(0, 151, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":159
* ])
*
* def __mul__(self, other): # <<<<<<<<<<<<<<
* if isinstance(other, int_types):
* return self.__class__([c * other % field_modulus for c in self.coeffs])
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_3FQP_7__mul__, 0, __pyx_n_s_FQP___mul, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__56)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 159, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_mul, __pyx_t_4) < 0) __PYX_ERR(0, 159, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":176
* return self.__class__([x % field_modulus for x in b])
*
* def __rmul__(self, other): # <<<<<<<<<<<<<<
* return self * other
*
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_3FQP_9__rmul__, 0, __pyx_n_s_FQP___rmul, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__58)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 176, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_rmul, __pyx_t_4) < 0) __PYX_ERR(0, 176, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":179
* return self * other
*
* def __div__(self, other): # <<<<<<<<<<<<<<
* if isinstance(other, int_types):
* return self.__class__([
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_3FQP_11__div__, 0, __pyx_n_s_FQP___div, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__60)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 179, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_div, __pyx_t_4) < 0) __PYX_ERR(0, 179, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":190
* return self * other.inv()
*
* def __truediv__(self, other): # <<<<<<<<<<<<<<
* return self.__div__(other)
*
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_3FQP_13__truediv__, 0, __pyx_n_s_FQP___truediv, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__62)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 190, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_truediv, __pyx_t_4) < 0) __PYX_ERR(0, 190, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":193
* return self.__div__(other)
*
* def __pow__(self, other): # <<<<<<<<<<<<<<
* o = self.__class__([1] + [0] * (self.degree - 1))
* t = self
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_3FQP_15__pow__, 0, __pyx_n_s_FQP___pow, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__64)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 193, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_pow, __pyx_t_4) < 0) __PYX_ERR(0, 193, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":204
*
* # Extended euclidean algorithm used to find the modular inverse
* def inv(self): # <<<<<<<<<<<<<<
* lm, hm = [1] + [0] * self.degree, [0] * (self.degree + 1)
* low, high = self.coeffs + [0], self.modulus_coeffs + [1]
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_3FQP_17inv, 0, __pyx_n_s_FQP_inv, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__66)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 204, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_inv, __pyx_t_4) < 0) __PYX_ERR(0, 204, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":222
* return self.__class__(lm[:self.degree]) / low[0]
*
* def __repr__(self): # <<<<<<<<<<<<<<
* return repr(self.coeffs)
*
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_3FQP_19__repr__, 0, __pyx_n_s_FQP___repr, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__68)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 222, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_repr, __pyx_t_4) < 0) __PYX_ERR(0, 222, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":225
* return repr(self.coeffs)
*
* def __eq__(self, other): # <<<<<<<<<<<<<<
* assert isinstance(other, self.__class__)
* for c1, c2 in zip(self.coeffs, other.coeffs):
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_3FQP_21__eq__, 0, __pyx_n_s_FQP___eq, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__70)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 225, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_eq, __pyx_t_4) < 0) __PYX_ERR(0, 225, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":232
* return True
*
* def __ne__(self, other): # <<<<<<<<<<<<<<
* return not self == other
*
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_3FQP_23__ne__, 0, __pyx_n_s_FQP___ne, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__72)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 232, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_ne, __pyx_t_4) < 0) __PYX_ERR(0, 232, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":235
* return not self == other
*
* def __neg__(self): # <<<<<<<<<<<<<<
* return self.__class__([-c for c in self.coeffs])
*
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_3FQP_25__neg__, 0, __pyx_n_s_FQP___neg, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__74)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 235, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_neg, __pyx_t_4) < 0) __PYX_ERR(0, 235, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":239
*
* @classmethod
* def one(cls): # <<<<<<<<<<<<<<
* return cls([1] + [0] * (cls.degree - 1))
*
*/
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_3FQP_27one, __Pyx_CYFUNCTION_CLASSMETHOD, __pyx_n_s_FQP_one, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__76)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 239, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
/* "optimized_field_elements.pyx":238
* return self.__class__([-c for c in self.coeffs])
*
* @classmethod # <<<<<<<<<<<<<<
* def one(cls):
* return cls([1] + [0] * (cls.degree - 1))
*/
__pyx_t_9 = __Pyx_Method_ClassMethod(__pyx_t_4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 238, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_9);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_one, __pyx_t_9) < 0) __PYX_ERR(0, 239, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
/* "optimized_field_elements.pyx":243
*
* @classmethod
* def zero(cls): # <<<<<<<<<<<<<<
* return cls([0] * cls.degree)
*
*/
__pyx_t_9 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_3FQP_29zero, __Pyx_CYFUNCTION_CLASSMETHOD, __pyx_n_s_FQP_zero, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__78)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 243, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_9);
/* "optimized_field_elements.pyx":242
* return cls([1] + [0] * (cls.degree - 1))
*
* @classmethod # <<<<<<<<<<<<<<
* def zero(cls):
* return cls([0] * cls.degree)
*/
__pyx_t_4 = __Pyx_Method_ClassMethod(__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 242, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
if (__Pyx_SetNameInClass(__pyx_t_1, __pyx_n_s_zero, __pyx_t_4) < 0) __PYX_ERR(0, 243, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
/* "optimized_field_elements.pyx":134
*
* # A class for elements in polynomial extension fields
* class FQP(object): # <<<<<<<<<<<<<<
* def __init__(self, coeffs, modulus_coeffs):
* assert len(coeffs) == len(modulus_coeffs)
*/
__pyx_t_4 = __Pyx_Py3ClassCreate(__pyx_t_2, __pyx_n_s_FQP, __pyx_tuple__48, __pyx_t_1, NULL, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 134, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (PyDict_SetItem(__pyx_d, __pyx_n_s_FQP, __pyx_t_4) < 0) __PYX_ERR(0, 134, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
/* "optimized_field_elements.pyx":248
*
* # The quadratic extension field
* class FQ2(FQP): # <<<<<<<<<<<<<<
* def __init__(self, coeffs):
* self.coeffs = coeffs
*/
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_FQP); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 248, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 248, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_GIVEREF(__pyx_t_2);
PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
__pyx_t_2 = 0;
__pyx_t_2 = __Pyx_CalculateMetaclass(NULL, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 248, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_4 = __Pyx_Py3MetaclassPrepare(__pyx_t_2, __pyx_t_1, __pyx_n_s_FQ2, __pyx_n_s_FQ2, (PyObject *) NULL, __pyx_n_s_optimized_field_elements, (PyObject *) NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 248, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
/* "optimized_field_elements.pyx":249
* # The quadratic extension field
* class FQ2(FQP):
* def __init__(self, coeffs): # <<<<<<<<<<<<<<
* self.coeffs = coeffs
* self.modulus_coeffs = [1, 0]
*/
__pyx_t_9 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_3FQ2_1__init__, 0, __pyx_n_s_FQ2___init, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__80)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 249, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_9);
if (__Pyx_SetNameInClass(__pyx_t_4, __pyx_n_s_init, __pyx_t_9) < 0) __PYX_ERR(0, 249, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
/* "optimized_field_elements.pyx":248
*
* # The quadratic extension field
* class FQ2(FQP): # <<<<<<<<<<<<<<
* def __init__(self, coeffs):
* self.coeffs = coeffs
*/
__pyx_t_9 = __Pyx_Py3ClassCreate(__pyx_t_2, __pyx_n_s_FQ2, __pyx_t_1, __pyx_t_4, NULL, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 248, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_9);
if (PyDict_SetItem(__pyx_d, __pyx_n_s_FQ2, __pyx_t_9) < 0) __PYX_ERR(0, 248, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/* "optimized_field_elements.pyx":258
*
* # The 12th-degree extension field
* class FQ12(FQP): # <<<<<<<<<<<<<<
* def __init__(self, coeffs):
* self.coeffs = coeffs
*/
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_FQP); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 258, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 258, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_GIVEREF(__pyx_t_1);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
__pyx_t_1 = 0;
__pyx_t_1 = __Pyx_CalculateMetaclass(NULL, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 258, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_4 = __Pyx_Py3MetaclassPrepare(__pyx_t_1, __pyx_t_2, __pyx_n_s_FQ12, __pyx_n_s_FQ12, (PyObject *) NULL, __pyx_n_s_optimized_field_elements, (PyObject *) NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 258, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
/* "optimized_field_elements.pyx":259
* # The 12th-degree extension field
* class FQ12(FQP):
* def __init__(self, coeffs): # <<<<<<<<<<<<<<
* self.coeffs = coeffs
* self.modulus_coeffs = FQ12_modulus_coeffs
*/
__pyx_t_9 = __Pyx_CyFunction_NewEx(&__pyx_mdef_24optimized_field_elements_4FQ12_1__init__, 0, __pyx_n_s_FQ12___init, NULL, __pyx_n_s_optimized_field_elements, __pyx_d, ((PyObject *)__pyx_codeobj__82)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 259, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_9);
if (__Pyx_SetNameInClass(__pyx_t_4, __pyx_n_s_init, __pyx_t_9) < 0) __PYX_ERR(0, 259, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
/* "optimized_field_elements.pyx":258
*
* # The 12th-degree extension field
* class FQ12(FQP): # <<<<<<<<<<<<<<
* def __init__(self, coeffs):
* self.coeffs = coeffs
*/
__pyx_t_9 = __Pyx_Py3ClassCreate(__pyx_t_1, __pyx_n_s_FQ12, __pyx_t_2, __pyx_t_4, NULL, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 258, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_9);
if (PyDict_SetItem(__pyx_d, __pyx_n_s_FQ12, __pyx_t_9) < 0) __PYX_ERR(0, 258, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
/* "optimized_field_elements.pyx":1
* from __future__ import absolute_import # <<<<<<<<<<<<<<
*
* import sys
*/
__pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
/*--- Wrapped vars code ---*/
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_8);
__Pyx_XDECREF(__pyx_t_9);
if (__pyx_m) {
if (__pyx_d) {
__Pyx_AddTraceback("init optimized_field_elements", 0, __pyx_lineno, __pyx_filename);
}
Py_DECREF(__pyx_m); __pyx_m = 0;
} else if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_ImportError, "init optimized_field_elements");
}
__pyx_L0:;
__Pyx_RefNannyFinishContext();
#if CYTHON_PEP489_MULTI_PHASE_INIT
return (__pyx_m != NULL) ? 0 : -1;
#elif PY_MAJOR_VERSION >= 3
return __pyx_m;
#else
return;
#endif
}
/* --- Runtime support code --- */
/* Refnanny */
#if CYTHON_REFNANNY
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
PyObject *m = NULL, *p = NULL;
void *r = NULL;
m = PyImport_ImportModule((char *)modname);
if (!m) goto end;
p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
if (!p) goto end;
r = PyLong_AsVoidPtr(p);
end:
Py_XDECREF(p);
Py_XDECREF(m);
return (__Pyx_RefNannyAPIStruct *)r;
}
#endif
/* PyObjectGetAttrStr */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
PyTypeObject* tp = Py_TYPE(obj);
if (likely(tp->tp_getattro))
return tp->tp_getattro(obj, attr_name);
#if PY_MAJOR_VERSION < 3
if (likely(tp->tp_getattr))
return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
#endif
return PyObject_GetAttr(obj, attr_name);
}
#endif
/* GetBuiltinName */
static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
if (unlikely(!result)) {
PyErr_Format(PyExc_NameError,
#if PY_MAJOR_VERSION >= 3
"name '%U' is not defined", name);
#else
"name '%.200s' is not defined", PyString_AS_STRING(name));
#endif
}
return result;
}
/* RaiseArgTupleInvalid */
static void __Pyx_RaiseArgtupleInvalid(
const char* func_name,
int exact,
Py_ssize_t num_min,
Py_ssize_t num_max,
Py_ssize_t num_found)
{
Py_ssize_t num_expected;
const char *more_or_less;
if (num_found < num_min) {
num_expected = num_min;
more_or_less = "at least";
} else {
num_expected = num_max;
more_or_less = "at most";
}
if (exact) {
more_or_less = "exactly";
}
PyErr_Format(PyExc_TypeError,
"%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
func_name, more_or_less, num_expected,
(num_expected == 1) ? "" : "s", num_found);
}
/* RaiseDoubleKeywords */
static void __Pyx_RaiseDoubleKeywordsError(
const char* func_name,
PyObject* kw_name)
{
PyErr_Format(PyExc_TypeError,
#if PY_MAJOR_VERSION >= 3
"%s() got multiple values for keyword argument '%U'", func_name, kw_name);
#else
"%s() got multiple values for keyword argument '%s'", func_name,
PyString_AsString(kw_name));
#endif
}
/* ParseKeywords */
static int __Pyx_ParseOptionalKeywords(
PyObject *kwds,
PyObject **argnames[],
PyObject *kwds2,
PyObject *values[],
Py_ssize_t num_pos_args,
const char* function_name)
{
PyObject *key = 0, *value = 0;
Py_ssize_t pos = 0;
PyObject*** name;
PyObject*** first_kw_arg = argnames + num_pos_args;
while (PyDict_Next(kwds, &pos, &key, &value)) {
name = first_kw_arg;
while (*name && (**name != key)) name++;
if (*name) {
values[name-argnames] = value;
continue;
}
name = first_kw_arg;
#if PY_MAJOR_VERSION < 3
if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) {
while (*name) {
if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
&& _PyString_Eq(**name, key)) {
values[name-argnames] = value;
break;
}
name++;
}
if (*name) continue;
else {
PyObject*** argname = argnames;
while (argname != first_kw_arg) {
if ((**argname == key) || (
(CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
&& _PyString_Eq(**argname, key))) {
goto arg_passed_twice;
}
argname++;
}
}
} else
#endif
if (likely(PyUnicode_Check(key))) {
while (*name) {
int cmp = (**name == key) ? 0 :
#if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
(PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
#endif
PyUnicode_Compare(**name, key);
if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
if (cmp == 0) {
values[name-argnames] = value;
break;
}
name++;
}
if (*name) continue;
else {
PyObject*** argname = argnames;
while (argname != first_kw_arg) {
int cmp = (**argname == key) ? 0 :
#if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
(PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
#endif
PyUnicode_Compare(**argname, key);
if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
if (cmp == 0) goto arg_passed_twice;
argname++;
}
}
} else
goto invalid_keyword_type;
if (kwds2) {
if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
} else {
goto invalid_keyword;
}
}
return 0;
arg_passed_twice:
__Pyx_RaiseDoubleKeywordsError(function_name, key);
goto bad;
invalid_keyword_type:
PyErr_Format(PyExc_TypeError,
"%.200s() keywords must be strings", function_name);
goto bad;
invalid_keyword:
PyErr_Format(PyExc_TypeError,
#if PY_MAJOR_VERSION < 3
"%.200s() got an unexpected keyword argument '%.200s'",
function_name, PyString_AsString(key));
#else
"%s() got an unexpected keyword argument '%U'",
function_name, key);
#endif
bad:
return -1;
}
/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
if (op1 == op2) {
Py_RETURN_TRUE;
}
#if PY_MAJOR_VERSION < 3
if (likely(PyInt_CheckExact(op1))) {
const long b = intval;
long a = PyInt_AS_LONG(op1);
if (a == b) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
#endif
#if CYTHON_USE_PYLONG_INTERNALS
if (likely(PyLong_CheckExact(op1))) {
const long b = intval;
long a;
const digit* digits = ((PyLongObject*)op1)->ob_digit;
const Py_ssize_t size = Py_SIZE(op1);
if (likely(__Pyx_sst_abs(size) <= 1)) {
a = likely(size) ? digits[0] : 0;
if (size == -1) a = -a;
} else {
switch (size) {
case -2:
if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
}
CYTHON_FALLTHROUGH;
case 2:
if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
}
CYTHON_FALLTHROUGH;
case -3:
if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
}
CYTHON_FALLTHROUGH;
case 3:
if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
}
CYTHON_FALLTHROUGH;
case -4:
if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
}
CYTHON_FALLTHROUGH;
case 4:
if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
}
CYTHON_FALLTHROUGH;
#if PyLong_SHIFT < 30 && PyLong_SHIFT != 15
default: return PyLong_Type.tp_richcompare(op1, op2, Py_EQ);
#else
default: Py_RETURN_FALSE;
#endif
}
}
if (a == b) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
#endif
if (PyFloat_CheckExact(op1)) {
const long b = intval;
double a = PyFloat_AS_DOUBLE(op1);
if ((double)a == (double)b) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
}
return PyObject_RichCompare(op1, op2, Py_EQ);
}
#endif
/* PyObjectSetAttrStr */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) {
PyTypeObject* tp = Py_TYPE(obj);
if (likely(tp->tp_setattro))
return tp->tp_setattro(obj, attr_name, value);
#if PY_MAJOR_VERSION < 3
if (likely(tp->tp_setattr))
return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value);
#endif
return PyObject_SetAttr(obj, attr_name, value);
}
#endif
/* GetModuleGlobalName */
static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) {
PyObject *result;
#if !CYTHON_AVOID_BORROWED_REFS
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1
result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash);
if (likely(result)) {
Py_INCREF(result);
} else if (unlikely(PyErr_Occurred())) {
result = NULL;
} else {
#else
result = PyDict_GetItem(__pyx_d, name);
if (likely(result)) {
Py_INCREF(result);
} else {
#endif
#else
result = PyObject_GetItem(__pyx_d, name);
if (!result) {
PyErr_Clear();
#endif
result = __Pyx_GetBuiltinName(name);
}
return result;
}
/* PyCFunctionFastCall */
#if CYTHON_FAST_PYCCALL
static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) {
PyCFunctionObject *func = (PyCFunctionObject*)func_obj;
PyCFunction meth = PyCFunction_GET_FUNCTION(func);
PyObject *self = PyCFunction_GET_SELF(func);
int flags = PyCFunction_GET_FLAGS(func);
assert(PyCFunction_Check(func));
assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS)));
assert(nargs >= 0);
assert(nargs == 0 || args != NULL);
/* _PyCFunction_FastCallDict() must not be called with an exception set,
because it may clear it (directly or indirectly) and so the
caller loses its exception */
assert(!PyErr_Occurred());
if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) {
return (*((__Pyx_PyCFunctionFastWithKeywords)meth)) (self, args, nargs, NULL);
} else {
return (*((__Pyx_PyCFunctionFast)meth)) (self, args, nargs);
}
}
#endif
/* PyFunctionFastCall */
#if CYTHON_FAST_PYCALL
#include "frameobject.h"
static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na,
PyObject *globals) {
PyFrameObject *f;
PyThreadState *tstate = __Pyx_PyThreadState_Current;
PyObject **fastlocals;
Py_ssize_t i;
PyObject *result;
assert(globals != NULL);
/* XXX Perhaps we should create a specialized
PyFrame_New() that doesn't take locals, but does
take builtins without sanity checking them.
*/
assert(tstate != NULL);
f = PyFrame_New(tstate, co, globals, NULL);
if (f == NULL) {
return NULL;
}
fastlocals = f->f_localsplus;
for (i = 0; i < na; i++) {
Py_INCREF(*args);
fastlocals[i] = *args++;
}
result = PyEval_EvalFrameEx(f,0);
++tstate->recursion_depth;
Py_DECREF(f);
--tstate->recursion_depth;
return result;
}
#if 1 || PY_VERSION_HEX < 0x030600B1
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs) {
PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
PyObject *globals = PyFunction_GET_GLOBALS(func);
PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
PyObject *closure;
#if PY_MAJOR_VERSION >= 3
PyObject *kwdefs;
#endif
PyObject *kwtuple, **k;
PyObject **d;
Py_ssize_t nd;
Py_ssize_t nk;
PyObject *result;
assert(kwargs == NULL || PyDict_Check(kwargs));
nk = kwargs ? PyDict_Size(kwargs) : 0;
if (Py_EnterRecursiveCall((char*)" while calling a Python object")) {
return NULL;
}
if (
#if PY_MAJOR_VERSION >= 3
co->co_kwonlyargcount == 0 &&
#endif
likely(kwargs == NULL || nk == 0) &&
co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
if (argdefs == NULL && co->co_argcount == nargs) {
result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals);
goto done;
}
else if (nargs == 0 && argdefs != NULL
&& co->co_argcount == Py_SIZE(argdefs)) {
/* function called with no arguments, but all parameters have
a default value: use default values as arguments .*/
args = &PyTuple_GET_ITEM(argdefs, 0);
result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals);
goto done;
}
}
if (kwargs != NULL) {
Py_ssize_t pos, i;
kwtuple = PyTuple_New(2 * nk);
if (kwtuple == NULL) {
result = NULL;
goto done;
}
k = &PyTuple_GET_ITEM(kwtuple, 0);
pos = i = 0;
while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
Py_INCREF(k[i]);
Py_INCREF(k[i+1]);
i += 2;
}
nk = i / 2;
}
else {
kwtuple = NULL;
k = NULL;
}
closure = PyFunction_GET_CLOSURE(func);
#if PY_MAJOR_VERSION >= 3
kwdefs = PyFunction_GET_KW_DEFAULTS(func);
#endif
if (argdefs != NULL) {
d = &PyTuple_GET_ITEM(argdefs, 0);
nd = Py_SIZE(argdefs);
}
else {
d = NULL;
nd = 0;
}
#if PY_MAJOR_VERSION >= 3
result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
args, nargs,
k, (int)nk,
d, (int)nd, kwdefs, closure);
#else
result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL,
args, nargs,
k, (int)nk,
d, (int)nd, closure);
#endif
Py_XDECREF(kwtuple);
done:
Py_LeaveRecursiveCall();
return result;
}
#endif
#endif
/* PyObjectCall */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
PyObject *result;
ternaryfunc call = func->ob_type->tp_call;
if (unlikely(!call))
return PyObject_Call(func, arg, kw);
if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
return NULL;
result = (*call)(func, arg, kw);
Py_LeaveRecursiveCall();
if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
PyErr_SetString(
PyExc_SystemError,
"NULL result without error in PyObject_Call");
}
return result;
}
#endif
/* PyObjectCallMethO */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
PyObject *self, *result;
PyCFunction cfunc;
cfunc = PyCFunction_GET_FUNCTION(func);
self = PyCFunction_GET_SELF(func);
if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
return NULL;
result = cfunc(self, arg);
Py_LeaveRecursiveCall();
if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
PyErr_SetString(
PyExc_SystemError,
"NULL result without error in PyObject_Call");
}
return result;
}
#endif
/* PyObjectCallOneArg */
#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
PyObject *result;
PyObject *args = PyTuple_New(1);
if (unlikely(!args)) return NULL;
Py_INCREF(arg);
PyTuple_SET_ITEM(args, 0, arg);
result = __Pyx_PyObject_Call(func, args, NULL);
Py_DECREF(args);
return result;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(func)) {
return __Pyx_PyFunction_FastCall(func, &arg, 1);
}
#endif
if (likely(PyCFunction_Check(func))) {
if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
return __Pyx_PyObject_CallMethO(func, arg);
#if CYTHON_FAST_PYCCALL
} else if (PyCFunction_GET_FLAGS(func) & METH_FASTCALL) {
return __Pyx_PyCFunction_FastCall(func, &arg, 1);
#endif
}
}
return __Pyx__PyObject_CallOneArg(func, arg);
}
#else
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
PyObject *result;
PyObject *args = PyTuple_Pack(1, arg);
if (unlikely(!args)) return NULL;
result = __Pyx_PyObject_Call(func, args, NULL);
Py_DECREF(args);
return result;
}
#endif
/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_RemainderObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
#if PY_MAJOR_VERSION < 3
if (likely(PyInt_CheckExact(op1))) {
const long b = intval;
long x;
long a = PyInt_AS_LONG(op1);
x = a % b;
x += ((x != 0) & ((x ^ b) < 0)) * b;
return PyInt_FromLong(x);
}
#endif
#if CYTHON_USE_PYLONG_INTERNALS
if (likely(PyLong_CheckExact(op1))) {
const long b = intval;
long a, x;
#ifdef HAVE_LONG_LONG
const PY_LONG_LONG llb = intval;
PY_LONG_LONG lla, llx;
#endif
const digit* digits = ((PyLongObject*)op1)->ob_digit;
const Py_ssize_t size = Py_SIZE(op1);
if (likely(__Pyx_sst_abs(size) <= 1)) {
a = likely(size) ? digits[0] : 0;
if (size == -1) a = -a;
} else {
switch (size) {
case -2:
if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case 2:
if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case -3:
if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case 3:
if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case -4:
if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case 4:
if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
default: return PyLong_Type.tp_as_number->nb_remainder(op1, op2);
}
}
x = a % b;
x += ((x != 0) & ((x ^ b) < 0)) * b;
return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
long_long:
llx = lla % llb;
llx += ((llx != 0) & ((llx ^ llb) < 0)) * llb;
return PyLong_FromLongLong(llx);
#endif
}
#endif
return (inplace ? PyNumber_InPlaceRemainder : PyNumber_Remainder)(op1, op2);
}
#endif
/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_FloorDivideObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
#if PY_MAJOR_VERSION < 3
if (likely(PyInt_CheckExact(op1))) {
const long b = intval;
long x;
long a = PyInt_AS_LONG(op1);
if (unlikely(b == -1 && ((unsigned long)a) == 0-(unsigned long)a))
return PyInt_Type.tp_as_number->nb_floor_divide(op1, op2);
else {
long q, r;
q = a / b;
r = a - q*b;
q -= ((r != 0) & ((r ^ b) < 0));
x = q;
}
return PyInt_FromLong(x);
}
#endif
#if CYTHON_USE_PYLONG_INTERNALS
if (likely(PyLong_CheckExact(op1))) {
const long b = intval;
long a, x;
#ifdef HAVE_LONG_LONG
const PY_LONG_LONG llb = intval;
PY_LONG_LONG lla, llx;
#endif
const digit* digits = ((PyLongObject*)op1)->ob_digit;
const Py_ssize_t size = Py_SIZE(op1);
if (likely(__Pyx_sst_abs(size) <= 1)) {
a = likely(size) ? digits[0] : 0;
if (size == -1) a = -a;
} else {
switch (size) {
case -2:
if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case 2:
if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case -3:
if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case 3:
if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case -4:
if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case 4:
if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
default: return PyLong_Type.tp_as_number->nb_floor_divide(op1, op2);
}
}
{
long q, r;
q = a / b;
r = a - q*b;
q -= ((r != 0) & ((r ^ b) < 0));
x = q;
}
return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
long_long:
{
PY_LONG_LONG q, r;
q = lla / llb;
r = lla - q*llb;
q -= ((r != 0) & ((r ^ llb) < 0));
llx = q;
}
return PyLong_FromLongLong(llx);
#endif
}
#endif
return (inplace ? PyNumber_InPlaceFloorDivide : PyNumber_FloorDivide)(op1, op2);
}
#endif
/* GetItemInt */
static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
PyObject *r;
if (!j) return NULL;
r = PyObject_GetItem(o, j);
Py_DECREF(j);
return r;
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
CYTHON_NCP_UNUSED int wraparound,
CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
Py_ssize_t wrapped_i = i;
if (wraparound & unlikely(i < 0)) {
wrapped_i += PyList_GET_SIZE(o);
}
if ((!boundscheck) || likely((0 <= wrapped_i) & (wrapped_i < PyList_GET_SIZE(o)))) {
PyObject *r = PyList_GET_ITEM(o, wrapped_i);
Py_INCREF(r);
return r;
}
return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
CYTHON_NCP_UNUSED int wraparound,
CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
Py_ssize_t wrapped_i = i;
if (wraparound & unlikely(i < 0)) {
wrapped_i += PyTuple_GET_SIZE(o);
}
if ((!boundscheck) || likely((0 <= wrapped_i) & (wrapped_i < PyTuple_GET_SIZE(o)))) {
PyObject *r = PyTuple_GET_ITEM(o, wrapped_i);
Py_INCREF(r);
return r;
}
return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
CYTHON_NCP_UNUSED int wraparound,
CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
if (is_list || PyList_CheckExact(o)) {
Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
if ((!boundscheck) || (likely((n >= 0) & (n < PyList_GET_SIZE(o))))) {
PyObject *r = PyList_GET_ITEM(o, n);
Py_INCREF(r);
return r;
}
}
else if (PyTuple_CheckExact(o)) {
Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) {
PyObject *r = PyTuple_GET_ITEM(o, n);
Py_INCREF(r);
return r;
}
} else {
PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
if (likely(m && m->sq_item)) {
if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
Py_ssize_t l = m->sq_length(o);
if (likely(l >= 0)) {
i += l;
} else {
if (!PyErr_ExceptionMatches(PyExc_OverflowError))
return NULL;
PyErr_Clear();
}
}
return m->sq_item(o, i);
}
}
#else
if (is_list || PySequence_Check(o)) {
return PySequence_GetItem(o, i);
}
#endif
return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}
/* ObjectGetItem */
#if CYTHON_USE_TYPE_SLOTS
static PyObject *__Pyx_PyObject_GetIndex(PyObject *obj, PyObject* index) {
PyObject *runerr;
Py_ssize_t key_value;
PySequenceMethods *m = Py_TYPE(obj)->tp_as_sequence;
if (unlikely(!(m && m->sq_item))) {
PyErr_Format(PyExc_TypeError, "'%.200s' object is not subscriptable", Py_TYPE(obj)->tp_name);
return NULL;
}
key_value = __Pyx_PyIndex_AsSsize_t(index);
if (likely(key_value != -1 || !(runerr = PyErr_Occurred()))) {
return __Pyx_GetItemInt_Fast(obj, key_value, 0, 1, 1);
}
if (PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) {
PyErr_Clear();
PyErr_Format(PyExc_IndexError, "cannot fit '%.200s' into an index-sized integer", Py_TYPE(index)->tp_name);
}
return NULL;
}
static PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key) {
PyMappingMethods *m = Py_TYPE(obj)->tp_as_mapping;
if (likely(m && m->mp_subscript)) {
return m->mp_subscript(obj, key);
}
return __Pyx_PyObject_GetIndex(obj, key);
}
#endif
/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
#if PY_MAJOR_VERSION < 3
if (likely(PyInt_CheckExact(op1))) {
const long b = intval;
long x;
long a = PyInt_AS_LONG(op1);
x = (long)((unsigned long)a - b);
if (likely((x^a) >= 0 || (x^~b) >= 0))
return PyInt_FromLong(x);
return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
}
#endif
#if CYTHON_USE_PYLONG_INTERNALS
if (likely(PyLong_CheckExact(op1))) {
const long b = intval;
long a, x;
#ifdef HAVE_LONG_LONG
const PY_LONG_LONG llb = intval;
PY_LONG_LONG lla, llx;
#endif
const digit* digits = ((PyLongObject*)op1)->ob_digit;
const Py_ssize_t size = Py_SIZE(op1);
if (likely(__Pyx_sst_abs(size) <= 1)) {
a = likely(size) ? digits[0] : 0;
if (size == -1) a = -a;
} else {
switch (size) {
case -2:
if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case 2:
if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case -3:
if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case 3:
if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case -4:
if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case 4:
if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
default: return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
}
}
x = a - b;
return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
long_long:
llx = lla - llb;
return PyLong_FromLongLong(llx);
#endif
}
#endif
if (PyFloat_CheckExact(op1)) {
const long b = intval;
double a = PyFloat_AS_DOUBLE(op1);
double result;
PyFPE_START_PROTECT("subtract", return NULL)
result = ((double)a) - (double)b;
PyFPE_END_PROTECT(result)
return PyFloat_FromDouble(result);
}
return (inplace ? PyNumber_InPlaceSubtract : PyNumber_Subtract)(op1, op2);
}
#endif
/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
#if PY_MAJOR_VERSION < 3
if (likely(PyInt_CheckExact(op1))) {
const long b = intval;
long x;
long a = PyInt_AS_LONG(op1);
x = (long)((unsigned long)a + b);
if (likely((x^a) >= 0 || (x^b) >= 0))
return PyInt_FromLong(x);
return PyLong_Type.tp_as_number->nb_add(op1, op2);
}
#endif
#if CYTHON_USE_PYLONG_INTERNALS
if (likely(PyLong_CheckExact(op1))) {
const long b = intval;
long a, x;
#ifdef HAVE_LONG_LONG
const PY_LONG_LONG llb = intval;
PY_LONG_LONG lla, llx;
#endif
const digit* digits = ((PyLongObject*)op1)->ob_digit;
const Py_ssize_t size = Py_SIZE(op1);
if (likely(__Pyx_sst_abs(size) <= 1)) {
a = likely(size) ? digits[0] : 0;
if (size == -1) a = -a;
} else {
switch (size) {
case -2:
if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case 2:
if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case -3:
if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case 3:
if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case -4:
if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case 4:
if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
default: return PyLong_Type.tp_as_number->nb_add(op1, op2);
}
}
x = a + b;
return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
long_long:
llx = lla + llb;
return PyLong_FromLongLong(llx);
#endif
}
#endif
if (PyFloat_CheckExact(op1)) {
const long b = intval;
double a = PyFloat_AS_DOUBLE(op1);
double result;
PyFPE_START_PROTECT("add", return NULL)
result = ((double)a) + (double)b;
PyFPE_END_PROTECT(result)
return PyFloat_FromDouble(result);
}
return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
}
#endif
/* SliceTupleAndList */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE void __Pyx_crop_slice(Py_ssize_t* _start, Py_ssize_t* _stop, Py_ssize_t* _length) {
Py_ssize_t start = *_start, stop = *_stop, length = *_length;
if (start < 0) {
start += length;
if (start < 0)
start = 0;
}
if (stop < 0)
stop += length;
else if (stop > length)
stop = length;
*_length = stop - start;
*_start = start;
*_stop = stop;
}
static CYTHON_INLINE void __Pyx_copy_object_array(PyObject** CYTHON_RESTRICT src, PyObject** CYTHON_RESTRICT dest, Py_ssize_t length) {
PyObject *v;
Py_ssize_t i;
for (i = 0; i < length; i++) {
v = dest[i] = src[i];
Py_INCREF(v);
}
}
static CYTHON_INLINE PyObject* __Pyx_PyList_GetSlice(
PyObject* src, Py_ssize_t start, Py_ssize_t stop) {
PyObject* dest;
Py_ssize_t length = PyList_GET_SIZE(src);
__Pyx_crop_slice(&start, &stop, &length);
if (unlikely(length <= 0))
return PyList_New(0);
dest = PyList_New(length);
if (unlikely(!dest))
return NULL;
__Pyx_copy_object_array(
((PyListObject*)src)->ob_item + start,
((PyListObject*)dest)->ob_item,
length);
return dest;
}
static CYTHON_INLINE PyObject* __Pyx_PyTuple_GetSlice(
PyObject* src, Py_ssize_t start, Py_ssize_t stop) {
PyObject* dest;
Py_ssize_t length = PyTuple_GET_SIZE(src);
__Pyx_crop_slice(&start, &stop, &length);
if (unlikely(length <= 0))
return PyTuple_New(0);
dest = PyTuple_New(length);
if (unlikely(!dest))
return NULL;
__Pyx_copy_object_array(
((PyTupleObject*)src)->ob_item + start,
((PyTupleObject*)dest)->ob_item,
length);
return dest;
}
#endif
/* RaiseTooManyValuesToUnpack */
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
PyErr_Format(PyExc_ValueError,
"too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
}
/* RaiseNeedMoreValuesToUnpack */
static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
PyErr_Format(PyExc_ValueError,
"need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack",
index, (index == 1) ? "" : "s");
}
/* IterFinish */
static CYTHON_INLINE int __Pyx_IterFinish(void) {
#if CYTHON_FAST_THREAD_STATE
PyThreadState *tstate = __Pyx_PyThreadState_Current;
PyObject* exc_type = tstate->curexc_type;
if (unlikely(exc_type)) {
if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) {
PyObject *exc_value, *exc_tb;
exc_value = tstate->curexc_value;
exc_tb = tstate->curexc_traceback;
tstate->curexc_type = 0;
tstate->curexc_value = 0;
tstate->curexc_traceback = 0;
Py_DECREF(exc_type);
Py_XDECREF(exc_value);
Py_XDECREF(exc_tb);
return 0;
} else {
return -1;
}
}
return 0;
#else
if (unlikely(PyErr_Occurred())) {
if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) {
PyErr_Clear();
return 0;
} else {
return -1;
}
}
return 0;
#endif
}
/* UnpackItemEndCheck */
static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
if (unlikely(retval)) {
Py_DECREF(retval);
__Pyx_RaiseTooManyValuesError(expected);
return -1;
} else {
return __Pyx_IterFinish();
}
return 0;
}
/* PyObjectCallNoArg */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(func)) {
return __Pyx_PyFunction_FastCall(func, NULL, 0);
}
#endif
#ifdef __Pyx_CyFunction_USED
if (likely(PyCFunction_Check(func) || __Pyx_TypeCheck(func, __pyx_CyFunctionType))) {
#else
if (likely(PyCFunction_Check(func))) {
#endif
if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
return __Pyx_PyObject_CallMethO(func, NULL);
}
}
return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
}
#endif
/* PyObjectCallMethod0 */
static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) {
PyObject *method, *result = NULL;
method = __Pyx_PyObject_GetAttrStr(obj, method_name);
if (unlikely(!method)) goto bad;
#if CYTHON_UNPACK_METHODS
if (likely(PyMethod_Check(method))) {
PyObject *self = PyMethod_GET_SELF(method);
if (likely(self)) {
PyObject *function = PyMethod_GET_FUNCTION(method);
result = __Pyx_PyObject_CallOneArg(function, self);
Py_DECREF(method);
return result;
}
}
#endif
result = __Pyx_PyObject_CallNoArg(method);
Py_DECREF(method);
bad:
return result;
}
/* UnpackUnboundCMethod */
static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) {
PyObject *method;
method = __Pyx_PyObject_GetAttrStr(target->type, *target->method_name);
if (unlikely(!method))
return -1;
target->method = method;
#if CYTHON_COMPILING_IN_CPYTHON
#if PY_MAJOR_VERSION >= 3
if (likely(__Pyx_TypeCheck(method, &PyMethodDescr_Type)))
#endif
{
PyMethodDescrObject *descr = (PyMethodDescrObject*) method;
target->func = descr->d_method->ml_meth;
target->flag = descr->d_method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
}
#endif
return 0;
}
/* CallUnboundCMethod0 */
static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self) {
PyObject *args, *result = NULL;
if (unlikely(!cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
#if CYTHON_ASSUME_SAFE_MACROS
args = PyTuple_New(1);
if (unlikely(!args)) goto bad;
Py_INCREF(self);
PyTuple_SET_ITEM(args, 0, self);
#else
args = PyTuple_Pack(1, self);
if (unlikely(!args)) goto bad;
#endif
result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
Py_DECREF(args);
bad:
return result;
}
/* pop */
static CYTHON_INLINE PyObject* __Pyx__PyObject_Pop(PyObject* L) {
if (Py_TYPE(L) == &PySet_Type) {
return PySet_Pop(L);
}
return __Pyx_PyObject_CallMethod0(L, __pyx_n_s_pop);
}
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
static CYTHON_INLINE PyObject* __Pyx_PyList_Pop(PyObject* L) {
if (likely(PyList_GET_SIZE(L) > (((PyListObject*)L)->allocated >> 1))) {
Py_SIZE(L) -= 1;
return PyList_GET_ITEM(L, PyList_GET_SIZE(L));
}
return __Pyx_CallUnboundCMethod0(&__pyx_umethod_PyList_Type_pop, L);
}
#endif
/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AndObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
#if PY_MAJOR_VERSION < 3
if (likely(PyInt_CheckExact(op1))) {
const long b = intval;
long a = PyInt_AS_LONG(op1);
return PyInt_FromLong(a & b);
}
#endif
#if CYTHON_USE_PYLONG_INTERNALS
if (likely(PyLong_CheckExact(op1))) {
const long b = intval;
long a, x;
#ifdef HAVE_LONG_LONG
const PY_LONG_LONG llb = intval;
PY_LONG_LONG lla, llx;
#endif
const digit* digits = ((PyLongObject*)op1)->ob_digit;
const Py_ssize_t size = Py_SIZE(op1);
if (likely(__Pyx_sst_abs(size) <= 1)) {
a = likely(size) ? digits[0] : 0;
if (size == -1) a = -a;
} else {
switch (size) {
case -2:
if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case 2:
if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case -3:
if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case 3:
if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case -4:
if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case 4:
if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
default: return PyLong_Type.tp_as_number->nb_and(op1, op2);
}
}
x = a & b;
return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
long_long:
llx = lla & llb;
return PyLong_FromLongLong(llx);
#endif
}
#endif
return (inplace ? PyNumber_InPlaceAnd : PyNumber_And)(op1, op2);
}
#endif
/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_RshiftObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
#if PY_MAJOR_VERSION < 3
if (likely(PyInt_CheckExact(op1))) {
const long b = intval;
long a = PyInt_AS_LONG(op1);
return PyInt_FromLong(a >> b);
}
#endif
#if CYTHON_USE_PYLONG_INTERNALS
if (likely(PyLong_CheckExact(op1))) {
const long b = intval;
long a, x;
#ifdef HAVE_LONG_LONG
const PY_LONG_LONG llb = intval;
PY_LONG_LONG lla, llx;
#endif
const digit* digits = ((PyLongObject*)op1)->ob_digit;
const Py_ssize_t size = Py_SIZE(op1);
if (likely(__Pyx_sst_abs(size) <= 1)) {
a = likely(size) ? digits[0] : 0;
if (size == -1) a = -a;
} else {
switch (size) {
case -2:
if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case 2:
if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case -3:
if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case 3:
if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case -4:
if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
case 4:
if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
break;
#ifdef HAVE_LONG_LONG
} else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
goto long_long;
#endif
}
CYTHON_FALLTHROUGH;
default: return PyLong_Type.tp_as_number->nb_rshift(op1, op2);
}
}
x = a >> b;
return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
long_long:
llx = lla >> llb;
return PyLong_FromLongLong(llx);
#endif
}
#endif
return (inplace ? PyNumber_InPlaceRshift : PyNumber_Rshift)(op1, op2);
}
#endif
/* Import */
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
PyObject *empty_list = 0;
PyObject *module = 0;
PyObject *global_dict = 0;
PyObject *empty_dict = 0;
PyObject *list;
#if PY_MAJOR_VERSION < 3
PyObject *py_import;
py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
if (!py_import)
goto bad;
#endif
if (from_list)
list = from_list;
else {
empty_list = PyList_New(0);
if (!empty_list)
goto bad;
list = empty_list;
}
global_dict = PyModule_GetDict(__pyx_m);
if (!global_dict)
goto bad;
empty_dict = PyDict_New();
if (!empty_dict)
goto bad;
{
#if PY_MAJOR_VERSION >= 3
if (level == -1) {
if (strchr(__Pyx_MODULE_NAME, '.')) {
module = PyImport_ImportModuleLevelObject(
name, global_dict, empty_dict, list, 1);
if (!module) {
if (!PyErr_ExceptionMatches(PyExc_ImportError))
goto bad;
PyErr_Clear();
}
}
level = 0;
}
#endif
if (!module) {
#if PY_MAJOR_VERSION < 3
PyObject *py_level = PyInt_FromLong(level);
if (!py_level)
goto bad;
module = PyObject_CallFunctionObjArgs(py_import,
name, global_dict, empty_dict, list, py_level, NULL);
Py_DECREF(py_level);
#else
module = PyImport_ImportModuleLevelObject(
name, global_dict, empty_dict, list, level);
#endif
}
}
bad:
#if PY_MAJOR_VERSION < 3
Py_XDECREF(py_import);
#endif
Py_XDECREF(empty_list);
Py_XDECREF(empty_dict);
return module;
}
/* CalculateMetaclass */
static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases) {
Py_ssize_t i, nbases = PyTuple_GET_SIZE(bases);
for (i=0; i < nbases; i++) {
PyTypeObject *tmptype;
PyObject *tmp = PyTuple_GET_ITEM(bases, i);
tmptype = Py_TYPE(tmp);
#if PY_MAJOR_VERSION < 3
if (tmptype == &PyClass_Type)
continue;
#endif
if (!metaclass) {
metaclass = tmptype;
continue;
}
if (PyType_IsSubtype(metaclass, tmptype))
continue;
if (PyType_IsSubtype(tmptype, metaclass)) {
metaclass = tmptype;
continue;
}
PyErr_SetString(PyExc_TypeError,
"metaclass conflict: "
"the metaclass of a derived class "
"must be a (non-strict) subclass "
"of the metaclasses of all its bases");
return NULL;
}
if (!metaclass) {
#if PY_MAJOR_VERSION < 3
metaclass = &PyClass_Type;
#else
metaclass = &PyType_Type;
#endif
}
Py_INCREF((PyObject*) metaclass);
return (PyObject*) metaclass;
}
/* FetchCommonType */
static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) {
PyObject* fake_module;
PyTypeObject* cached_type = NULL;
fake_module = PyImport_AddModule((char*) "_cython_" CYTHON_ABI);
if (!fake_module) return NULL;
Py_INCREF(fake_module);
cached_type = (PyTypeObject*) PyObject_GetAttrString(fake_module, type->tp_name);
if (cached_type) {
if (!PyType_Check((PyObject*)cached_type)) {
PyErr_Format(PyExc_TypeError,
"Shared Cython type %.200s is not a type object",
type->tp_name);
goto bad;
}
if (cached_type->tp_basicsize != type->tp_basicsize) {
PyErr_Format(PyExc_TypeError,
"Shared Cython type %.200s has the wrong size, try recompiling",
type->tp_name);
goto bad;
}
} else {
if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad;
PyErr_Clear();
if (PyType_Ready(type) < 0) goto bad;
if (PyObject_SetAttrString(fake_module, type->tp_name, (PyObject*) type) < 0)
goto bad;
Py_INCREF(type);
cached_type = type;
}
done:
Py_DECREF(fake_module);
return cached_type;
bad:
Py_XDECREF(cached_type);
cached_type = NULL;
goto done;
}
/* CythonFunction */
#include <structmember.h>
static PyObject *
__Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *closure)
{
if (unlikely(op->func_doc == NULL)) {
if (op->func.m_ml->ml_doc) {
#if PY_MAJOR_VERSION >= 3
op->func_doc = PyUnicode_FromString(op->func.m_ml->ml_doc);
#else
op->func_doc = PyString_FromString(op->func.m_ml->ml_doc);
#endif
if (unlikely(op->func_doc == NULL))
return NULL;
} else {
Py_INCREF(Py_None);
return Py_None;
}
}
Py_INCREF(op->func_doc);
return op->func_doc;
}
static int
__Pyx_CyFunction_set_doc(__pyx_CyFunctionObject *op, PyObject *value)
{
PyObject *tmp = op->func_doc;
if (value == NULL) {
value = Py_None;
}
Py_INCREF(value);
op->func_doc = value;
Py_XDECREF(tmp);
return 0;
}
static PyObject *
__Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op)
{
if (unlikely(op->func_name == NULL)) {
#if PY_MAJOR_VERSION >= 3
op->func_name = PyUnicode_InternFromString(op->func.m_ml->ml_name);
#else
op->func_name = PyString_InternFromString(op->func.m_ml->ml_name);
#endif
if (unlikely(op->func_name == NULL))
return NULL;
}
Py_INCREF(op->func_name);
return op->func_name;
}
static int
__Pyx_CyFunction_set_name(__pyx_CyFunctionObject *op, PyObject *value)
{
PyObject *tmp;
#if PY_MAJOR_VERSION >= 3
if (unlikely(value == NULL || !PyUnicode_Check(value))) {
#else
if (unlikely(value == NULL || !PyString_Check(value))) {
#endif
PyErr_SetString(PyExc_TypeError,
"__name__ must be set to a string object");
return -1;
}
tmp = op->func_name;
Py_INCREF(value);
op->func_name = value;
Py_XDECREF(tmp);
return 0;
}
static PyObject *
__Pyx_CyFunction_get_qualname(__pyx_CyFunctionObject *op)
{
Py_INCREF(op->func_qualname);
return op->func_qualname;
}
static int
__Pyx_CyFunction_set_qualname(__pyx_CyFunctionObject *op, PyObject *value)
{
PyObject *tmp;
#if PY_MAJOR_VERSION >= 3
if (unlikely(value == NULL || !PyUnicode_Check(value))) {
#else
if (unlikely(value == NULL || !PyString_Check(value))) {
#endif
PyErr_SetString(PyExc_TypeError,
"__qualname__ must be set to a string object");
return -1;
}
tmp = op->func_qualname;
Py_INCREF(value);
op->func_qualname = value;
Py_XDECREF(tmp);
return 0;
}
static PyObject *
__Pyx_CyFunction_get_self(__pyx_CyFunctionObject *m, CYTHON_UNUSED void *closure)
{
PyObject *self;
self = m->func_closure;
if (self == NULL)
self = Py_None;
Py_INCREF(self);
return self;
}
static PyObject *
__Pyx_CyFunction_get_dict(__pyx_CyFunctionObject *op)
{
if (unlikely(op->func_dict == NULL)) {
op->func_dict = PyDict_New();
if (unlikely(op->func_dict == NULL))
return NULL;
}
Py_INCREF(op->func_dict);
return op->func_dict;
}
static int
__Pyx_CyFunction_set_dict(__pyx_CyFunctionObject *op, PyObject *value)
{
PyObject *tmp;
if (unlikely(value == NULL)) {
PyErr_SetString(PyExc_TypeError,
"function's dictionary may not be deleted");
return -1;
}
if (unlikely(!PyDict_Check(value))) {
PyErr_SetString(PyExc_TypeError,
"setting function's dictionary to a non-dict");
return -1;
}
tmp = op->func_dict;
Py_INCREF(value);
op->func_dict = value;
Py_XDECREF(tmp);
return 0;
}
static PyObject *
__Pyx_CyFunction_get_globals(__pyx_CyFunctionObject *op)
{
Py_INCREF(op->func_globals);
return op->func_globals;
}
static PyObject *
__Pyx_CyFunction_get_closure(CYTHON_UNUSED __pyx_CyFunctionObject *op)
{
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
__Pyx_CyFunction_get_code(__pyx_CyFunctionObject *op)
{
PyObject* result = (op->func_code) ? op->func_code : Py_None;
Py_INCREF(result);
return result;
}
static int
__Pyx_CyFunction_init_defaults(__pyx_CyFunctionObject *op) {
int result = 0;
PyObject *res = op->defaults_getter((PyObject *) op);
if (unlikely(!res))
return -1;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
op->defaults_tuple = PyTuple_GET_ITEM(res, 0);
Py_INCREF(op->defaults_tuple);
op->defaults_kwdict = PyTuple_GET_ITEM(res, 1);
Py_INCREF(op->defaults_kwdict);
#else
op->defaults_tuple = PySequence_ITEM(res, 0);
if (unlikely(!op->defaults_tuple)) result = -1;
else {
op->defaults_kwdict = PySequence_ITEM(res, 1);
if (unlikely(!op->defaults_kwdict)) result = -1;
}
#endif
Py_DECREF(res);
return result;
}
static int
__Pyx_CyFunction_set_defaults(__pyx_CyFunctionObject *op, PyObject* value) {
PyObject* tmp;
if (!value) {
value = Py_None;
} else if (value != Py_None && !PyTuple_Check(value)) {
PyErr_SetString(PyExc_TypeError,
"__defaults__ must be set to a tuple object");
return -1;
}
Py_INCREF(value);
tmp = op->defaults_tuple;
op->defaults_tuple = value;
Py_XDECREF(tmp);
return 0;
}
static PyObject *
__Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject *op) {
PyObject* result = op->defaults_tuple;
if (unlikely(!result)) {
if (op->defaults_getter) {
if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL;
result = op->defaults_tuple;
} else {
result = Py_None;
}
}
Py_INCREF(result);
return result;
}
static int
__Pyx_CyFunction_set_kwdefaults(__pyx_CyFunctionObject *op, PyObject* value) {
PyObject* tmp;
if (!value) {
value = Py_None;
} else if (value != Py_None && !PyDict_Check(value)) {
PyErr_SetString(PyExc_TypeError,
"__kwdefaults__ must be set to a dict object");
return -1;
}
Py_INCREF(value);
tmp = op->defaults_kwdict;
op->defaults_kwdict = value;
Py_XDECREF(tmp);
return 0;
}
static PyObject *
__Pyx_CyFunction_get_kwdefaults(__pyx_CyFunctionObject *op) {
PyObject* result = op->defaults_kwdict;
if (unlikely(!result)) {
if (op->defaults_getter) {
if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL;
result = op->defaults_kwdict;
} else {
result = Py_None;
}
}
Py_INCREF(result);
return result;
}
static int
__Pyx_CyFunction_set_annotations(__pyx_CyFunctionObject *op, PyObject* value) {
PyObject* tmp;
if (!value || value == Py_None) {
value = NULL;
} else if (!PyDict_Check(value)) {
PyErr_SetString(PyExc_TypeError,
"__annotations__ must be set to a dict object");
return -1;
}
Py_XINCREF(value);
tmp = op->func_annotations;
op->func_annotations = value;
Py_XDECREF(tmp);
return 0;
}
static PyObject *
__Pyx_CyFunction_get_annotations(__pyx_CyFunctionObject *op) {
PyObject* result = op->func_annotations;
if (unlikely(!result)) {
result = PyDict_New();
if (unlikely(!result)) return NULL;
op->func_annotations = result;
}
Py_INCREF(result);
return result;
}
static PyGetSetDef __pyx_CyFunction_getsets[] = {
{(char *) "func_doc", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
{(char *) "__doc__", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
{(char *) "func_name", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0},
{(char *) "__name__", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0},
{(char *) "__qualname__", (getter)__Pyx_CyFunction_get_qualname, (setter)__Pyx_CyFunction_set_qualname, 0, 0},
{(char *) "__self__", (getter)__Pyx_CyFunction_get_self, 0, 0, 0},
{(char *) "func_dict", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0},
{(char *) "__dict__", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0},
{(char *) "func_globals", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0},
{(char *) "__globals__", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0},
{(char *) "func_closure", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0},
{(char *) "__closure__", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0},
{(char *) "func_code", (getter)__Pyx_CyFunction_get_code, 0, 0, 0},
{(char *) "__code__", (getter)__Pyx_CyFunction_get_code, 0, 0, 0},
{(char *) "func_defaults", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
{(char *) "__defaults__", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
{(char *) "__kwdefaults__", (getter)__Pyx_CyFunction_get_kwdefaults, (setter)__Pyx_CyFunction_set_kwdefaults, 0, 0},
{(char *) "__annotations__", (getter)__Pyx_CyFunction_get_annotations, (setter)__Pyx_CyFunction_set_annotations, 0, 0},
{0, 0, 0, 0, 0}
};
static PyMemberDef __pyx_CyFunction_members[] = {
{(char *) "__module__", T_OBJECT, offsetof(PyCFunctionObject, m_module), PY_WRITE_RESTRICTED, 0},
{0, 0, 0, 0, 0}
};
static PyObject *
__Pyx_CyFunction_reduce(__pyx_CyFunctionObject *m, CYTHON_UNUSED PyObject *args)
{
#if PY_MAJOR_VERSION >= 3
return PyUnicode_FromString(m->func.m_ml->ml_name);
#else
return PyString_FromString(m->func.m_ml->ml_name);
#endif
}
static PyMethodDef __pyx_CyFunction_methods[] = {
{"__reduce__", (PyCFunction)__Pyx_CyFunction_reduce, METH_VARARGS, 0},
{0, 0, 0, 0}
};
#if PY_VERSION_HEX < 0x030500A0
#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func_weakreflist)
#else
#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func.m_weakreflist)
#endif
static PyObject *__Pyx_CyFunction_New(PyTypeObject *type, PyMethodDef *ml, int flags, PyObject* qualname,
PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) {
__pyx_CyFunctionObject *op = PyObject_GC_New(__pyx_CyFunctionObject, type);
if (op == NULL)
return NULL;
op->flags = flags;
__Pyx_CyFunction_weakreflist(op) = NULL;
op->func.m_ml = ml;
op->func.m_self = (PyObject *) op;
Py_XINCREF(closure);
op->func_closure = closure;
Py_XINCREF(module);
op->func.m_module = module;
op->func_dict = NULL;
op->func_name = NULL;
Py_INCREF(qualname);
op->func_qualname = qualname;
op->func_doc = NULL;
op->func_classobj = NULL;
op->func_globals = globals;
Py_INCREF(op->func_globals);
Py_XINCREF(code);
op->func_code = code;
op->defaults_pyobjects = 0;
op->defaults = NULL;
op->defaults_tuple = NULL;
op->defaults_kwdict = NULL;
op->defaults_getter = NULL;
op->func_annotations = NULL;
PyObject_GC_Track(op);
return (PyObject *) op;
}
static int
__Pyx_CyFunction_clear(__pyx_CyFunctionObject *m)
{
Py_CLEAR(m->func_closure);
Py_CLEAR(m->func.m_module);
Py_CLEAR(m->func_dict);
Py_CLEAR(m->func_name);
Py_CLEAR(m->func_qualname);
Py_CLEAR(m->func_doc);
Py_CLEAR(m->func_globals);
Py_CLEAR(m->func_code);
Py_CLEAR(m->func_classobj);
Py_CLEAR(m->defaults_tuple);
Py_CLEAR(m->defaults_kwdict);
Py_CLEAR(m->func_annotations);
if (m->defaults) {
PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
int i;
for (i = 0; i < m->defaults_pyobjects; i++)
Py_XDECREF(pydefaults[i]);
PyObject_Free(m->defaults);
m->defaults = NULL;
}
return 0;
}
static void __Pyx__CyFunction_dealloc(__pyx_CyFunctionObject *m)
{
if (__Pyx_CyFunction_weakreflist(m) != NULL)
PyObject_ClearWeakRefs((PyObject *) m);
__Pyx_CyFunction_clear(m);
PyObject_GC_Del(m);
}
static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject *m)
{
PyObject_GC_UnTrack(m);
__Pyx__CyFunction_dealloc(m);
}
static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit, void *arg)
{
Py_VISIT(m->func_closure);
Py_VISIT(m->func.m_module);
Py_VISIT(m->func_dict);
Py_VISIT(m->func_name);
Py_VISIT(m->func_qualname);
Py_VISIT(m->func_doc);
Py_VISIT(m->func_globals);
Py_VISIT(m->func_code);
Py_VISIT(m->func_classobj);
Py_VISIT(m->defaults_tuple);
Py_VISIT(m->defaults_kwdict);
if (m->defaults) {
PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
int i;
for (i = 0; i < m->defaults_pyobjects; i++)
Py_VISIT(pydefaults[i]);
}
return 0;
}
static PyObject *__Pyx_CyFunction_descr_get(PyObject *func, PyObject *obj, PyObject *type)
{
__pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
if (m->flags & __Pyx_CYFUNCTION_STATICMETHOD) {
Py_INCREF(func);
return func;
}
if (m->flags & __Pyx_CYFUNCTION_CLASSMETHOD) {
if (type == NULL)
type = (PyObject *)(Py_TYPE(obj));
return __Pyx_PyMethod_New(func, type, (PyObject *)(Py_TYPE(type)));
}
if (obj == Py_None)
obj = NULL;
return __Pyx_PyMethod_New(func, obj, type);
}
static PyObject*
__Pyx_CyFunction_repr(__pyx_CyFunctionObject *op)
{
#if PY_MAJOR_VERSION >= 3
return PyUnicode_FromFormat("<cyfunction %U at %p>",
op->func_qualname, (void *)op);
#else
return PyString_FromFormat("<cyfunction %s at %p>",
PyString_AsString(op->func_qualname), (void *)op);
#endif
}
static PyObject * __Pyx_CyFunction_CallMethod(PyObject *func, PyObject *self, PyObject *arg, PyObject *kw) {
PyCFunctionObject* f = (PyCFunctionObject*)func;
PyCFunction meth = f->m_ml->ml_meth;
Py_ssize_t size;
switch (f->m_ml->ml_flags & (METH_VARARGS | METH_KEYWORDS | METH_NOARGS | METH_O)) {
case METH_VARARGS:
if (likely(kw == NULL || PyDict_Size(kw) == 0))
return (*meth)(self, arg);
break;
case METH_VARARGS | METH_KEYWORDS:
return (*(PyCFunctionWithKeywords)meth)(self, arg, kw);
case METH_NOARGS:
if (likely(kw == NULL || PyDict_Size(kw) == 0)) {
size = PyTuple_GET_SIZE(arg);
if (likely(size == 0))
return (*meth)(self, NULL);
PyErr_Format(PyExc_TypeError,
"%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)",
f->m_ml->ml_name, size);
return NULL;
}
break;
case METH_O:
if (likely(kw == NULL || PyDict_Size(kw) == 0)) {
size = PyTuple_GET_SIZE(arg);
if (likely(size == 1)) {
PyObject *result, *arg0;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
arg0 = PyTuple_GET_ITEM(arg, 0);
#else
arg0 = PySequence_ITEM(arg, 0); if (unlikely(!arg0)) return NULL;
#endif
result = (*meth)(self, arg0);
#if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS)
Py_DECREF(arg0);
#endif
return result;
}
PyErr_Format(PyExc_TypeError,
"%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)",
f->m_ml->ml_name, size);
return NULL;
}
break;
default:
PyErr_SetString(PyExc_SystemError, "Bad call flags in "
"__Pyx_CyFunction_Call. METH_OLDARGS is no "
"longer supported!");
return NULL;
}
PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments",
f->m_ml->ml_name);
return NULL;
}
static CYTHON_INLINE PyObject *__Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) {
return __Pyx_CyFunction_CallMethod(func, ((PyCFunctionObject*)func)->m_self, arg, kw);
}
static PyObject *__Pyx_CyFunction_CallAsMethod(PyObject *func, PyObject *args, PyObject *kw) {
PyObject *result;
__pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *) func;
if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) {
Py_ssize_t argc;
PyObject *new_args;
PyObject *self;
argc = PyTuple_GET_SIZE(args);
new_args = PyTuple_GetSlice(args, 1, argc);
if (unlikely(!new_args))
return NULL;
self = PyTuple_GetItem(args, 0);
if (unlikely(!self)) {
Py_DECREF(new_args);
return NULL;
}
result = __Pyx_CyFunction_CallMethod(func, self, new_args, kw);
Py_DECREF(new_args);
} else {
result = __Pyx_CyFunction_Call(func, args, kw);
}
return result;
}
static PyTypeObject __pyx_CyFunctionType_type = {
PyVarObject_HEAD_INIT(0, 0)
"cython_function_or_method",
sizeof(__pyx_CyFunctionObject),
0,
(destructor) __Pyx_CyFunction_dealloc,
0,
0,
0,
#if PY_MAJOR_VERSION < 3
0,
#else
0,
#endif
(reprfunc) __Pyx_CyFunction_repr,
0,
0,
0,
0,
__Pyx_CyFunction_CallAsMethod,
0,
0,
0,
0,
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
0,
(traverseproc) __Pyx_CyFunction_traverse,
(inquiry) __Pyx_CyFunction_clear,
0,
#if PY_VERSION_HEX < 0x030500A0
offsetof(__pyx_CyFunctionObject, func_weakreflist),
#else
offsetof(PyCFunctionObject, m_weakreflist),
#endif
0,
0,
__pyx_CyFunction_methods,
__pyx_CyFunction_members,
__pyx_CyFunction_getsets,
0,
0,
__Pyx_CyFunction_descr_get,
0,
offsetof(__pyx_CyFunctionObject, func_dict),
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
#if PY_VERSION_HEX >= 0x030400a1
0,
#endif
};
static int __pyx_CyFunction_init(void) {
__pyx_CyFunctionType = __Pyx_FetchCommonType(&__pyx_CyFunctionType_type);
if (unlikely(__pyx_CyFunctionType == NULL)) {
return -1;
}
return 0;
}
static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects) {
__pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
m->defaults = PyObject_Malloc(size);
if (unlikely(!m->defaults))
return PyErr_NoMemory();
memset(m->defaults, 0, size);
m->defaults_pyobjects = pyobjects;
return m->defaults;
}
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) {
__pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
m->defaults_tuple = tuple;
Py_INCREF(tuple);
}
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *func, PyObject *dict) {
__pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
m->defaults_kwdict = dict;
Py_INCREF(dict);
}
static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *func, PyObject *dict) {
__pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
m->func_annotations = dict;
Py_INCREF(dict);
}
/* ClassMethod */
static PyObject* __Pyx_Method_ClassMethod(PyObject *method) {
#if CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM <= 0x05080000
if (PyObject_TypeCheck(method, &PyWrapperDescr_Type)) {
return PyClassMethod_New(method);
}
#else
#if CYTHON_COMPILING_IN_PYSTON || CYTHON_COMPILING_IN_PYPY
if (PyMethodDescr_Check(method)) {
#else
static PyTypeObject *methoddescr_type = NULL;
if (methoddescr_type == NULL) {
PyObject *meth = PyObject_GetAttrString((PyObject*)&PyList_Type, "append");
if (!meth) return NULL;
methoddescr_type = Py_TYPE(meth);
Py_DECREF(meth);
}
if (__Pyx_TypeCheck(method, methoddescr_type)) {
#endif
PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
#if PY_VERSION_HEX < 0x03020000
PyTypeObject *d_type = descr->d_type;
#else
PyTypeObject *d_type = descr->d_common.d_type;
#endif
return PyDescr_NewClassMethod(d_type, descr->d_method);
}
#endif
else if (PyMethod_Check(method)) {
return PyClassMethod_New(PyMethod_GET_FUNCTION(method));
}
else if (PyCFunction_Check(method)) {
return PyClassMethod_New(method);
}
#ifdef __Pyx_CyFunction_USED
else if (__Pyx_TypeCheck(method, __pyx_CyFunctionType)) {
return PyClassMethod_New(method);
}
#endif
PyErr_SetString(PyExc_TypeError,
"Class-level classmethod() can only be called on "
"a method_descriptor or instance method.");
return NULL;
}
/* Py3ClassCreate */
static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name,
PyObject *qualname, PyObject *mkw, PyObject *modname, PyObject *doc) {
PyObject *ns;
if (metaclass) {
PyObject *prep = __Pyx_PyObject_GetAttrStr(metaclass, __pyx_n_s_prepare);
if (prep) {
PyObject *pargs = PyTuple_Pack(2, name, bases);
if (unlikely(!pargs)) {
Py_DECREF(prep);
return NULL;
}
ns = PyObject_Call(prep, pargs, mkw);
Py_DECREF(prep);
Py_DECREF(pargs);
} else {
if (unlikely(!PyErr_ExceptionMatches(PyExc_AttributeError)))
return NULL;
PyErr_Clear();
ns = PyDict_New();
}
} else {
ns = PyDict_New();
}
if (unlikely(!ns))
return NULL;
if (unlikely(PyObject_SetItem(ns, __pyx_n_s_module, modname) < 0)) goto bad;
if (unlikely(PyObject_SetItem(ns, __pyx_n_s_qualname, qualname) < 0)) goto bad;
if (unlikely(doc && PyObject_SetItem(ns, __pyx_n_s_doc, doc) < 0)) goto bad;
return ns;
bad:
Py_DECREF(ns);
return NULL;
}
static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases,
PyObject *dict, PyObject *mkw,
int calculate_metaclass, int allow_py2_metaclass) {
PyObject *result, *margs;
PyObject *owned_metaclass = NULL;
if (allow_py2_metaclass) {
owned_metaclass = PyObject_GetItem(dict, __pyx_n_s_metaclass);
if (owned_metaclass) {
metaclass = owned_metaclass;
} else if (likely(PyErr_ExceptionMatches(PyExc_KeyError))) {
PyErr_Clear();
} else {
return NULL;
}
}
if (calculate_metaclass && (!metaclass || PyType_Check(metaclass))) {
metaclass = __Pyx_CalculateMetaclass((PyTypeObject*) metaclass, bases);
Py_XDECREF(owned_metaclass);
if (unlikely(!metaclass))
return NULL;
owned_metaclass = metaclass;
}
margs = PyTuple_Pack(3, name, bases, dict);
if (unlikely(!margs)) {
result = NULL;
} else {
result = PyObject_Call(metaclass, margs, mkw);
Py_DECREF(margs);
}
Py_XDECREF(owned_metaclass);
return result;
}
/* PyErrFetchRestore */
#if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
PyObject *tmp_type, *tmp_value, *tmp_tb;
tmp_type = tstate->curexc_type;
tmp_value = tstate->curexc_value;
tmp_tb = tstate->curexc_traceback;
tstate->curexc_type = type;
tstate->curexc_value = value;
tstate->curexc_traceback = tb;
Py_XDECREF(tmp_type);
Py_XDECREF(tmp_value);
Py_XDECREF(tmp_tb);
}
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
*type = tstate->curexc_type;
*value = tstate->curexc_value;
*tb = tstate->curexc_traceback;
tstate->curexc_type = 0;
tstate->curexc_value = 0;
tstate->curexc_traceback = 0;
}
#endif
/* CLineInTraceback */
#ifndef CYTHON_CLINE_IN_TRACEBACK
static int __Pyx_CLineForTraceback(CYTHON_UNUSED PyThreadState *tstate, int c_line) {
PyObject *use_cline;
PyObject *ptype, *pvalue, *ptraceback;
#if CYTHON_COMPILING_IN_CPYTHON
PyObject **cython_runtime_dict;
#endif
if (unlikely(!__pyx_cython_runtime)) {
return c_line;
}
__Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
#if CYTHON_COMPILING_IN_CPYTHON
cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime);
if (likely(cython_runtime_dict)) {
use_cline = __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback);
} else
#endif
{
PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback);
if (use_cline_obj) {
use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True;
Py_DECREF(use_cline_obj);
} else {
PyErr_Clear();
use_cline = NULL;
}
}
if (!use_cline) {
c_line = 0;
PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False);
}
else if (PyObject_Not(use_cline) != 0) {
c_line = 0;
}
__Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
return c_line;
}
#endif
/* CodeObjectCache */
static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
int start = 0, mid = 0, end = count - 1;
if (end >= 0 && code_line > entries[end].code_line) {
return count;
}
while (start < end) {
mid = start + (end - start) / 2;
if (code_line < entries[mid].code_line) {
end = mid;
} else if (code_line > entries[mid].code_line) {
start = mid + 1;
} else {
return mid;
}
}
if (code_line <= entries[mid].code_line) {
return mid;
} else {
return mid + 1;
}
}
static PyCodeObject *__pyx_find_code_object(int code_line) {
PyCodeObject* code_object;
int pos;
if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
return NULL;
}
pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
return NULL;
}
code_object = __pyx_code_cache.entries[pos].code_object;
Py_INCREF(code_object);
return code_object;
}
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
int pos, i;
__Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
if (unlikely(!code_line)) {
return;
}
if (unlikely(!entries)) {
entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
if (likely(entries)) {
__pyx_code_cache.entries = entries;
__pyx_code_cache.max_count = 64;
__pyx_code_cache.count = 1;
entries[0].code_line = code_line;
entries[0].code_object = code_object;
Py_INCREF(code_object);
}
return;
}
pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
PyCodeObject* tmp = entries[pos].code_object;
entries[pos].code_object = code_object;
Py_DECREF(tmp);
return;
}
if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
int new_max = __pyx_code_cache.max_count + 64;
entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
__pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry));
if (unlikely(!entries)) {
return;
}
__pyx_code_cache.entries = entries;
__pyx_code_cache.max_count = new_max;
}
for (i=__pyx_code_cache.count; i>pos; i--) {
entries[i] = entries[i-1];
}
entries[pos].code_line = code_line;
entries[pos].code_object = code_object;
__pyx_code_cache.count++;
Py_INCREF(code_object);
}
/* AddTraceback */
#include "compile.h"
#include "frameobject.h"
#include "traceback.h"
static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
const char *funcname, int c_line,
int py_line, const char *filename) {
PyCodeObject *py_code = 0;
PyObject *py_srcfile = 0;
PyObject *py_funcname = 0;
#if PY_MAJOR_VERSION < 3
py_srcfile = PyString_FromString(filename);
#else
py_srcfile = PyUnicode_FromString(filename);
#endif
if (!py_srcfile) goto bad;
if (c_line) {
#if PY_MAJOR_VERSION < 3
py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
#else
py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
#endif
}
else {
#if PY_MAJOR_VERSION < 3
py_funcname = PyString_FromString(funcname);
#else
py_funcname = PyUnicode_FromString(funcname);
#endif
}
if (!py_funcname) goto bad;
py_code = __Pyx_PyCode_New(
0,
0,
0,
0,
0,
__pyx_empty_bytes, /*PyObject *code,*/
__pyx_empty_tuple, /*PyObject *consts,*/
__pyx_empty_tuple, /*PyObject *names,*/
__pyx_empty_tuple, /*PyObject *varnames,*/
__pyx_empty_tuple, /*PyObject *freevars,*/
__pyx_empty_tuple, /*PyObject *cellvars,*/
py_srcfile, /*PyObject *filename,*/
py_funcname, /*PyObject *name,*/
py_line,
__pyx_empty_bytes /*PyObject *lnotab*/
);
Py_DECREF(py_srcfile);
Py_DECREF(py_funcname);
return py_code;
bad:
Py_XDECREF(py_srcfile);
Py_XDECREF(py_funcname);
return NULL;
}
static void __Pyx_AddTraceback(const char *funcname, int c_line,
int py_line, const char *filename) {
PyCodeObject *py_code = 0;
PyFrameObject *py_frame = 0;
PyThreadState *tstate = __Pyx_PyThreadState_Current;
if (c_line) {
c_line = __Pyx_CLineForTraceback(tstate, c_line);
}
py_code = __pyx_find_code_object(c_line ? -c_line : py_line);
if (!py_code) {
py_code = __Pyx_CreateCodeObjectForTraceback(
funcname, c_line, py_line, filename);
if (!py_code) goto bad;
__pyx_insert_code_object(c_line ? -c_line : py_line, py_code);
}
py_frame = PyFrame_New(
tstate, /*PyThreadState *tstate,*/
py_code, /*PyCodeObject *code,*/
__pyx_d, /*PyObject *globals,*/
0 /*PyObject *locals*/
);
if (!py_frame) goto bad;
__Pyx_PyFrame_SetLineNumber(py_frame, py_line);
PyTraceBack_Here(py_frame);
bad:
Py_XDECREF(py_code);
Py_XDECREF(py_frame);
}
/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
const long neg_one = (long) -1, const_zero = (long) 0;
const int is_unsigned = neg_one > const_zero;
if (is_unsigned) {
if (sizeof(long) < sizeof(long)) {
return PyInt_FromLong((long) value);
} else if (sizeof(long) <= sizeof(unsigned long)) {
return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
} else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
}
} else {
if (sizeof(long) <= sizeof(long)) {
return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
} else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
}
}
{
int one = 1; int little = (int)*(unsigned char *)&one;
unsigned char *bytes = (unsigned char *)&value;
return _PyLong_FromByteArray(bytes, sizeof(long),
little, !is_unsigned);
}
}
/* CIntFromPyVerify */
#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
__PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
__PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
{\
func_type value = func_value;\
if (sizeof(target_type) < sizeof(func_type)) {\
if (unlikely(value != (func_type) (target_type) value)) {\
func_type zero = 0;\
if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
return (target_type) -1;\
if (is_unsigned && unlikely(value < zero))\
goto raise_neg_overflow;\
else\
goto raise_overflow;\
}\
}\
return (target_type) value;\
}
/* CIntFromPy */
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
const long neg_one = (long) -1, const_zero = (long) 0;
const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
if (likely(PyInt_Check(x))) {
if (sizeof(long) < sizeof(long)) {
__PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
} else {
long val = PyInt_AS_LONG(x);
if (is_unsigned && unlikely(val < 0)) {
goto raise_neg_overflow;
}
return (long) val;
}
} else
#endif
if (likely(PyLong_Check(x))) {
if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
const digit* digits = ((PyLongObject*)x)->ob_digit;
switch (Py_SIZE(x)) {
case 0: return (long) 0;
case 1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
case 2:
if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
__PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
}
}
break;
case 3:
if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
__PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
}
}
break;
case 4:
if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
__PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
}
}
break;
}
#endif
#if CYTHON_COMPILING_IN_CPYTHON
if (unlikely(Py_SIZE(x) < 0)) {
goto raise_neg_overflow;
}
#else
{
int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
if (unlikely(result < 0))
return (long) -1;
if (unlikely(result == 1))
goto raise_neg_overflow;
}
#endif
if (sizeof(long) <= sizeof(unsigned long)) {
__PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
} else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
__PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
}
} else {
#if CYTHON_USE_PYLONG_INTERNALS
const digit* digits = ((PyLongObject*)x)->ob_digit;
switch (Py_SIZE(x)) {
case 0: return (long) 0;
case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0]))
case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0])
case -2:
if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
__PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
}
}
break;
case 2:
if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
__PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
}
}
break;
case -3:
if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
__PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
}
}
break;
case 3:
if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
__PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
}
}
break;
case -4:
if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
__PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
}
}
break;
case 4:
if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
__PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
}
}
break;
}
#endif
if (sizeof(long) <= sizeof(long)) {
__PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
} else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
__PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
}
}
{
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
PyErr_SetString(PyExc_RuntimeError,
"_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
long val;
PyObject *v = __Pyx_PyNumber_IntOrLong(x);
#if PY_MAJOR_VERSION < 3
if (likely(v) && !PyLong_Check(v)) {
PyObject *tmp = v;
v = PyNumber_Long(tmp);
Py_DECREF(tmp);
}
#endif
if (likely(v)) {
int one = 1; int is_little = (int)*(unsigned char *)&one;
unsigned char *bytes = (unsigned char *)&val;
int ret = _PyLong_AsByteArray((PyLongObject *)v,
bytes, sizeof(val),
is_little, !is_unsigned);
Py_DECREF(v);
if (likely(!ret))
return val;
}
#endif
return (long) -1;
}
} else {
long val;
PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
if (!tmp) return (long) -1;
val = __Pyx_PyInt_As_long(tmp);
Py_DECREF(tmp);
return val;
}
raise_overflow:
PyErr_SetString(PyExc_OverflowError,
"value too large to convert to long");
return (long) -1;
raise_neg_overflow:
PyErr_SetString(PyExc_OverflowError,
"can't convert negative value to long");
return (long) -1;
}
/* CIntFromPy */
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
const int neg_one = (int) -1, const_zero = (int) 0;
const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
if (likely(PyInt_Check(x))) {
if (sizeof(int) < sizeof(long)) {
__PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
} else {
long val = PyInt_AS_LONG(x);
if (is_unsigned && unlikely(val < 0)) {
goto raise_neg_overflow;
}
return (int) val;
}
} else
#endif
if (likely(PyLong_Check(x))) {
if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
const digit* digits = ((PyLongObject*)x)->ob_digit;
switch (Py_SIZE(x)) {
case 0: return (int) 0;
case 1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
case 2:
if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
}
}
break;
case 3:
if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
}
}
break;
case 4:
if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
}
}
break;
}
#endif
#if CYTHON_COMPILING_IN_CPYTHON
if (unlikely(Py_SIZE(x) < 0)) {
goto raise_neg_overflow;
}
#else
{
int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
if (unlikely(result < 0))
return (int) -1;
if (unlikely(result == 1))
goto raise_neg_overflow;
}
#endif
if (sizeof(int) <= sizeof(unsigned long)) {
__PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
} else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
__PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
}
} else {
#if CYTHON_USE_PYLONG_INTERNALS
const digit* digits = ((PyLongObject*)x)->ob_digit;
switch (Py_SIZE(x)) {
case 0: return (int) 0;
case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0]))
case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0])
case -2:
if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
__PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
}
}
break;
case 2:
if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
}
}
break;
case -3:
if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
__PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
}
}
break;
case 3:
if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
}
}
break;
case -4:
if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
__PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
}
}
break;
case 4:
if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
}
}
break;
}
#endif
if (sizeof(int) <= sizeof(long)) {
__PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
} else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
__PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
}
}
{
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
PyErr_SetString(PyExc_RuntimeError,
"_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
int val;
PyObject *v = __Pyx_PyNumber_IntOrLong(x);
#if PY_MAJOR_VERSION < 3
if (likely(v) && !PyLong_Check(v)) {
PyObject *tmp = v;
v = PyNumber_Long(tmp);
Py_DECREF(tmp);
}
#endif
if (likely(v)) {
int one = 1; int is_little = (int)*(unsigned char *)&one;
unsigned char *bytes = (unsigned char *)&val;
int ret = _PyLong_AsByteArray((PyLongObject *)v,
bytes, sizeof(val),
is_little, !is_unsigned);
Py_DECREF(v);
if (likely(!ret))
return val;
}
#endif
return (int) -1;
}
} else {
int val;
PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
if (!tmp) return (int) -1;
val = __Pyx_PyInt_As_int(tmp);
Py_DECREF(tmp);
return val;
}
raise_overflow:
PyErr_SetString(PyExc_OverflowError,
"value too large to convert to int");
return (int) -1;
raise_neg_overflow:
PyErr_SetString(PyExc_OverflowError,
"can't convert negative value to int");
return (int) -1;
}
/* FastTypeChecks */
#if CYTHON_COMPILING_IN_CPYTHON
static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) {
while (a) {
a = a->tp_base;
if (a == b)
return 1;
}
return b == &PyBaseObject_Type;
}
static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) {
PyObject *mro;
if (a == b) return 1;
mro = a->tp_mro;
if (likely(mro)) {
Py_ssize_t i, n;
n = PyTuple_GET_SIZE(mro);
for (i = 0; i < n; i++) {
if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
return 1;
}
return 0;
}
return __Pyx_InBases(a, b);
}
#if PY_MAJOR_VERSION == 2
static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) {
PyObject *exception, *value, *tb;
int res;
__Pyx_PyThreadState_declare
__Pyx_PyThreadState_assign
__Pyx_ErrFetch(&exception, &value, &tb);
res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0;
if (unlikely(res == -1)) {
PyErr_WriteUnraisable(err);
res = 0;
}
if (!res) {
res = PyObject_IsSubclass(err, exc_type2);
if (unlikely(res == -1)) {
PyErr_WriteUnraisable(err);
res = 0;
}
}
__Pyx_ErrRestore(exception, value, tb);
return res;
}
#else
static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) {
int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0;
if (!res) {
res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2);
}
return res;
}
#endif
static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
Py_ssize_t i, n;
assert(PyExceptionClass_Check(exc_type));
n = PyTuple_GET_SIZE(tuple);
#if PY_MAJOR_VERSION >= 3
for (i=0; i<n; i++) {
if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
}
#endif
for (i=0; i<n; i++) {
PyObject *t = PyTuple_GET_ITEM(tuple, i);
#if PY_MAJOR_VERSION < 3
if (likely(exc_type == t)) return 1;
#endif
if (likely(PyExceptionClass_Check(t))) {
if (__Pyx_inner_PyErr_GivenExceptionMatches2(exc_type, NULL, t)) return 1;
} else {
}
}
return 0;
}
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) {
if (likely(err == exc_type)) return 1;
if (likely(PyExceptionClass_Check(err))) {
if (likely(PyExceptionClass_Check(exc_type))) {
return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type);
} else if (likely(PyTuple_Check(exc_type))) {
return __Pyx_PyErr_GivenExceptionMatchesTuple(err, exc_type);
} else {
}
}
return PyErr_GivenExceptionMatches(err, exc_type);
}
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) {
assert(PyExceptionClass_Check(exc_type1));
assert(PyExceptionClass_Check(exc_type2));
if (likely(err == exc_type1 || err == exc_type2)) return 1;
if (likely(PyExceptionClass_Check(err))) {
return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2);
}
return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2));
}
#endif
/* CheckBinaryVersion */
static int __Pyx_check_binary_version(void) {
char ctversion[4], rtversion[4];
PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
char message[200];
PyOS_snprintf(message, sizeof(message),
"compiletime version %s of module '%.100s' "
"does not match runtime version %s",
ctversion, __Pyx_MODULE_NAME, rtversion);
return PyErr_WarnEx(NULL, message, 1);
}
return 0;
}
/* InitStrings */
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
while (t->p) {
#if PY_MAJOR_VERSION < 3
if (t->is_unicode) {
*t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
} else if (t->intern) {
*t->p = PyString_InternFromString(t->s);
} else {
*t->p = PyString_FromStringAndSize(t->s, t->n - 1);
}
#else
if (t->is_unicode | t->is_str) {
if (t->intern) {
*t->p = PyUnicode_InternFromString(t->s);
} else if (t->encoding) {
*t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
} else {
*t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
}
} else {
*t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
}
#endif
if (!*t->p)
return -1;
if (PyObject_Hash(*t->p) == -1)
return -1;
++t;
}
return 0;
}
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
}
static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
Py_ssize_t ignore;
return __Pyx_PyObject_AsStringAndSize(o, &ignore);
}
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
#if !CYTHON_PEP393_ENABLED
static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
char* defenc_c;
PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
if (!defenc) return NULL;
defenc_c = PyBytes_AS_STRING(defenc);
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
{
char* end = defenc_c + PyBytes_GET_SIZE(defenc);
char* c;
for (c = defenc_c; c < end; c++) {
if ((unsigned char) (*c) >= 128) {
PyUnicode_AsASCIIString(o);
return NULL;
}
}
}
#endif
*length = PyBytes_GET_SIZE(defenc);
return defenc_c;
}
#else
static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
if (likely(PyUnicode_IS_ASCII(o))) {
*length = PyUnicode_GET_LENGTH(o);
return PyUnicode_AsUTF8(o);
} else {
PyUnicode_AsASCIIString(o);
return NULL;
}
#else
return PyUnicode_AsUTF8AndSize(o, length);
#endif
}
#endif
#endif
static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
if (
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
__Pyx_sys_getdefaultencoding_not_ascii &&
#endif
PyUnicode_Check(o)) {
return __Pyx_PyUnicode_AsStringAndSize(o, length);
} else
#endif
#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
if (PyByteArray_Check(o)) {
*length = PyByteArray_GET_SIZE(o);
return PyByteArray_AS_STRING(o);
} else
#endif
{
char* result;
int r = PyBytes_AsStringAndSize(o, &result, length);
if (unlikely(r < 0)) {
return NULL;
} else {
return result;
}
}
}
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
int is_true = x == Py_True;
if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
else return PyObject_IsTrue(x);
}
static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) {
#if PY_MAJOR_VERSION >= 3
if (PyLong_Check(result)) {
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
"__int__ returned non-int (type %.200s). "
"The ability to return an instance of a strict subclass of int "
"is deprecated, and may be removed in a future version of Python.",
Py_TYPE(result)->tp_name)) {
Py_DECREF(result);
return NULL;
}
return result;
}
#endif
PyErr_Format(PyExc_TypeError,
"__%.4s__ returned non-%.4s (type %.200s)",
type_name, type_name, Py_TYPE(result)->tp_name);
Py_DECREF(result);
return NULL;
}
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
#if CYTHON_USE_TYPE_SLOTS
PyNumberMethods *m;
#endif
const char *name = NULL;
PyObject *res = NULL;
#if PY_MAJOR_VERSION < 3
if (likely(PyInt_Check(x) || PyLong_Check(x)))
#else
if (likely(PyLong_Check(x)))
#endif
return __Pyx_NewRef(x);
#if CYTHON_USE_TYPE_SLOTS
m = Py_TYPE(x)->tp_as_number;
#if PY_MAJOR_VERSION < 3
if (m && m->nb_int) {
name = "int";
res = m->nb_int(x);
}
else if (m && m->nb_long) {
name = "long";
res = m->nb_long(x);
}
#else
if (likely(m && m->nb_int)) {
name = "int";
res = m->nb_int(x);
}
#endif
#else
if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) {
res = PyNumber_Int(x);
}
#endif
if (likely(res)) {
#if PY_MAJOR_VERSION < 3
if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) {
#else
if (unlikely(!PyLong_CheckExact(res))) {
#endif
return __Pyx_PyNumber_IntOrLongWrongResultType(res, name);
}
}
else if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_TypeError,
"an integer is required");
}
return res;
}
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
Py_ssize_t ival;
PyObject *x;
#if PY_MAJOR_VERSION < 3
if (likely(PyInt_CheckExact(b))) {
if (sizeof(Py_ssize_t) >= sizeof(long))
return PyInt_AS_LONG(b);
else
return PyInt_AsSsize_t(x);
}
#endif
if (likely(PyLong_CheckExact(b))) {
#if CYTHON_USE_PYLONG_INTERNALS
const digit* digits = ((PyLongObject*)b)->ob_digit;
const Py_ssize_t size = Py_SIZE(b);
if (likely(__Pyx_sst_abs(size) <= 1)) {
ival = likely(size) ? digits[0] : 0;
if (size == -1) ival = -ival;
return ival;
} else {
switch (size) {
case 2:
if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
}
break;
case -2:
if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
}
break;
case 3:
if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
}
break;
case -3:
if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
}
break;
case 4:
if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
}
break;
case -4:
if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
}
break;
}
}
#endif
return PyLong_AsSsize_t(b);
}
x = PyNumber_Index(b);
if (!x) return -1;
ival = PyInt_AsSsize_t(x);
Py_DECREF(x);
return ival;
}
static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) {
return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
}
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
return PyInt_FromSize_t(ival);
}
#endif /* Py_PYTHON_H */
| 42.459769 | 366 | 0.670942 |
2519623e309b9f545c991b58e8e83e9352c410f2 | 44,428 | h | C | sim800ATM8/sim800ATM8/sim800ATM8/gsm_lib.h | hoshang1371/micro | 34a78c157bbe7664b82d68e46a54075b07796a88 | [
"MIT"
] | null | null | null | sim800ATM8/sim800ATM8/sim800ATM8/gsm_lib.h | hoshang1371/micro | 34a78c157bbe7664b82d68e46a54075b07796a88 | [
"MIT"
] | null | null | null | sim800ATM8/sim800ATM8/sim800ATM8/gsm_lib.h | hoshang1371/micro | 34a78c157bbe7664b82d68e46a54075b07796a88 | [
"MIT"
] | null | null | null | /************************************************************************/
/* GSM LIB */
/* Ver 1.8 */
/* Abolfazl Shakeri */
/* Designer2013.blogsky.com */
/* Designer2100@outlook.com */
/************************************************************************/
#ifndef _GSM_UART_LIB_H
#define _GSM_UART_LIB_H
#include <avr/interrupt.h>
#include <util/delay.h>
#include <string.h>
#include "compiler.h"
#include "uart_lib_m32-16.h"
#define SIM800_MODULE 2
#define SIM900_MODULE 1
/************************************************************************/
/* EDIT THIS DEFINE's */
/************************************************************************/
//#define DEBUGE_GSM 1
#define GSM_MODULE SIM800_MODULE
#define GSM_ON_DDR DDRD
#define GSM_ON_PORT PORTD
#define GSM_ON_PIN PORTD4
#define GSM_STATE_DDR DDRD
#define GSM_STATE_PORT PORTD
#define GSM_STATE_IN PIND
#define GSM_STATE_PIN PORTD3
#define GSM_UART_ISR USART_RXC_vect
//#define LCD_PROGRESS 1
//#define LCD 1
//#define CLOCK 1
#define _WDT 1
/************************************************************************/
/* DONT EDIT THIS DEFINE's */
/************************************************************************/
//---------------------------------------
#define SEND_SMS 1
#define OFF_GSM 2
#define GET_IMEI 3
#define GSM_MOD 4
#define UCS2_MOD 5
#define DEL_ALL 6
#define GET_CHARJ 7
#define SIM_NAME 8
#define NET_STATUS 9
#define GSM_RST 10
#define CHARJ_SIM 11
#define DELL_SMS 12
#define SIGNAL_Q 13
#define REQUEST_TA 14
#define HANG_UP 15
#define ANSWER_RING 16
#define CMICH 17
#define CMICL 18
#define CUSD_ON 19
#define CUSD_OFF 20
#define RST_GSM 21
#define RECIEVED_UNREAD 22
//--------------------------------------
#define SMS_MOD UCS2_MOD
//--------------------------------------
#define BUFFER_LEN 180
#define TEX_RECIVE_LEN 100
#define MOBILE_NUMBER_LEN 53
#define COMPAR_LEN 50
#define DATA_LEN 250
#define CHARGE_LEN 15
#define MOBILE_BUFFER_LEN 14
#define TEX_SEND_LEN 80
#define SMS_QUEUE 8
#define CH_SMS_LEN 3
#define NAME_OPERATOR_LEN 10
//--------------------------------------
#define NET_REGISTRED 10
#define NET_NOT_REGISTRED 0
//--------------------------------------
#define IRANCELL 1
#define IR_MCI 2
#define NO_KNOW 4
#define NO_SIM 3
//---------------------------------------
#define APPLY_GSM 1
//---------------------------------------
#define GSM_DELET 1
#define GSM_PRE_DELET 2
#define GSM_GET_SMS 3
#define GSM_READ_SMS 4
#define GSM_READ_CHARJ 5
#define ERROR_MODULE 6
//--------------------------------------
#define ON_GSM_HIGH (GSM_ON_PORT |= 1<<GSM_ON_PIN)
#define ON_GSM_LOW (GSM_ON_PORT &= ~(1<<GSM_ON_PIN))
//---------------------------------------
#define STATUS (GSM_STATE_IN & 1<<GSM_STATE_PIN)
//---------------------------------------
struct{
char buffer[BUFFER_LEN+1],unread,tex_recive[TEX_RECIVE_LEN+1],net_registration,sim_operator,name_operator[NAME_OPERATOR_LEN+1],charge[CHARGE_LEN+1],tex_send[TEX_SEND_LEN+1];
char compar[COMPAR_LEN+1],data[DATA_LEN+1],ch,ch_sms[CH_SMS_LEN],err_counter,recived_sms[SMS_QUEUE+1][2],mobile_number[MOBILE_NUMBER_LEN+1],mobile_buffer[MOBILE_BUFFER_LEN+1];
char recive_sms,dell,rdy,re_send,flag,charj,flag_charj,flag_simname,net_state,ring,apply,signal_value,rdy_tout,hangup,answer,flag_unread;
int index,stat,recived_sms_counter,number_of_charecter;
volatile char recive;
}gsm;
char buffer_gsm[20];
char get_charj_code_irancell[10]="*141*1#";
char get_charj_code_ir_mci[10]="*140*11#";
int sms_number,sms_number_tout;
int counter;
int temp1_gsm,temp2_gsm,temp3_gsm;
void gsm_ready();
char a_to_i_gsm(char i);
char get_info(void);
char gsm_handl(void);
void wait_flage(void);
void detect_gsm(void);
void gsm_start(void);
void read_sms(void);
void read_charj(void);
void get_sms(int ch);
void send2gsm(char select);
void gsm_initializing(void);
char convert_to_char(char *buffer_in);
void gsm_send_sms(char *mobile,char *tex);
void select_unicode(char ch, char *buffer_out);
void chang_to_unicode(char *tex_in ,char *unicode_buffer);
//--------------------------------------
char get_ok(void)
{
char con=0;
repet_get_ok:
uart_put_string("AT",1);
wait_flage();
if ((strstr_P(gsm.buffer,PSTR("OK"))) == 0){con++;if(con<2){_delay_ms(250);uart_put_string("ATE0",1);_delay_ms(300);goto repet_get_ok;}}else{return TRUE;}
return FALSE;
}
//--------------------------------------
char gsm_handl(void)
{
if (STATUS==0)
{
gsm.stat = DISABLE;
return OFF_GSM;
}
else if(gsm.stat==DISABLE)
{
gsm.stat = ENABLE;
}
if (gsm.dell==ENABLE)
{
gsm.recive_sms = DISABLE;
gsm.dell = DISABLE;
send2gsm(GSM_MOD);
send2gsm(DELL_SMS);
_delay_ms(200);
}
if (gsm.hangup==ENABLE && gsm.rdy==ENABLE)
{
send2gsm(HANG_UP);
gsm.hangup = DISABLE;
}
if (sms_number==0 && gsm.rdy==ENABLE)
{
for (int t=0; t<SMS_QUEUE; t++)
{
if (gsm.recived_sms[t][0]!=0)
{
sms_number=gsm.recived_sms[t][0];
gsm.recived_sms[t][0]=0;
break;
}
}
if (sms_number>0)
{
gsm.rdy_tout=0;
get_sms(sms_number);
gsm.flag = GSM_GET_SMS;
}
else if(gsm.unread==ENABLE)
{
gsm.flag_unread = ENABLE;
send2gsm(RECIEVED_UNREAD);
}
}
if (gsm.answer==ENABLE && gsm.rdy==ENABLE)
{
send2gsm(ANSWER_RING);
gsm.answer = DISABLE;
}
if (gsm.flag==GSM_READ_SMS)
{
read_sms();
gsm.flag=DISABLE;
}
else if (gsm.flag==GSM_READ_CHARJ)
{
read_charj();
gsm.flag = DISABLE;
}
if(gsm.apply==APPLY_GSM)
{
memset(gsm.tex_send,0,TEX_SEND_LEN);
gsm.apply = DISABLE;
return APPLY_GSM;
}
if (gsm.err_counter>3)
{
return ERROR_MODULE;
}
if (gsm.net_registration>599 && gsm.recive_sms==DISABLE)
{
gsm.net_registration = 0;
send2gsm(NET_STATUS);
}
if (gsm.dell==GSM_PRE_DELET)
{
counter++;
if (counter>800)
{
gsm.dell=ENABLE;
counter = 0;
}
_delay_ms(10);
}
if (gsm.sim_operator==0)
{
//send2gsm(SIM_NAME);
}
return 0;
}
//--------------------------------------
char a_to_i_gsm(char i)
{
if (i>47 && i<58)
{
return(i-48);
}
else
{
return 10;
}
}
//--------------------------------------
void gsm_initializing(void)
{
#ifdef _WDT
wdt_reset();
#endif
#ifdef DEBUGE_GSM
uart_put_string("GSM_UART INIT",1);
#endif
#ifdef DEBUGE_GSM
uart_put_string("AT",1);
#endif
uart_put_string_p(PSTR("AT"),1);
wait_flage();
_delay_ms(600);
#ifdef _WDT
wdt_reset();
#endif
#ifdef DEBUGE_GSM
uart_put_string("ATE0",1);
#endif
uart_put_string_p(PSTR("ATE0"),1);
wait_flage();
_delay_ms(600);
#ifdef _WDT
wdt_reset();
#endif
#ifdef DEBUGE_GSM
uart_put_string("AT+CMGF=1",1);
#endif
uart_put_string_p(PSTR("AT+CMGF=1"),1);
wait_flage();
_delay_ms(600);
#ifdef _WDT
wdt_reset();
#endif
#ifdef DEBUGE_GSM
uart_put_string("AT+CLIP=1",1);
#endif
uart_put_string_p(PSTR("AT+CLIP=1"),1);
wait_flage();
_delay_ms(600);
#ifdef _WDT
wdt_reset();
#endif
#ifdef DEBUGE_GSM
uart_put_string("AT+CMGDA=\"DEL ALL\"",1);
#endif
uart_put_string_p(PSTR("AT+CMGDA=\"DEL ALL\""),1);
wait_flage();
_delay_ms(600);
#ifdef _WDT
wdt_reset();
#endif
#ifdef DEBUGE_GSM
uart_put_string("AT+CSMP=17,167,0,25",1);
#endif
uart_put_string_p(PSTR("AT+CSMP=17,167,0,25"),1);
wait_flage();
_delay_ms(600);
#ifdef _WDT
wdt_reset();
#endif
/*#ifdef _WDT
wdt_reset();
#endif
#ifdef DEBUGE_GSM
uart_put_string("AT+CUSD=1",1);
#endif
uart_put_string("AT+CUSD=1",1);
wait_flage();
_delay_ms(600);
#ifdef _WDT
wdt_reset();
#endif*/
}
//--------------------------------------
void detect_gsm(void)
{
static int cou=0;
/*if (strstr(gsm.buffer,">")==0)
{
uart_putchar('<');
uart_put_string(gsm.buffer,0);
uart_putchar('>');
uart_putchar(13);
}*/
if(strstr_P(gsm.buffer,PSTR("+CMTI:"))!=0)
{
gsm.err_counter = 0;
for (cou=0; cou<16; cou++)
{
if (gsm.buffer[cou]==',' && a_to_i_gsm(gsm.buffer[cou+1])<10)
{
gsm.recived_sms[gsm.recived_sms_counter][0]=a_to_i_gsm(gsm.buffer[cou+1]);
if (a_to_i_gsm(gsm.buffer[cou+2])<10)
{
gsm.recived_sms[gsm.recived_sms_counter][0]= ((gsm.recived_sms[gsm.recived_sms_counter][0]*10)+a_to_i_gsm(gsm.buffer[cou+2]));
}
#ifdef DEBUGE_GSM
uart_put_string("RECIVE SMS",0);
uart_mini_printf(" %d\r\n",gsm.recived_sms[gsm.recived_sms_counter][0]);
#endif
gsm.recived_sms_counter++;if(gsm.recived_sms_counter>SMS_QUEUE){gsm.recived_sms_counter=0;}
if(gsm.recive_sms==DISABLE)gsm.rdy = ENABLE;
}
}
//return;
}
if (strstr_P(gsm.buffer,PSTR("+CMGR:"))!=0)
{
gsm.flag = GSM_READ_SMS;
//#ifdef DEBUGE_GSM
uart_put_string("flag=read_sms",1);
//#endif
return;
}
if(strstr_P(gsm.buffer,PSTR("+CMGL:"))!=0)
{
gsm.unread=DISABLE;
gsm.flag_unread = DISABLE;
gsm.err_counter = 0;
for (cou=0; cou<16; cou++)
{
if (gsm.buffer[cou]==' ' && a_to_i_gsm(gsm.buffer[cou+1])<10)
{
gsm.recived_sms[gsm.recived_sms_counter][0]=a_to_i_gsm(gsm.buffer[cou+1]);
if (a_to_i_gsm(gsm.buffer[cou+2])<10)
{
gsm.recived_sms[gsm.recived_sms_counter][0]= ((gsm.recived_sms[gsm.recived_sms_counter][0]*10)+a_to_i_gsm(gsm.buffer[cou+2]));
}
#ifdef DEBUGE_GSM
uart_put_string("RECIVED SMS",0);
uart_mini_printf(" %d\r\n",gsm.recived_sms[gsm.recived_sms_counter][0]);
#endif
gsm.recived_sms_counter++;if(gsm.recived_sms_counter>SMS_QUEUE){gsm.recived_sms_counter=0;}
if(gsm.recive_sms==DISABLE)gsm.rdy = ENABLE;
}
}
return;
}
if (strstr_P(gsm.buffer,PSTR("+CMGS:"))!=0)
{
#ifdef DEBUGE_GSM
uart_put_string("+CMGS:_D",1);
#endif
if(gsm.recive_sms==ENABLE){
gsm.dell = ENABLE;
#ifdef DEBUGE_GSM
uart_put_string("dell=EN",1);
#endif
}
else
{
gsm.rdy = ENABLE;
}
return;
}
if (strstr_P(gsm.buffer,PSTR("ERROR"))!=0 && gsm.dell==GSM_PRE_DELET)
{
#ifdef DEBUGE_GSM
uart_put_string("ERR1_D",1);
#endif
if(gsm.recive_sms==ENABLE){
gsm.dell = ENABLE;
#ifdef DEBUGE_GSM
uart_put_string("dell=EN(2)",1);
#endif
}
return;
}
if (strstr_P(gsm.buffer,PSTR("ERROR"))!=0 && gsm.rdy==DISABLE)
{
#ifdef DEBUGE_GSM
uart_put_string("rdy=EN",1);
#endif
gsm.err_counter++;
if(gsm.re_send==ENABLE ){gsm.re_send=DISABLE;gsm.rdy = ENABLE;return;}
if(gsm.re_send==DISABLE){gsm.re_send=ENABLE;}
return;
}
if (strstr_P(gsm.buffer,PSTR("+CUSD: 0"))!=0)
{
gsm.flag = GSM_READ_CHARJ;
#ifdef DEBUGE_GSM
uart_put_string("flag=read_charj",1);
#endif
return;
}
if (strstr_P(gsm.buffer,PSTR("NO CARRIER"))!=0 && gsm.flag_charj==ENABLE)
{
gsm.flag_charj = DISABLE;
gsm.charj = ENABLE;
strcpy(gsm.charge,"NET WRONG ");
#ifdef DEBUGE_GSM
uart_put_string("charj=EN",1);
#endif
return;
}
if (strstr_P(gsm.buffer,PSTR("+CUSD: 2"))!=0)
{
gsm.charj = ENABLE;
strcpy(gsm.charge,"NET WRONG ");
#ifdef DEBUGE_GSM
uart_put_string("charj=EN",1);
#endif
return;
}
if (strstr_P(gsm.buffer,PSTR("+CREG"))!=0)
{
if (gsm.buffer[11]!='1' && gsm.buffer[11]!='5')
{
gsm.net_state = NET_NOT_REGISTRED;
#ifdef DEBUGE_GSM
uart_put_string("NET_NOT_REGISTRED",1);
#endif
}
else
{
gsm.net_state = NET_REGISTRED;
#ifdef DEBUGE_GSM
uart_put_string("NET_REGISTRED",1);
#endif
}
return;
}
if(strstr_P(gsm.buffer,PSTR("+CLIP:"))!=0)
{
gsm.number_of_charecter = strlen(gsm.buffer);
memset(gsm.mobile_number,0,MOBILE_NUMBER_LEN);
for (temp1_gsm=0; temp1_gsm<gsm.number_of_charecter; temp1_gsm++)
{
if (gsm.buffer[temp1_gsm]==34)
{
temp2_gsm=0;
for (temp3_gsm=++temp1_gsm; temp3_gsm<gsm.number_of_charecter; temp3_gsm++)
{
if ((gsm.buffer[temp3_gsm]!=34)){gsm.mobile_number[temp2_gsm] = gsm.buffer[temp3_gsm];temp2_gsm++;}
if ((gsm.buffer[temp3_gsm]==34)){goto re_dial;}
}
}
}
re_dial:
temp2_gsm = strlen(gsm.mobile_number);
gsm.mobile_number[0]='0';
for (temp3_gsm=3; temp3_gsm<temp2_gsm; temp3_gsm++)
{
gsm.mobile_number[temp3_gsm-2] = gsm.mobile_number[temp3_gsm];
}
gsm.mobile_number[13]=0;
gsm.mobile_number[12]=0;
gsm.mobile_number[11]=0;
if (strcmp(gsm.mobile_number,gsm.mobile_buffer)!=0)
{
strcpy(gsm.mobile_buffer,gsm.mobile_number);
gsm.ring = 0;
}
gsm.ring++;
return;
}
if ((strstr_P(gsm.buffer,PSTR("+CSQ:")))!=0)
{
memset(gsm.compar,0,COMPAR_LEN);
temp2_gsm=0;
gsm.number_of_charecter = strlen(gsm.buffer);
for (temp1_gsm=6; temp1_gsm<gsm.number_of_charecter; temp1_gsm++)
{
if(gsm.buffer[temp1_gsm]==','){break;}
if(a_to_i_gsm(gsm.buffer[temp1_gsm])<10){gsm.compar[temp2_gsm] = gsm.buffer[temp1_gsm];temp2_gsm++;}
}
gsm.signal_value = atoi(gsm.compar);
return;
}
if (strstr_P(gsm.buffer,PSTR("SMS Ready"))!=0)
{
gsm.rdy = ENABLE;
#ifdef DEBUGE_GSM
uart_put_string("AT+CSMP=17,167,0,25",1);
#endif
_delay_ms(200);
uart_put_string("AT+CSMP=17,167,0,25",1);
wait_flage();
return;
}
if ((strstr_P(gsm.buffer,PSTR("+CSPN:"))) != 0)
{
gsm.flag_simname = DISABLE;
gsm.number_of_charecter = strlen(gsm.buffer);
memset(gsm.compar,0,COMPAR_LEN);
for (temp1_gsm=0; temp1_gsm<gsm.number_of_charecter; temp1_gsm++)
{
if (gsm.buffer[temp1_gsm]==34)
{
temp3_gsm=0;
for (temp2_gsm=(temp1_gsm+1);temp2_gsm<gsm.number_of_charecter;temp2_gsm++)
{
if (gsm.buffer[temp2_gsm]!=34){gsm.compar[temp3_gsm]=gsm.buffer[temp2_gsm];temp3_gsm++;}
if (gsm.buffer[temp2_gsm]==34){goto re_cspn;}
}
}
}
re_cspn:
memset(gsm.name_operator,0,NAME_OPERATOR_LEN);
#ifdef DEBUGE_GSM
uart_put_string(gsm.compar,1);
#endif
if ((strcmp_P(gsm.compar,PSTR("IRANCELL")))==0)
{
gsm.sim_operator = IRANCELL;
strcpy(gsm.name_operator,gsm.compar);
#ifdef LCD
LCDGotoXY(0,0);
LCDstring((uint8_t *)" IRANCELL ",16);
_delay_ms(700);
#endif
}
else if ((strcmp_P(gsm.compar,PSTR("IR-MCI")))==0)
{
gsm.sim_operator = IR_MCI;
strcpy(gsm.name_operator,gsm.compar);
#ifdef LCD
LCDGotoXY(0,0);
LCDstring((uint8_t *)" IR-MCI ",16);
_delay_ms(700);
#endif
}
else
{
gsm.sim_operator = NO_KNOW;
strcpy(gsm.name_operator,"NO KNOW");
#ifdef LCD
LCDGotoXY(0,0);
LCDstring((uint8_t *)" UNKNOWN ",16);
_delay_ms(700);
#endif
}
//show_txt(gsm.name_operator,1,them,ALINE_CENTER,20,0,0);
}
if ((strstr_P(gsm.buffer,PSTR("ERROR"))) != 0 && gsm.flag_simname == ENABLE)
{
gsm.flag_simname = DISABLE;
gsm.sim_operator = NO_SIM;
strcpy(gsm.name_operator,"NO SIM");
#ifdef LCD
LCDGotoXY(0,0);
LCDstring((uint8_t *)" NO SIM ",16);
_delay_ms(1000);
#endif
//show_txt(gsm.name_operator,1,them,ALINE_CENTER,20,0,0);
}
if(gsm.flag_unread==ENABLE && (strstr_P(gsm.buffer,PSTR("OK")))!= 0)
{
gsm.unread=DISABLE;
gsm.flag_unread=DISABLE;
}
if (gsm.flag==GSM_GET_SMS && (strstr_P(gsm.buffer,PSTR("OK")))!= 0)
{
sms_number = 0;
gsm.flag = DISABLE;
}
#ifdef _WDT
wdt_reset();
#endif
}
//--------------------------------------
void wait_flage(void)
{
static int cu=0;
gsm.recive = DISABLE;
while(gsm.recive==DISABLE){cu++;_delay_ms(10);if(cu>400){break;}}
gsm.recive = DISABLE;
}
//--------------------------------------
void get_sms(int ch)
{
gsm.recive_sms=ENABLE;
memset(gsm.ch_sms,0,CH_SMS_LEN);
sprintf(gsm.ch_sms,"%d",ch);//gsm.ch_sms = ch;
#ifdef DEBUGE_GSM
uart_put_string("get_sms-",0);
uart_put_string(gsm.ch_sms,ENABLE);
#endif
memset(gsm.data,0,DATA_LEN);
memset(gsm.mobile_number,0,MOBILE_NUMBER_LEN);
//memset(gsm.buffer,0,BUFFER_LEN);
memset(gsm.tex_send,0,TEX_SEND_LEN);
send2gsm(UCS2_MOD);
wait_flage();/*_delay_ms(400);*/
#ifdef _WDT
wdt_reset();
#endif
gsm_ready();
#ifdef _WDT
wdt_reset();
#endif
_delay_ms(400);
#ifdef DEBUGE_GSM
uart_put_string("AT+CMGR=",0);
uart_put_string(gsm.ch_sms,0);
#endif
uart_put_string("AT+CMGR=",0);
uart_put_string(gsm.ch_sms,ENABLE);
}
//--------------------------------------
void read_charj(void)
{
#ifdef DEBUGE_GSM
uart_put_string("read_charj",1);
#endif
/*#ifdef LCD
LCDGotoXY(0,1);
LCDstring((uint8_t*)gsm.buffer,16);
_delay_ms(600);
#endif*/
gsm.flag = DISABLE;
memset(gsm.charge,0,CHARGE_LEN);
int len = strlen(gsm.buffer);
if (gsm.sim_operator==IRANCELL)
{
for (int i=8; i<len; i++)
{
if (gsm.buffer[i]==':' && gsm.buffer[i+1]==' ')
{
int v=0;
for (int ii=i+2; ii<len; ii++)
{
if(gsm.buffer[ii]!=' '){gsm.charge[v] = gsm.buffer[ii];v++;}
if(gsm.buffer[ii]==' ')break;
}
break;
}
}
}
else if (gsm.sim_operator==IR_MCI)
{
memset(gsm.compar,0,COMPAR_LEN);
temp3_gsm = 0;
for (temp1_gsm=12; temp1_gsm<95; temp1_gsm+=4)
{
buffer_gsm[0]=gsm.buffer[temp1_gsm];
buffer_gsm[1]=gsm.buffer[temp1_gsm+1];
buffer_gsm[2]=gsm.buffer[temp1_gsm+2];
buffer_gsm[3]=gsm.buffer[temp1_gsm+3];
gsm.compar[temp3_gsm] = convert_to_char(buffer_gsm);
temp3_gsm++;
}
memset(gsm.tex_send,0,TEX_SEND_LEN);
strcpy(gsm.tex_send,gsm.compar);
#ifdef DEBUGE_GSM
uart_put_string(gsm.tex_send,1);
#endif
memset(gsm.charge,0,CHARGE_LEN);
int len = strlen(gsm.tex_send);
for (int i=8; i<len; i++)
{
if (gsm.tex_send[i]=='�')
{
int v=0;
for (int ii=i+1; ii<len; ii++)
{
if(gsm.tex_send[ii]!='�'){gsm.charge[v] = gsm.tex_send[ii];v++;}
if(gsm.tex_send[ii]=='�')break;
}
break;
}
}
#ifdef DEBUGE_GSM
uart_put_string(gsm.charge,1);
#endif
}
gsm.charj = ENABLE;
}
//--------------------------------------
void read_sms(void)
{
int temp_read_sms=0,len=0,cou=0;
cli();
len=strlen(gsm.buffer);
for (temp_read_sms=2; temp_read_sms<len; temp_read_sms++)
{
if(gsm.buffer[temp_read_sms]==0xd || gsm.buffer[temp_read_sms]==0xa){break;}
if(temp_read_sms<DATA_LEN){gsm.data[temp_read_sms-2]=gsm.buffer[temp_read_sms];}
}
cou=0;
for (temp_read_sms=temp_read_sms+2; temp_read_sms<len; temp_read_sms++)
{
if(gsm.buffer[temp_read_sms]==0xd || gsm.buffer[temp_read_sms]==0xa){break;}
if(cou<TEX_SEND_LEN){gsm.tex_send[cou]=gsm.buffer[temp_read_sms];}
cou++;
}
#ifdef DEBUGE_GSM
uart_put_string(gsm.tex_send,1);
uart_put_string(gsm.data,1);
#endif
memset(gsm.compar,0,COMPAR_LEN);
temp3_gsm = 0;
for (temp1_gsm=0; temp1_gsm<=(TEX_SEND_LEN-5); temp1_gsm+=4)
{
buffer_gsm[0]=gsm.tex_send[temp1_gsm];
buffer_gsm[1]=gsm.tex_send[temp1_gsm+1];
buffer_gsm[2]=gsm.tex_send[temp1_gsm+2];
buffer_gsm[3]=gsm.tex_send[temp1_gsm+3];
gsm.compar[temp3_gsm] = convert_to_char(buffer_gsm);
temp3_gsm++;
}
memset(gsm.tex_recive,0,TEX_RECIVE_LEN);
strcpy(gsm.tex_recive,gsm.compar);
sei();
#ifdef _WDT
wdt_reset();
#endif
#ifdef DEBUGE_GSM
uart_put_string(">>",0);
uart_put_string(gsm.tex_recive,1);
#endif
gsm.number_of_charecter = strlen(gsm.data);
for (temp1_gsm=0;temp1_gsm<gsm.number_of_charecter;temp1_gsm++)
{
if (gsm.data[temp1_gsm]==',')
{
temp2_gsm=0;
for (temp3_gsm=(temp1_gsm+2);temp3_gsm<gsm.number_of_charecter;temp3_gsm++)
{
if ((gsm.data[temp3_gsm]!=34)){gsm.mobile_number[temp2_gsm] = gsm.data[temp3_gsm];temp2_gsm++;}
if ((gsm.data[temp3_gsm]==34)){goto resum;}
}
}
}
resum:
gsm.mobile_number[0]='+';
temp2_gsm = 7;
for (temp1_gsm=1; temp1_gsm<13; temp1_gsm++)
{
gsm.mobile_number[temp1_gsm] = gsm.mobile_number[temp2_gsm];
temp2_gsm += 4;
}
temp1_gsm = strlen(gsm.mobile_number);
for (temp2_gsm=13; temp2_gsm<temp1_gsm; temp2_gsm++)
{
gsm.mobile_number[temp2_gsm]=0;
}
temp2_gsm = strlen(gsm.mobile_number);
gsm.mobile_number[0]='0';
for (temp3_gsm=3; temp3_gsm<temp2_gsm; temp3_gsm++)
{
gsm.mobile_number[temp3_gsm-2] = gsm.mobile_number[temp3_gsm];
}
gsm.mobile_number[13]=0;
gsm.mobile_number[12]=0;
gsm.mobile_number[11]=0;
#ifdef DEBUGE_GSM
uart_put_string(">>",0);
uart_put_string(gsm.mobile_number,1);
#endif
#ifdef LCD
LCDclr();
LCDstring((uint8_t *)">:",12);
LCDstring((uint8_t *)gsm.mobile_number,16);
#endif
#ifdef _WDT
wdt_reset();
#endif
gsm.apply = APPLY_GSM;
gsm.dell = GSM_PRE_DELET;
//return;
/*_delay_ms(250);
send2gsm(GSM_MOD);
send2gsm(DELL_SMS);*/
}
//--------------------------------------
void select_unicode(char ch, char *buffer_out)
{
switch(ch)
{
case ' ': strcpy_P(buffer_out,PSTR("00A0"));break;
case '�': strcpy_P(buffer_out,PSTR("0622"));break;
case '�': strcpy_P(buffer_out,PSTR("0627"));break;
case '�': strcpy_P(buffer_out,PSTR("0628"));break;
case '�': strcpy_P(buffer_out,PSTR("067E"));break;
case '�': strcpy_P(buffer_out,PSTR("062A"));break;
case '�': strcpy_P(buffer_out,PSTR("062B"));break;
case '�': strcpy_P(buffer_out,PSTR("062C"));break;
case '�': strcpy_P(buffer_out,PSTR("0686"));break;
case '�': strcpy_P(buffer_out,PSTR("062D"));break;
case '�': strcpy_P(buffer_out,PSTR("062E"));break;
case '�': strcpy_P(buffer_out,PSTR("062F"));break;
case '�': strcpy_P(buffer_out,PSTR("0630"));break;
case '�': strcpy_P(buffer_out,PSTR("0631"));break;
case '�': strcpy_P(buffer_out,PSTR("0632"));break;
case '�': strcpy_P(buffer_out,PSTR("0633"));break;
case '�': strcpy_P(buffer_out,PSTR("0634"));break;
case '�': strcpy_P(buffer_out,PSTR("0635"));break;
case '�': strcpy_P(buffer_out,PSTR("0636"));break;
case '�': strcpy_P(buffer_out,PSTR("0637"));break;
case '�': strcpy_P(buffer_out,PSTR("0638"));break;
case '�': strcpy_P(buffer_out,PSTR("0639"));break;
case '�': strcpy_P(buffer_out,PSTR("063A"));break;
case '�': strcpy_P(buffer_out,PSTR("0641"));break;
case '�': strcpy_P(buffer_out,PSTR("0642"));break;
//case '�': strcpy_P(buffer_out,PSTR("0643"));break;
case '�': strcpy_P(buffer_out,PSTR("06A9"));break;
case '�': strcpy_P(buffer_out,PSTR("06AF"));break;
case '�': strcpy_P(buffer_out,PSTR("0644"));break;
case '�': strcpy_P(buffer_out,PSTR("0645"));break;
case '�': strcpy_P(buffer_out,PSTR("0646"));break;
case '�': strcpy_P(buffer_out,PSTR("0647"));break;
case '�': strcpy_P(buffer_out,PSTR("0648"));break;
case '�': strcpy_P(buffer_out,PSTR("06CC"));break;
case '?': strcpy_P(buffer_out,PSTR("064A"));break;
case '�': strcpy_P(buffer_out,PSTR("0698"));break;
case '0': strcpy_P(buffer_out,PSTR("0030"));break;
case '1': strcpy_P(buffer_out,PSTR("0031"));break;
case '2': strcpy_P(buffer_out,PSTR("0032"));break;
case '3': strcpy_P(buffer_out,PSTR("0033"));break;
case '4': strcpy_P(buffer_out,PSTR("0034"));break;
case '5': strcpy_P(buffer_out,PSTR("0035"));break;
case '6': strcpy_P(buffer_out,PSTR("0036"));break;
case '7': strcpy_P(buffer_out,PSTR("0037"));break;
case '8': strcpy_P(buffer_out,PSTR("0038"));break;
case '9': strcpy_P(buffer_out,PSTR("0039"));break;
case 'A': strcpy_P(buffer_out,PSTR("0041"));break;
case 'B': strcpy_P(buffer_out,PSTR("0042"));break;
case 'C': strcpy_P(buffer_out,PSTR("0043"));break;
case 'D': strcpy_P(buffer_out,PSTR("0044"));break;
case 'E': strcpy_P(buffer_out,PSTR("0045"));break;
case 'F': strcpy_P(buffer_out,PSTR("0046"));break;
case 'G': strcpy_P(buffer_out,PSTR("0047"));break;
case 'H': strcpy_P(buffer_out,PSTR("0048"));break;
case 'I': strcpy_P(buffer_out,PSTR("0049"));break;
case 'J': strcpy_P(buffer_out,PSTR("004A"));break;
case 'K': strcpy_P(buffer_out,PSTR("004B"));break;
case 'L': strcpy_P(buffer_out,PSTR("004C"));break;
case 'M': strcpy_P(buffer_out,PSTR("004D"));break;
case 'N': strcpy_P(buffer_out,PSTR("004E"));break;
case 'O': strcpy_P(buffer_out,PSTR("004F"));break;
case 'P': strcpy_P(buffer_out,PSTR("0050"));break;
case 'Q': strcpy_P(buffer_out,PSTR("0051"));break;
case 'R': strcpy_P(buffer_out,PSTR("0052"));break;
case 'S': strcpy_P(buffer_out,PSTR("0053"));break;
case 'T': strcpy_P(buffer_out,PSTR("0054"));break;
case 'U': strcpy_P(buffer_out,PSTR("0055"));break;
case 'V': strcpy_P(buffer_out,PSTR("0056"));break;
case 'W': strcpy_P(buffer_out,PSTR("0057"));break;
case 'X': strcpy_P(buffer_out,PSTR("0058"));break;
case 'Y': strcpy_P(buffer_out,PSTR("0059"));break;
case 'Z': strcpy_P(buffer_out,PSTR("005A"));break;
case 'a': strcpy_P(buffer_out,PSTR("0061"));break;
case 'b': strcpy_P(buffer_out,PSTR("0062"));break;
case 'c': strcpy_P(buffer_out,PSTR("0063"));break;
case 'd': strcpy_P(buffer_out,PSTR("0064"));break;
case 'e': strcpy_P(buffer_out,PSTR("0065"));break;
case 'f': strcpy_P(buffer_out,PSTR("0066"));break;
case 'g': strcpy_P(buffer_out,PSTR("0067"));break;
case 'h': strcpy_P(buffer_out,PSTR("0068"));break;
case 'i': strcpy_P(buffer_out,PSTR("0069"));break;
case 'j': strcpy_P(buffer_out,PSTR("006A"));break;
case 'k': strcpy_P(buffer_out,PSTR("006B"));break;
case 'l': strcpy_P(buffer_out,PSTR("006C"));break;
case 'm': strcpy_P(buffer_out,PSTR("006D"));break;
case 'n': strcpy_P(buffer_out,PSTR("006E"));break;
case 'o': strcpy_P(buffer_out,PSTR("006F"));break;
case 'p': strcpy_P(buffer_out,PSTR("0070"));break;
case 'q': strcpy_P(buffer_out,PSTR("0071"));break;
case 'r': strcpy_P(buffer_out,PSTR("0072"));break;
case 's': strcpy_P(buffer_out,PSTR("0073"));break;
case 't': strcpy_P(buffer_out,PSTR("0074"));break;
case 'u': strcpy_P(buffer_out,PSTR("0075"));break;
case 'v': strcpy_P(buffer_out,PSTR("0076"));break;
case 'w': strcpy_P(buffer_out,PSTR("0077"));break;
case 'x': strcpy_P(buffer_out,PSTR("0078"));break;
case 'y': strcpy_P(buffer_out,PSTR("0079"));break;
case 'z': strcpy_P(buffer_out,PSTR("007A"));break;
case '=': strcpy_P(buffer_out,PSTR("003D"));break;
case ',': strcpy_P(buffer_out,PSTR("002C"));break;
case '(': strcpy_P(buffer_out,PSTR("0028"));break;
case ')': strcpy_P(buffer_out,PSTR("0029"));break;
case ':': strcpy_P(buffer_out,PSTR("003A"));break;
case ';': strcpy_P(buffer_out,PSTR("003B"));break;
case '#': strcpy_P(buffer_out,PSTR("0023"));break;
case '*': strcpy_P(buffer_out,PSTR("002A"));break;
case '$': strcpy_P(buffer_out,PSTR("0024"));break;
case '+': strcpy_P(buffer_out,PSTR("002B"));break;
case '@': strcpy_P(buffer_out,PSTR("0040"));break;
case '.': strcpy_P(buffer_out,PSTR("002E"));break;
case '\'':strcpy_P(buffer_out,PSTR("0027"));break;
case '\"':strcpy_P(buffer_out,PSTR("0022"));break;
case '�': strcpy_P(buffer_out,PSTR("00B0"));break;
case '>': strcpy_P(buffer_out,PSTR("003E"));break;
case '<': strcpy_P(buffer_out,PSTR("003C"));break;
case '-': strcpy_P(buffer_out,PSTR("002D"));break;
case '_': strcpy_P(buffer_out,PSTR("005F"));break;
case '\\':strcpy_P(buffer_out,PSTR("000A"));break; //NEW LINE
}
}
//--------------------------------------
void chang_to_unicode(char *tex_in ,char *unicode_buffer)
{
int i=0;
gsm.number_of_charecter = strlen(tex_in);
memset(gsm.compar,0,COMPAR_LEN);
select_unicode(tex_in[0],gsm.compar);strcpy(unicode_buffer, gsm.compar);
for (i=1; i<gsm.number_of_charecter; i++)
{
select_unicode(tex_in[i],gsm.compar);strcat(unicode_buffer,gsm.compar);
}
}
//--------------------------------------
char convert_to_char(char *buffer_in)
{
if(strcmp_P(buffer_in,PSTR("0030"))==0){return '0';}
else if(strcmp_P(buffer_in,PSTR("0040"))==0){return '@';}
else if(strcmp_P(buffer_in,PSTR("002E"))==0){return '.';}
else if(strcmp_P(buffer_in,PSTR("0031"))==0){return '1';}
else if(strcmp_P(buffer_in,PSTR("0032"))==0){return '2';}
else if(strcmp_P(buffer_in,PSTR("0033"))==0){return '3';}
else if(strcmp_P(buffer_in,PSTR("0034"))==0){return '4';}
else if(strcmp_P(buffer_in,PSTR("0035"))==0){return '5';}
else if(strcmp_P(buffer_in,PSTR("0036"))==0){return '6';}
else if(strcmp_P(buffer_in,PSTR("0037"))==0){return '7';}
else if(strcmp_P(buffer_in,PSTR("0038"))==0){return '8';}
else if(strcmp_P(buffer_in,PSTR("0039"))==0){return '9';}
else if(strcmp_P(buffer_in,PSTR("0041"))==0){return 'A';}
else if(strcmp_P(buffer_in,PSTR("0042"))==0){return 'B';}
else if(strcmp_P(buffer_in,PSTR("0043"))==0){return 'C';}
else if(strcmp_P(buffer_in,PSTR("0044"))==0){return 'D';}
else if(strcmp_P(buffer_in,PSTR("0045"))==0){return 'E';}
else if(strcmp_P(buffer_in,PSTR("0046"))==0){return 'F';}
else if(strcmp_P(buffer_in,PSTR("0047"))==0){return 'G';}
else if(strcmp_P(buffer_in,PSTR("0048"))==0){return 'H';}
else if(strcmp_P(buffer_in,PSTR("0049"))==0){return 'I';}
else if(strcmp_P(buffer_in,PSTR("004A"))==0){return 'J';}
else if(strcmp_P(buffer_in,PSTR("004B"))==0){return 'K';}
else if(strcmp_P(buffer_in,PSTR("004C"))==0){return 'L';}
else if(strcmp_P(buffer_in,PSTR("004D"))==0){return 'M';}
else if(strcmp_P(buffer_in,PSTR("004E"))==0){return 'N';}
else if(strcmp_P(buffer_in,PSTR("004F"))==0){return 'O';}
else if(strcmp_P(buffer_in,PSTR("0050"))==0){return 'P';}
else if(strcmp_P(buffer_in,PSTR("0051"))==0){return 'Q';}
else if(strcmp_P(buffer_in,PSTR("0052"))==0){return 'R';}
else if(strcmp_P(buffer_in,PSTR("0053"))==0){return 'S';}
else if(strcmp_P(buffer_in,PSTR("0054"))==0){return 'T';}
else if(strcmp_P(buffer_in,PSTR("0055"))==0){return 'U';}
else if(strcmp_P(buffer_in,PSTR("0056"))==0){return 'V';}
else if(strcmp_P(buffer_in,PSTR("0057"))==0){return 'W';}
else if(strcmp_P(buffer_in,PSTR("0058"))==0){return 'X';}
else if(strcmp_P(buffer_in,PSTR("0059"))==0){return 'Y';}
else if(strcmp_P(buffer_in,PSTR("005A"))==0){return 'Z';}
else if(strcmp_P(buffer_in,PSTR("0061"))==0){return 'a';}
else if(strcmp_P(buffer_in,PSTR("0062"))==0){return 'b';}
else if(strcmp_P(buffer_in,PSTR("0063"))==0){return 'c';}
else if(strcmp_P(buffer_in,PSTR("0064"))==0){return 'd';}
else if(strcmp_P(buffer_in,PSTR("0065"))==0){return 'e';}
else if(strcmp_P(buffer_in,PSTR("0066"))==0){return 'f';}
else if(strcmp_P(buffer_in,PSTR("0067"))==0){return 'g';}
else if(strcmp_P(buffer_in,PSTR("0068"))==0){return 'h';}
else if(strcmp_P(buffer_in,PSTR("0069"))==0){return 'i';}
else if(strcmp_P(buffer_in,PSTR("006A"))==0){return 'j';}
else if(strcmp_P(buffer_in,PSTR("006B"))==0){return 'k';}
else if(strcmp_P(buffer_in,PSTR("006C"))==0){return 'l';}
else if(strcmp_P(buffer_in,PSTR("006D"))==0){return 'm';}
else if(strcmp_P(buffer_in,PSTR("006E"))==0){return 'n';}
else if(strcmp_P(buffer_in,PSTR("006F"))==0){return 'o';}
else if(strcmp_P(buffer_in,PSTR("0070"))==0){return 'p';}
else if(strcmp_P(buffer_in,PSTR("0071"))==0){return 'q';}
else if(strcmp_P(buffer_in,PSTR("0072"))==0){return 'r';}
else if(strcmp_P(buffer_in,PSTR("0073"))==0){return 's';}
else if(strcmp_P(buffer_in,PSTR("0074"))==0){return 't';}
else if(strcmp_P(buffer_in,PSTR("0075"))==0){return 'u';}
else if(strcmp_P(buffer_in,PSTR("0076"))==0){return 'v';}
else if(strcmp_P(buffer_in,PSTR("0077"))==0){return 'w';}
else if(strcmp_P(buffer_in,PSTR("0078"))==0){return 'x';}
else if(strcmp_P(buffer_in,PSTR("0079"))==0){return 'y';}
else if(strcmp_P(buffer_in,PSTR("007A"))==0){return 'z';}
else if(strcmp_P(buffer_in,PSTR("003D"))==0){return '=';}
else if(strcmp_P(buffer_in,PSTR("002C"))==0){return ',';}
else if(strcmp_P(buffer_in,PSTR("0028"))==0){return '(';}
else if(strcmp_P(buffer_in,PSTR("0029"))==0){return ')';}
else if(strcmp_P(buffer_in,PSTR("003A"))==0){return ':';}
else if(strcmp_P(buffer_in,PSTR("003B"))==0){return ';';}
else if(strcmp_P(buffer_in,PSTR("0023"))==0){return '#';}
else if(strcmp_P(buffer_in,PSTR("002A"))==0){return '*';}
else if(strcmp_P(buffer_in,PSTR("002B"))==0){return '+';}
else if(strcmp_P(buffer_in,PSTR("002B"))==0){return '+';}
else if(strcmp_P(buffer_in,PSTR("0027"))==0){return '\'';}
else if(strcmp_P(buffer_in,PSTR("0022"))==0){return '\"';}
else if(strcmp_P(buffer_in,PSTR("002B"))==0){return '+';}
else if(strcmp_P(buffer_in,PSTR("00B0"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("00A0"))==0){return ' ';}
else if(strcmp_P(buffer_in,PSTR("0622"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("0627"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("0628"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("067E"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("062A"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("062B"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("062C"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("0686"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("062D"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("062E"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("062F"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("0630"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("0631"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("0632"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("0633"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("0634"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("0635"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("0636"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("0637"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("0638"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("0639"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("063A"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("0641"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("0642"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("0643"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("06A9"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("06AF"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("0644"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("0645"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("0646"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("0647"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("0648"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("0649"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("064A"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("06CC"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("0698"))==0){return '�';}
else if(strcmp_P(buffer_in,PSTR("0660"))==0){return '0';}
else if(strcmp_P(buffer_in,PSTR("0661"))==0){return '1';}
else if(strcmp_P(buffer_in,PSTR("0662"))==0){return '2';}
else if(strcmp_P(buffer_in,PSTR("0663"))==0){return '3';}
else if(strcmp_P(buffer_in,PSTR("0664"))==0){return '4';}
else if(strcmp_P(buffer_in,PSTR("0665"))==0){return '5';}
else if(strcmp_P(buffer_in,PSTR("0666"))==0){return '6';}
else if(strcmp_P(buffer_in,PSTR("0667"))==0){return '7';}
else if(strcmp_P(buffer_in,PSTR("0668"))==0){return '8';}
else if(strcmp_P(buffer_in,PSTR("0669"))==0){return '9';}
else if(strcmp_P(buffer_in,PSTR("06F0"))==0){return '0';}
else if(strcmp_P(buffer_in,PSTR("06F1"))==0){return '1';}
else if(strcmp_P(buffer_in,PSTR("06F2"))==0){return '2';}
else if(strcmp_P(buffer_in,PSTR("06F3"))==0){return '3';}
else if(strcmp_P(buffer_in,PSTR("06F4"))==0){return '4';}
else if(strcmp_P(buffer_in,PSTR("06F5"))==0){return '5';}
else if(strcmp_P(buffer_in,PSTR("06F6"))==0){return '6';}
else if(strcmp_P(buffer_in,PSTR("06F7"))==0){return '7';}
else if(strcmp_P(buffer_in,PSTR("06F8"))==0){return '8';}
else if(strcmp_P(buffer_in,PSTR("06F9"))==0){return '9';}
else if(strcmp_P(buffer_in,PSTR("007C"))==0){return '|';} // pass char ____ xxxx|
else if(strcmp_P(buffer_in,PSTR("0024"))==0){return '$';}
else if(strcmp_P(buffer_in,PSTR("000A"))==0){return '\\';}
else if(strcmp_P(buffer_in,PSTR("003E"))==0){return '>';}
else if(strcmp_P(buffer_in,PSTR("003C"))==0){return '<';}
else if(strcmp_P(buffer_in,PSTR("002D"))==0){return '-';}
else if(strcmp_P(buffer_in,PSTR("005F"))==0){return '_';}
return 0;
}
//--------------------------------------
void gsm_ready()
{
static char count=0;
#ifdef _WDT
wdt_reset();
#endif
repet:
#ifdef DEBUGE_GSM
uart_put_string("AT",1);
#endif
uart_put_string("AT",1);
wait_flage();
if ((strstr_P(gsm.buffer,PSTR("OK"))) == 0){_delay_ms(300);count++;if(count<4){goto repet;}}
#ifdef _WDT
wdt_reset();
#endif
_delay_ms(400);
}
//--------------------------------------
void gsm_dialing(char *tex)
{
gsm_ready();
#ifdef DEBUGE_GSM
uart_put_string("ATD",0);
uart_put_string(tex,1);
#endif
uart_put_string("ATD",0);
uart_put_string(tex,1);
wait_flage();
_delay_ms(400);
}
//--------------------------------------
void gsm_send_sms(char *mobile,char *tex)
{
char count=0;
#ifdef _WDT
wdt_reset();
#endif
if (gsm.stat==ENABLE)
{
counter=0;
gsm_ready();
gsm.rdy = DISABLE;
memset(gsm.tex_recive,0,TEX_RECIVE_LEN); //mobile number
memset(gsm.data,0,DATA_LEN);
#ifdef LCD
LCDclr();
LCDstring((uint8_t *)"Send To:",16);
LCDGotoXY(0,1);
LCDstring((uint8_t *)mobile,16);
#endif
chang_to_unicode(mobile,gsm.tex_recive);
chang_to_unicode(tex,gsm.data);
#ifdef DEBUGE_GSM
uart_put_string(tex,1);
#endif
#ifdef _WDT
wdt_reset();
#endif
#ifdef DEBUGE_GSM
uart_put_string("AT+CSCS=\"UCS2\"",1);
#endif
uart_put_string("AT+CSCS=\"UCS2\"",1);
_delay_ms(500);
#ifdef _WDT
wdt_reset();
#endif
#ifdef DEBUGE_GSM
uart_put_string("AT+CMGS=\"",0);
uart_put_string(gsm.tex_recive,0);
uart_put_string("\"\r",0);
#endif
uart_put_string("AT+CMGS=\"",0);
uart_put_string(gsm.tex_recive,0);
uart_put_string("\"\r",0);
#ifdef _WDT
wdt_reset();
#endif
repet_:
wait_flage();
if ((strstr_P(gsm.buffer,PSTR(">"))) == 0){_delay_ms(300);count++;if(count<4){goto repet_;}}
_delay_ms(300);
#ifdef DEBUGE_GSM
uart_put_string(gsm.data,1);
#endif
uart_put_string(gsm.data,1);
uart_putchar(26);
uart_putchar(13);
#ifdef _WDT
wdt_reset();
#endif
_delay_ms(200);
}
}
//--------------------------------------
void send2gsm(char select)
{
#ifdef _WDT
wdt_reset();
#endif
if (gsm.stat==ENABLE)
{
gsm_ready();
#ifdef _WDT
wdt_reset();
#endif
_delay_ms(400);
switch(select)
{
case OFF_GSM:
//re_off:
#ifdef DEBUGE_GSM
uart_put_string("AT+CPOWD=1",1);
#endif
uart_put_string("AT+CPOWD=1",1);
wait_flage();
//if(STATUS)goto re_off;
break;
case GET_IMEI:
#ifdef DEBUGE_GSM
uart_put_string("AT+GSN",1);
#endif
uart_put_string("AT+GSN",1);
wait_flage();
break;
case UCS2_MOD:
#ifdef DEBUGE_GSM
uart_put_string("AT+CSCS=\"UCS2\"",1);
#endif
uart_put_string("AT+CSCS=\"UCS2\"",1);
wait_flage();
break;
case GSM_MOD:
#ifdef DEBUGE_GSM
uart_put_string("AT+CSCS=\"GSM\"",1);
#endif
uart_put_string("AT+CSCS=\"GSM\"",1);
wait_flage();
break;
case DEL_ALL:
#ifdef DEBUGE_GSM
uart_put_string("AT+CMGDA=\"DEL ALL\"",1);
#endif
uart_put_string("AT+CMGDA=\"DEL ALL\"",1);
sms_number=0;
gsm.dell = DISABLE;
wait_flage();
break;
case DELL_SMS:
#ifdef DEBUGE_GSM
uart_put_string("AT+CMGD=",0);
uart_put_string(gsm.ch_sms,ENABLE);
#endif
uart_put_string("AT+CMGD=",0);
uart_put_string(gsm.ch_sms,ENABLE);
sms_number=0;
gsm.unread = ENABLE;
gsm.dell = DISABLE;
#ifdef DEBUGE_GSM
uart_put_string("gsm_rdy=ENABLE",1);
#endif
gsm.rdy = ENABLE;
break;
case GET_CHARJ:
#ifdef _WDT
wdt_reset();
#endif
gsm.charj = DISABLE;
if (gsm.sim_operator == IRANCELL)
{
#ifdef DEBUGE_GSM
uart_put_string("ATD",0);
uart_put_string(get_charj_code_irancell,1);
#endif
uart_put_string("ATD",0);
uart_put_string(get_charj_code_irancell,1);
}
else if (gsm.sim_operator == IR_MCI)
{
#ifdef DEBUGE_GSM
uart_put_string("ATD",0);
uart_put_string(get_charj_code_ir_mci,1);
#endif
uart_put_string("ATD",0);
uart_put_string(get_charj_code_ir_mci,1);
}
gsm.flag_charj = ENABLE;
break;
case SIM_NAME:
#ifdef DEBUGE_GSM
uart_put_string("AT+CSPN?",1);
#endif
uart_put_string("AT+CSPN?",1);
gsm.flag_simname = ENABLE;
wait_flage();
break;
case NET_STATUS:
#ifdef DEBUGE_GSM
uart_put_string("AT+CREG?",1);
#endif
uart_put_string("AT+CREG?",1);
wait_flage();
break;
case GSM_RST:
#ifdef DEBUGE_GSM
uart_put_string("AT+CFUN=1,1",1);
#endif
uart_put_string("AT+CFUN=1,1",1);
wait_flage();
break;
case SIGNAL_Q:
uart_put_string("AT+CSQ",1);
wait_flage();
break;
case REQUEST_TA:
uart_put_string("AT+GSN",1);
wait_flage();
break;
case HANG_UP:
uart_put_string("ATH",1);
wait_flage();
break;
case ANSWER_RING:
uart_put_string("ATA",1);
break;
case CMICH:
uart_put_string("AT+CMIC=0,15",1);
wait_flage();
break;
case CMICL:
uart_put_string("AT+CMIC=0,10",1);
wait_flage();
break;
case RECIEVED_UNREAD:
#ifdef DEBUGE_GSM
uart_put_string("AT+CMGL",1);
#endif
uart_put_string("AT+CMGL",1);
break;
case CUSD_ON:
uart_put_string("AT+CUSD=1",1);
wait_flage();
break;
case CUSD_OFF:
uart_put_string("AT+CUSD=0",1);
wait_flage();
break;
case RST_GSM:
uart_put_string("ATZ",1);
wait_flage();
break;
}
#ifdef _WDT
wdt_reset();
#endif
}
}
//--------------------------------------
void gsm_start(void)
{
GSM_ON_PORT &= ~(1<<GSM_ON_PIN);
GSM_ON_DDR |= 1<<GSM_ON_PIN;
GSM_STATE_PORT &= ~(1<<GSM_STATE_PIN);
GSM_STATE_DDR &= ~(1<<GSM_STATE_PIN);
/************************************************************************/
/* CONFIG UART */
/************************************************************************/
uart_init(CONF_8BIT_NOPAR_1STOP);
UCSRB |= 1<<RXCIE;
#ifdef _WDT
wdt_reset();
#endif
if (STATUS == 0)
{
ON_GSM_HIGH;
_delay_ms(1100);
ON_GSM_LOW;
_delay_ms(11000);
if (STATUS)
{
gsm.stat = ENABLE;
#ifdef LCD
LCDGotoXY(0,0);
LCDstring((uint8_t *)" GSM ON ",16);
#endif
_delay_ms(4000);
}
else
{
gsm.stat = DISABLE;
#ifdef LCD
LCDGotoXY(0,0);
LCDstring((uint8_t *)" NO GSM ",16);
_delay_ms(500);
#endif
}
}
else
{
gsm.stat = ENABLE;
gsm.rdy = ENABLE;
}
//gsm.stat = ENABLE;
if (gsm.stat == ENABLE)
{
_delay_ms(1000);
gsm_initializing();
send2gsm(SIM_NAME);
send2gsm(SIGNAL_Q);
send2gsm(NET_STATUS);
if (gsm.sim_operator==NO_SIM)
{
/*#ifdef LCD
LCDGotoXY(0,0);
LCDstring((uint8_t *)" GSM OFF... ",16);
#endif*/
//send2gsm(OFF_GSM);
gsm.stat = DISABLE;
}
if(GSM_MODULE==SIM900_MODULE)gsm.rdy=ENABLE;
}
}
//--------------------------------------
char get_info()
{
return gsm.sim_operator;
}
//--------------------------------------
ISR(GSM_UART_ISR)
{
gsm.number_of_charecter = uart_getstring(gsm.buffer,BUFFER_LEN);
#ifdef DEBUGE_GSM
uart_put_string(gsm.buffer,1);
#endif
detect_gsm();
gsm.recive=ENABLE;
}
#endif | 29.190539 | 177 | 0.608625 |
68c578e1556f989f4b0c03ca24f3246b04e2998c | 1,834 | h | C | Includes/Art/LevelDetector.h | ArselonHub/ArtCore-stm32f4 | 78954fd823d477674d47ce30ab6df63ea47538f7 | [
"MIT"
] | 2 | 2017-12-05T20:18:04.000Z | 2020-01-05T09:21:57.000Z | Includes/Art/LevelDetector.h | ArselonHub/ArtCore-stm32f4 | 78954fd823d477674d47ce30ab6df63ea47538f7 | [
"MIT"
] | 1 | 2017-12-16T13:23:33.000Z | 2017-12-16T13:23:33.000Z | Includes/Art/LevelDetector.h | ArselonHub/ArtCore-stm32f4 | 78954fd823d477674d47ce30ab6df63ea47538f7 | [
"MIT"
] | null | null | null | /*
* FilteredEdgeDetector.h
*
* Created on: Dec 17, 2016
* Author: denizcan
*/
#ifndef SOURCE_ART_LEVELDETECTOR_H_
#define SOURCE_ART_LEVELDETECTOR_H_
#include <Art/Device.h>
#include <Art/Thread.h>
#include <Art/CoreTimer.h>
#include <Art/CoreEdgeDetector.h>
namespace Art
{
class LevelDetector : public Device
{
public:
LevelDetector();
Signal<void*> onEvent() SIGNAL;
Word period();
void setPeriod(Word value);
Bool level() const;
Pin* pin();
Word setPin(Pin* value);
Edge edge() const;
void setEdge(Edge edge);
Thread* thread() const;
void setThread(Thread* thread);
private:
class EdgeDetector : public CoreEdgeDetector
{
virtual void doEventSvc();
};
class EventTask : public Task
{
virtual void execute();
};
class LevelTimer : public CoreTimer
{
virtual void doTimeoutSvc();
};
virtual Word openDevice();
virtual Word closeDevice();
virtual Word enableDevice();
virtual Word disableDevice();
Byte m_level;
Edge m_edge;
Word m_period;
Thread* m_thread;
EdgeDetector m_edgeDetector;
EventTask m_eventTask;
LevelTimer m_levelTimer;
};
inline Word LevelDetector::period()
{
return m_period;
}
inline void LevelDetector::setPeriod(Word value)
{
m_period = value;
}
inline Bool LevelDetector::level() const
{
return m_level;
}
inline Pin* LevelDetector::pin()
{
return m_edgeDetector.pin();
}
inline Word LevelDetector::setPin(Pin* value)
{
return m_edgeDetector.setPin(value);
}
inline Art::Edge LevelDetector::edge() const
{
return m_edge;
}
inline void LevelDetector::setEdge(Edge edge)
{
m_edge = edge;
}
inline Thread* LevelDetector::thread() const
{
return m_thread;
}
inline void LevelDetector::setThread(Thread* thread)
{
m_thread = thread;
}
}
#endif
| 15.810345 | 53 | 0.688113 |
84c8eacdc892284c4d02a99e2b9e3df817ea2548 | 7,113 | c | C | src/diffusion.c | edorig/xmfract | bdde3c5669e78cdc1fce27a771aa374714a97be2 | [
"X11",
"Unlicense"
] | null | null | null | src/diffusion.c | edorig/xmfract | bdde3c5669e78cdc1fce27a771aa374714a97be2 | [
"X11",
"Unlicense"
] | null | null | null | src/diffusion.c | edorig/xmfract | bdde3c5669e78cdc1fce27a771aa374714a97be2 | [
"X11",
"Unlicense"
] | null | null | null |
#include "xmfract.h"
#include "fractype.h"
#include "macros.h"
#include "helpdefs.h"
#include "mpmath.h"
#include "globals.h"
#include "prototyp.h"
#ifndef NO_IDENT
#ident "$Id: diffusion.c,v 1.400 1995/06/20 15:39:23 darryl Exp $"
#endif
int diffusion()
{
int xmax,ymax,xmin,ymin; /* Current maximum coordinates */
int border; /* Distance between release point and fractal */
int mode; /* Determines diffusion type: 0 = central (classic) */
/* 1 = falling particles */
/* 2 = square cavity */
int i;
double cosine,sine,angle;
long lcosine,lsine;
int x,y;
float r, radius, f_tmp;
x = y = 0;
if (diskvideo)
notdiskmsg();
bitshift = 16;
fudge = 1L << 16;
border = param[0];
mode = param[1];
if (mode > 2)
mode=0;
if (border <= 0)
border = 10;
srand(rseed);
if (!rflag)
++rseed;
if (mode == 0)
{
xmax = xdots / 2 + border; /* Initial box */
xmin = xdots / 2 - border;
ymax = ydots / 2 + border;
ymin = ydots / 2 - border;
}
if (mode == 1)
{
xmax = xdots / 2 + border; /* Initial box */
xmin = xdots / 2 - border;
ymin = ydots - 20;
}
if (mode == 2)
{
if (xdots>ydots)
radius = ydots - 5;
else
radius = xdots - 5;
}
if (resuming) /* restore worklist, if we can't the above will stay in place */
{
start_resume();
if (mode != 2)
get_resume(sizeof(int),&xmax,sizeof(int),&xmin,sizeof(int),&ymax,
sizeof(int),&ymin,0);
else
get_resume(sizeof(int),&xmax,sizeof(int),&xmin,sizeof(int),&ymax,
sizeof(int),&radius,0);
end_resume();
}
if (mode==0)
putcolor(xdots / 2, ydots / 2,RANDOM(colors-1)+1); /* Seed point */
if (mode==1)
for (i=0;i<=xdots;i++)
putcolor(i,ydots-1,colors-1);
if (mode==2)
{
if (xdots>ydots)
{
for (i=0;i<ydots;i++)
{
putcolor(xdots/2-ydots/2 , i , colors-1);
putcolor(xdots/2+ydots/2 , i , colors-1);
putcolor(xdots/2-ydots/2+i , 0 , colors-1);
putcolor(xdots/2-ydots/2+i , ydots-1 , colors-1);
}
}
else
{
for (i=0;i<xdots;i++)
{
putcolor(0 , ydots/2-xdots/2+i , colors-1);
putcolor(xdots-1 , ydots/2-xdots/2+i , colors-1);
putcolor(i , ydots/2-xdots/2 , colors-1);
putcolor(i , ydots/2+xdots/2 , colors-1);
}
}
}
while (1)
{
/* Release new point on circle just inside the box */
if (mode==0)
{
if (floatflag)
{
angle=2*(double)rand()/(RAND_MAX/PI);
FPUsincos(&angle,&sine,&cosine);
x = cosine*(xmax-xmin) + xdots;
y = sine *(ymax-ymin) + ydots;
}
else
{
SinCos086(multiply((long)rand15(),FOURPI,16),&lsine,&lcosine);
x = (lcosine*(long)(xmax-xmin) >> 16) + xdots;
y = (lsine *(long)(ymax-ymin) >> 16) + ydots;
}
x = x >> 1; /* divide by 2 */
y = y >> 1;
}
if (mode==1)
{
y=ymin;
x=RANDOM(xmax-xmin) + (xdots-xmax+xmin)/2;
}
if (mode==2)
{
if (floatflag)
{
angle=2*(double)rand()/(RAND_MAX/PI);
FPUsincos(&angle,&sine,&cosine);
x = cosine*radius + xdots;
y = sine *radius + ydots;
}
else
{
SinCos086(multiply((long)rand15(),FOURPI,16),&lsine,&lcosine);
x = (lcosine*(long)(radius) >> 16) + xdots;
y = (lsine *(long)(radius) >> 16) + ydots;
}
x = x >> 1;
y = y >> 1;
}
/* Loop as long as the point (x,y) is surrounded by color 0 */
/* on all eight sides */
while((getcolor(x+1,y+1) == 0) && (getcolor(x+1,y) == 0) &&
(getcolor(x+1,y-1) == 0) && (getcolor(x ,y+1) == 0) &&
(getcolor(x ,y-1) == 0) && (getcolor(x-1,y+1) == 0) &&
(getcolor(x-1,y) == 0) && (getcolor(x-1,y-1) == 0))
{
/* Erase moving point */
if (show_orbit)
putcolor(x,y,0);
/* Make sure point is inside the box (if mode==0)*/
if (mode==0){
if (x==xmax)
x--;
else if (x==xmin)
x++;
if (y==ymax)
y--;
else if (y==ymin)
y++;
}
if (mode==1)
{
if (x>xdots-2)
x--;
else if (x<1)
x++;
if (y<ymin)
y++;
}
/* Take one random step */
x += RANDOM(3) - 1;
y += RANDOM(3) - 1;
/* Check keyboard */
if ((++plasma_check & 0x7f) == 1)
if(check_key() != 0)
{
alloc_resume(20,1);
if (mode!=2)
put_resume(sizeof(int),&xmax,sizeof(int),&xmin, sizeof(int),&ymax,
sizeof(int),&ymin,0);
else
put_resume(sizeof(int),&xmax,sizeof(int),&xmin, sizeof(int),&ymax,
sizeof(int),&radius,0);
plasma_check--;
return 1;
}
/* Show the moving point */
if (show_orbit)
putcolor(x,y,RANDOM(colors-1)+1);
}
putcolor(x,y,RANDOM(colors-1)+1);
/* Is point too close to the edge? */
if (mode==0)
{
if (((x+border)>xmax) || ((x-border)<xmin)
|| ((y-border)<ymin) || ((y+border)>ymax))
{
/* Increase box size, but not past the edge of the screen */
if (ymin != 1)
{
ymin--;
ymax++;
}
if (xmin != 1)
{
xmin--;
xmax++;
}
if ((ymin==1) || (xmin==1))
return 0;
}
}
if (mode==1)
{
if (y < ymin+5)
ymin = y - 5;
if (ymin<2)
return 0;
}
if (mode==2)
{
if (abs(x-xdots/2)<5 && abs(y-ydots/2)<5)
return 0;
r = (x-xdots/2)*(x-xdots/2)+(y-ydots/2)*(y-ydots/2);
fSqrt14(r,f_tmp);
r = 2 * f_tmp;
if (r < radius)
radius = r;
}
}
}
/*******************************************************************
* MODIFICATION HISTORY
*
* $Log: diffusion.c,v $
* Revision 1.400 1995/06/20 15:39:23 darryl
* Revision sync - release 1.4
*
* Revision 1.4 1995/03/20 04:01:03 darryl
* Revision sync. Change all BulletinBoard dialogs to Forms.
* Delete all specific widget positioning and sizing resources.
* Change popup menus to option menus. Add Undo command to
* the color editor. Change usepixtab to 1 if privatecolor.
*
* Revision 1.1 1995/03/03 22:56:36 darryl
* Linux and HPUX enhancements, bug fixes. New basic options
* dialog, 'Flip' submenu created differently. EditRes protocol
* event handlers conditionally included. xmconfig.h generalized.
*
* Revision 0.300 1994/12/16 18:58:09 darryl
* Revision sync - beta3 version.
*
* Revision 0.200 1994/12/02 02:54:24 darryl
* Revision sync - beta2 version.
*
* Revision 0.100 1994/11/18 05:31:10 darryl
* Initial beta version.
*
* END MODIFICATION HISTORY
*******************************************************************/
| 24.359589 | 80 | 0.484887 |
b409136c384dd7c23554c26a5dc24f55c8408786 | 2,872 | h | C | Class/DataManager/ActiveRecord/FlyingLessonData.h | songbaoqiang/ffm_ios_app | f0c58cd6bb67bd6d4d020eb1fd7e7d823cdc9af8 | [
"MIT"
] | null | null | null | Class/DataManager/ActiveRecord/FlyingLessonData.h | songbaoqiang/ffm_ios_app | f0c58cd6bb67bd6d4d020eb1fd7e7d823cdc9af8 | [
"MIT"
] | null | null | null | Class/DataManager/ActiveRecord/FlyingLessonData.h | songbaoqiang/ffm_ios_app | f0c58cd6bb67bd6d4d020eb1fd7e7d823cdc9af8 | [
"MIT"
] | null | null | null | //
// FlyingLessonData.h
// FlyingEnglish
//
// Created by vincent sung on 1/21/13.
// Copyright (c) 2013 vincent sung. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "shareDefine.h"
@class FlyingPubLessonData;
@interface FlyingLessonData : NSObject
@property (nonatomic, strong) NSString *BELESSONID; //课程ID
@property (nonatomic, strong) NSString *BETITLE; //课程名称
@property (nonatomic, strong) NSString *BEDESC; //课程描述
@property (nonatomic, strong) NSString *BEIMAGEURL; //课程截图
@property (nonatomic, strong) NSString *BECONTENTURL; //内容连接
@property (nonatomic, strong) NSString *BESUBURL; //课程字幕
@property (nonatomic, strong) NSString *BEPROURL; //字典地址
@property (nonatomic, strong) NSString *BEWEBURL; //课程首页
@property (nonatomic, strong) NSString *BESHAREURL; //分享地址
@property (nonatomic, assign) double BEDURATION; //课程时长
@property (nonatomic, assign) double BEDLPERCENT; //本地内容下载百分比
@property (nonatomic, assign) BOOL BEDLSTATE; //下载状态
@property (nonatomic, assign) BOOL BEOFFICIAL; //官方资源
@property (nonatomic, strong) NSString *BECONTENTTYPE; //资源类型
@property (nonatomic, strong) NSString *BEDOWNLOADTYPE; //下载类型
@property (nonatomic, strong) NSString *BETAG; //标签
@property (nonatomic, assign) NSInteger BECoinPrice; //价格
@property (nonatomic, strong) NSString *BEISBN; //对应ISBN
@property (nonatomic, strong) NSString *BERELATIVEURL; //内容辅助资源
@property (nonatomic, strong) NSString *localURLOfContent; //本地课程内容地址
@property (nonatomic, strong) NSString *localURLOfSub; //本地字幕内容地址
@property (nonatomic, strong) NSString *localURLOfCover; //本地封面地址
@property (nonatomic, strong) NSString *localURLOfPro; //本地课程字典库地址
@property (nonatomic, strong) NSString *localURLOfRelative;//本地课程辅助资源地址
//数据库数据初始化
- (id)initWithLessonID: (NSString *)lessonID
Title: (NSString *) title
DESC: (NSString *) description
IMageURL: (NSString *) imageURL
ContentURL: (NSString *) contentURL
SubtitleURL: (NSString *) subtitleURL
PronunciationURL: (NSString *) pronunciationURL
ShareURL: (NSString *) shareURL
Duration: (double) duration
DownloadPercent: (double) downloadPercent
DownloadSate: (BOOL) downloadState
officialFlag: (BOOL) official
ContentType: (NSString *) contentType
DownloadType: (NSString *) downloadType
Tag: (NSString *) tag
coinPrice: (int) coinPrice
webURL: (NSString *) webURL
ISBN: (NSString *) ISBN
relativeURL: (NSString *) relativeURL;
- (id)initWithPubData:(FlyingPubLessonData *)pubLessonData;
@end
| 39.888889 | 71 | 0.650418 |
f1dfd2bd03be4e9e361cc92a2901fa436f2169b5 | 748 | h | C | Frogger/GameObject.h | Andre-Pires/Three-Dimensional-Visualization-and-Animation | 6bd41160648a298ef1b05f856763958cd089f566 | [
"Apache-2.0"
] | 1 | 2016-01-11T02:46:27.000Z | 2016-01-11T02:46:27.000Z | Frogger/GameObject.h | Andre-Pires/Three-Dimensional-Visualization-and-Animation | 6bd41160648a298ef1b05f856763958cd089f566 | [
"Apache-2.0"
] | null | null | null | Frogger/GameObject.h | Andre-Pires/Three-Dimensional-Visualization-and-Animation | 6bd41160648a298ef1b05f856763958cd089f566 | [
"Apache-2.0"
] | null | null | null | #pragma once
#include "vsMathLib.h"
#include "vsShaderLib.h"
#include "Entity.h"
#include "vsResSurfRevLib.h"
class GameObject : public Entity
{
VSMathLib *vsml;
VSShaderLib *shader;
VSResSurfRevLib surfRev;
Vector3D* rotation;
Vector3D* scale;
float rotationAngle;
public:
GameObject();
~GameObject();
virtual void draw() = 0;
void setRotation(float x, float y, float z);
Vector3D * getRotation();
void setRotationAngle(float angle);
float getRotationAngle();
void setVSML(VSMathLib *vsml);
VSMathLib * getVSML();
VSShaderLib * getShader();
void setShader(VSShaderLib *shader);
VSResSurfRevLib getResSurfRev();
void setResSurfRev(VSResSurfRevLib surfRev);
void setScale(float x, float y, float z);
Vector3D * getScale();
};
| 22.666667 | 45 | 0.744652 |
7d52342353dd124c3a0e246c788eb81436aa8020 | 1,260 | c | C | stdlib/printf.c | mahavirj/tinyos | 8cf7f14ff784779fa327566005e4e87d38b4bcbd | [
"Apache-2.0"
] | 34 | 2017-03-04T13:23:46.000Z | 2022-01-17T09:11:21.000Z | stdlib/printf.c | mahavirj/tinyos | 8cf7f14ff784779fa327566005e4e87d38b4bcbd | [
"Apache-2.0"
] | null | null | null | stdlib/printf.c | mahavirj/tinyos | 8cf7f14ff784779fa327566005e4e87d38b4bcbd | [
"Apache-2.0"
] | 9 | 2019-03-05T04:51:32.000Z | 2021-08-09T01:58:33.000Z | #include <stdarg.h>
#include <string.h>
#include <unistd.h>
extern int hex_to_str(const int num, char buf[]);
extern int dec_to_str(const int num, char buf[]);
int printf(const char *fmt, ...)
{
va_list ap;
int d, x;
char c, *s;
const char *p;
void *pi;
char buf[96];
int index = 0;
int ret;
va_start(ap, fmt);
for (p = fmt; *p; p++) {
if (*p != '%') {
buf[index++] = *p;
continue;
}
switch (*++p) {
case 's': /* string */
s = va_arg(ap, char *);
strncpy(&buf[index], s, strlen(s));
index += strlen(s);
break;
case 'd': /* int */
d = va_arg(ap, int);
ret = dec_to_str(d, &buf[index]);
index += ret;
break;
case 'x': /* hex */
x = va_arg(ap, int);
ret = hex_to_str(x, &buf[index]);
index += ret;
break;
case 'p': /* pointer */
pi = va_arg(ap, void *);
if (pi) {
ret = hex_to_str((int) pi, &buf[index]);
index += ret;
} else {
strncpy(&buf[index], "NULL", strlen("NULL"));
index += strlen("NULL");
}
break;
case 'c': /* char */
/* need a cast here since va_arg only
takes fully promoted types */
c = (char) va_arg(ap, int);
buf[index++] = c;
break;
}
}
va_end(ap);
return write(1, buf, index);
}
| 20.322581 | 49 | 0.519841 |
0428a62ae42dc65e958f536ace9569d62eb92b38 | 2,221 | c | C | Clara/test.c | Grinnell-CSC282/api-2017 | 140e64a05f3cd85f04b73b1f0e8e248da877f496 | [
"MIT"
] | null | null | null | Clara/test.c | Grinnell-CSC282/api-2017 | 140e64a05f3cd85f04b73b1f0e8e248da877f496 | [
"MIT"
] | null | null | null | Clara/test.c | Grinnell-CSC282/api-2017 | 140e64a05f3cd85f04b73b1f0e8e248da877f496 | [
"MIT"
] | null | null | null | #include "alint.c"
#include <stdio.h>
#include <assert.h>
int main(int argc, char * argv[]) {
// creating ALInts
ALInt * ali1 = int2ali(213);
ALInt * ali2 = int2ali(5042);
ALInt * ali3 = int2ali(-42);
ALInt * ali4 = int2ali(-162);
ALInt * ali5 = int2ali(300000);
// checking pointers
assert (ali2->first->value == 5);
assert (ali2->first->prev == NULL);
assert (ali2->first->next->prev == ali2->first);
assert (ali2->last->next == NULL);
assert (ali2->last->prev == ali2->first->next->next);
assert (ali2->last->value = 2);
assert (ali2->last->prev->prev == ali2->first->next);
// checking ali2str
assert (strcmp(ali2str(ali2), "5042") == 0);
assert (strcmp(ali2str(ali1), "213") == 0);
assert (strcmp(ali2str(ali3), "-42") == 0);
// checking signs
assert (ali1->sign == 1);
assert (ali3->sign == 0);
// checking conversions
assert (ali2int(ali1) == 213);
assert (ali2double(ali2) == 5042.0);
assert (ali2long(ali3) == -42);
assert (ali2int(double2ali(120.6)) == 120);
assert (ali2int(int2ali(-120)) == -120);
assert (ali2int(long2ali(45)) == 45);
// checking ali_add
assert (strcmp(ali2str(ali_add(ali1, ali2)), "5255") == 0);
assert (strcmp(ali2str(ali_add(ali3, ali4)), "-204") == 0);
assert (strcmp(ali2str(ali_add(ali5, ali2)), "305042") == 0);
// ordering check
assert (strcmp(ali2str(ali_add(ali2, ali5)), "305042") == 0);
// conversion to subtraction check
assert (strcmp(ali2str(ali_add(ali2, ali3)), "5000") == 0);
printf("%s\n", ali2str(ali_add(ali3, ali2)));
// assert (strcmp(ali2str(ali_add(ali3, ali2)), "5000") == 0);
// checking ali_subtract
assert (strcmp(ali2str(ali_subtract(ali1, ali2)), "-4829") == 0);
printf("%s\n", ali2str(ali_subtract(ali2, ali3)));
//assert (strcmp(ali2str(ali_subtract(ali2, ali3)), "5084") == 0);
printf("%s\n", ali2str(ali_subtract(ali3, ali4)));
//assert (strcmp(ali2str(ali_subtract(ali3, ali4)), "120") == 0);
printf("%s\n", ali2str(ali_subtract(ali5, ali1)));
//assert (strcmp(ali2str(ali_subtract(ali5, ali1)), "299787") == 0);
printf("%s\n", ali2str(ali_subtract(ali1, ali5)));
//assert (strcmp(ali2str(ali_subtract(ali1, ali5)), "-299787") == 0);
return 0;
}
| 34.703125 | 71 | 0.628095 |
75d761c8587faef068540b0fc2c5c76f46946499 | 433 | h | C | LMAOKeyboard/Classes/LMAOSafeKeyboard.h | GodFatherSS/LMAOKeyboard | 8b41debce86829078cc7f648bdc072daeafa5d5c | [
"MIT"
] | null | null | null | LMAOKeyboard/Classes/LMAOSafeKeyboard.h | GodFatherSS/LMAOKeyboard | 8b41debce86829078cc7f648bdc072daeafa5d5c | [
"MIT"
] | null | null | null | LMAOKeyboard/Classes/LMAOSafeKeyboard.h | GodFatherSS/LMAOKeyboard | 8b41debce86829078cc7f648bdc072daeafa5d5c | [
"MIT"
] | null | null | null | //
// LMAOSafeKeyboard.h
// LMAOKeybord
//
// Created by Seth on 2016/11/11.
// Copyright © 2016年 Seth. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef enum{
LMAOTypeNumberPad = 1,
LMAOTypeDecimalPad ,
LMAOTypeASCIICapable
}LMAOType;
@interface LMAOSafeKeyboard : UIView
@property (nonatomic, strong) UIView *inputSource;
+ (LMAOSafeKeyboard *)keyboardWithOriginY:(CGFloat)y withType:(LMAOType)type;
@end
| 19.681818 | 77 | 0.727483 |
f38f293df8a06685b1a661a1abc6f26bd389d3f1 | 1,334 | h | C | src/daemon/modules/container/container_events_handler.h | Apraso/iSulad_test | c9bb9b9e2787275f6147c9353f279e49f6a4a086 | [
"MulanPSL-1.0"
] | 34 | 2020-03-09T11:57:08.000Z | 2022-03-29T12:18:33.000Z | src/daemon/modules/container/container_events_handler.h | Apraso/iSulad_test | c9bb9b9e2787275f6147c9353f279e49f6a4a086 | [
"MulanPSL-1.0"
] | null | null | null | src/daemon/modules/container/container_events_handler.h | Apraso/iSulad_test | c9bb9b9e2787275f6147c9353f279e49f6a4a086 | [
"MulanPSL-1.0"
] | 8 | 2020-03-21T02:36:22.000Z | 2021-11-13T18:15:43.000Z | /******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2020-06-22
* Description: provide container events handler definition
******************************************************************************/
#ifndef DAEMON_MODULES_CONTAINER_CONTAINER_EVENTS_HANDLER_H
#define DAEMON_MODULES_CONTAINER_CONTAINER_EVENTS_HANDLER_H
#include <stdint.h>
#include <pthread.h>
#include "linked_list.h"
#include "container_api.h"
#include "events_format.h"
container_events_handler_t *container_events_handler_new();
void container_events_handler_free(container_events_handler_t *handler);
int container_events_handler_post_events(const struct isulad_events_format *event);
#endif // DAEMON_MODULES_CONTAINER_CONTAINER_EVENTS_HANDLER_H
| 41.6875 | 99 | 0.703898 |
0605963a2e5d0fc89dd86ff690c8c9ee08572488 | 12,863 | c | C | source/kernel/lib/avl_tree.c | aejsmith/kiwi | 756d5b85d7dff631ad54c942a9da137ea298794e | [
"0BSD"
] | 15 | 2015-08-02T18:20:40.000Z | 2022-03-22T13:36:44.000Z | source/kernel/lib/avl_tree.c | aejsmith/kiwi | 756d5b85d7dff631ad54c942a9da137ea298794e | [
"0BSD"
] | null | null | null | source/kernel/lib/avl_tree.c | aejsmith/kiwi | 756d5b85d7dff631ad54c942a9da137ea298794e | [
"0BSD"
] | 3 | 2016-03-04T06:15:34.000Z | 2020-12-12T03:01:42.000Z | /*
* Copyright (C) 2009-2021 Alex Smith
*
* 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.
*/
/**
* @file
* @brief AVL tree implementation.
*
* Reference:
* - Wikipedia - AVL tree:
* http://en.wikipedia.org/wiki/AVL_Tree
* - Wikipedia - Tree rotation:
* http://en.wikipedia.org/wiki/Tree_rotation
* - AVL Tree Rotations Tutorial:
* http://fortheloot.com/public/AVLTreeTutorial.rtf
* - AVL Trees: Tutorial and C++ Implementation:
* http://www.cmcrossroads.com/bradapp/ftp/src/libs/C++/AvlTrees.html
*/
#include <lib/avl_tree.h>
#include <mm/malloc.h>
#include <assert.h>
/** Get the height of a subtree. Assumes that child heights are up-to-date. */
static inline int avl_tree_subtree_height(avl_tree_node_t *node) {
if (!node)
return 0;
/* Get the heights of the children and add 1 to account for the node itself. */
int left = (node->left) ? (node->left->height + 1) : 1;
int right = (node->right) ? (node->right->height + 1) : 1;
/* Store the largest of the heights and return it. */
node->height = (right > left) ? right : left;
return node->height;
}
static inline int avl_tree_balance_factor(avl_tree_node_t *node) {
return avl_tree_subtree_height(node->right) - avl_tree_subtree_height(node->left);
}
static inline void avl_tree_rotate_left(avl_tree_t *tree, avl_tree_node_t *node) {
/* Store the node's current right child. */
avl_tree_node_t *child = node->right;
/* Node takes ownership of the child's left child as its right child
* (replacing the existing right child). */
node->right = child->left;
if (node->right)
node->right->parent = node;
/* Reparent the child to node's parent. */
child->parent = node->parent;
if (!child->parent) {
/* If parent becomes NULL we're at the root of the tree. */
tree->root = child;
} else {
if (child->parent->left == node) {
child->parent->left = child;
} else {
child->parent->right = child;
}
}
/* Child now takes ownership of the old root node as its left child. */
child->left = node;
node->parent = child;
}
static inline void avl_tree_rotate_right(avl_tree_t *tree, avl_tree_node_t *node) {
/* Store the node's current left child. */
avl_tree_node_t *child = node->left;
/* Node takes ownership of the child's right child as its left child
* (replacing the existing left child). */
node->left = child->right;
if (node->left)
node->left->parent = node;
/* Reparent the child to node's parent. */
child->parent = node->parent;
if (!child->parent) {
/* If parent becomes NULL we're at the root of the tree. */
tree->root = child;
} else {
if (child->parent->left == node) {
child->parent->left = child;
} else {
child->parent->right = child;
}
}
/* Child now takes ownership of the old root node as its right child. */
child->right = node;
node->parent = child;
}
static inline void avl_tree_balance_node(avl_tree_t *tree, avl_tree_node_t *node, int balance) {
/* See "AVL Tree Rotations Tutorial" (in Reference at top of file). */
if (balance > 1) {
/* Tree is right-heavy, check whether a LR rotation is necessary (if
* the right subtree is left-heavy). Note that if the tree is right-
* heavy, then node->right is guaranteed not to be a null pointer. */
if (avl_tree_balance_factor(node->right) < 0) {
/* LR rotation. Perform a right rotation of the right subtree. */
avl_tree_rotate_right(tree, node->right);
}
avl_tree_rotate_left(tree, node);
} else if (balance < -1) {
/* Tree is left-heavy, check whether a RL rotation is necessary (if the
* left subtree is right-heavy). */
if (avl_tree_balance_factor(node->left) > 0) {
/* RL rotation. Perform a left rotation of the left subtree. */
avl_tree_rotate_left(tree, node->left);
}
avl_tree_rotate_right(tree, node);
}
}
/** Insert a node in an AVL tree.
* @param tree Tree to insert into.
* @param key Key to give the node.
* @param node Node that the key will map to. This function does NOT
* check if the node is already in another tree: it must
* be removed by the caller if it is. */
void avl_tree_insert(avl_tree_t *tree, avl_tree_key_t key, avl_tree_node_t *node) {
node->left = NULL;
node->right = NULL;
node->height = 0;
node->key = key;
/* If tree is currently empty, just insert and finish. */
if (!tree->root) {
node->parent = NULL;
tree->root = node;
return;
}
/* Descend to where we want to insert the node. */
avl_tree_node_t **next = &tree->root;
avl_tree_node_t *curr = NULL;
while (*next) {
curr = *next;
/* Ensure that the key is unique. */
assert(key != curr->key);
/* Get the next pointer. */
next = (key > curr->key) ? &curr->right : &curr->left;
}
/* We now have an insertion point for the new node. */
node->parent = curr;
*next = node;
/* Now go back up the tree and check its balance. */
while (curr) {
int balance = avl_tree_balance_factor(curr);
if (balance < -1 || balance > 1)
avl_tree_balance_node(tree, curr, balance);
curr = curr->parent;
}
}
/** Remove a node from an AVL tree.
* @param tree Tree to remove from.
* @param node Node to remove. */
void avl_tree_remove(avl_tree_t *tree, avl_tree_node_t *node) {
avl_tree_node_t *start;
/* First we need to detach the node from the tree. */
if (node->left) {
/* Left node exists. Descend onto it, and then find the right-most node,
* which will replace the node that we're removing. */
avl_tree_node_t *child = node->left;
while (child->right)
child = child->right;
if (child != node->left) {
if (child->left) {
/* There is a left subtree. This must be moved up to replace
* child. */
child->left->parent = child->parent;
child->parent->right = child->left;
start = child->left;
} else {
/* Detach the child. */
child->parent->right = NULL;
start = child->parent;
}
child->left = node->left;
} else {
/* The left child has no right child. It will replace the node being
* deleted as-is. */
start = child;
}
/* Replace the node and fix up pointers. */
child->right = node->right;
child->parent = node->parent;
if (child->right)
child->right->parent = child;
if (child->left)
child->left->parent = child;
if (node->parent) {
if (node->parent->left == node) {
node->parent->left = child;
} else {
node->parent->right = child;
}
} else {
assert(node == tree->root);
tree->root = child;
}
} else if (node->right) {
/* Left node doesn't exist but right node does. This is easy. Just
* replace the node with its right child. */
node->right->parent = node->parent;
if (node->parent) {
if (node->parent->left == node) {
node->parent->left = node->right;
} else {
node->parent->right = node->right;
}
} else {
assert(node == tree->root);
tree->root = node->right;
}
start = node->right;
} else {
/* Node is a leaf. If it is the only element in the tree, then just
* remove it and return - no rebalancing required. Otherwise, remove it
* and then rebalance. */
if (node->parent) {
if (node->parent->left == node) {
node->parent->left = NULL;
} else {
node->parent->right = NULL;
}
} else {
assert(node == tree->root);
tree->root = NULL;
return;
}
start = node->parent;
}
/* Start now points to where we want to start rebalancing from. */
while (start) {
int balance = avl_tree_balance_factor(start);
if (balance < -1 || balance > 1)
avl_tree_balance_node(tree, start, balance);
start = start->parent;
}
}
/** Look up a node in an AVL tree.
* @param tree Tree to look up in.
* @param key Key to look for.
* @return Pointer to node if found, NULL if not. */
avl_tree_node_t *avl_tree_lookup_node(avl_tree_t *tree, avl_tree_key_t key) {
/* Descend down the tree to find the required node. */
avl_tree_node_t *node = tree->root;
while (node) {
if (node->key > key) {
node = node->left;
} else if (node->key < key) {
node = node->right;
} else {
return node;
}
}
return NULL;
}
/**
* Gets a pointer to the first node (the one with the lowest key) in an AVL
* tree by descending down the tree's left-hand side.
*
* @param tree Tree to get from.
*
* @return Pointer to node, or NULL if tree empty.
*/
avl_tree_node_t *avl_tree_first(avl_tree_t *tree) {
avl_tree_node_t *node = tree->root;
if (node) {
/* Descend down the left-hand side of the tree to find the smallest
* node. */
while (node->left)
node = node->left;
}
return node;
}
/**
* Gets a pointer to the last node (the one with the highest key) in an AVL
* tree by descending down the tree's right-hand side.
*
* @param tree Tree to get from.
*
* @return Pointer to node, or NULL if tree empty.
*/
avl_tree_node_t *avl_tree_last(avl_tree_t *tree) {
avl_tree_node_t *node = tree->root;
if (node) {
/* Descend down the right-hand side of the tree to find the largest
* node. */
while (node->right)
node = node->right;
}
return node;
}
/** Get the node preceding another node in an AVL tree.
* @param node Node to get preceding node of.
* @return Preceding node or NULL if none found. */
avl_tree_node_t *avl_tree_prev(avl_tree_node_t *node) {
if (!node)
return NULL;
/* If there's a left-hand child, move onto it and then go as far right as
* we can. */
if (node->left) {
node = node->left;
while (node->right)
node = node->right;
return node;
} else {
/* There's no left-hand children, go up until we find an ancestor that
* is the right-hand child of its parent. */
while (node->parent && node == node->parent->left)
node = node->parent;
/* The parent will now point to the preceding node (or NULL, if we reach
* the top of the tree). */
return node->parent;
}
}
/** Get the node following another node in an AVL tree.
* @param node Node to get following node of.
* @return Following node or NULL if none found. */
avl_tree_node_t *avl_tree_next(avl_tree_node_t *node) {
if (!node)
return NULL;
/* If there's a right-hand child, move onto it and then go as far left as
* we can. */
if (node->right) {
node = node->right;
while (node->left)
node = node->left;
return node;
} else {
/* There's no right-hand children, go up until we find an ancestor that
* is the left-hand child of its parent. */
while (node->parent && node == node->parent->right)
node = node->parent;
/* The parent will now point to the following node (or NULL, if we
* reach the top of the tree). */
return node->parent;
}
}
| 33.066838 | 96 | 0.577237 |
064d81183260b660975357baa13b4b4247c35f5c | 812 | h | C | src/Kernel/LambdaAffectorInterpolate.h | Terryhata6/Mengine | dfe36fdc84d7398fbbbd199feffc46c6f157f1d4 | [
"MIT"
] | 39 | 2016-04-21T03:25:26.000Z | 2022-01-19T14:16:38.000Z | src/Kernel/LambdaAffectorInterpolate.h | Terryhata6/Mengine | dfe36fdc84d7398fbbbd199feffc46c6f157f1d4 | [
"MIT"
] | 23 | 2016-06-28T13:03:17.000Z | 2022-02-02T10:11:54.000Z | src/Kernel/LambdaAffectorInterpolate.h | Terryhata6/Mengine | dfe36fdc84d7398fbbbd199feffc46c6f157f1d4 | [
"MIT"
] | 14 | 2016-06-22T20:45:37.000Z | 2021-07-05T12:25:19.000Z | #pragma once
#include "Kernel/LambdaAffector.h"
namespace Mengine
{
template<class T, class Interpolator>
class LambdaAffectorInterpolate
: public LambdaAffector<T>
{
protected:
Interpolator & getInterpolator()
{
return m_interpolator;
}
protected:
bool _affect( const UpdateContext * _context, float * const _used ) override
{
const EasingInterfacePtr & easing = this->getEasing();
T value;
bool finish = m_interpolator.update( easing, _context, &value, _used );
this->callSettuper( value );
return finish;
}
void _stop() override
{
m_interpolator.stop();
}
protected:
Interpolator m_interpolator;
};
}
| 20.820513 | 84 | 0.573892 |
9ecae72248acb1abcb81022d888c76d2e3c26254 | 11,093 | c | C | src/f32-sigmoid/gen/neonfma-rr1-lut2048-p1-nr1recps1fma-x4.c | shi510/XNNPACK | ea2088b668b760cdc5c67df7d2854320ee34aeb8 | [
"BSD-3-Clause"
] | 1 | 2020-07-16T09:19:15.000Z | 2020-07-16T09:19:15.000Z | src/f32-sigmoid/gen/neonfma-rr1-lut2048-p1-nr1recps1fma-x4.c | shi510/XNNPACK | ea2088b668b760cdc5c67df7d2854320ee34aeb8 | [
"BSD-3-Clause"
] | null | null | null | src/f32-sigmoid/gen/neonfma-rr1-lut2048-p1-nr1recps1fma-x4.c | shi510/XNNPACK | ea2088b668b760cdc5c67df7d2854320ee34aeb8 | [
"BSD-3-Clause"
] | null | null | null | // Auto-generated file. Do not edit!
// Template: src/f32-sigmoid/neon-lut2048-p1.c.in
// Generator: tools/xngen
//
// Copyright 2019 Google LLC
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.
#include <assert.h>
#include <arm_neon.h>
#include <xnnpack/common.h>
#include <xnnpack/vunary.h>
extern XNN_INTERNAL const float xnn_table_exp2_k_over_2048[2048];
void xnn_f32_sigmoid_ukernel__neonfma_rr1_lut2048_p1_nr1recps1fma_x4(
size_t n,
const float* x,
float* y,
const void* params) XNN_DISABLE_TSAN
{
assert(n % sizeof(float) == 0);
const float32x4_t vmagic_bias = vmovq_n_f32(0x1.800000p23f);
// The largest z for which sigmoidf(-z) is normalized.
// This number is also the largest z for which expf(-z) is normalized.
const float32x4_t vdenorm_cutoff = vmovq_n_f32(0x1.5D589Ep+6f);
const float32x4_t vminus_log2e_x2048 = vmovq_n_f32(-0x1.715476p11f);
const float32x4_t vln2_o2048 = vmovq_n_f32(0x1.62E43p-12f);
const float32x4_t vone = vmovq_n_f32(1.0f);
const float32x4_t vc1 = vmovq_n_f32(-0x1.FFFFFEp-1f);
const int32x4_t vindex_mask = vmovq_n_s32(INT32_C(0x7FF));
for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
const float32x4_t vx = vld1q_f32(x); x += 4;
// General structure of the algorithm:
// / exp(x) / (1 + exp(x)) if x <= 0
// f[x] :=
// \ 1 - f[-x] if x >= 0
//
// First we compute f[-z] := exp(-z) / (1 + exp(-z)) where z = abs(x),
// then replace result with 1 - f[-z] if x >= 0.
const float32x4_t vz = vabsq_f32(vx);
// Compute reduced argument n := round(-z * 2048 / log(2)).
// We do it by adding a large number (magic bias), which cause rounding of the result to an integer, then subtracing
// the large number back. The first addition is combined with multiplication by log2e into a single FMA instruction.
// The trick with adding large number is valid only within certain bounds (|z * 2048 / log(2)| <= 2**22, i.e.
// |z| <= 0x1.62E43p+10 = 1419.5654296875), but that is acceptable, because inputs x outside of
// [-87.336544, 17.328678] (i.e. z outsize [0, 87.336544]) underflow or saturate sigmoidf(x). We fixup the result
// for such inputs at the very end of the algorithm.
float32x4_t vn = vfmaq_f32(vmagic_bias, vz, vminus_log2e_x2048);
// Create a floating-point number s (scale) such that s := 2**(n / 2048) for such inputs that sigmoidf(-z) is
// normalized, i.e. 0 <= z <= 87.33642. As n has 11 fractional bits, we split s == 2**(n / 2048) =
// = 2**e * 2**(n / 2048 - e), where e := int(n / 2048). We create s in two steps:
// 1. Fetch 2**(n / 2048 - e) = 2**(n % 2048) from exp2_k_over_2048_table using the 6 low bits of n, as integer. Note that the
// fetched values are in the [1.0, 2.0) range, i.e. their floating-point exponent is 0.
// 2. Adjust fecthed value by addition of e to its floating-point exponent. The result is always a normalized
// number, because for 0 <= z <= 87.33642 (inputs for which sigmoidf(-z) is normalized) we have -126 <= e <= 0,
// and thus the adjusted exponent is not lower than -126.
//
// Extract e from bits 11:19 of n and shift it into bits 23:31 (position of floating-point exponent).
const int32x4_t ve = vshlq_n_s32(vbicq_s32(vreinterpretq_s32_f32(vn), vmovq_n_s32(INT32_C(0x7FF))), 12);
// Use bits 0:11 bits of n, as integer, as an index for table lookup of l := 2**(n % 2048).
const uint64x2_t vidx = vreinterpretq_u64_s32(vandq_s32(vreinterpretq_s32_f32(vn), vindex_mask));
const uint64_t vidx_lo = vgetq_lane_u64(vidx, 0);
const uint64_t vidx_hi = vgetq_lane_u64(vidx, 1);
float32x2_t vl_lo = vld1_dup_f32(&xnn_table_exp2_k_over_2048[(uint32_t) vidx_lo]);
float32x2_t vl_hi = vld1_dup_f32(&xnn_table_exp2_k_over_2048[(uint32_t) vidx_hi]);
vl_lo = vld1_lane_f32(&xnn_table_exp2_k_over_2048[(uint32_t) (vidx_lo >> 32)], vl_lo, 1);
vl_hi = vld1_lane_f32(&xnn_table_exp2_k_over_2048[(uint32_t) (vidx_hi >> 32)], vl_hi, 1);
const float32x4_t vl = vcombine_f32(vl_lo, vl_hi);
// Adjust exponent of the value l fetched from the exp2_k_over_2048_table to get the final s value.
const float32x4_t vs = vreinterpretq_f32_s32(vaddq_s32(vreinterpretq_s32_f32(vl), ve));
// Subtract the large number back to get the final n := round(-z * 2048 / log(2)) as a floating-point number.
vn = vsubq_f32(vn, vmagic_bias);
// Compute reduced argument t := (z + n * log(2) / 2048). Note that -t = -z - n * log(2) / 2048.
float32x4_t vt = vfmaq_f32(vz, vn, vln2_o2048);
// Compute degree-1 polynomial approximation for exp(-t) on [-log(2)/2048, log(2)/2048]:
// P1(t) = 1 + t * c1
const float32x4_t vp = vmulq_f32(vt, vc1);
// Reconstruct the exp(-z) value:
// y = s * (1 + t * c1)
// = s + s * (t * c1))
// = s + s * p
const float32x4_t vy = vfmaq_f32(vs, vs, vp);
// Denominator of the sigmoid fraction: 1.0 + exp(-z)
const float32x4_t vd = vaddq_f32(vy, vone);
// Use Newton-Raphson method (2 iterations) to compute reciprocal of denominator.
// Note: 1 < d <= 2, because z >= 0.0 and 0 < exp(-z) <= 1.0.
// Thus the reciprocal of the denominator never overflows.
float32x4_t vr = vrecpeq_f32(vd);
vr = vmulq_f32(vr, vrecpsq_f32(vr, vd));
vr = vfmaq_f32(vr, vr, vfmsq_f32(vone, vr, vd));
// Reconstruct sigmoid(-z) = exp(-z) / (1.0 + exp(-z))
float32x4_t vf = vmulq_f32(vy, vr);
// For inputs below denormal cutoff, replace output with +0.0f.
// Note that for NaN inputs, comparison result is false, and outputs are left unchanged.
vf = vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(vf), vcagtq_f32(vx, vdenorm_cutoff)));
// Reconstruct sigmoid(x) = x < 0 ? sigmoid(-z) : 1.0 - sigmoid(-z)
const uint32x4_t vm = vcltq_f32(vx, vmovq_n_f32(0.0f));
vf = vbslq_f32(vm, vf, vsubq_f32(vone, vf));
vst1q_f32(y, vf); y += 4;
}
if XNN_UNLIKELY(n != 0) {
const float32x4_t vx = vld1q_f32(x);
// General structure of the algorithm:
// / exp(x) / (1 + exp(x)) if x <= 0
// f[x] :=
// \ 1 - f[-x] if x >= 0
//
// First we compute f[-z] := exp(-z) / (1 + exp(-z)) where z = abs(x),
// then replace result with 1 - f[-z] if x >= 0.
const float32x4_t vz = vabsq_f32(vx);
// Compute reduced argument n := round(-z * 2048 / log(2)).
// We do it by adding a large number (magic bias), which cause rounding of the result to an integer, then subtracing
// the large number back. The first addition is combined with multiplication by log2e into a single FMA instruction.
// The trick with adding large number is valid only within certain bounds (|z * 2048 / log(2)| <= 2**22, i.e.
// |z| <= 0x1.62E43p+10 = 1419.5654296875), but that is acceptable, because inputs x outside of
// [-87.336544, 17.328678] (i.e. z outsize [0, 87.336544]) underflow or saturate sigmoidf(x). We fixup the result
// for such inputs at the very end of the algorithm.
float32x4_t vn = vfmaq_f32(vmagic_bias, vz, vminus_log2e_x2048);
// Create a floating-point number s (scale) such that s := 2**(n / 2048) for such inputs that sigmoidf(-z) is
// normalized, i.e. 0 <= z <= 87.33642. As n has 11 fractional bits, we split s == 2**(n / 2048) =
// = 2**e * 2**(n / 2048 - e), where e := int(n / 2048). We create s in two steps:
// 1. Fetch 2**(n / 2048 - e) = 2**(n % 2048) from exp2_k_over_2048_table using the 6 low bits of n, as integer. Note that the
// fetched values are in the [1.0, 2.0) range, i.e. their floating-point exponent is 0.
// 2. Adjust fecthed value by addition of e to its floating-point exponent. The result is always a normalized
// number, because for 0 <= z <= 87.33642 (inputs for which sigmoidf(-z) is normalized) we have -126 <= e <= 0,
// and thus the adjusted exponent is not lower than -126.
//
// Extract e from bits 11:19 of n and shift it into bits 23:31 (position of floating-point exponent).
const int32x4_t ve = vshlq_n_s32(vbicq_s32(vreinterpretq_s32_f32(vn), vmovq_n_s32(INT32_C(0x7FF))), 12);
// Use bits 0:11 bits of n, as integer, as an index for table lookup of l := 2**(n % 2048).
const uint64x2_t vidx = vreinterpretq_u64_s32(vandq_s32(vreinterpretq_s32_f32(vn), vindex_mask));
const uint64_t vidx_lo = vgetq_lane_u64(vidx, 0);
const uint64_t vidx_hi = vgetq_lane_u64(vidx, 1);
float32x2_t vl_lo = vld1_dup_f32(&xnn_table_exp2_k_over_2048[(uint32_t) vidx_lo]);
float32x2_t vl_hi = vld1_dup_f32(&xnn_table_exp2_k_over_2048[(uint32_t) vidx_hi]);
vl_lo = vld1_lane_f32(&xnn_table_exp2_k_over_2048[(uint32_t) (vidx_lo >> 32)], vl_lo, 1);
vl_hi = vld1_lane_f32(&xnn_table_exp2_k_over_2048[(uint32_t) (vidx_hi >> 32)], vl_hi, 1);
const float32x4_t vl = vcombine_f32(vl_lo, vl_hi);
// Adjust exponent of the value l fetched from the exp2_k_over_2048_table to get the final s value.
const float32x4_t vs = vreinterpretq_f32_s32(vaddq_s32(vreinterpretq_s32_f32(vl), ve));
// Subtract the large number back to get the final n := round(-z * 2048 / log(2)) as a floating-point number.
vn = vsubq_f32(vn, vmagic_bias);
// Compute reduced argument t := (z + n * log(2) / 2048). Note that -t = -z - n * log(2) / 2048.
float32x4_t vt = vfmaq_f32(vz, vn, vln2_o2048);
// Compute degree-1 polynomial approximation for exp(-t) on [-log(2)/2048, log(2)/2048]:
// P1(t) = 1 + t * c1
const float32x4_t vp = vmulq_f32(vt, vc1);
// Reconstruct the exp(-z) value:
// y = s * (1 + t * c1)
// = s + s * (t * c1))
// = s + s * p
const float32x4_t vy = vfmaq_f32(vs, vs, vp);
// Denominator of the sigmoid fraction: 1.0 + exp(-z)
const float32x4_t vd = vaddq_f32(vy, vone);
// Use Newton-Raphson method (2 iterations) to compute reciprocal of denominator.
// Note: 1 < d <= 2, because z >= 0.0 and 0 < exp(-z) <= 1.0.
// Thus the reciprocal of the denominator never overflows.
float32x4_t vr = vrecpeq_f32(vd);
vr = vmulq_f32(vr, vrecpsq_f32(vr, vd));
vr = vfmaq_f32(vr, vr, vfmsq_f32(vone, vr, vd));
// Reconstruct sigmoid(-z) = exp(-z) / (1.0 + exp(-z))
float32x4_t vf = vmulq_f32(vy, vr);
// For inputs below denormal cutoff, replace output with +0.0f.
// Note that for NaN inputs, comparison result is false, and outputs are left unchanged.
vf = vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(vf), vcagtq_f32(vx, vdenorm_cutoff)));
// Reconstruct sigmoid(x) = x < 0 ? sigmoid(-z) : 1.0 - sigmoid(-z)
const uint32x4_t vm = vcltq_f32(vx, vmovq_n_f32(0.0f));
vf = vbslq_f32(vm, vf, vsubq_f32(vone, vf));
float32x2_t vf_lo = vget_low_f32(vf);
if (n & (2 * sizeof(float))) {
vst1_f32(y, vf_lo); y += 2;
vf_lo = vget_high_f32(vf);
}
if (n & (1 * sizeof(float))) {
vst1_lane_f32(y, vf_lo, 0);
}
}
}
| 50.422727 | 130 | 0.653655 |
cfa89fc68d3fa5176989e245f904a56a96cc6575 | 21,209 | h | C | OsiriXAPI.framework/Versions/A/Headers/H5Ppublic.h | nevitdilmen/Osirix-ColorMRI | 47549f97dd09b414742e773f365a4e7143bf2067 | [
"MIT"
] | 20 | 2016-02-02T10:31:41.000Z | 2021-11-08T08:35:25.000Z | OsiriXAPI.framework/Versions/A/Headers/H5Ppublic.h | nevitdilmen/Osirix-ColorMRI | 47549f97dd09b414742e773f365a4e7143bf2067 | [
"MIT"
] | 14 | 2018-01-03T16:49:04.000Z | 2018-06-01T15:19:06.000Z | OsiriXAPI.framework/Versions/A/Headers/H5Ppublic.h | nevitdilmen/Osirix-ColorMRI | 47549f97dd09b414742e773f365a4e7143bf2067 | [
"MIT"
] | 9 | 2018-01-24T21:46:10.000Z | 2022-03-08T09:42:42.000Z | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* This file contains function prototypes for each exported function in the
* H5P module.
*/
#ifndef _H5Ppublic_H
#define _H5Ppublic_H
/* System headers needed by this file */
/* Public headers needed by this file */
#include "H5public.h"
#include "H5Cpublic.h"
#include "H5Dpublic.h"
#include "H5Fpublic.h"
#include "H5FDpublic.h"
#include "H5Ipublic.h"
#include "H5Lpublic.h"
#include "H5MMpublic.h"
#include "H5Tpublic.h"
#include "H5Zpublic.h"
/*****************/
/* Public Macros */
/*****************/
/* When this header is included from a private HDF5 header, don't make calls to H5open() */
#undef H5OPEN
#ifndef _H5private_H
#define H5OPEN H5open(),
#else /* _H5private_H */
#define H5OPEN
#endif /* _H5private_H */
/*
* The library's property list classes
*/
#define H5P_ROOT (H5OPEN H5P_CLS_ROOT_g)
#define H5P_OBJECT_CREATE (H5OPEN H5P_CLS_OBJECT_CREATE_g)
#define H5P_FILE_CREATE (H5OPEN H5P_CLS_FILE_CREATE_g)
#define H5P_FILE_ACCESS (H5OPEN H5P_CLS_FILE_ACCESS_g)
#define H5P_DATASET_CREATE (H5OPEN H5P_CLS_DATASET_CREATE_g)
#define H5P_DATASET_ACCESS (H5OPEN H5P_CLS_DATASET_ACCESS_g)
#define H5P_DATASET_XFER (H5OPEN H5P_CLS_DATASET_XFER_g)
#define H5P_FILE_MOUNT (H5OPEN H5P_CLS_FILE_MOUNT_g)
#define H5P_GROUP_CREATE (H5OPEN H5P_CLS_GROUP_CREATE_g)
#define H5P_GROUP_ACCESS (H5OPEN H5P_CLS_GROUP_ACCESS_g)
#define H5P_DATATYPE_CREATE (H5OPEN H5P_CLS_DATATYPE_CREATE_g)
#define H5P_DATATYPE_ACCESS (H5OPEN H5P_CLS_DATATYPE_ACCESS_g)
#define H5P_STRING_CREATE (H5OPEN H5P_CLS_STRING_CREATE_g)
#define H5P_ATTRIBUTE_CREATE (H5OPEN H5P_CLS_ATTRIBUTE_CREATE_g)
#define H5P_OBJECT_COPY (H5OPEN H5P_CLS_OBJECT_COPY_g)
#define H5P_LINK_CREATE (H5OPEN H5P_CLS_LINK_CREATE_g)
#define H5P_LINK_ACCESS (H5OPEN H5P_CLS_LINK_ACCESS_g)
/*
* The library's default property lists
*/
#define H5P_FILE_CREATE_DEFAULT (H5OPEN H5P_LST_FILE_CREATE_g)
#define H5P_FILE_ACCESS_DEFAULT (H5OPEN H5P_LST_FILE_ACCESS_g)
#define H5P_DATASET_CREATE_DEFAULT (H5OPEN H5P_LST_DATASET_CREATE_g)
#define H5P_DATASET_ACCESS_DEFAULT (H5OPEN H5P_LST_DATASET_ACCESS_g)
#define H5P_DATASET_XFER_DEFAULT (H5OPEN H5P_LST_DATASET_XFER_g)
#define H5P_FILE_MOUNT_DEFAULT (H5OPEN H5P_LST_FILE_MOUNT_g)
#define H5P_GROUP_CREATE_DEFAULT (H5OPEN H5P_LST_GROUP_CREATE_g)
#define H5P_GROUP_ACCESS_DEFAULT (H5OPEN H5P_LST_GROUP_ACCESS_g)
#define H5P_DATATYPE_CREATE_DEFAULT (H5OPEN H5P_LST_DATATYPE_CREATE_g)
#define H5P_DATATYPE_ACCESS_DEFAULT (H5OPEN H5P_LST_DATATYPE_ACCESS_g)
#define H5P_ATTRIBUTE_CREATE_DEFAULT (H5OPEN H5P_LST_ATTRIBUTE_CREATE_g)
#define H5P_OBJECT_COPY_DEFAULT (H5OPEN H5P_LST_OBJECT_COPY_g)
#define H5P_LINK_CREATE_DEFAULT (H5OPEN H5P_LST_LINK_CREATE_g)
#define H5P_LINK_ACCESS_DEFAULT (H5OPEN H5P_LST_LINK_ACCESS_g)
/* Common creation order flags (for links in groups and attributes on objects) */
#define H5P_CRT_ORDER_TRACKED 0x0001
#define H5P_CRT_ORDER_INDEXED 0x0002
#ifdef __cplusplus
extern "C" {
#endif
/*******************/
/* Public Typedefs */
/*******************/
/* Define property list class callback function pointer types */
typedef herr_t (*H5P_cls_create_func_t)(hid_t prop_id, void *create_data);
typedef herr_t (*H5P_cls_copy_func_t)(hid_t new_prop_id, hid_t old_prop_id,
void *copy_data);
typedef herr_t (*H5P_cls_close_func_t)(hid_t prop_id, void *close_data);
/* Define property list callback function pointer types */
typedef herr_t (*H5P_prp_cb1_t)(const char *name, size_t size, void *value);
typedef herr_t (*H5P_prp_cb2_t)(hid_t prop_id, const char *name, size_t size, void *value);
typedef H5P_prp_cb1_t H5P_prp_create_func_t;
typedef H5P_prp_cb2_t H5P_prp_set_func_t;
typedef H5P_prp_cb2_t H5P_prp_get_func_t;
typedef H5P_prp_cb2_t H5P_prp_delete_func_t;
typedef H5P_prp_cb1_t H5P_prp_copy_func_t;
typedef int (*H5P_prp_compare_func_t)(const void *value1, const void *value2, size_t size);
typedef H5P_prp_cb1_t H5P_prp_close_func_t;
/* Define property list iteration function type */
typedef herr_t (*H5P_iterate_t)(hid_t id, const char *name, void *iter_data);
/********************/
/* Public Variables */
/********************/
/* Property list class IDs */
/* (Internal to library, do not use! Use macros above) */
H5_DLLVAR hid_t H5P_CLS_ROOT_g;
H5_DLLVAR hid_t H5P_CLS_OBJECT_CREATE_g;
H5_DLLVAR hid_t H5P_CLS_FILE_CREATE_g;
H5_DLLVAR hid_t H5P_CLS_FILE_ACCESS_g;
H5_DLLVAR hid_t H5P_CLS_DATASET_CREATE_g;
H5_DLLVAR hid_t H5P_CLS_DATASET_ACCESS_g;
H5_DLLVAR hid_t H5P_CLS_DATASET_XFER_g;
H5_DLLVAR hid_t H5P_CLS_FILE_MOUNT_g;
H5_DLLVAR hid_t H5P_CLS_GROUP_CREATE_g;
H5_DLLVAR hid_t H5P_CLS_GROUP_ACCESS_g;
H5_DLLVAR hid_t H5P_CLS_DATATYPE_CREATE_g;
H5_DLLVAR hid_t H5P_CLS_DATATYPE_ACCESS_g;
H5_DLLVAR hid_t H5P_CLS_STRING_CREATE_g;
H5_DLLVAR hid_t H5P_CLS_ATTRIBUTE_CREATE_g;
H5_DLLVAR hid_t H5P_CLS_OBJECT_COPY_g;
H5_DLLVAR hid_t H5P_CLS_LINK_CREATE_g;
H5_DLLVAR hid_t H5P_CLS_LINK_ACCESS_g;
/* Default roperty list IDs */
/* (Internal to library, do not use! Use macros above) */
H5_DLLVAR hid_t H5P_LST_FILE_CREATE_g;
H5_DLLVAR hid_t H5P_LST_FILE_ACCESS_g;
H5_DLLVAR hid_t H5P_LST_DATASET_CREATE_g;
H5_DLLVAR hid_t H5P_LST_DATASET_ACCESS_g;
H5_DLLVAR hid_t H5P_LST_DATASET_XFER_g;
H5_DLLVAR hid_t H5P_LST_FILE_MOUNT_g;
H5_DLLVAR hid_t H5P_LST_GROUP_CREATE_g;
H5_DLLVAR hid_t H5P_LST_GROUP_ACCESS_g;
H5_DLLVAR hid_t H5P_LST_DATATYPE_CREATE_g;
H5_DLLVAR hid_t H5P_LST_DATATYPE_ACCESS_g;
H5_DLLVAR hid_t H5P_LST_ATTRIBUTE_CREATE_g;
H5_DLLVAR hid_t H5P_LST_OBJECT_COPY_g;
H5_DLLVAR hid_t H5P_LST_LINK_CREATE_g;
H5_DLLVAR hid_t H5P_LST_LINK_ACCESS_g;
/*********************/
/* Public Prototypes */
/*********************/
/* Generic property list routines */
H5_DLL hid_t H5Pcreate_class(hid_t parent, const char *name,
H5P_cls_create_func_t cls_create, void *create_data,
H5P_cls_copy_func_t cls_copy, void *copy_data,
H5P_cls_close_func_t cls_close, void *close_data);
H5_DLL char *H5Pget_class_name(hid_t pclass_id);
H5_DLL hid_t H5Pcreate(hid_t cls_id);
H5_DLL herr_t H5Pregister2(hid_t cls_id, const char *name, size_t size,
void *def_value, H5P_prp_create_func_t prp_create,
H5P_prp_set_func_t prp_set, H5P_prp_get_func_t prp_get,
H5P_prp_delete_func_t prp_del, H5P_prp_copy_func_t prp_copy,
H5P_prp_compare_func_t prp_cmp, H5P_prp_close_func_t prp_close);
H5_DLL herr_t H5Pinsert2(hid_t plist_id, const char *name, size_t size,
void *value, H5P_prp_set_func_t prp_set, H5P_prp_get_func_t prp_get,
H5P_prp_delete_func_t prp_delete, H5P_prp_copy_func_t prp_copy,
H5P_prp_compare_func_t prp_cmp, H5P_prp_close_func_t prp_close);
H5_DLL herr_t H5Pset(hid_t plist_id, const char *name, void *value);
H5_DLL htri_t H5Pexist(hid_t plist_id, const char *name);
H5_DLL herr_t H5Pget_size(hid_t id, const char *name, size_t *size);
H5_DLL herr_t H5Pget_nprops(hid_t id, size_t *nprops);
H5_DLL hid_t H5Pget_class(hid_t plist_id);
H5_DLL hid_t H5Pget_class_parent(hid_t pclass_id);
H5_DLL herr_t H5Pget(hid_t plist_id, const char *name, void * value);
H5_DLL htri_t H5Pequal(hid_t id1, hid_t id2);
H5_DLL htri_t H5Pisa_class(hid_t plist_id, hid_t pclass_id);
H5_DLL int H5Piterate(hid_t id, int *idx, H5P_iterate_t iter_func,
void *iter_data);
H5_DLL herr_t H5Pcopy_prop(hid_t dst_id, hid_t src_id, const char *name);
H5_DLL herr_t H5Premove(hid_t plist_id, const char *name);
H5_DLL herr_t H5Punregister(hid_t pclass_id, const char *name);
H5_DLL herr_t H5Pclose_class(hid_t plist_id);
H5_DLL herr_t H5Pclose(hid_t plist_id);
H5_DLL hid_t H5Pcopy(hid_t plist_id);
/* Object creation property list (OCPL) routines */
H5_DLL herr_t H5Pset_attr_phase_change(hid_t plist_id, unsigned max_compact, unsigned min_dense);
H5_DLL herr_t H5Pget_attr_phase_change(hid_t plist_id, unsigned *max_compact, unsigned *min_dense);
H5_DLL herr_t H5Pset_attr_creation_order(hid_t plist_id, unsigned crt_order_flags);
H5_DLL herr_t H5Pget_attr_creation_order(hid_t plist_id, unsigned *crt_order_flags);
H5_DLL herr_t H5Pset_obj_track_times(hid_t plist_id, hbool_t track_times);
H5_DLL herr_t H5Pget_obj_track_times(hid_t plist_id, hbool_t *track_times);
H5_DLL herr_t H5Pmodify_filter(hid_t plist_id, H5Z_filter_t filter,
unsigned int flags, size_t cd_nelmts,
const unsigned int cd_values[/*cd_nelmts*/]);
H5_DLL herr_t H5Pset_filter(hid_t plist_id, H5Z_filter_t filter,
unsigned int flags, size_t cd_nelmts,
const unsigned int c_values[]);
H5_DLL int H5Pget_nfilters(hid_t plist_id);
H5_DLL H5Z_filter_t H5Pget_filter2(hid_t plist_id, unsigned filter,
unsigned int *flags/*out*/,
size_t *cd_nelmts/*out*/,
unsigned cd_values[]/*out*/,
size_t namelen, char name[],
unsigned *filter_config /*out*/);
H5_DLL herr_t H5Pget_filter_by_id2(hid_t plist_id, H5Z_filter_t id,
unsigned int *flags/*out*/, size_t *cd_nelmts/*out*/,
unsigned cd_values[]/*out*/, size_t namelen, char name[]/*out*/,
unsigned *filter_config/*out*/);
H5_DLL htri_t H5Pall_filters_avail(hid_t plist_id);
H5_DLL herr_t H5Premove_filter(hid_t plist_id, H5Z_filter_t filter);
H5_DLL herr_t H5Pset_deflate(hid_t plist_id, unsigned aggression);
H5_DLL herr_t H5Pset_fletcher32(hid_t plist_id);
/* File creation property list (FCPL) routines */
H5_DLL herr_t H5Pget_version(hid_t plist_id, unsigned *boot/*out*/,
unsigned *freelist/*out*/, unsigned *stab/*out*/,
unsigned *shhdr/*out*/);
H5_DLL herr_t H5Pset_userblock(hid_t plist_id, hsize_t size);
H5_DLL herr_t H5Pget_userblock(hid_t plist_id, hsize_t *size);
H5_DLL herr_t H5Pset_sizes(hid_t plist_id, size_t sizeof_addr,
size_t sizeof_size);
H5_DLL herr_t H5Pget_sizes(hid_t plist_id, size_t *sizeof_addr/*out*/,
size_t *sizeof_size/*out*/);
H5_DLL herr_t H5Pset_sym_k(hid_t plist_id, unsigned ik, unsigned lk);
H5_DLL herr_t H5Pget_sym_k(hid_t plist_id, unsigned *ik/*out*/, unsigned *lk/*out*/);
H5_DLL herr_t H5Pset_istore_k(hid_t plist_id, unsigned ik);
H5_DLL herr_t H5Pget_istore_k(hid_t plist_id, unsigned *ik/*out*/);
H5_DLL herr_t H5Pset_shared_mesg_nindexes(hid_t plist_id, unsigned nindexes);
H5_DLL herr_t H5Pget_shared_mesg_nindexes(hid_t plist_id, unsigned *nindexes);
H5_DLL herr_t H5Pset_shared_mesg_index(hid_t plist_id, unsigned index_num, unsigned mesg_type_flags, unsigned min_mesg_size);
H5_DLL herr_t H5Pget_shared_mesg_index(hid_t plist_id, unsigned index_num, unsigned *mesg_type_flags, unsigned *min_mesg_size);
H5_DLL herr_t H5Pset_shared_mesg_phase_change(hid_t plist_id, unsigned max_list, unsigned min_btree);
H5_DLL herr_t H5Pget_shared_mesg_phase_change(hid_t plist_id, unsigned *max_list, unsigned *min_btree);
/* File access property list (FAPL) routines */
H5_DLL herr_t H5Pset_alignment(hid_t fapl_id, hsize_t threshold,
hsize_t alignment);
H5_DLL herr_t H5Pget_alignment(hid_t fapl_id, hsize_t *threshold/*out*/,
hsize_t *alignment/*out*/);
H5_DLL herr_t H5Pset_driver(hid_t plist_id, hid_t driver_id,
const void *driver_info);
H5_DLL hid_t H5Pget_driver(hid_t plist_id);
H5_DLL void *H5Pget_driver_info(hid_t plist_id);
H5_DLL herr_t H5Pset_family_offset(hid_t fapl_id, hsize_t offset);
H5_DLL herr_t H5Pget_family_offset(hid_t fapl_id, hsize_t *offset);
H5_DLL herr_t H5Pset_multi_type(hid_t fapl_id, H5FD_mem_t type);
H5_DLL herr_t H5Pget_multi_type(hid_t fapl_id, H5FD_mem_t *type);
H5_DLL herr_t H5Pset_cache(hid_t plist_id, int mdc_nelmts,
size_t rdcc_nslots, size_t rdcc_nbytes,
double rdcc_w0);
H5_DLL herr_t H5Pget_cache(hid_t plist_id,
int *mdc_nelmts, /* out */
size_t *rdcc_nslots/*out*/,
size_t *rdcc_nbytes/*out*/, double *rdcc_w0);
H5_DLL herr_t H5Pset_mdc_config(hid_t plist_id,
H5AC_cache_config_t * config_ptr);
H5_DLL herr_t H5Pget_mdc_config(hid_t plist_id,
H5AC_cache_config_t * config_ptr); /* out */
H5_DLL herr_t H5Pset_gc_references(hid_t fapl_id, unsigned gc_ref);
H5_DLL herr_t H5Pget_gc_references(hid_t fapl_id, unsigned *gc_ref/*out*/);
H5_DLL herr_t H5Pset_fclose_degree(hid_t fapl_id, H5F_close_degree_t degree);
H5_DLL herr_t H5Pget_fclose_degree(hid_t fapl_id, H5F_close_degree_t *degree);
H5_DLL herr_t H5Pset_meta_block_size(hid_t fapl_id, hsize_t size);
H5_DLL herr_t H5Pget_meta_block_size(hid_t fapl_id, hsize_t *size/*out*/);
H5_DLL herr_t H5Pset_sieve_buf_size(hid_t fapl_id, size_t size);
H5_DLL herr_t H5Pget_sieve_buf_size(hid_t fapl_id, size_t *size/*out*/);
H5_DLL herr_t H5Pset_small_data_block_size(hid_t fapl_id, hsize_t size);
H5_DLL herr_t H5Pget_small_data_block_size(hid_t fapl_id, hsize_t *size/*out*/);
H5_DLL herr_t H5Pset_libver_bounds(hid_t plist_id, H5F_libver_t low,
H5F_libver_t high);
H5_DLL herr_t H5Pget_libver_bounds(hid_t plist_id, H5F_libver_t *low,
H5F_libver_t *high);
/* Dataset creation property list (DCPL) routines */
H5_DLL herr_t H5Pset_layout(hid_t plist_id, H5D_layout_t layout);
H5_DLL H5D_layout_t H5Pget_layout(hid_t plist_id);
H5_DLL herr_t H5Pset_chunk(hid_t plist_id, int ndims, const hsize_t dim[/*ndims*/]);
H5_DLL int H5Pget_chunk(hid_t plist_id, int max_ndims, hsize_t dim[]/*out*/);
H5_DLL herr_t H5Pset_external(hid_t plist_id, const char *name, off_t offset,
hsize_t size);
H5_DLL int H5Pget_external_count(hid_t plist_id);
H5_DLL herr_t H5Pget_external(hid_t plist_id, unsigned idx, size_t name_size,
char *name/*out*/, off_t *offset/*out*/,
hsize_t *size/*out*/);
H5_DLL herr_t H5Pset_szip(hid_t plist_id, unsigned options_mask, unsigned pixels_per_block);
H5_DLL herr_t H5Pset_shuffle(hid_t plist_id);
H5_DLL herr_t H5Pset_nbit(hid_t plist_id);
H5_DLL herr_t H5Pset_scaleoffset(hid_t plist_id, H5Z_SO_scale_type_t scale_type, int scale_factor);
H5_DLL herr_t H5Pset_fill_value(hid_t plist_id, hid_t type_id,
const void *value);
H5_DLL herr_t H5Pget_fill_value(hid_t plist_id, hid_t type_id,
void *value/*out*/);
H5_DLL herr_t H5Pfill_value_defined(hid_t plist, H5D_fill_value_t *status);
H5_DLL herr_t H5Pset_alloc_time(hid_t plist_id, H5D_alloc_time_t
alloc_time);
H5_DLL herr_t H5Pget_alloc_time(hid_t plist_id, H5D_alloc_time_t
*alloc_time/*out*/);
H5_DLL herr_t H5Pset_fill_time(hid_t plist_id, H5D_fill_time_t fill_time);
H5_DLL herr_t H5Pget_fill_time(hid_t plist_id, H5D_fill_time_t
*fill_time/*out*/);
/* Dataset access property list (DAPL) routines */
H5_DLL herr_t H5Pset_chunk_cache(hid_t dapl_id, size_t rdcc_nslots,
size_t rdcc_nbytes, double rdcc_w0);
H5_DLL herr_t H5Pget_chunk_cache(hid_t dapl_id,
size_t *rdcc_nslots/*out*/,
size_t *rdcc_nbytes/*out*/,
double *rdcc_w0/*out*/);
/* Dataset xfer property list (DXPL) routines */
H5_DLL herr_t H5Pset_data_transform(hid_t plist_id, const char* expression);
H5_DLL ssize_t H5Pget_data_transform(hid_t plist_id, char* expression /*out*/, size_t size);
H5_DLL herr_t H5Pset_buffer(hid_t plist_id, size_t size, void *tconv,
void *bkg);
H5_DLL size_t H5Pget_buffer(hid_t plist_id, void **tconv/*out*/,
void **bkg/*out*/);
H5_DLL herr_t H5Pset_preserve(hid_t plist_id, hbool_t status);
H5_DLL int H5Pget_preserve(hid_t plist_id);
H5_DLL herr_t H5Pset_edc_check(hid_t plist_id, H5Z_EDC_t check);
H5_DLL H5Z_EDC_t H5Pget_edc_check(hid_t plist_id);
H5_DLL herr_t H5Pset_filter_callback(hid_t plist_id, H5Z_filter_func_t func,
void* op_data);
H5_DLL herr_t H5Pset_btree_ratios(hid_t plist_id, double left, double middle,
double right);
H5_DLL herr_t H5Pget_btree_ratios(hid_t plist_id, double *left/*out*/,
double *middle/*out*/,
double *right/*out*/);
H5_DLL herr_t H5Pset_vlen_mem_manager(hid_t plist_id,
H5MM_allocate_t alloc_func,
void *alloc_info, H5MM_free_t free_func,
void *free_info);
H5_DLL herr_t H5Pget_vlen_mem_manager(hid_t plist_id,
H5MM_allocate_t *alloc_func,
void **alloc_info,
H5MM_free_t *free_func,
void **free_info);
H5_DLL herr_t H5Pset_hyper_vector_size(hid_t fapl_id, size_t size);
H5_DLL herr_t H5Pget_hyper_vector_size(hid_t fapl_id, size_t *size/*out*/);
H5_DLL herr_t H5Pset_type_conv_cb(hid_t dxpl_id, H5T_conv_except_func_t op, void* operate_data);
H5_DLL herr_t H5Pget_type_conv_cb(hid_t dxpl_id, H5T_conv_except_func_t *op, void** operate_data);
/* Link creation property list (LCPL) routines */
H5_DLL herr_t H5Pset_create_intermediate_group(hid_t plist_id, unsigned crt_intmd);
H5_DLL herr_t H5Pget_create_intermediate_group(hid_t plist_id, unsigned *crt_intmd /*out*/);
/* Group creation property list (GCPL) routines */
H5_DLL herr_t H5Pset_local_heap_size_hint(hid_t plist_id, size_t size_hint);
H5_DLL herr_t H5Pget_local_heap_size_hint(hid_t plist_id, size_t *size_hint /*out*/);
H5_DLL herr_t H5Pset_link_phase_change(hid_t plist_id, unsigned max_compact, unsigned min_dense);
H5_DLL herr_t H5Pget_link_phase_change(hid_t plist_id, unsigned *max_compact /*out*/, unsigned *min_dense /*out*/);
H5_DLL herr_t H5Pset_est_link_info(hid_t plist_id, unsigned est_num_entries, unsigned est_name_len);
H5_DLL herr_t H5Pget_est_link_info(hid_t plist_id, unsigned *est_num_entries /* out */, unsigned *est_name_len /* out */);
H5_DLL herr_t H5Pset_link_creation_order(hid_t plist_id, unsigned crt_order_flags);
H5_DLL herr_t H5Pget_link_creation_order(hid_t plist_id, unsigned *crt_order_flags /* out */);
/* String creation property list (STRCPL) routines */
H5_DLL herr_t H5Pset_char_encoding(hid_t plist_id, H5T_cset_t encoding);
H5_DLL herr_t H5Pget_char_encoding(hid_t plist_id, H5T_cset_t *encoding /*out*/);
/* Link access property list (LAPL) routines */
H5_DLL herr_t H5Pset_nlinks(hid_t plist_id, size_t nlinks);
H5_DLL herr_t H5Pget_nlinks(hid_t plist_id, size_t *nlinks);
H5_DLL herr_t H5Pset_elink_prefix(hid_t plist_id, const char *prefix);
H5_DLL ssize_t H5Pget_elink_prefix(hid_t plist_id, char *prefix, size_t size);
H5_DLL hid_t H5Pget_elink_fapl(hid_t lapl_id);
H5_DLL herr_t H5Pset_elink_fapl(hid_t lapl_id, hid_t fapl_id);
H5_DLL herr_t H5Pset_elink_acc_flags(hid_t lapl_id, unsigned flags);
H5_DLL herr_t H5Pget_elink_acc_flags(hid_t lapl_id, unsigned *flags);
H5_DLL herr_t H5Pset_elink_cb(hid_t lapl_id, H5L_elink_traverse_t func, void *op_data);
H5_DLL herr_t H5Pget_elink_cb(hid_t lapl_id, H5L_elink_traverse_t *func, void **op_data);
/* Object copy property list (OCPYPL) routines */
H5_DLL herr_t H5Pset_copy_object(hid_t plist_id, unsigned crt_intmd);
H5_DLL herr_t H5Pget_copy_object(hid_t plist_id, unsigned *crt_intmd /*out*/);
/* Symbols defined for compatibility with previous versions of the HDF5 API.
*
* Use of these symbols is deprecated.
*/
#ifndef H5_NO_DEPRECATED_SYMBOLS
/* Macros */
/* We renamed the "root" of the property list class hierarchy */
#define H5P_NO_CLASS H5P_ROOT
/* Typedefs */
/* Function prototypes */
H5_DLL herr_t H5Pregister1(hid_t cls_id, const char *name, size_t size,
void *def_value, H5P_prp_create_func_t prp_create,
H5P_prp_set_func_t prp_set, H5P_prp_get_func_t prp_get,
H5P_prp_delete_func_t prp_del, H5P_prp_copy_func_t prp_copy,
H5P_prp_close_func_t prp_close);
H5_DLL herr_t H5Pinsert1(hid_t plist_id, const char *name, size_t size,
void *value, H5P_prp_set_func_t prp_set, H5P_prp_get_func_t prp_get,
H5P_prp_delete_func_t prp_delete, H5P_prp_copy_func_t prp_copy,
H5P_prp_close_func_t prp_close);
H5_DLL H5Z_filter_t H5Pget_filter1(hid_t plist_id, unsigned filter,
unsigned int *flags/*out*/, size_t *cd_nelmts/*out*/,
unsigned cd_values[]/*out*/, size_t namelen, char name[]);
H5_DLL herr_t H5Pget_filter_by_id1(hid_t plist_id, H5Z_filter_t id,
unsigned int *flags/*out*/, size_t *cd_nelmts/*out*/,
unsigned cd_values[]/*out*/, size_t namelen, char name[]/*out*/);
#endif /* H5_NO_DEPRECATED_SYMBOLS */
#ifdef __cplusplus
}
#endif
#endif /* _H5Ppublic_H */
| 48.981524 | 127 | 0.763261 |
3c0732857751dcb07ebffcff5216dcecf8d8a274 | 1,166 | h | C | examples/pursuit/channels.h | PositronicsLab/tcs | c43bc3244b3c68cd1b42358afd18d5a0716d3e0f | [
"Apache-2.0"
] | null | null | null | examples/pursuit/channels.h | PositronicsLab/tcs | c43bc3244b3c68cd1b42358afd18d5a0716d3e0f | [
"Apache-2.0"
] | null | null | null | examples/pursuit/channels.h | PositronicsLab/tcs | c43bc3244b3c68cd1b42358afd18d5a0716d3e0f | [
"Apache-2.0"
] | null | null | null | #ifndef _CHANNELS_H_
#define _CHANNELS_H_
//-----------------------------------------------------------------------------
#define FD_TIMER_TO_COORDINATOR_READ_CHANNEL 1001
#define FD_TIMER_TO_COORDINATOR_WRITE_CHANNEL 1002
#define FD_WAKEUP_TO_COORDINATOR_READ_CHANNEL 1003
#define FD_WAKEUP_TO_COORDINATOR_WRITE_CHANNEL 1004
#define FD_COORDINATOR_TO_PREYCONTROLLER_READ_CHANNEL 1010
#define FD_COORDINATOR_TO_PREYCONTROLLER_WRITE_CHANNEL 1011
#define FD_PREYCONTROLLER_TO_COORDINATOR_READ_CHANNEL 1012
#define FD_PREYCONTROLLER_TO_COORDINATOR_WRITE_CHANNEL 1013
#define FD_COORDINATOR_TO_PREDPLANNER_READ_CHANNEL 1014
#define FD_COORDINATOR_TO_PREDPLANNER_WRITE_CHANNEL 1015
#define FD_PREDPLANNER_TO_COORDINATOR_READ_CHANNEL 1016
#define FD_PREDPLANNER_TO_COORDINATOR_WRITE_CHANNEL 1017
#define FD_COORDINATOR_TO_PREDCONTROLLER_READ_CHANNEL 1018
#define FD_COORDINATOR_TO_PREDCONTROLLER_WRITE_CHANNEL 1019
#define FD_PREDCONTROLLER_TO_COORDINATOR_READ_CHANNEL 1020
#define FD_PREDCONTROLLER_TO_COORDINATOR_WRITE_CHANNEL 1021
//-----------------------------------------------------------------------------
#endif // _CHANNELS_H_
| 35.333333 | 79 | 0.767581 |
2ce12e3edac87b2e33c2a6c12d41733c5ee652ea | 100 | h | C | include/front.h | journey-c/lyuling | afac8c08cd11d2bb31e46869c8db46c07d6ce09e | [
"MIT"
] | null | null | null | include/front.h | journey-c/lyuling | afac8c08cd11d2bb31e46869c8db46c07d6ce09e | [
"MIT"
] | null | null | null | include/front.h | journey-c/lyuling | afac8c08cd11d2bb31e46869c8db46c07d6ce09e | [
"MIT"
] | null | null | null | #ifndef _FRONT_H_
#define _FRONT_H_
extern void *front_listen(void * arg);
#endif /* _FRONT_H_ */
| 14.285714 | 38 | 0.73 |
7e14c0d328f1f3f27aa7cb6bf4159fce0df423a4 | 48,448 | h | C | arch/mips/include/asm/octeon/cvmx-pko-defs.h | fergy/aplit_linux-5 | a6ef4cb0e17e1eec9743c064e65f730c49765711 | [
"MIT"
] | 44 | 2022-03-16T08:32:31.000Z | 2022-03-31T16:02:35.000Z | arch/mips/include/asm/octeon/cvmx-pko-defs.h | fergy/aplit_linux-5 | a6ef4cb0e17e1eec9743c064e65f730c49765711 | [
"MIT"
] | 13 | 2021-07-10T04:36:17.000Z | 2022-03-03T10:50:05.000Z | arch/mips/include/asm/octeon/cvmx-pko-defs.h | fergy/aplit_linux-5 | a6ef4cb0e17e1eec9743c064e65f730c49765711 | [
"MIT"
] | 18 | 2022-03-19T04:41:04.000Z | 2022-03-31T03:32:12.000Z | /***********************license start***************
* Author: Cavium Networks
*
* Contact: support@caviumnetworks.com
* This file is part of the OCTEON SDK
*
* Copyright (c) 2003-2012 Cavium Networks
*
* This file 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.
*
* This file is distributed in the hope that it will be useful, but
* AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
* NONINFRINGEMENT. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this file; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* or visit http://www.gnu.org/licenses/.
*
* This file may also be available under a different license from Cavium.
* Contact Cavium Networks for more information
***********************license end**************************************/
#ifndef __CVMX_PKO_DEFS_H__
#define __CVMX_PKO_DEFS_H__
#define CVMX_PKO_MEM_COUNT0 (CVMX_ADD_IO_SEG(0x0001180050001080ull))
#define CVMX_PKO_MEM_COUNT1 (CVMX_ADD_IO_SEG(0x0001180050001088ull))
#define CVMX_PKO_MEM_DEBUG0 (CVMX_ADD_IO_SEG(0x0001180050001100ull))
#define CVMX_PKO_MEM_DEBUG1 (CVMX_ADD_IO_SEG(0x0001180050001108ull))
#define CVMX_PKO_MEM_DEBUG10 (CVMX_ADD_IO_SEG(0x0001180050001150ull))
#define CVMX_PKO_MEM_DEBUG11 (CVMX_ADD_IO_SEG(0x0001180050001158ull))
#define CVMX_PKO_MEM_DEBUG12 (CVMX_ADD_IO_SEG(0x0001180050001160ull))
#define CVMX_PKO_MEM_DEBUG13 (CVMX_ADD_IO_SEG(0x0001180050001168ull))
#define CVMX_PKO_MEM_DEBUG14 (CVMX_ADD_IO_SEG(0x0001180050001170ull))
#define CVMX_PKO_MEM_DEBUG2 (CVMX_ADD_IO_SEG(0x0001180050001110ull))
#define CVMX_PKO_MEM_DEBUG3 (CVMX_ADD_IO_SEG(0x0001180050001118ull))
#define CVMX_PKO_MEM_DEBUG4 (CVMX_ADD_IO_SEG(0x0001180050001120ull))
#define CVMX_PKO_MEM_DEBUG5 (CVMX_ADD_IO_SEG(0x0001180050001128ull))
#define CVMX_PKO_MEM_DEBUG6 (CVMX_ADD_IO_SEG(0x0001180050001130ull))
#define CVMX_PKO_MEM_DEBUG7 (CVMX_ADD_IO_SEG(0x0001180050001138ull))
#define CVMX_PKO_MEM_DEBUG8 (CVMX_ADD_IO_SEG(0x0001180050001140ull))
#define CVMX_PKO_MEM_DEBUG9 (CVMX_ADD_IO_SEG(0x0001180050001148ull))
#define CVMX_PKO_MEM_IPORT_PTRS (CVMX_ADD_IO_SEG(0x0001180050001030ull))
#define CVMX_PKO_MEM_IPORT_QOS (CVMX_ADD_IO_SEG(0x0001180050001038ull))
#define CVMX_PKO_MEM_IQUEUE_PTRS (CVMX_ADD_IO_SEG(0x0001180050001040ull))
#define CVMX_PKO_MEM_IQUEUE_QOS (CVMX_ADD_IO_SEG(0x0001180050001048ull))
#define CVMX_PKO_MEM_PORT_PTRS (CVMX_ADD_IO_SEG(0x0001180050001010ull))
#define CVMX_PKO_MEM_PORT_QOS (CVMX_ADD_IO_SEG(0x0001180050001018ull))
#define CVMX_PKO_MEM_PORT_RATE0 (CVMX_ADD_IO_SEG(0x0001180050001020ull))
#define CVMX_PKO_MEM_PORT_RATE1 (CVMX_ADD_IO_SEG(0x0001180050001028ull))
#define CVMX_PKO_MEM_QUEUE_PTRS (CVMX_ADD_IO_SEG(0x0001180050001000ull))
#define CVMX_PKO_MEM_QUEUE_QOS (CVMX_ADD_IO_SEG(0x0001180050001008ull))
#define CVMX_PKO_MEM_THROTTLE_INT (CVMX_ADD_IO_SEG(0x0001180050001058ull))
#define CVMX_PKO_MEM_THROTTLE_PIPE (CVMX_ADD_IO_SEG(0x0001180050001050ull))
#define CVMX_PKO_REG_BIST_RESULT (CVMX_ADD_IO_SEG(0x0001180050000080ull))
#define CVMX_PKO_REG_CMD_BUF (CVMX_ADD_IO_SEG(0x0001180050000010ull))
#define CVMX_PKO_REG_CRC_CTLX(offset) (CVMX_ADD_IO_SEG(0x0001180050000028ull) + ((offset) & 1) * 8)
#define CVMX_PKO_REG_CRC_ENABLE (CVMX_ADD_IO_SEG(0x0001180050000020ull))
#define CVMX_PKO_REG_CRC_IVX(offset) (CVMX_ADD_IO_SEG(0x0001180050000038ull) + ((offset) & 1) * 8)
#define CVMX_PKO_REG_DEBUG0 (CVMX_ADD_IO_SEG(0x0001180050000098ull))
#define CVMX_PKO_REG_DEBUG1 (CVMX_ADD_IO_SEG(0x00011800500000A0ull))
#define CVMX_PKO_REG_DEBUG2 (CVMX_ADD_IO_SEG(0x00011800500000A8ull))
#define CVMX_PKO_REG_DEBUG3 (CVMX_ADD_IO_SEG(0x00011800500000B0ull))
#define CVMX_PKO_REG_DEBUG4 (CVMX_ADD_IO_SEG(0x00011800500000B8ull))
#define CVMX_PKO_REG_ENGINE_INFLIGHT (CVMX_ADD_IO_SEG(0x0001180050000050ull))
#define CVMX_PKO_REG_ENGINE_INFLIGHT1 (CVMX_ADD_IO_SEG(0x0001180050000318ull))
#define CVMX_PKO_REG_ENGINE_STORAGEX(offset) (CVMX_ADD_IO_SEG(0x0001180050000300ull) + ((offset) & 1) * 8)
#define CVMX_PKO_REG_ENGINE_THRESH (CVMX_ADD_IO_SEG(0x0001180050000058ull))
#define CVMX_PKO_REG_ERROR (CVMX_ADD_IO_SEG(0x0001180050000088ull))
#define CVMX_PKO_REG_FLAGS (CVMX_ADD_IO_SEG(0x0001180050000000ull))
#define CVMX_PKO_REG_GMX_PORT_MODE (CVMX_ADD_IO_SEG(0x0001180050000018ull))
#define CVMX_PKO_REG_INT_MASK (CVMX_ADD_IO_SEG(0x0001180050000090ull))
#define CVMX_PKO_REG_LOOPBACK_BPID (CVMX_ADD_IO_SEG(0x0001180050000118ull))
#define CVMX_PKO_REG_LOOPBACK_PKIND (CVMX_ADD_IO_SEG(0x0001180050000068ull))
#define CVMX_PKO_REG_MIN_PKT (CVMX_ADD_IO_SEG(0x0001180050000070ull))
#define CVMX_PKO_REG_PREEMPT (CVMX_ADD_IO_SEG(0x0001180050000110ull))
#define CVMX_PKO_REG_QUEUE_MODE (CVMX_ADD_IO_SEG(0x0001180050000048ull))
#define CVMX_PKO_REG_QUEUE_PREEMPT (CVMX_ADD_IO_SEG(0x0001180050000108ull))
#define CVMX_PKO_REG_QUEUE_PTRS1 (CVMX_ADD_IO_SEG(0x0001180050000100ull))
#define CVMX_PKO_REG_READ_IDX (CVMX_ADD_IO_SEG(0x0001180050000008ull))
#define CVMX_PKO_REG_THROTTLE (CVMX_ADD_IO_SEG(0x0001180050000078ull))
#define CVMX_PKO_REG_TIMESTAMP (CVMX_ADD_IO_SEG(0x0001180050000060ull))
union cvmx_pko_mem_count0 {
uint64_t u64;
struct cvmx_pko_mem_count0_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_32_63:32;
uint64_t count:32;
#else
uint64_t count:32;
uint64_t reserved_32_63:32;
#endif
} s;
};
union cvmx_pko_mem_count1 {
uint64_t u64;
struct cvmx_pko_mem_count1_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_48_63:16;
uint64_t count:48;
#else
uint64_t count:48;
uint64_t reserved_48_63:16;
#endif
} s;
};
union cvmx_pko_mem_debug0 {
uint64_t u64;
struct cvmx_pko_mem_debug0_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t fau:28;
uint64_t cmd:14;
uint64_t segs:6;
uint64_t size:16;
#else
uint64_t size:16;
uint64_t segs:6;
uint64_t cmd:14;
uint64_t fau:28;
#endif
} s;
};
union cvmx_pko_mem_debug1 {
uint64_t u64;
struct cvmx_pko_mem_debug1_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t i:1;
uint64_t back:4;
uint64_t pool:3;
uint64_t size:16;
uint64_t ptr:40;
#else
uint64_t ptr:40;
uint64_t size:16;
uint64_t pool:3;
uint64_t back:4;
uint64_t i:1;
#endif
} s;
};
union cvmx_pko_mem_debug10 {
uint64_t u64;
struct cvmx_pko_mem_debug10_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_0_63:64;
#else
uint64_t reserved_0_63:64;
#endif
} s;
struct cvmx_pko_mem_debug10_cn30xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t fau:28;
uint64_t cmd:14;
uint64_t segs:6;
uint64_t size:16;
#else
uint64_t size:16;
uint64_t segs:6;
uint64_t cmd:14;
uint64_t fau:28;
#endif
} cn30xx;
struct cvmx_pko_mem_debug10_cn50xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_49_63:15;
uint64_t ptrs1:17;
uint64_t reserved_17_31:15;
uint64_t ptrs2:17;
#else
uint64_t ptrs2:17;
uint64_t reserved_17_31:15;
uint64_t ptrs1:17;
uint64_t reserved_49_63:15;
#endif
} cn50xx;
};
union cvmx_pko_mem_debug11 {
uint64_t u64;
struct cvmx_pko_mem_debug11_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t i:1;
uint64_t back:4;
uint64_t pool:3;
uint64_t size:16;
uint64_t reserved_0_39:40;
#else
uint64_t reserved_0_39:40;
uint64_t size:16;
uint64_t pool:3;
uint64_t back:4;
uint64_t i:1;
#endif
} s;
struct cvmx_pko_mem_debug11_cn30xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t i:1;
uint64_t back:4;
uint64_t pool:3;
uint64_t size:16;
uint64_t ptr:40;
#else
uint64_t ptr:40;
uint64_t size:16;
uint64_t pool:3;
uint64_t back:4;
uint64_t i:1;
#endif
} cn30xx;
struct cvmx_pko_mem_debug11_cn50xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_23_63:41;
uint64_t maj:1;
uint64_t uid:3;
uint64_t sop:1;
uint64_t len:1;
uint64_t chk:1;
uint64_t cnt:13;
uint64_t mod:3;
#else
uint64_t mod:3;
uint64_t cnt:13;
uint64_t chk:1;
uint64_t len:1;
uint64_t sop:1;
uint64_t uid:3;
uint64_t maj:1;
uint64_t reserved_23_63:41;
#endif
} cn50xx;
};
union cvmx_pko_mem_debug12 {
uint64_t u64;
struct cvmx_pko_mem_debug12_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_0_63:64;
#else
uint64_t reserved_0_63:64;
#endif
} s;
struct cvmx_pko_mem_debug12_cn30xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t data:64;
#else
uint64_t data:64;
#endif
} cn30xx;
struct cvmx_pko_mem_debug12_cn50xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t fau:28;
uint64_t cmd:14;
uint64_t segs:6;
uint64_t size:16;
#else
uint64_t size:16;
uint64_t segs:6;
uint64_t cmd:14;
uint64_t fau:28;
#endif
} cn50xx;
struct cvmx_pko_mem_debug12_cn68xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t state:64;
#else
uint64_t state:64;
#endif
} cn68xx;
};
union cvmx_pko_mem_debug13 {
uint64_t u64;
struct cvmx_pko_mem_debug13_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_0_63:64;
#else
uint64_t reserved_0_63:64;
#endif
} s;
struct cvmx_pko_mem_debug13_cn30xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_51_63:13;
uint64_t widx:17;
uint64_t ridx2:17;
uint64_t widx2:17;
#else
uint64_t widx2:17;
uint64_t ridx2:17;
uint64_t widx:17;
uint64_t reserved_51_63:13;
#endif
} cn30xx;
struct cvmx_pko_mem_debug13_cn50xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t i:1;
uint64_t back:4;
uint64_t pool:3;
uint64_t size:16;
uint64_t ptr:40;
#else
uint64_t ptr:40;
uint64_t size:16;
uint64_t pool:3;
uint64_t back:4;
uint64_t i:1;
#endif
} cn50xx;
struct cvmx_pko_mem_debug13_cn68xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t state:64;
#else
uint64_t state:64;
#endif
} cn68xx;
};
union cvmx_pko_mem_debug14 {
uint64_t u64;
struct cvmx_pko_mem_debug14_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_0_63:64;
#else
uint64_t reserved_0_63:64;
#endif
} s;
struct cvmx_pko_mem_debug14_cn30xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_17_63:47;
uint64_t ridx:17;
#else
uint64_t ridx:17;
uint64_t reserved_17_63:47;
#endif
} cn30xx;
struct cvmx_pko_mem_debug14_cn52xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t data:64;
#else
uint64_t data:64;
#endif
} cn52xx;
};
union cvmx_pko_mem_debug2 {
uint64_t u64;
struct cvmx_pko_mem_debug2_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t i:1;
uint64_t back:4;
uint64_t pool:3;
uint64_t size:16;
uint64_t ptr:40;
#else
uint64_t ptr:40;
uint64_t size:16;
uint64_t pool:3;
uint64_t back:4;
uint64_t i:1;
#endif
} s;
};
union cvmx_pko_mem_debug3 {
uint64_t u64;
struct cvmx_pko_mem_debug3_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_0_63:64;
#else
uint64_t reserved_0_63:64;
#endif
} s;
struct cvmx_pko_mem_debug3_cn30xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t i:1;
uint64_t back:4;
uint64_t pool:3;
uint64_t size:16;
uint64_t ptr:40;
#else
uint64_t ptr:40;
uint64_t size:16;
uint64_t pool:3;
uint64_t back:4;
uint64_t i:1;
#endif
} cn30xx;
struct cvmx_pko_mem_debug3_cn50xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t data:64;
#else
uint64_t data:64;
#endif
} cn50xx;
};
union cvmx_pko_mem_debug4 {
uint64_t u64;
struct cvmx_pko_mem_debug4_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_0_63:64;
#else
uint64_t reserved_0_63:64;
#endif
} s;
struct cvmx_pko_mem_debug4_cn30xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t data:64;
#else
uint64_t data:64;
#endif
} cn30xx;
struct cvmx_pko_mem_debug4_cn50xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t cmnd_segs:3;
uint64_t cmnd_siz:16;
uint64_t cmnd_off:6;
uint64_t uid:3;
uint64_t dread_sop:1;
uint64_t init_dwrite:1;
uint64_t chk_once:1;
uint64_t chk_mode:1;
uint64_t active:1;
uint64_t static_p:1;
uint64_t qos:3;
uint64_t qcb_ridx:5;
uint64_t qid_off_max:4;
uint64_t qid_off:4;
uint64_t qid_base:8;
uint64_t wait:1;
uint64_t minor:2;
uint64_t major:3;
#else
uint64_t major:3;
uint64_t minor:2;
uint64_t wait:1;
uint64_t qid_base:8;
uint64_t qid_off:4;
uint64_t qid_off_max:4;
uint64_t qcb_ridx:5;
uint64_t qos:3;
uint64_t static_p:1;
uint64_t active:1;
uint64_t chk_mode:1;
uint64_t chk_once:1;
uint64_t init_dwrite:1;
uint64_t dread_sop:1;
uint64_t uid:3;
uint64_t cmnd_off:6;
uint64_t cmnd_siz:16;
uint64_t cmnd_segs:3;
#endif
} cn50xx;
struct cvmx_pko_mem_debug4_cn52xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t curr_siz:8;
uint64_t curr_off:16;
uint64_t cmnd_segs:6;
uint64_t cmnd_siz:16;
uint64_t cmnd_off:6;
uint64_t uid:2;
uint64_t dread_sop:1;
uint64_t init_dwrite:1;
uint64_t chk_once:1;
uint64_t chk_mode:1;
uint64_t wait:1;
uint64_t minor:2;
uint64_t major:3;
#else
uint64_t major:3;
uint64_t minor:2;
uint64_t wait:1;
uint64_t chk_mode:1;
uint64_t chk_once:1;
uint64_t init_dwrite:1;
uint64_t dread_sop:1;
uint64_t uid:2;
uint64_t cmnd_off:6;
uint64_t cmnd_siz:16;
uint64_t cmnd_segs:6;
uint64_t curr_off:16;
uint64_t curr_siz:8;
#endif
} cn52xx;
};
union cvmx_pko_mem_debug5 {
uint64_t u64;
struct cvmx_pko_mem_debug5_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_0_63:64;
#else
uint64_t reserved_0_63:64;
#endif
} s;
struct cvmx_pko_mem_debug5_cn30xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t dwri_mod:1;
uint64_t dwri_sop:1;
uint64_t dwri_len:1;
uint64_t dwri_cnt:13;
uint64_t cmnd_siz:16;
uint64_t uid:1;
uint64_t xfer_wor:1;
uint64_t xfer_dwr:1;
uint64_t cbuf_fre:1;
uint64_t reserved_27_27:1;
uint64_t chk_mode:1;
uint64_t active:1;
uint64_t qos:3;
uint64_t qcb_ridx:5;
uint64_t qid_off:3;
uint64_t qid_base:7;
uint64_t wait:1;
uint64_t minor:2;
uint64_t major:4;
#else
uint64_t major:4;
uint64_t minor:2;
uint64_t wait:1;
uint64_t qid_base:7;
uint64_t qid_off:3;
uint64_t qcb_ridx:5;
uint64_t qos:3;
uint64_t active:1;
uint64_t chk_mode:1;
uint64_t reserved_27_27:1;
uint64_t cbuf_fre:1;
uint64_t xfer_dwr:1;
uint64_t xfer_wor:1;
uint64_t uid:1;
uint64_t cmnd_siz:16;
uint64_t dwri_cnt:13;
uint64_t dwri_len:1;
uint64_t dwri_sop:1;
uint64_t dwri_mod:1;
#endif
} cn30xx;
struct cvmx_pko_mem_debug5_cn50xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t curr_ptr:29;
uint64_t curr_siz:16;
uint64_t curr_off:16;
uint64_t cmnd_segs:3;
#else
uint64_t cmnd_segs:3;
uint64_t curr_off:16;
uint64_t curr_siz:16;
uint64_t curr_ptr:29;
#endif
} cn50xx;
struct cvmx_pko_mem_debug5_cn52xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_54_63:10;
uint64_t nxt_inflt:6;
uint64_t curr_ptr:40;
uint64_t curr_siz:8;
#else
uint64_t curr_siz:8;
uint64_t curr_ptr:40;
uint64_t nxt_inflt:6;
uint64_t reserved_54_63:10;
#endif
} cn52xx;
struct cvmx_pko_mem_debug5_cn61xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_56_63:8;
uint64_t ptp:1;
uint64_t major_3:1;
uint64_t nxt_inflt:6;
uint64_t curr_ptr:40;
uint64_t curr_siz:8;
#else
uint64_t curr_siz:8;
uint64_t curr_ptr:40;
uint64_t nxt_inflt:6;
uint64_t major_3:1;
uint64_t ptp:1;
uint64_t reserved_56_63:8;
#endif
} cn61xx;
struct cvmx_pko_mem_debug5_cn68xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_57_63:7;
uint64_t uid_2:1;
uint64_t ptp:1;
uint64_t major_3:1;
uint64_t nxt_inflt:6;
uint64_t curr_ptr:40;
uint64_t curr_siz:8;
#else
uint64_t curr_siz:8;
uint64_t curr_ptr:40;
uint64_t nxt_inflt:6;
uint64_t major_3:1;
uint64_t ptp:1;
uint64_t uid_2:1;
uint64_t reserved_57_63:7;
#endif
} cn68xx;
};
union cvmx_pko_mem_debug6 {
uint64_t u64;
struct cvmx_pko_mem_debug6_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_37_63:27;
uint64_t qid_offres:4;
uint64_t qid_offths:4;
uint64_t preempter:1;
uint64_t preemptee:1;
uint64_t preempted:1;
uint64_t active:1;
uint64_t statc:1;
uint64_t qos:3;
uint64_t qcb_ridx:5;
uint64_t qid_offmax:4;
uint64_t reserved_0_11:12;
#else
uint64_t reserved_0_11:12;
uint64_t qid_offmax:4;
uint64_t qcb_ridx:5;
uint64_t qos:3;
uint64_t statc:1;
uint64_t active:1;
uint64_t preempted:1;
uint64_t preemptee:1;
uint64_t preempter:1;
uint64_t qid_offths:4;
uint64_t qid_offres:4;
uint64_t reserved_37_63:27;
#endif
} s;
struct cvmx_pko_mem_debug6_cn30xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_11_63:53;
uint64_t qid_offm:3;
uint64_t static_p:1;
uint64_t work_min:3;
uint64_t dwri_chk:1;
uint64_t dwri_uid:1;
uint64_t dwri_mod:2;
#else
uint64_t dwri_mod:2;
uint64_t dwri_uid:1;
uint64_t dwri_chk:1;
uint64_t work_min:3;
uint64_t static_p:1;
uint64_t qid_offm:3;
uint64_t reserved_11_63:53;
#endif
} cn30xx;
struct cvmx_pko_mem_debug6_cn50xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_11_63:53;
uint64_t curr_ptr:11;
#else
uint64_t curr_ptr:11;
uint64_t reserved_11_63:53;
#endif
} cn50xx;
struct cvmx_pko_mem_debug6_cn52xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_37_63:27;
uint64_t qid_offres:4;
uint64_t qid_offths:4;
uint64_t preempter:1;
uint64_t preemptee:1;
uint64_t preempted:1;
uint64_t active:1;
uint64_t statc:1;
uint64_t qos:3;
uint64_t qcb_ridx:5;
uint64_t qid_offmax:4;
uint64_t qid_off:4;
uint64_t qid_base:8;
#else
uint64_t qid_base:8;
uint64_t qid_off:4;
uint64_t qid_offmax:4;
uint64_t qcb_ridx:5;
uint64_t qos:3;
uint64_t statc:1;
uint64_t active:1;
uint64_t preempted:1;
uint64_t preemptee:1;
uint64_t preempter:1;
uint64_t qid_offths:4;
uint64_t qid_offres:4;
uint64_t reserved_37_63:27;
#endif
} cn52xx;
};
union cvmx_pko_mem_debug7 {
uint64_t u64;
struct cvmx_pko_mem_debug7_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_0_63:64;
#else
uint64_t reserved_0_63:64;
#endif
} s;
struct cvmx_pko_mem_debug7_cn30xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_58_63:6;
uint64_t dwb:9;
uint64_t start:33;
uint64_t size:16;
#else
uint64_t size:16;
uint64_t start:33;
uint64_t dwb:9;
uint64_t reserved_58_63:6;
#endif
} cn30xx;
struct cvmx_pko_mem_debug7_cn50xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t qos:5;
uint64_t tail:1;
uint64_t buf_siz:13;
uint64_t buf_ptr:33;
uint64_t qcb_widx:6;
uint64_t qcb_ridx:6;
#else
uint64_t qcb_ridx:6;
uint64_t qcb_widx:6;
uint64_t buf_ptr:33;
uint64_t buf_siz:13;
uint64_t tail:1;
uint64_t qos:5;
#endif
} cn50xx;
struct cvmx_pko_mem_debug7_cn68xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t qos:3;
uint64_t tail:1;
uint64_t buf_siz:13;
uint64_t buf_ptr:33;
uint64_t qcb_widx:7;
uint64_t qcb_ridx:7;
#else
uint64_t qcb_ridx:7;
uint64_t qcb_widx:7;
uint64_t buf_ptr:33;
uint64_t buf_siz:13;
uint64_t tail:1;
uint64_t qos:3;
#endif
} cn68xx;
};
union cvmx_pko_mem_debug8 {
uint64_t u64;
struct cvmx_pko_mem_debug8_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_59_63:5;
uint64_t tail:1;
uint64_t buf_siz:13;
uint64_t reserved_0_44:45;
#else
uint64_t reserved_0_44:45;
uint64_t buf_siz:13;
uint64_t tail:1;
uint64_t reserved_59_63:5;
#endif
} s;
struct cvmx_pko_mem_debug8_cn30xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t qos:5;
uint64_t tail:1;
uint64_t buf_siz:13;
uint64_t buf_ptr:33;
uint64_t qcb_widx:6;
uint64_t qcb_ridx:6;
#else
uint64_t qcb_ridx:6;
uint64_t qcb_widx:6;
uint64_t buf_ptr:33;
uint64_t buf_siz:13;
uint64_t tail:1;
uint64_t qos:5;
#endif
} cn30xx;
struct cvmx_pko_mem_debug8_cn50xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_28_63:36;
uint64_t doorbell:20;
uint64_t reserved_6_7:2;
uint64_t static_p:1;
uint64_t s_tail:1;
uint64_t static_q:1;
uint64_t qos:3;
#else
uint64_t qos:3;
uint64_t static_q:1;
uint64_t s_tail:1;
uint64_t static_p:1;
uint64_t reserved_6_7:2;
uint64_t doorbell:20;
uint64_t reserved_28_63:36;
#endif
} cn50xx;
struct cvmx_pko_mem_debug8_cn52xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_29_63:35;
uint64_t preempter:1;
uint64_t doorbell:20;
uint64_t reserved_7_7:1;
uint64_t preemptee:1;
uint64_t static_p:1;
uint64_t s_tail:1;
uint64_t static_q:1;
uint64_t qos:3;
#else
uint64_t qos:3;
uint64_t static_q:1;
uint64_t s_tail:1;
uint64_t static_p:1;
uint64_t preemptee:1;
uint64_t reserved_7_7:1;
uint64_t doorbell:20;
uint64_t preempter:1;
uint64_t reserved_29_63:35;
#endif
} cn52xx;
struct cvmx_pko_mem_debug8_cn61xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_42_63:22;
uint64_t qid_qqos:8;
uint64_t reserved_33_33:1;
uint64_t qid_idx:4;
uint64_t preempter:1;
uint64_t doorbell:20;
uint64_t reserved_7_7:1;
uint64_t preemptee:1;
uint64_t static_p:1;
uint64_t s_tail:1;
uint64_t static_q:1;
uint64_t qos:3;
#else
uint64_t qos:3;
uint64_t static_q:1;
uint64_t s_tail:1;
uint64_t static_p:1;
uint64_t preemptee:1;
uint64_t reserved_7_7:1;
uint64_t doorbell:20;
uint64_t preempter:1;
uint64_t qid_idx:4;
uint64_t reserved_33_33:1;
uint64_t qid_qqos:8;
uint64_t reserved_42_63:22;
#endif
} cn61xx;
struct cvmx_pko_mem_debug8_cn68xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_37_63:27;
uint64_t preempter:1;
uint64_t doorbell:20;
uint64_t reserved_9_15:7;
uint64_t preemptee:1;
uint64_t static_p:1;
uint64_t s_tail:1;
uint64_t static_q:1;
uint64_t qos:5;
#else
uint64_t qos:5;
uint64_t static_q:1;
uint64_t s_tail:1;
uint64_t static_p:1;
uint64_t preemptee:1;
uint64_t reserved_9_15:7;
uint64_t doorbell:20;
uint64_t preempter:1;
uint64_t reserved_37_63:27;
#endif
} cn68xx;
};
union cvmx_pko_mem_debug9 {
uint64_t u64;
struct cvmx_pko_mem_debug9_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_49_63:15;
uint64_t ptrs0:17;
uint64_t reserved_0_31:32;
#else
uint64_t reserved_0_31:32;
uint64_t ptrs0:17;
uint64_t reserved_49_63:15;
#endif
} s;
struct cvmx_pko_mem_debug9_cn30xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_28_63:36;
uint64_t doorbell:20;
uint64_t reserved_5_7:3;
uint64_t s_tail:1;
uint64_t static_q:1;
uint64_t qos:3;
#else
uint64_t qos:3;
uint64_t static_q:1;
uint64_t s_tail:1;
uint64_t reserved_5_7:3;
uint64_t doorbell:20;
uint64_t reserved_28_63:36;
#endif
} cn30xx;
struct cvmx_pko_mem_debug9_cn38xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_28_63:36;
uint64_t doorbell:20;
uint64_t reserved_6_7:2;
uint64_t static_p:1;
uint64_t s_tail:1;
uint64_t static_q:1;
uint64_t qos:3;
#else
uint64_t qos:3;
uint64_t static_q:1;
uint64_t s_tail:1;
uint64_t static_p:1;
uint64_t reserved_6_7:2;
uint64_t doorbell:20;
uint64_t reserved_28_63:36;
#endif
} cn38xx;
struct cvmx_pko_mem_debug9_cn50xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_49_63:15;
uint64_t ptrs0:17;
uint64_t reserved_17_31:15;
uint64_t ptrs3:17;
#else
uint64_t ptrs3:17;
uint64_t reserved_17_31:15;
uint64_t ptrs0:17;
uint64_t reserved_49_63:15;
#endif
} cn50xx;
};
union cvmx_pko_mem_iport_ptrs {
uint64_t u64;
struct cvmx_pko_mem_iport_ptrs_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_63_63:1;
uint64_t crc:1;
uint64_t static_p:1;
uint64_t qos_mask:8;
uint64_t min_pkt:3;
uint64_t reserved_31_49:19;
uint64_t pipe:7;
uint64_t reserved_21_23:3;
uint64_t intr:5;
uint64_t reserved_13_15:3;
uint64_t eid:5;
uint64_t reserved_7_7:1;
uint64_t ipid:7;
#else
uint64_t ipid:7;
uint64_t reserved_7_7:1;
uint64_t eid:5;
uint64_t reserved_13_15:3;
uint64_t intr:5;
uint64_t reserved_21_23:3;
uint64_t pipe:7;
uint64_t reserved_31_49:19;
uint64_t min_pkt:3;
uint64_t qos_mask:8;
uint64_t static_p:1;
uint64_t crc:1;
uint64_t reserved_63_63:1;
#endif
} s;
};
union cvmx_pko_mem_iport_qos {
uint64_t u64;
struct cvmx_pko_mem_iport_qos_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_61_63:3;
uint64_t qos_mask:8;
uint64_t reserved_13_52:40;
uint64_t eid:5;
uint64_t reserved_7_7:1;
uint64_t ipid:7;
#else
uint64_t ipid:7;
uint64_t reserved_7_7:1;
uint64_t eid:5;
uint64_t reserved_13_52:40;
uint64_t qos_mask:8;
uint64_t reserved_61_63:3;
#endif
} s;
};
union cvmx_pko_mem_iqueue_ptrs {
uint64_t u64;
struct cvmx_pko_mem_iqueue_ptrs_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t s_tail:1;
uint64_t static_p:1;
uint64_t static_q:1;
uint64_t qos_mask:8;
uint64_t buf_ptr:31;
uint64_t tail:1;
uint64_t index:5;
uint64_t reserved_15_15:1;
uint64_t ipid:7;
uint64_t qid:8;
#else
uint64_t qid:8;
uint64_t ipid:7;
uint64_t reserved_15_15:1;
uint64_t index:5;
uint64_t tail:1;
uint64_t buf_ptr:31;
uint64_t qos_mask:8;
uint64_t static_q:1;
uint64_t static_p:1;
uint64_t s_tail:1;
#endif
} s;
};
union cvmx_pko_mem_iqueue_qos {
uint64_t u64;
struct cvmx_pko_mem_iqueue_qos_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_61_63:3;
uint64_t qos_mask:8;
uint64_t reserved_15_52:38;
uint64_t ipid:7;
uint64_t qid:8;
#else
uint64_t qid:8;
uint64_t ipid:7;
uint64_t reserved_15_52:38;
uint64_t qos_mask:8;
uint64_t reserved_61_63:3;
#endif
} s;
};
union cvmx_pko_mem_port_ptrs {
uint64_t u64;
struct cvmx_pko_mem_port_ptrs_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_62_63:2;
uint64_t static_p:1;
uint64_t qos_mask:8;
uint64_t reserved_16_52:37;
uint64_t bp_port:6;
uint64_t eid:4;
uint64_t pid:6;
#else
uint64_t pid:6;
uint64_t eid:4;
uint64_t bp_port:6;
uint64_t reserved_16_52:37;
uint64_t qos_mask:8;
uint64_t static_p:1;
uint64_t reserved_62_63:2;
#endif
} s;
};
union cvmx_pko_mem_port_qos {
uint64_t u64;
struct cvmx_pko_mem_port_qos_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_61_63:3;
uint64_t qos_mask:8;
uint64_t reserved_10_52:43;
uint64_t eid:4;
uint64_t pid:6;
#else
uint64_t pid:6;
uint64_t eid:4;
uint64_t reserved_10_52:43;
uint64_t qos_mask:8;
uint64_t reserved_61_63:3;
#endif
} s;
};
union cvmx_pko_mem_port_rate0 {
uint64_t u64;
struct cvmx_pko_mem_port_rate0_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_51_63:13;
uint64_t rate_word:19;
uint64_t rate_pkt:24;
uint64_t reserved_7_7:1;
uint64_t pid:7;
#else
uint64_t pid:7;
uint64_t reserved_7_7:1;
uint64_t rate_pkt:24;
uint64_t rate_word:19;
uint64_t reserved_51_63:13;
#endif
} s;
struct cvmx_pko_mem_port_rate0_cn52xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_51_63:13;
uint64_t rate_word:19;
uint64_t rate_pkt:24;
uint64_t reserved_6_7:2;
uint64_t pid:6;
#else
uint64_t pid:6;
uint64_t reserved_6_7:2;
uint64_t rate_pkt:24;
uint64_t rate_word:19;
uint64_t reserved_51_63:13;
#endif
} cn52xx;
};
union cvmx_pko_mem_port_rate1 {
uint64_t u64;
struct cvmx_pko_mem_port_rate1_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_32_63:32;
uint64_t rate_lim:24;
uint64_t reserved_7_7:1;
uint64_t pid:7;
#else
uint64_t pid:7;
uint64_t reserved_7_7:1;
uint64_t rate_lim:24;
uint64_t reserved_32_63:32;
#endif
} s;
struct cvmx_pko_mem_port_rate1_cn52xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_32_63:32;
uint64_t rate_lim:24;
uint64_t reserved_6_7:2;
uint64_t pid:6;
#else
uint64_t pid:6;
uint64_t reserved_6_7:2;
uint64_t rate_lim:24;
uint64_t reserved_32_63:32;
#endif
} cn52xx;
};
union cvmx_pko_mem_queue_ptrs {
uint64_t u64;
struct cvmx_pko_mem_queue_ptrs_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t s_tail:1;
uint64_t static_p:1;
uint64_t static_q:1;
uint64_t qos_mask:8;
uint64_t buf_ptr:36;
uint64_t tail:1;
uint64_t index:3;
uint64_t port:6;
uint64_t queue:7;
#else
uint64_t queue:7;
uint64_t port:6;
uint64_t index:3;
uint64_t tail:1;
uint64_t buf_ptr:36;
uint64_t qos_mask:8;
uint64_t static_q:1;
uint64_t static_p:1;
uint64_t s_tail:1;
#endif
} s;
};
union cvmx_pko_mem_queue_qos {
uint64_t u64;
struct cvmx_pko_mem_queue_qos_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_61_63:3;
uint64_t qos_mask:8;
uint64_t reserved_13_52:40;
uint64_t pid:6;
uint64_t qid:7;
#else
uint64_t qid:7;
uint64_t pid:6;
uint64_t reserved_13_52:40;
uint64_t qos_mask:8;
uint64_t reserved_61_63:3;
#endif
} s;
};
union cvmx_pko_mem_throttle_int {
uint64_t u64;
struct cvmx_pko_mem_throttle_int_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_47_63:17;
uint64_t word:15;
uint64_t reserved_14_31:18;
uint64_t packet:6;
uint64_t reserved_5_7:3;
uint64_t intr:5;
#else
uint64_t intr:5;
uint64_t reserved_5_7:3;
uint64_t packet:6;
uint64_t reserved_14_31:18;
uint64_t word:15;
uint64_t reserved_47_63:17;
#endif
} s;
};
union cvmx_pko_mem_throttle_pipe {
uint64_t u64;
struct cvmx_pko_mem_throttle_pipe_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_47_63:17;
uint64_t word:15;
uint64_t reserved_14_31:18;
uint64_t packet:6;
uint64_t reserved_7_7:1;
uint64_t pipe:7;
#else
uint64_t pipe:7;
uint64_t reserved_7_7:1;
uint64_t packet:6;
uint64_t reserved_14_31:18;
uint64_t word:15;
uint64_t reserved_47_63:17;
#endif
} s;
};
union cvmx_pko_reg_bist_result {
uint64_t u64;
struct cvmx_pko_reg_bist_result_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_0_63:64;
#else
uint64_t reserved_0_63:64;
#endif
} s;
struct cvmx_pko_reg_bist_result_cn30xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_27_63:37;
uint64_t psb2:5;
uint64_t count:1;
uint64_t rif:1;
uint64_t wif:1;
uint64_t ncb:1;
uint64_t out:1;
uint64_t crc:1;
uint64_t chk:1;
uint64_t qsb:2;
uint64_t qcb:2;
uint64_t pdb:4;
uint64_t psb:7;
#else
uint64_t psb:7;
uint64_t pdb:4;
uint64_t qcb:2;
uint64_t qsb:2;
uint64_t chk:1;
uint64_t crc:1;
uint64_t out:1;
uint64_t ncb:1;
uint64_t wif:1;
uint64_t rif:1;
uint64_t count:1;
uint64_t psb2:5;
uint64_t reserved_27_63:37;
#endif
} cn30xx;
struct cvmx_pko_reg_bist_result_cn50xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_33_63:31;
uint64_t csr:1;
uint64_t iob:1;
uint64_t out_crc:1;
uint64_t out_ctl:3;
uint64_t out_sta:1;
uint64_t out_wif:1;
uint64_t prt_chk:3;
uint64_t prt_nxt:1;
uint64_t prt_psb:6;
uint64_t ncb_inb:2;
uint64_t prt_qcb:2;
uint64_t prt_qsb:3;
uint64_t dat_dat:4;
uint64_t dat_ptr:4;
#else
uint64_t dat_ptr:4;
uint64_t dat_dat:4;
uint64_t prt_qsb:3;
uint64_t prt_qcb:2;
uint64_t ncb_inb:2;
uint64_t prt_psb:6;
uint64_t prt_nxt:1;
uint64_t prt_chk:3;
uint64_t out_wif:1;
uint64_t out_sta:1;
uint64_t out_ctl:3;
uint64_t out_crc:1;
uint64_t iob:1;
uint64_t csr:1;
uint64_t reserved_33_63:31;
#endif
} cn50xx;
struct cvmx_pko_reg_bist_result_cn52xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_35_63:29;
uint64_t csr:1;
uint64_t iob:1;
uint64_t out_dat:1;
uint64_t out_ctl:3;
uint64_t out_sta:1;
uint64_t out_wif:1;
uint64_t prt_chk:3;
uint64_t prt_nxt:1;
uint64_t prt_psb:8;
uint64_t ncb_inb:2;
uint64_t prt_qcb:2;
uint64_t prt_qsb:3;
uint64_t prt_ctl:2;
uint64_t dat_dat:2;
uint64_t dat_ptr:4;
#else
uint64_t dat_ptr:4;
uint64_t dat_dat:2;
uint64_t prt_ctl:2;
uint64_t prt_qsb:3;
uint64_t prt_qcb:2;
uint64_t ncb_inb:2;
uint64_t prt_psb:8;
uint64_t prt_nxt:1;
uint64_t prt_chk:3;
uint64_t out_wif:1;
uint64_t out_sta:1;
uint64_t out_ctl:3;
uint64_t out_dat:1;
uint64_t iob:1;
uint64_t csr:1;
uint64_t reserved_35_63:29;
#endif
} cn52xx;
struct cvmx_pko_reg_bist_result_cn68xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_36_63:28;
uint64_t crc:1;
uint64_t csr:1;
uint64_t iob:1;
uint64_t out_dat:1;
uint64_t reserved_31_31:1;
uint64_t out_ctl:2;
uint64_t out_sta:1;
uint64_t out_wif:1;
uint64_t prt_chk:3;
uint64_t prt_nxt:1;
uint64_t prt_psb7:1;
uint64_t reserved_21_21:1;
uint64_t prt_psb:6;
uint64_t ncb_inb:2;
uint64_t prt_qcb:2;
uint64_t prt_qsb:3;
uint64_t prt_ctl:2;
uint64_t dat_dat:2;
uint64_t dat_ptr:4;
#else
uint64_t dat_ptr:4;
uint64_t dat_dat:2;
uint64_t prt_ctl:2;
uint64_t prt_qsb:3;
uint64_t prt_qcb:2;
uint64_t ncb_inb:2;
uint64_t prt_psb:6;
uint64_t reserved_21_21:1;
uint64_t prt_psb7:1;
uint64_t prt_nxt:1;
uint64_t prt_chk:3;
uint64_t out_wif:1;
uint64_t out_sta:1;
uint64_t out_ctl:2;
uint64_t reserved_31_31:1;
uint64_t out_dat:1;
uint64_t iob:1;
uint64_t csr:1;
uint64_t crc:1;
uint64_t reserved_36_63:28;
#endif
} cn68xx;
struct cvmx_pko_reg_bist_result_cn68xxp1 {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_35_63:29;
uint64_t csr:1;
uint64_t iob:1;
uint64_t out_dat:1;
uint64_t reserved_31_31:1;
uint64_t out_ctl:2;
uint64_t out_sta:1;
uint64_t out_wif:1;
uint64_t prt_chk:3;
uint64_t prt_nxt:1;
uint64_t prt_psb7:1;
uint64_t reserved_21_21:1;
uint64_t prt_psb:6;
uint64_t ncb_inb:2;
uint64_t prt_qcb:2;
uint64_t prt_qsb:3;
uint64_t prt_ctl:2;
uint64_t dat_dat:2;
uint64_t dat_ptr:4;
#else
uint64_t dat_ptr:4;
uint64_t dat_dat:2;
uint64_t prt_ctl:2;
uint64_t prt_qsb:3;
uint64_t prt_qcb:2;
uint64_t ncb_inb:2;
uint64_t prt_psb:6;
uint64_t reserved_21_21:1;
uint64_t prt_psb7:1;
uint64_t prt_nxt:1;
uint64_t prt_chk:3;
uint64_t out_wif:1;
uint64_t out_sta:1;
uint64_t out_ctl:2;
uint64_t reserved_31_31:1;
uint64_t out_dat:1;
uint64_t iob:1;
uint64_t csr:1;
uint64_t reserved_35_63:29;
#endif
} cn68xxp1;
};
union cvmx_pko_reg_cmd_buf {
uint64_t u64;
struct cvmx_pko_reg_cmd_buf_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_23_63:41;
uint64_t pool:3;
uint64_t reserved_13_19:7;
uint64_t size:13;
#else
uint64_t size:13;
uint64_t reserved_13_19:7;
uint64_t pool:3;
uint64_t reserved_23_63:41;
#endif
} s;
};
union cvmx_pko_reg_crc_ctlx {
uint64_t u64;
struct cvmx_pko_reg_crc_ctlx_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_2_63:62;
uint64_t invres:1;
uint64_t refin:1;
#else
uint64_t refin:1;
uint64_t invres:1;
uint64_t reserved_2_63:62;
#endif
} s;
};
union cvmx_pko_reg_crc_enable {
uint64_t u64;
struct cvmx_pko_reg_crc_enable_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_32_63:32;
uint64_t enable:32;
#else
uint64_t enable:32;
uint64_t reserved_32_63:32;
#endif
} s;
};
union cvmx_pko_reg_crc_ivx {
uint64_t u64;
struct cvmx_pko_reg_crc_ivx_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_32_63:32;
uint64_t iv:32;
#else
uint64_t iv:32;
uint64_t reserved_32_63:32;
#endif
} s;
};
union cvmx_pko_reg_debug0 {
uint64_t u64;
struct cvmx_pko_reg_debug0_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t asserts:64;
#else
uint64_t asserts:64;
#endif
} s;
struct cvmx_pko_reg_debug0_cn30xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_17_63:47;
uint64_t asserts:17;
#else
uint64_t asserts:17;
uint64_t reserved_17_63:47;
#endif
} cn30xx;
};
union cvmx_pko_reg_debug1 {
uint64_t u64;
struct cvmx_pko_reg_debug1_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t asserts:64;
#else
uint64_t asserts:64;
#endif
} s;
};
union cvmx_pko_reg_debug2 {
uint64_t u64;
struct cvmx_pko_reg_debug2_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t asserts:64;
#else
uint64_t asserts:64;
#endif
} s;
};
union cvmx_pko_reg_debug3 {
uint64_t u64;
struct cvmx_pko_reg_debug3_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t asserts:64;
#else
uint64_t asserts:64;
#endif
} s;
};
union cvmx_pko_reg_debug4 {
uint64_t u64;
struct cvmx_pko_reg_debug4_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t asserts:64;
#else
uint64_t asserts:64;
#endif
} s;
};
union cvmx_pko_reg_engine_inflight {
uint64_t u64;
struct cvmx_pko_reg_engine_inflight_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t engine15:4;
uint64_t engine14:4;
uint64_t engine13:4;
uint64_t engine12:4;
uint64_t engine11:4;
uint64_t engine10:4;
uint64_t engine9:4;
uint64_t engine8:4;
uint64_t engine7:4;
uint64_t engine6:4;
uint64_t engine5:4;
uint64_t engine4:4;
uint64_t engine3:4;
uint64_t engine2:4;
uint64_t engine1:4;
uint64_t engine0:4;
#else
uint64_t engine0:4;
uint64_t engine1:4;
uint64_t engine2:4;
uint64_t engine3:4;
uint64_t engine4:4;
uint64_t engine5:4;
uint64_t engine6:4;
uint64_t engine7:4;
uint64_t engine8:4;
uint64_t engine9:4;
uint64_t engine10:4;
uint64_t engine11:4;
uint64_t engine12:4;
uint64_t engine13:4;
uint64_t engine14:4;
uint64_t engine15:4;
#endif
} s;
struct cvmx_pko_reg_engine_inflight_cn52xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_40_63:24;
uint64_t engine9:4;
uint64_t engine8:4;
uint64_t engine7:4;
uint64_t engine6:4;
uint64_t engine5:4;
uint64_t engine4:4;
uint64_t engine3:4;
uint64_t engine2:4;
uint64_t engine1:4;
uint64_t engine0:4;
#else
uint64_t engine0:4;
uint64_t engine1:4;
uint64_t engine2:4;
uint64_t engine3:4;
uint64_t engine4:4;
uint64_t engine5:4;
uint64_t engine6:4;
uint64_t engine7:4;
uint64_t engine8:4;
uint64_t engine9:4;
uint64_t reserved_40_63:24;
#endif
} cn52xx;
struct cvmx_pko_reg_engine_inflight_cn61xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_56_63:8;
uint64_t engine13:4;
uint64_t engine12:4;
uint64_t engine11:4;
uint64_t engine10:4;
uint64_t engine9:4;
uint64_t engine8:4;
uint64_t engine7:4;
uint64_t engine6:4;
uint64_t engine5:4;
uint64_t engine4:4;
uint64_t engine3:4;
uint64_t engine2:4;
uint64_t engine1:4;
uint64_t engine0:4;
#else
uint64_t engine0:4;
uint64_t engine1:4;
uint64_t engine2:4;
uint64_t engine3:4;
uint64_t engine4:4;
uint64_t engine5:4;
uint64_t engine6:4;
uint64_t engine7:4;
uint64_t engine8:4;
uint64_t engine9:4;
uint64_t engine10:4;
uint64_t engine11:4;
uint64_t engine12:4;
uint64_t engine13:4;
uint64_t reserved_56_63:8;
#endif
} cn61xx;
struct cvmx_pko_reg_engine_inflight_cn63xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_48_63:16;
uint64_t engine11:4;
uint64_t engine10:4;
uint64_t engine9:4;
uint64_t engine8:4;
uint64_t engine7:4;
uint64_t engine6:4;
uint64_t engine5:4;
uint64_t engine4:4;
uint64_t engine3:4;
uint64_t engine2:4;
uint64_t engine1:4;
uint64_t engine0:4;
#else
uint64_t engine0:4;
uint64_t engine1:4;
uint64_t engine2:4;
uint64_t engine3:4;
uint64_t engine4:4;
uint64_t engine5:4;
uint64_t engine6:4;
uint64_t engine7:4;
uint64_t engine8:4;
uint64_t engine9:4;
uint64_t engine10:4;
uint64_t engine11:4;
uint64_t reserved_48_63:16;
#endif
} cn63xx;
};
union cvmx_pko_reg_engine_inflight1 {
uint64_t u64;
struct cvmx_pko_reg_engine_inflight1_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_16_63:48;
uint64_t engine19:4;
uint64_t engine18:4;
uint64_t engine17:4;
uint64_t engine16:4;
#else
uint64_t engine16:4;
uint64_t engine17:4;
uint64_t engine18:4;
uint64_t engine19:4;
uint64_t reserved_16_63:48;
#endif
} s;
};
union cvmx_pko_reg_engine_storagex {
uint64_t u64;
struct cvmx_pko_reg_engine_storagex_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t engine15:4;
uint64_t engine14:4;
uint64_t engine13:4;
uint64_t engine12:4;
uint64_t engine11:4;
uint64_t engine10:4;
uint64_t engine9:4;
uint64_t engine8:4;
uint64_t engine7:4;
uint64_t engine6:4;
uint64_t engine5:4;
uint64_t engine4:4;
uint64_t engine3:4;
uint64_t engine2:4;
uint64_t engine1:4;
uint64_t engine0:4;
#else
uint64_t engine0:4;
uint64_t engine1:4;
uint64_t engine2:4;
uint64_t engine3:4;
uint64_t engine4:4;
uint64_t engine5:4;
uint64_t engine6:4;
uint64_t engine7:4;
uint64_t engine8:4;
uint64_t engine9:4;
uint64_t engine10:4;
uint64_t engine11:4;
uint64_t engine12:4;
uint64_t engine13:4;
uint64_t engine14:4;
uint64_t engine15:4;
#endif
} s;
};
union cvmx_pko_reg_engine_thresh {
uint64_t u64;
struct cvmx_pko_reg_engine_thresh_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_20_63:44;
uint64_t mask:20;
#else
uint64_t mask:20;
uint64_t reserved_20_63:44;
#endif
} s;
struct cvmx_pko_reg_engine_thresh_cn52xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_10_63:54;
uint64_t mask:10;
#else
uint64_t mask:10;
uint64_t reserved_10_63:54;
#endif
} cn52xx;
struct cvmx_pko_reg_engine_thresh_cn61xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_14_63:50;
uint64_t mask:14;
#else
uint64_t mask:14;
uint64_t reserved_14_63:50;
#endif
} cn61xx;
struct cvmx_pko_reg_engine_thresh_cn63xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_12_63:52;
uint64_t mask:12;
#else
uint64_t mask:12;
uint64_t reserved_12_63:52;
#endif
} cn63xx;
};
union cvmx_pko_reg_error {
uint64_t u64;
struct cvmx_pko_reg_error_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_4_63:60;
uint64_t loopback:1;
uint64_t currzero:1;
uint64_t doorbell:1;
uint64_t parity:1;
#else
uint64_t parity:1;
uint64_t doorbell:1;
uint64_t currzero:1;
uint64_t loopback:1;
uint64_t reserved_4_63:60;
#endif
} s;
struct cvmx_pko_reg_error_cn30xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_2_63:62;
uint64_t doorbell:1;
uint64_t parity:1;
#else
uint64_t parity:1;
uint64_t doorbell:1;
uint64_t reserved_2_63:62;
#endif
} cn30xx;
struct cvmx_pko_reg_error_cn50xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_3_63:61;
uint64_t currzero:1;
uint64_t doorbell:1;
uint64_t parity:1;
#else
uint64_t parity:1;
uint64_t doorbell:1;
uint64_t currzero:1;
uint64_t reserved_3_63:61;
#endif
} cn50xx;
};
union cvmx_pko_reg_flags {
uint64_t u64;
struct cvmx_pko_reg_flags_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_9_63:55;
uint64_t dis_perf3:1;
uint64_t dis_perf2:1;
uint64_t dis_perf1:1;
uint64_t dis_perf0:1;
uint64_t ena_throttle:1;
uint64_t reset:1;
uint64_t store_be:1;
uint64_t ena_dwb:1;
uint64_t ena_pko:1;
#else
uint64_t ena_pko:1;
uint64_t ena_dwb:1;
uint64_t store_be:1;
uint64_t reset:1;
uint64_t ena_throttle:1;
uint64_t dis_perf0:1;
uint64_t dis_perf1:1;
uint64_t dis_perf2:1;
uint64_t dis_perf3:1;
uint64_t reserved_9_63:55;
#endif
} s;
struct cvmx_pko_reg_flags_cn30xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_4_63:60;
uint64_t reset:1;
uint64_t store_be:1;
uint64_t ena_dwb:1;
uint64_t ena_pko:1;
#else
uint64_t ena_pko:1;
uint64_t ena_dwb:1;
uint64_t store_be:1;
uint64_t reset:1;
uint64_t reserved_4_63:60;
#endif
} cn30xx;
struct cvmx_pko_reg_flags_cn61xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_9_63:55;
uint64_t dis_perf3:1;
uint64_t dis_perf2:1;
uint64_t reserved_4_6:3;
uint64_t reset:1;
uint64_t store_be:1;
uint64_t ena_dwb:1;
uint64_t ena_pko:1;
#else
uint64_t ena_pko:1;
uint64_t ena_dwb:1;
uint64_t store_be:1;
uint64_t reset:1;
uint64_t reserved_4_6:3;
uint64_t dis_perf2:1;
uint64_t dis_perf3:1;
uint64_t reserved_9_63:55;
#endif
} cn61xx;
struct cvmx_pko_reg_flags_cn68xxp1 {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_7_63:57;
uint64_t dis_perf1:1;
uint64_t dis_perf0:1;
uint64_t ena_throttle:1;
uint64_t reset:1;
uint64_t store_be:1;
uint64_t ena_dwb:1;
uint64_t ena_pko:1;
#else
uint64_t ena_pko:1;
uint64_t ena_dwb:1;
uint64_t store_be:1;
uint64_t reset:1;
uint64_t ena_throttle:1;
uint64_t dis_perf0:1;
uint64_t dis_perf1:1;
uint64_t reserved_7_63:57;
#endif
} cn68xxp1;
};
union cvmx_pko_reg_gmx_port_mode {
uint64_t u64;
struct cvmx_pko_reg_gmx_port_mode_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_6_63:58;
uint64_t mode1:3;
uint64_t mode0:3;
#else
uint64_t mode0:3;
uint64_t mode1:3;
uint64_t reserved_6_63:58;
#endif
} s;
};
union cvmx_pko_reg_int_mask {
uint64_t u64;
struct cvmx_pko_reg_int_mask_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_4_63:60;
uint64_t loopback:1;
uint64_t currzero:1;
uint64_t doorbell:1;
uint64_t parity:1;
#else
uint64_t parity:1;
uint64_t doorbell:1;
uint64_t currzero:1;
uint64_t loopback:1;
uint64_t reserved_4_63:60;
#endif
} s;
struct cvmx_pko_reg_int_mask_cn30xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_2_63:62;
uint64_t doorbell:1;
uint64_t parity:1;
#else
uint64_t parity:1;
uint64_t doorbell:1;
uint64_t reserved_2_63:62;
#endif
} cn30xx;
struct cvmx_pko_reg_int_mask_cn50xx {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_3_63:61;
uint64_t currzero:1;
uint64_t doorbell:1;
uint64_t parity:1;
#else
uint64_t parity:1;
uint64_t doorbell:1;
uint64_t currzero:1;
uint64_t reserved_3_63:61;
#endif
} cn50xx;
};
union cvmx_pko_reg_loopback_bpid {
uint64_t u64;
struct cvmx_pko_reg_loopback_bpid_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_59_63:5;
uint64_t bpid7:6;
uint64_t reserved_52_52:1;
uint64_t bpid6:6;
uint64_t reserved_45_45:1;
uint64_t bpid5:6;
uint64_t reserved_38_38:1;
uint64_t bpid4:6;
uint64_t reserved_31_31:1;
uint64_t bpid3:6;
uint64_t reserved_24_24:1;
uint64_t bpid2:6;
uint64_t reserved_17_17:1;
uint64_t bpid1:6;
uint64_t reserved_10_10:1;
uint64_t bpid0:6;
uint64_t reserved_0_3:4;
#else
uint64_t reserved_0_3:4;
uint64_t bpid0:6;
uint64_t reserved_10_10:1;
uint64_t bpid1:6;
uint64_t reserved_17_17:1;
uint64_t bpid2:6;
uint64_t reserved_24_24:1;
uint64_t bpid3:6;
uint64_t reserved_31_31:1;
uint64_t bpid4:6;
uint64_t reserved_38_38:1;
uint64_t bpid5:6;
uint64_t reserved_45_45:1;
uint64_t bpid6:6;
uint64_t reserved_52_52:1;
uint64_t bpid7:6;
uint64_t reserved_59_63:5;
#endif
} s;
};
union cvmx_pko_reg_loopback_pkind {
uint64_t u64;
struct cvmx_pko_reg_loopback_pkind_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_59_63:5;
uint64_t pkind7:6;
uint64_t reserved_52_52:1;
uint64_t pkind6:6;
uint64_t reserved_45_45:1;
uint64_t pkind5:6;
uint64_t reserved_38_38:1;
uint64_t pkind4:6;
uint64_t reserved_31_31:1;
uint64_t pkind3:6;
uint64_t reserved_24_24:1;
uint64_t pkind2:6;
uint64_t reserved_17_17:1;
uint64_t pkind1:6;
uint64_t reserved_10_10:1;
uint64_t pkind0:6;
uint64_t num_ports:4;
#else
uint64_t num_ports:4;
uint64_t pkind0:6;
uint64_t reserved_10_10:1;
uint64_t pkind1:6;
uint64_t reserved_17_17:1;
uint64_t pkind2:6;
uint64_t reserved_24_24:1;
uint64_t pkind3:6;
uint64_t reserved_31_31:1;
uint64_t pkind4:6;
uint64_t reserved_38_38:1;
uint64_t pkind5:6;
uint64_t reserved_45_45:1;
uint64_t pkind6:6;
uint64_t reserved_52_52:1;
uint64_t pkind7:6;
uint64_t reserved_59_63:5;
#endif
} s;
};
union cvmx_pko_reg_min_pkt {
uint64_t u64;
struct cvmx_pko_reg_min_pkt_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t size7:8;
uint64_t size6:8;
uint64_t size5:8;
uint64_t size4:8;
uint64_t size3:8;
uint64_t size2:8;
uint64_t size1:8;
uint64_t size0:8;
#else
uint64_t size0:8;
uint64_t size1:8;
uint64_t size2:8;
uint64_t size3:8;
uint64_t size4:8;
uint64_t size5:8;
uint64_t size6:8;
uint64_t size7:8;
#endif
} s;
};
union cvmx_pko_reg_preempt {
uint64_t u64;
struct cvmx_pko_reg_preempt_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_16_63:48;
uint64_t min_size:16;
#else
uint64_t min_size:16;
uint64_t reserved_16_63:48;
#endif
} s;
};
union cvmx_pko_reg_queue_mode {
uint64_t u64;
struct cvmx_pko_reg_queue_mode_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_2_63:62;
uint64_t mode:2;
#else
uint64_t mode:2;
uint64_t reserved_2_63:62;
#endif
} s;
};
union cvmx_pko_reg_queue_preempt {
uint64_t u64;
struct cvmx_pko_reg_queue_preempt_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_2_63:62;
uint64_t preemptee:1;
uint64_t preempter:1;
#else
uint64_t preempter:1;
uint64_t preemptee:1;
uint64_t reserved_2_63:62;
#endif
} s;
};
union cvmx_pko_reg_queue_ptrs1 {
uint64_t u64;
struct cvmx_pko_reg_queue_ptrs1_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_2_63:62;
uint64_t idx3:1;
uint64_t qid7:1;
#else
uint64_t qid7:1;
uint64_t idx3:1;
uint64_t reserved_2_63:62;
#endif
} s;
};
union cvmx_pko_reg_read_idx {
uint64_t u64;
struct cvmx_pko_reg_read_idx_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_16_63:48;
uint64_t inc:8;
uint64_t index:8;
#else
uint64_t index:8;
uint64_t inc:8;
uint64_t reserved_16_63:48;
#endif
} s;
};
union cvmx_pko_reg_throttle {
uint64_t u64;
struct cvmx_pko_reg_throttle_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_32_63:32;
uint64_t int_mask:32;
#else
uint64_t int_mask:32;
uint64_t reserved_32_63:32;
#endif
} s;
};
union cvmx_pko_reg_timestamp {
uint64_t u64;
struct cvmx_pko_reg_timestamp_s {
#ifdef __BIG_ENDIAN_BITFIELD
uint64_t reserved_4_63:60;
uint64_t wqe_word:4;
#else
uint64_t wqe_word:4;
uint64_t reserved_4_63:60;
#endif
} s;
};
#endif
| 21.961922 | 106 | 0.764614 |
7ebd33efa535fd86e78a19062bcf8a9f89fde051 | 677 | c | C | src/ontheroad/ipc/fifo/fifo_read.c | aaronize/coppercoin | fcbbf74db8f558291138fde02403b7bbd21b7eb8 | [
"MIT"
] | null | null | null | src/ontheroad/ipc/fifo/fifo_read.c | aaronize/coppercoin | fcbbf74db8f558291138fde02403b7bbd21b7eb8 | [
"MIT"
] | null | null | null | src/ontheroad/ipc/fifo/fifo_read.c | aaronize/coppercoin | fcbbf74db8f558291138fde02403b7bbd21b7eb8 | [
"MIT"
] | null | null | null | #include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
const char *path = "/tmp/fifo1";
int main()
{
int fd;
int len;
char buf[1024];
if (mkfifo(path, 0666) < 0 && errno != EEXIST)
perror("create FIFO failed!");
if ((fd = open(path, O_RDONLY)) < 0)
{
perror("open FIFO error");
exit(1);
}
while ((len = read(fd, buf, 1024)) > 0)
{
printf("received message: %s", buf);
}
// while (1) {
// read(fd, buf, 1024); // write端关闭后,read也不会阻塞
// printf("received message: %s\n", buf);
// }
close(fd);
return 0;
}
| 18.297297 | 55 | 0.497784 |
b42fe553451b757db9225fe3f486b1735bfffa6d | 1,782 | c | C | libraries/libft/ft_strlen.c | CoZZmOnAvT/socket_chat | 6242895c5e305b864957737bedf3a362d8551dbb | [
"MIT"
] | 3 | 2019-09-24T18:32:06.000Z | 2019-11-25T07:47:10.000Z | libraries/libft/ft_strlen.c | CoZZmOnAvT/socket_chat | 6242895c5e305b864957737bedf3a362d8551dbb | [
"MIT"
] | null | null | null | libraries/libft/ft_strlen.c | CoZZmOnAvT/socket_chat | 6242895c5e305b864957737bedf3a362d8551dbb | [
"MIT"
] | 2 | 2018-10-17T09:07:31.000Z | 2020-05-02T13:35:55.000Z | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pgritsen <pgritsen@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/26 21:18:40 by pgritsen #+# #+# */
/* Updated: 2017/12/08 14:02:40 by pgritsen ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_ucharlen(t_wint c)
{
if (c <= 0x7F)
return (1);
else if (c <= 0x7FF)
return (2);
else if (c <= 0xFFFF)
return (3);
else if (c <= 0x10FFFF)
return (4);
return (0);
}
size_t ft_strlen(const char *s)
{
const char *p_s;
if (!s)
return (6);
p_s = s;
while (*p_s)
p_s++;
return (p_s - s);
}
size_t ft_strulen(const t_wint *s)
{
size_t len;
if (!s)
return (6);
len = 0;
while (*s)
len += ft_ucharlen(*s++);
return (len);
}
size_t ft_strnlen(const char *s, size_t len)
{
size_t tmp;
if (!s)
return (6);
tmp = ft_strlen(s);
return (len > tmp ? tmp : len);
}
size_t ft_strunlen(const t_wint *s, size_t len)
{
size_t ulen;
intmax_t tmp;
if (!s)
return (6);
ulen = 0;
tmp = ft_strulen(s);
(intmax_t)len < tmp ? tmp = len : 0;
while (*s && (tmp -= ft_ucharlen(*s)) >= 0)
ulen += ft_ucharlen(*s++);
return (ulen);
}
| 23.447368 | 80 | 0.34624 |
706d556aa96403dd892614e06258584acb728075 | 257 | c | C | test/transform/replace/replace_12.tfm.c | vladem/tsar | 3771068d47a8a258ee4a74ad5fc9c246f8aba7cb | [
"Apache-2.0"
] | null | null | null | test/transform/replace/replace_12.tfm.c | vladem/tsar | 3771068d47a8a258ee4a74ad5fc9c246f8aba7cb | [
"Apache-2.0"
] | 11 | 2021-01-28T21:06:08.000Z | 2021-02-24T09:49:35.000Z | tests/transform/replace/replace_12/sample/main.c | zoocide/tsar-test-template | b3047eaa2ad8e4d6c0ab2a86f61a596736dbd762 | [
"Apache-2.0"
] | null | null | null | struct STy {
int X;
};
struct UnusedTy {};
void foo(struct STy *S, struct UnusedTy *U) { S->X = 5; }
/* Replacement for void foo(struct STy *S, struct UnusedTy *U) */
void foo_spf0(struct STy *S) {
#pragma spf metadata replace(foo(S, {}))
S->X = 5;
}
| 19.769231 | 65 | 0.626459 |
24985eabbdb1f863483fdd7b8c099e874348877d | 148 | h | C | sys/arch/armv7/include/trap.h | ArrogantWombatics/openbsd-src | 75721e1d44322953075b7c4b89337b163a395291 | [
"BSD-3-Clause"
] | 1 | 2019-02-16T13:29:23.000Z | 2019-02-16T13:29:23.000Z | sys/arch/armv7/include/trap.h | ArrogantWombatics/openbsd-src | 75721e1d44322953075b7c4b89337b163a395291 | [
"BSD-3-Clause"
] | 1 | 2018-08-21T03:56:33.000Z | 2018-08-21T03:56:33.000Z | sys/arch/armv7/include/trap.h | ArrogantWombatics/openbsd-src | 75721e1d44322953075b7c4b89337b163a395291 | [
"BSD-3-Clause"
] | null | null | null | /* $OpenBSD: trap.h,v 1.1 2013/09/04 14:38:29 patrick Exp $ */
/* $NetBSD: trap.h,v 1.3 2001/11/25 15:55:58 thorpej Exp $ */
#include <arm/trap.h>
| 29.6 | 62 | 0.621622 |
d7dad0a65a552916fe488262abc72eff49703ad2 | 1,328 | c | C | test_cases/driver.c | yosha4523/SystemsSoftwareProject | f6670c67af8ea32755a7b7672f2c3a868271a1d9 | [
"MIT"
] | null | null | null | test_cases/driver.c | yosha4523/SystemsSoftwareProject | f6670c67af8ea32755a7b7672f2c3a868271a1d9 | [
"MIT"
] | null | null | null | test_cases/driver.c | yosha4523/SystemsSoftwareProject | f6670c67af8ea32755a7b7672f2c3a868271a1d9 | [
"MIT"
] | null | null | null | /*
This is the driver for the UCF Fall 2021 Systems Software Project
If you choose to alter this, you MUST make a note of that in your
readme file, otherwise you will lose 5 points.
*/
#include <stdlib.h>
#include <stdio.h>
#include "compiler.h"
#define MAX_CODE_LENGTH 3000
int main(int argc, char *argv[])
{
FILE *ifp;
char *input;
char c;
lexeme *list;
instruction *code;
int i;
int tokens = 0, symbols = 0, codes = 0, outputs = 0;
if (argc < 2)
{
printf("Error : please include the file name\n");
return 0;
}
ifp = fopen(argv[1], "r");
input = malloc(MAX_CODE_LENGTH * sizeof(char));
i = 0;
c = fgetc(ifp);
while (1)
{
input[i++] = c;
c = fgetc(ifp);
if (c == EOF)
break;
}
input[i] = '\0';
for (i = 2; i < argc; i++)
{
if (argv[i][1] == 'l')
tokens = 1;
else if (argv[i][1] == 's')
symbols = 1;
else if (argv[i][1] == 'a')
codes = 1;
else if (argv[i][1] == 'v')
outputs = 1;
else
{
printf("Error : unrecognized directive\n");
free(input);
return 0;
}
}
list = lexanalyzer(input, tokens);
if (list == NULL)
{
free(input);
return 0;
}
code = parse(list, symbols, codes);
if (code == NULL)
{
free(input);
free(list);
return 0;
}
execute_program(code, outputs);
free(input);
free(list);
free(code);
return 0;
} | 16.195122 | 66 | 0.582831 |
cc64224c5dd4b2dc5caa57e378478cc3d59735f0 | 1,071 | h | C | src/protocols/protocol.h | Majubs/libKonkerESP | 6adebfa083940391b63a964cb7bdbfc898ee6e9f | [
"MIT"
] | 1 | 2021-07-07T19:44:32.000Z | 2021-07-07T19:44:32.000Z | src/protocols/protocol.h | Majubs/libKonkerESP | 6adebfa083940391b63a964cb7bdbfc898ee6e9f | [
"MIT"
] | null | null | null | src/protocols/protocol.h | Majubs/libKonkerESP | 6adebfa083940391b63a964cb7bdbfc898ee6e9f | [
"MIT"
] | null | null | null | #ifndef __PROTOCOL_H__
#define __PROTOCOL_H__
#include <Arduino.h>
#include <WiFiClient.h>
class Protocol
{
public:
virtual void init() = 0;
virtual int send(const char* , String) = 0;
virtual int receive(String *) = 0;
virtual int request(String *, String) = 0;
virtual void setConnection(String, int);
virtual String getHost();
virtual int getPort();
virtual int getNumConnFail();
virtual void setNumConnFail(uint16_t);
virtual void increaseConnFail();
virtual void setDeviceId(String);
virtual void setPlatformCredentials(String, String);
virtual String getUser();
virtual String getPassword();
virtual String getDeviceId();
virtual bool isCredentialSet();
virtual int savePlatformCredentials();
virtual int restorePlatformCredentials();
virtual bool getPlatformCredentials(String *, String);
virtual int connect();
virtual int disconnect(); //return connection status from globals.h
virtual int checkConnection();
virtual bool isConnectionOriented();
virtual bool protocolLoop();
};
#endif /* __PROTOCOL_H__ */
| 25.5 | 69 | 0.743231 |
78d527c107c262effcf0b46e38569bb345445ef7 | 610 | h | C | System/Library/PrivateFrameworks/SiriFindMy.framework/SiriFindMy.BluetoothStateProvider.h | zhangkn/iOS14Header | 4323e9459ed6f6f5504ecbea2710bfd6c3d7c946 | [
"MIT"
] | 1 | 2020-11-04T15:43:01.000Z | 2020-11-04T15:43:01.000Z | System/Library/PrivateFrameworks/SiriFindMy.framework/SiriFindMy.BluetoothStateProvider.h | zhangkn/iOS14Header | 4323e9459ed6f6f5504ecbea2710bfd6c3d7c946 | [
"MIT"
] | null | null | null | System/Library/PrivateFrameworks/SiriFindMy.framework/SiriFindMy.BluetoothStateProvider.h | zhangkn/iOS14Header | 4323e9459ed6f6f5504ecbea2710bfd6c3d7c946 | [
"MIT"
] | null | null | null | /*
* This header is generated by classdump-dyld 1.0
* on Sunday, September 27, 2020 at 11:52:51 AM Mountain Standard Time
* Operating System: Version 14.0 (Build 18A373)
* Image Source: /System/Library/PrivateFrameworks/SiriFindMy.framework/SiriFindMy
* classdump-dyld is licensed under GPLv3, Copyright © 2013-2016 by Elias Limneos.
*/
#import <libobjc.A.dylib/CBCentralManagerDelegate.h>
@interface SiriFindMy.BluetoothStateProvider : NSObject <CBCentralManagerDelegate> {
subject;
bluetoothManager;
statePublisher;
subscription;
}
-(void)centralManagerDidUpdateState:(id)arg1 ;
-(id)init;
@end
| 26.521739 | 84 | 0.777049 |
d13ad038074ac983d9c0986a1f6cadd5b157b1ae | 3,741 | h | C | include/ptp_container.h | KArashid/cmtp-responder | 91d29dadca7d6e3e62339a8d60c043f1addc3b24 | [
"Apache-2.0"
] | 15 | 2019-05-16T17:55:39.000Z | 2021-11-15T12:38:28.000Z | include/ptp_container.h | KArashid/cmtp-responder | 91d29dadca7d6e3e62339a8d60c043f1addc3b24 | [
"Apache-2.0"
] | 10 | 2019-05-17T11:46:46.000Z | 2022-02-05T18:52:42.000Z | include/ptp_container.h | KArashid/cmtp-responder | 91d29dadca7d6e3e62339a8d60c043f1addc3b24 | [
"Apache-2.0"
] | 9 | 2019-05-16T17:55:41.000Z | 2022-02-05T16:42:24.000Z | /*
* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
* Copyright (c) 2019 Collabora Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _PTP_CONTAINER_H_
#define _PTP_CONTAINER_H_
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "mtp_datatype.h"
#define MAX_MTP_PARAMS 5
#define MTP_USB_HEADER_LENGTH 12
typedef enum {
CONTAINER_UNDEFINED = 0x00,
CONTAINER_CMD_BLK,
CONTAINER_DATA_BLK,
CONTAINER_RESP_BLK,
CONTAINER_EVENT_BLK
} container_type_t;
/*
* A generic USB container header.
*/
typedef struct {
mtp_uint32 len; /* the valid container size in BYTES */
mtp_uint16 type; /* Container type */
mtp_uint16 code; /* Operation, response or Event code */
mtp_uint32 tid; /* host generated transaction id */
} header_container_t;
/*
* A generic USB container.
*/
typedef struct {
mtp_uint32 len; /* the valid container size in BYTES */
mtp_uint16 type; /* Container type */
mtp_uint16 code; /* Operation, response or Event code */
mtp_uint32 tid; /* host generated transaction id */
mtp_uint32 params[MAX_MTP_PARAMS];
mtp_uint32 no_param;
} cmd_container_t;
/*
* A USB container for sending data.
*/
typedef struct {
mtp_uint32 len; /* the valid container size in BYTES */
mtp_uint16 type; /* Container type */
mtp_uint16 code; /* Operation, response or Event code */
mtp_uint32 tid; /* host generated transaction id */
mtp_uint32 params[MAX_MTP_PARAMS];
mtp_uint32 no_param;
mtp_uchar *data;
} data_container_t;
typedef cmd_container_t cmd_blk_t;
typedef cmd_container_t resp_blk_t;
typedef data_container_t data_blk_t;
void _hdlr_init_cmd_container(cmd_container_t *cntr);
mtp_uint32 _hdlr_get_param_cmd_container(cmd_container_t *cntr,
mtp_uint32 index);
void _hdlr_copy_cmd_container_unknown_params(cmd_container_t *src,
cmd_container_t *dst);
void _hdlr_copy_cmd_container(cmd_container_t *src, cmd_container_t *dst);
mtp_bool _hdlr_add_param_resp_container(resp_blk_t *dst, mtp_uint32 num,
mtp_uint32 *params);
mtp_bool _hdlr_validate_cmd_container(mtp_uchar *blk, mtp_uint32 size);
void _hdlr_init_data_container(data_container_t *dst, mtp_uint16 code,
mtp_uint32 trans_id);
mtp_uchar *_hdlr_alloc_buf_data_container(data_container_t *dst,
mtp_uint32 bufsz, mtp_uint64 pkt_size);
mtp_bool _hdlr_send_data_container(data_container_t *dst);
mtp_bool _hdlr_send_bulk_data(mtp_uchar *dst, mtp_uint32 len);
mtp_bool _hdlr_rcv_data_container(data_container_t *dst, mtp_uint32 size);
mtp_bool _hdlr_rcv_file_in_data_container(data_container_t *dst,
mtp_char *filepath, mtp_uint32 path_len);
mtp_uint32 _hdlr_get_payload_size(data_container_t *dst);
mtp_uchar *_hdlr_get_payload_data(data_container_t *dst);
void _hdlr_resp_container_init(cmd_container_t *dst, mtp_uint16 resp_code,
mtp_uint32 tid);
mtp_bool _hdlr_send_resp_container(cmd_container_t *dst);
void _hdlr_init_event_container(cmd_container_t *dst, mtp_uint16 code,
mtp_uint32 tid, mtp_uint32 param1, mtp_uint32 param2);
mtp_bool _hdlr_send_event_container(cmd_container_t *dst);
void _hdlr_conv_cmd_container_byte_order(cmd_container_t *dst);
void _hdlr_conv_data_container_byte_order(data_container_t *dst);
#ifdef __cplusplus
}
#endif
#endif /* _PTP_CONTAINER_H_ */
| 33.106195 | 75 | 0.792302 |
600a53c0a13616a6a5889b64b940fe01077b25c1 | 167 | h | C | HCPods/Classes/HCFirstPod.h | HChong3210/FirstPod | 3ab166947b232a2afa57275917a161efa8abf481 | [
"MIT"
] | null | null | null | HCPods/Classes/HCFirstPod.h | HChong3210/FirstPod | 3ab166947b232a2afa57275917a161efa8abf481 | [
"MIT"
] | null | null | null | HCPods/Classes/HCFirstPod.h | HChong3210/FirstPod | 3ab166947b232a2afa57275917a161efa8abf481 | [
"MIT"
] | null | null | null | //
// HCFirstPod.h
// Pods
//
// Created by HChong on 2017/8/16.
//
//
#import <Foundation/Foundation.h>
@interface HCFirstPod : NSObject
+ (void)sayHello;
@end
| 11.133333 | 35 | 0.646707 |
4f0255cc2334196a381454351c82ad26a6349384 | 2,401 | h | C | util/types.h | kirmorozov/pecl-database-mysql_xdevapi | 214e0b13dcea17dfa86000092860e3fb35f02257 | [
"PHP-3.01"
] | 14 | 2017-11-16T03:13:31.000Z | 2022-03-10T14:59:53.000Z | util/types.h | kirmorozov/pecl-database-mysql_xdevapi | 214e0b13dcea17dfa86000092860e3fb35f02257 | [
"PHP-3.01"
] | 8 | 2018-03-02T06:08:27.000Z | 2022-01-18T10:34:43.000Z | util/types.h | kirmorozov/pecl-database-mysql_xdevapi | 214e0b13dcea17dfa86000092860e3fb35f02257 | [
"PHP-3.01"
] | 18 | 2018-03-01T13:45:16.000Z | 2022-03-10T06:30:02.000Z | /*
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Darek Slusarczyk <marines@php.net> |
+----------------------------------------------------------------------+
*/
#ifndef MYSQL_XDEVAPI_PHP_TYPES_H
#define MYSQL_XDEVAPI_PHP_TYPES_H
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "allocator.h"
namespace mysqlx {
namespace util {
template<typename T>
using vector = std::vector<T, allocator<T>>;
template<typename Key, typename T, typename Compare = std::less<Key>>
using map = std::map<Key, T, Compare, allocator<std::pair<const Key, T>>>;
template<typename Key, typename Compare = std::less<Key>>
using set = std::set<Key, Compare, allocator<Key>>;
template<typename Key, typename T, typename Hash = std::hash<Key>,typename KeyEqual = std::equal_to<Key>>
using unordered_map = std::unordered_map<Key, T, Hash, KeyEqual, allocator<std::pair<const Key, T>>>;
template<typename Key, typename Hash = std::hash<Key>,typename KeyEqual = std::equal_to<Key>>
using unordered_set = std::unordered_set<Key, Hash, KeyEqual, allocator<Key>>;
template<typename T>
using deque = std::deque<T, std::allocator<T>>;
template<typename T, typename Container = deque<T>>
using stack = std::stack<T, Container>;
using byte = unsigned char;
using bytes = vector<byte>;
} // namespace util
} // namespace mysqlx
#endif // MYSQL_XDEVAPI_PHP_TYPES_H
| 38.111111 | 105 | 0.550187 |
94e5cbef122222e70ffe5165f0a5ed0f144cf909 | 174 | h | C | PrivateFrameworks/PowerlogLiteOperators.framework/PLBBMsgItem.h | shaojiankui/iOS10-Runtime-Headers | 6b0d842bed0c52c2a7c1464087b3081af7e10c43 | [
"MIT"
] | 36 | 2016-04-20T04:19:04.000Z | 2018-10-08T04:12:25.000Z | PrivateFrameworks/PowerlogLiteOperators.framework/PLBBMsgItem.h | shaojiankui/iOS10-Runtime-Headers | 6b0d842bed0c52c2a7c1464087b3081af7e10c43 | [
"MIT"
] | null | null | null | PrivateFrameworks/PowerlogLiteOperators.framework/PLBBMsgItem.h | shaojiankui/iOS10-Runtime-Headers | 6b0d842bed0c52c2a7c1464087b3081af7e10c43 | [
"MIT"
] | 10 | 2016-06-16T02:40:44.000Z | 2019-01-15T03:31:45.000Z | /* Generated by RuntimeBrowser
Image: /System/Library/PrivateFrameworks/PowerlogLiteOperators.framework/PowerlogLiteOperators
*/
@interface PLBBMsgItem : NSObject
@end
| 21.75 | 97 | 0.816092 |
9e60b970623b5a3daf35cea53bf55d80b382cd85 | 29,000 | h | C | arch/arm/src/stm32/hardware/stm32g4xxxx_dmamux.h | eenurkka/incubator-nuttx | 5c3d6bba6d9ec5015896c3019cd2064696373210 | [
"Apache-2.0"
] | 1,006 | 2019-12-17T23:45:41.000Z | 2022-03-31T19:42:44.000Z | arch/arm/src/stm32/hardware/stm32g4xxxx_dmamux.h | eenurkka/incubator-nuttx | 5c3d6bba6d9ec5015896c3019cd2064696373210 | [
"Apache-2.0"
] | 2,661 | 2019-12-21T15:16:09.000Z | 2022-03-31T22:30:04.000Z | arch/arm/src/stm32/hardware/stm32g4xxxx_dmamux.h | eenurkka/incubator-nuttx | 5c3d6bba6d9ec5015896c3019cd2064696373210 | [
"Apache-2.0"
] | 613 | 2019-12-21T10:17:37.000Z | 2022-03-28T09:42:20.000Z | /****************************************************************************
* arch/arm/src/stm32/hardware/stm32g4xxxx_dmamux.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __ARCH_ARM_SRC_STM32_HARDWARE_STM32G4XXXX_DMAMUX_H
#define __ARCH_ARM_SRC_STM32_HARDWARE_STM32G4XXXX_DMAMUX_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* DMAMUX1 mapping **********************************************************/
/* For category 3 and category 4 devices:
* DMAMUX1 channels 0 to 7 are connected to DMA1 channels 1 to 8.
* DMAMUX1 channels 8 to 15 are connected to DMA2 channels 1 to 8.
*
* For category 2:
* DMAMUX1 channels 0 to 5 are connected to DMA1 channels 1 to 6.
* DMAMUX1 channels 6 to 11 are connected to DMA2 channels 1 to 6.
*/
#define DMAMUX1_REQ_MEM2MEM (0) /* Memory to memory transfer */
#define DMAMUX1_REQ_GEN0 (1) /* DMAMUX Request Generator 0 */
#define DMAMUX1_REQ_GEN1 (2) /* DMAMUX Request Generator 1 */
#define DMAMUX1_REQ_GEN2 (3) /* DMAMUX Request Generator 2 */
#define DMAMUX1_REQ_GEN3 (4) /* DMAMUX Request Generator 3 */
#define DMAMUX1_ADC1 (5) /* DMAMUX ADC1 request */
#define DMAMUX1_DAC1_CH1 (6) /* DMAMUX DAC1 Channel 1 request */
#define DMAMUX1_DAC1_CH2 (7) /* DMAMUX DAC1 Channel 2 request */
#define DMAMUX1_TIM6_UP (8) /* DMAMUX TIM6 Update request */
#define DMAMUX1_TIM7_UP (9) /* DMAMUX TIM7 Update request */
#define DMAMUX1_SPI1_RX (10) /* DMAMUX SPI1 Rx request */
#define DMAMUX1_SPI1_TX (11) /* DMAMUX SPI1 Tx request */
#define DMAMUX1_SPI2_RX (12) /* DMAMUX SPI2 Rx request */
#define DMAMUX1_SPI2_TX (13) /* DMAMUX SPI2 Tx request */
#define DMAMUX1_SPI3_RX (14) /* DMAMUX SPI3 Rx request */
#define DMAMUX1_SPI3_TX (15) /* DMAMUX SPI3 Tx request */
#define DMAMUX1_I2C1_RX (16) /* DMAMUX I2C1 Rx request */
#define DMAMUX1_I2C1_TX (17) /* DMAMUX I2C1 Tx request */
#define DMAMUX1_I2C2_RX (18) /* DMAMUX I2C2 Rx request */
#define DMAMUX1_I2C2_TX (19) /* DMAMUX I2C2 Tx request */
#define DMAMUX1_I2C3_RX (20) /* DMAMUX I2C3 Rx request */
#define DMAMUX1_I2C3_TX (21) /* DMAMUX I2C3 Tx request */
#define DMAMUX1_I2C4_RX (22) /* DMAMUX I2C4 Rx request */
#define DMAMUX1_I2C4_TX (23) /* DMAMUX I2C4 Tx request */
#define DMAMUX1_USART1_RX (24) /* DMAMUX USART1 Rx request */
#define DMAMUX1_USART1_TX (25) /* DMAMUX USART1 Tx request */
#define DMAMUX1_USART2_RX (26) /* DMAMUX USART2 Rx request */
#define DMAMUX1_USART2_TX (27) /* DMAMUX USART2 Tx request */
#define DMAMUX1_USART3_RX (28) /* DMAMUX USART3 Rx request */
#define DMAMUX1_USART3_TX (29) /* DMAMUX USART3 Tx request */
#define DMAMUX1_UART4_RX (30) /* DMAMUX UART4 Rx request */
#define DMAMUX1_UART4_TX (31) /* DMAMUX UART4 Tx request */
#define DMAMUX1_UART5_RX (32) /* DMAMUX UART5 Rx request */
#define DMAMUX1_UART5_TX (33) /* DMAMUX UART5 Tx request */
#define DMAMUX1_LPUART1_RX (34) /* DMAMUX LPUART1 Rx request */
#define DMAMUX1_LPUART1_TX (35) /* DMAMUX LPUART1 Tx request */
#define DMAMUX1_ADC2 (36) /* DMAMUX ADC2 request */
#define DMAMUX1_ADC3 (37) /* DMAMUX ADC3 request */
#define DMAMUX1_ADC4 (38) /* DMAMUX ADC4 request */
#define DMAMUX1_ADC5 (39) /* DMAMUX ADC5 request */
#define DMAMUX1_QSPI (40) /* DMAMUX QSPI request */
#define DMAMUX1_DAC2_CH1 (41) /* DMAMUX DAC2 Channel 1 request */
#define DMAMUX1_TIM1_CH1 (42) /* DMAMUX TIM1 Channel 1 request */
#define DMAMUX1_TIM1_CH2 (43) /* DMAMUX TIM1 Channel 2 request */
#define DMAMUX1_TIM1_CH3 (44) /* DMAMUX TIM1 Channel 3 request */
#define DMAMUX1_TIM1_CH4 (45) /* DMAMUX TIM1 Channel 4 request */
#define DMAMUX1_TIM1_UP (46) /* DMAMUX TIM1 Update request */
#define DMAMUX1_TIM1_TRIG (47) /* DMAMUX TIM1 Trigger request */
#define DMAMUX1_TIM1_COM (48) /* DMAMUX TIM1 Commutation request */
#define DMAMUX1_TIM8_CH1 (49) /* DMAMUX TIM8 Channel 1 request */
#define DMAMUX1_TIM8_CH2 (50) /* DMAMUX TIM8 Channel 2 request */
#define DMAMUX1_TIM8_CH3 (51) /* DMAMUX TIM8 Channel 3 request */
#define DMAMUX1_TIM8_CH4 (52) /* DMAMUX TIM8 Channel 4 request */
#define DMAMUX1_TIM8_UP (53) /* DMAMUX TIM8 Update request */
#define DMAMUX1_TIM8_TRIG (54) /* DMAMUX TIM8 Trigger request */
#define DMAMUX1_TIM8_COM (55) /* DMAMUX TIM8 Commutation request */
#define DMAMUX1_TIM2_CH1 (56) /* DMAMUX TIM2 Channel 1 request */
#define DMAMUX1_TIM2_CH2 (57) /* DMAMUX TIM2 Channel 2 request */
#define DMAMUX1_TIM2_CH3 (58) /* DMAMUX TIM2 Channel 3 request */
#define DMAMUX1_TIM2_CH4 (59) /* DMAMUX TIM2 Channel 4 request */
#define DMAMUX1_TIM2_UP (60) /* DMAMUX TIM2 Update request */
#define DMAMUX1_TIM3_CH1 (61) /* DMAMUX TIM3 Channel 1 request */
#define DMAMUX1_TIM3_CH2 (62) /* DMAMUX TIM3 Channel 2 request */
#define DMAMUX1_TIM3_CH3 (63) /* DMAMUX TIM3 Channel 3 request */
#define DMAMUX1_TIM3_CH4 (64) /* DMAMUX TIM3 Channel 4 request */
#define DMAMUX1_TIM3_UP (65) /* DMAMUX TIM3 Update request */
#define DMAMUX1_TIM3_TRIG (66) /* DMAMUX TIM3 Trigger request */
#define DMAMUX1_TIM4_CH1 (67) /* DMAMUX TIM4 Channel 1 request */
#define DMAMUX1_TIM4_CH2 (68) /* DMAMUX TIM4 Channel 2 request */
#define DMAMUX1_TIM4_CH3 (69) /* DMAMUX TIM4 Channel 3 request */
#define DMAMUX1_TIM4_CH4 (70) /* DMAMUX TIM4 Channel 4 request */
#define DMAMUX1_TIM4_UP (71) /* DMAMUX TIM4 Update request */
#define DMAMUX1_TIM5_CH1 (72) /* DMAMUX TIM5 Channel 1 request */
#define DMAMUX1_TIM5_CH2 (73) /* DMAMUX TIM5 Channel 2 request */
#define DMAMUX1_TIM5_CH3 (74) /* DMAMUX TIM5 Channel 3 request */
#define DMAMUX1_TIM5_CH4 (75) /* DMAMUX TIM5 Channel 4 request */
#define DMAMUX1_TIM5_UP (76) /* DMAMUX TIM5 Update request */
#define DMAMUX1_TIM5_TRIG (77) /* DMAMUX TIM5 Trigger request */
#define DMAMUX1_TIM15_CH1 (78) /* DMAMUX TIM15 Channel 1 request */
#define DMAMUX1_TIM15_UP (79) /* DMAMUX TIM15 Update request */
#define DMAMUX1_TIM15_TRIG (80) /* DMAMUX TIM15 Trigger request */
#define DMAMUX1_TIM15_COM (81) /* DMAMUX TIM15 Commutation request */
#define DMAMUX1_TIM16_CH1 (82) /* DMAMUX TIM16 Channel 1 request */
#define DMAMUX1_TIM16_UP (83) /* DMAMUX TIM16 Update request */
#define DMAMUX1_TIM17_CH1 (84) /* DMAMUX TIM17 Channel 1 request */
#define DMAMUX1_TIM17_UP (85) /* DMAMUX TIM17 Update request */
#define DMAMUX1_TIM20_CH1 (86) /* DMAMUX TIM20 Channel 1 request */
#define DMAMUX1_TIM20_CH2 (87) /* DMAMUX TIM20 Channel 2 request */
#define DMAMUX1_TIM20_CH3 (88) /* DMAMUX TIM20 Channel 3 request */
#define DMAMUX1_TIM20_CH4 (89) /* DMAMUX TIM20 Channel 4 request */
#define DMAMUX1_TIM20_UP (90) /* DMAMUX TIM20 Update request */
#define DMAMUX1_AES_IN (91) /* DMAMUX AES In request */
#define DMAMUX1_AES_OUT (92) /* DMAMUX AES Out request */
#define DMAMUX1_TIM20_TRIG (93) /* DMAMUX TIM20 Trigger request */
#define DMAMUX1_TIM20_COM (94) /* DMAMUX TIM20 Commutation request */
#define DMAMUX1_HRTIM1_M (95) /* DMAMUX HRTIM M request */
#define DMAMUX1_HRTIM1_A (96) /* DMAMUX HRTIM A request */
#define DMAMUX1_HRTIM1_B (97) /* DMAMUX HRTIM B request */
#define DMAMUX1_HRTIM1_C (98) /* DMAMUX HRTIM C request */
#define DMAMUX1_HRTIM1_D (99) /* DMAMUX HRTIM D request */
#define DMAMUX1_HRTIM1_E (100) /* DMAMUX HRTIM E request */
#define DMAMUX1_HRTIM1_F (101) /* DMAMUX HRTIM F request */
#define DMAMUX1_DAC3_CH1 (102) /* DMAMUX DAC3 Channel 1 request */
#define DMAMUX1_DAC3_CH2 (103) /* DMAMUX DAC3 Channel 2 request */
#define DMAMUX1_DAC4_CH1 (104) /* DMAMUX DAC4 Channel 1 request */
#define DMAMUX1_DAC4_CH2 (105) /* DMAMUX DAC4 Channel 2 request */
#define DMAMUX1_SPI4_RX (106) /* DMAMUX SPI4 Rx request */
#define DMAMUX1_SPI4_TX (107) /* DMAMUX SPI4 Tx request */
#define DMAMUX1_SAI1_A (108) /* DMAMUX SAI1 A request */
#define DMAMUX1_SAI1_B (109) /* DMAMUX SAI1 B request */
#define DMAMUX1_FMAC_READ (110) /* DMAMUX FMAC Read request */
#define DMAMUX1_FMAC_WRITE (111) /* DMAMUX FMAC Write request */
#define DMAMUX1_CORDIC_READ (112) /* DMAMUX CORDIC Read request */
#define DMAMUX1_CORDIC_WRITE (113) /* DMAMUX CORDIC Write request */
#define DMAMUX1_UCPD1_RX (114) /* DMAMUX USBPD1 Rx request */
#define DMAMUX1_UCPD1_TX (115) /* DMAMUX USBPD1 Tx request */
/* DMAMAP for DMA1 and DMA2 (DMAMUX1) */
#define DMAMAP_DMA12_MEM2MEM_0 DMAMAP_MAP(DMA1, DMAMUX1_MEM2MEM)
#define DMAMAP_DMA12_MEM2MEM_1 DMAMAP_MAP(DMA2, DMAMUX1_MEM2MEM)
#define DMAMAP_DMA12_REQGEN0_0 DMAMAP_MAP(DMA1, DMAMUX1_REQ_GEN0)
#define DMAMAP_DMA12_REQGEN0_1 DMAMAP_MAP(DMA2, DMAMUX1_REQ_GEN0)
#define DMAMAP_DMA12_REQGEN1_0 DMAMAP_MAP(DMA1, DMAMUX1_REQ_GEN1)
#define DMAMAP_DMA12_REQGEN1_1 DMAMAP_MAP(DMA2, DMAMUX1_REQ_GEN1)
#define DMAMAP_DMA12_REQGEN2_0 DMAMAP_MAP(DMA1, DMAMUX1_REQ_GEN2)
#define DMAMAP_DMA12_REQGEN2_1 DMAMAP_MAP(DMA2, DMAMUX1_REQ_GEN2)
#define DMAMAP_DMA12_REQGEN3_0 DMAMAP_MAP(DMA1, DMAMUX1_REQ_GEN3)
#define DMAMAP_DMA12_REQGEN3_1 DMAMAP_MAP(DMA2, DMAMUX1_REQ_GEN3)
#define DMAMAP_DMA12_ADC1_0 DMAMAP_MAP(DMA1, DMAMUX1_ADC1)
#define DMAMAP_DMA12_ADC1_1 DMAMAP_MAP(DMA2, DMAMUX1_ADC1)
#define DMAMAP_DMA12_DAC1CH1_0 DMAMAP_MAP(DMA1, DMAMUX1_DAC1_CH1)
#define DMAMAP_DMA12_DAC1CH1_1 DMAMAP_MAP(DMA2, DMAMUX1_DAC1_CH1)
#define DMAMAP_DMA12_DAC1CH2_0 DMAMAP_MAP(DMA1, DMAMUX1_DAC1_CH2)
#define DMAMAP_DMA12_DAC1CH2_1 DMAMAP_MAP(DMA2, DMAMUX1_DAC1_CH2)
#define DMAMAP_DMA12_TIM6UP_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM6_UP)
#define DMAMAP_DMA12_TIM6UP_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM6_UP)
#define DMAMAP_DMA12_TIM7UP_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM7_UP)
#define DMAMAP_DMA12_TIM7UP_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM7_UP)
#define DMAMAP_DMA12_SPI1RX_0 DMAMAP_MAP(DMA1, DMAMUX1_SPI1_RX)
#define DMAMAP_DMA12_SPI1RX_1 DMAMAP_MAP(DMA2, DMAMUX1_SPI1_RX)
#define DMAMAP_DMA12_SPI1TX_0 DMAMAP_MAP(DMA1, DMAMUX1_SPI1_TX)
#define DMAMAP_DMA12_SPI1TX_1 DMAMAP_MAP(DMA2, DMAMUX1_SPI1_TX)
#define DMAMAP_DMA12_SPI2RX_0 DMAMAP_MAP(DMA1, DMAMUX1_SPI2_RX)
#define DMAMAP_DMA12_SPI2RX_1 DMAMAP_MAP(DMA2, DMAMUX1_SPI2_RX)
#define DMAMAP_DMA12_SPI2TX_0 DMAMAP_MAP(DMA1, DMAMUX1_SPI2_TX)
#define DMAMAP_DMA12_SPI2TX_1 DMAMAP_MAP(DMA2, DMAMUX1_SPI2_TX)
#define DMAMAP_DMA12_SPI3RX_0 DMAMAP_MAP(DMA1, DMAMUX1_SPI3_RX)
#define DMAMAP_DMA12_SPI3RX_1 DMAMAP_MAP(DMA2, DMAMUX1_SPI3_RX)
#define DMAMAP_DMA12_SPI3TX_0 DMAMAP_MAP(DMA1, DMAMUX1_SPI3_TX)
#define DMAMAP_DMA12_SPI3TX_1 DMAMAP_MAP(DMA2, DMAMUX1_SPI3_TX)
#define DMAMAP_DMA12_I2C1RX_0 DMAMAP_MAP(DMA1, DMAMUX1_I2C1_RX)
#define DMAMAP_DMA12_I2C1RX_1 DMAMAP_MAP(DMA2, DMAMUX1_I2C1_RX)
#define DMAMAP_DMA12_I2C1TX_0 DMAMAP_MAP(DMA1, DMAMUX1_I2C1_TX)
#define DMAMAP_DMA12_I2C1TX_1 DMAMAP_MAP(DMA2, DMAMUX1_I2C1_TX)
#define DMAMAP_DMA12_I2C2RX_0 DMAMAP_MAP(DMA1, DMAMUX1_I2C2_RX)
#define DMAMAP_DMA12_I2C2RX_1 DMAMAP_MAP(DMA2, DMAMUX1_I2C2_RX)
#define DMAMAP_DMA12_I2C2TX_0 DMAMAP_MAP(DMA1, DMAMUX1_I2C2_TX)
#define DMAMAP_DMA12_I2C2TX_1 DMAMAP_MAP(DMA2, DMAMUX1_I2C2_TX)
#define DMAMAP_DMA12_I2C3RX_0 DMAMAP_MAP(DMA1, DMAMUX1_I2C3_RX)
#define DMAMAP_DMA12_I2C3RX_1 DMAMAP_MAP(DMA2, DMAMUX1_I2C3_RX)
#define DMAMAP_DMA12_I2C3TX_0 DMAMAP_MAP(DMA1, DMAMUX1_I2C3_TX)
#define DMAMAP_DMA12_I2C3TX_1 DMAMAP_MAP(DMA2, DMAMUX1_I2C3_TX)
#define DMAMAP_DMA12_I2C4RX_0 DMAMAP_MAP(DMA1, DMAMUX1_I2C4_RX)
#define DMAMAP_DMA12_I2C4RX_1 DMAMAP_MAP(DMA2, DMAMUX1_I2C4_RX)
#define DMAMAP_DMA12_I2C4TX_0 DMAMAP_MAP(DMA1, DMAMUX1_I2C4_TX)
#define DMAMAP_DMA12_I2C4TX_1 DMAMAP_MAP(DMA2, DMAMUX1_I2C4_TX)
#define DMAMAP_DMA12_USART1RX_0 DMAMAP_MAP(DMA1, DMAMUX1_USART1_RX)
#define DMAMAP_DMA12_USART1RX_1 DMAMAP_MAP(DMA2, DMAMUX1_USART1_RX)
#define DMAMAP_DMA12_USART1TX_0 DMAMAP_MAP(DMA1, DMAMUX1_USART1_TX)
#define DMAMAP_DMA12_USART1TX_1 DMAMAP_MAP(DMA2, DMAMUX1_USART1_TX)
#define DMAMAP_DMA12_USART2RX_0 DMAMAP_MAP(DMA1, DMAMUX1_USART2_RX)
#define DMAMAP_DMA12_USART2RX_1 DMAMAP_MAP(DMA2, DMAMUX1_USART2_RX)
#define DMAMAP_DMA12_USART2TX_0 DMAMAP_MAP(DMA1, DMAMUX1_USART2_TX)
#define DMAMAP_DMA12_USART2TX_1 DMAMAP_MAP(DMA2, DMAMUX1_USART2_TX)
#define DMAMAP_DMA12_USART3RX_0 DMAMAP_MAP(DMA1, DMAMUX1_USART3_RX)
#define DMAMAP_DMA12_USART3RX_1 DMAMAP_MAP(DMA2, DMAMUX1_USART3_RX)
#define DMAMAP_DMA12_USART3TX_0 DMAMAP_MAP(DMA1, DMAMUX1_USART3_TX)
#define DMAMAP_DMA12_USART3TX_1 DMAMAP_MAP(DMA2, DMAMUX1_USART3_TX)
#define DMAMAP_DMA12_UART4RX_0 DMAMAP_MAP(DMA1, DMAMUX1_UART4_RX)
#define DMAMAP_DMA12_UART4RX_1 DMAMAP_MAP(DMA2, DMAMUX1_UART4_RX)
#define DMAMAP_DMA12_UART4TX_0 DMAMAP_MAP(DMA1, DMAMUX1_UART4_TX)
#define DMAMAP_DMA12_UART4TX_1 DMAMAP_MAP(DMA2, DMAMUX1_UART4_TX)
#define DMAMAP_DMA12_UART5RX_0 DMAMAP_MAP(DMA1, DMAMUX1_UART5_RX)
#define DMAMAP_DMA12_UART5RX_1 DMAMAP_MAP(DMA2, DMAMUX1_UART5_RX)
#define DMAMAP_DMA12_UART5TX_0 DMAMAP_MAP(DMA1, DMAMUX1_UART5_TX)
#define DMAMAP_DMA12_UART5TX_1 DMAMAP_MAP(DMA2, DMAMUX1_UART5_TX)
#define DMAMAP_DMA12_LPUART1RX_0 DMAMAP_MAP(DMA1, DMAMUX1_LPUART1_RX)
#define DMAMAP_DMA12_LPUART1RX_1 DMAMAP_MAP(DMA2, DMAMUX1_LPUART1_RX)
#define DMAMAP_DMA12_LPUART1TX_0 DMAMAP_MAP(DMA1, DMAMUX1_LPUART1_TX)
#define DMAMAP_DMA12_LPUART1TX_1 DMAMAP_MAP(DMA2, DMAMUX1_LPUART1_TX)
#define DMAMAP_DMA12_ADC2_0 DMAMAP_MAP(DMA1, DMAMUX1_ADC2)
#define DMAMAP_DMA12_ADC2_1 DMAMAP_MAP(DMA2, DMAMUX1_ADC2)
#define DMAMAP_DMA12_ADC3_0 DMAMAP_MAP(DMA1, DMAMUX1_ADC3)
#define DMAMAP_DMA12_ADC3_1 DMAMAP_MAP(DMA2, DMAMUX1_ADC3)
#define DMAMAP_DMA12_ADC4_0 DMAMAP_MAP(DMA1, DMAMUX1_ADC4)
#define DMAMAP_DMA12_ADC4_1 DMAMAP_MAP(DMA2, DMAMUX1_ADC4)
#define DMAMAP_DMA12_ADC5_0 DMAMAP_MAP(DMA1, DMAMUX1_ADC5)
#define DMAMAP_DMA12_ADC5_1 DMAMAP_MAP(DMA2, DMAMUX1_ADC5)
#define DMAMAP_DMA12_QSPI_0 DMAMAP_MAP(DMA1, DMAMUX1_QSPI)
#define DMAMAP_DMA12_QSPI_1 DMAMAP_MAP(DMA2, DMAMUX1_QSPI)
#define DMAMAP_DMA12_DAC2CH1_0 DMAMAP_MAP(DMA1, DMAMUX1_DAC2_CH1)
#define DMAMAP_DMA12_DAC2CH1_1 DMAMAP_MAP(DMA2, DMAMUX1_DAC2_CH1)
#define DMAMAP_DMA12_TIM1CH1_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM1_CH1)
#define DMAMAP_DMA12_TIM1CH1_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM1_CH1)
#define DMAMAP_DMA12_TIM1CH2_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM1_CH2)
#define DMAMAP_DMA12_TIM1CH2_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM1_CH2)
#define DMAMAP_DMA12_TIM1CH3_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM1_CH3)
#define DMAMAP_DMA12_TIM1CH3_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM1_CH3)
#define DMAMAP_DMA12_TIM1CH4_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM1_CH4)
#define DMAMAP_DMA12_TIM1CH4_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM1_CH4)
#define DMAMAP_DMA12_TIM1UP_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM1_UP)
#define DMAMAP_DMA12_TIM1UP_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM1_UP)
#define DMAMAP_DMA12_TIM1TRIG_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM1_TRIG)
#define DMAMAP_DMA12_TIM1TRIG_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM1_TRIG)
#define DMAMAP_DMA12_TIM1COM_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM1_COM)
#define DMAMAP_DMA12_TIM1COM_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM1_COM)
#define DMAMAP_DMA12_TIM8CH1_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM8_CH1)
#define DMAMAP_DMA12_TIM8CH1_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM8_CH1)
#define DMAMAP_DMA12_TIM8CH2_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM8_CH2)
#define DMAMAP_DMA12_TIM8CH2_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM8_CH2)
#define DMAMAP_DMA12_TIM8CH3_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM8_CH3)
#define DMAMAP_DMA12_TIM8CH3_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM8_CH3)
#define DMAMAP_DMA12_TIM8CH4_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM8_CH4)
#define DMAMAP_DMA12_TIM8CH4_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM8_CH4)
#define DMAMAP_DMA12_TIM8UP_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM8_UP)
#define DMAMAP_DMA12_TIM8UP_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM8_UP)
#define DMAMAP_DMA12_TIM8TRIG_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM8_TRIG)
#define DMAMAP_DMA12_TIM8TRIG_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM8_TRIG)
#define DMAMAP_DMA12_TIM8COM_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM8_COM)
#define DMAMAP_DMA12_TIM8COM_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM8_COM)
#define DMAMAP_DMA12_TIM2CH1_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM2_CH1)
#define DMAMAP_DMA12_TIM2CH1_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM2_CH1)
#define DMAMAP_DMA12_TIM2CH2_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM2_CH2)
#define DMAMAP_DMA12_TIM2CH2_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM2_CH2)
#define DMAMAP_DMA12_TIM2CH3_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM2_CH3)
#define DMAMAP_DMA12_TIM2CH3_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM2_CH3)
#define DMAMAP_DMA12_TIM2CH4_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM2_CH4)
#define DMAMAP_DMA12_TIM2CH4_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM2_CH4)
#define DMAMAP_DMA12_TIM2UP_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM2_UP)
#define DMAMAP_DMA12_TIM2UP_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM2_UP)
#define DMAMAP_DMA12_TIM3CH1_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM3_CH1)
#define DMAMAP_DMA12_TIM3CH1_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM3_CH1)
#define DMAMAP_DMA12_TIM3CH2_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM3_CH2)
#define DMAMAP_DMA12_TIM3CH2_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM3_CH2)
#define DMAMAP_DMA12_TIM3CH3_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM3_CH3)
#define DMAMAP_DMA12_TIM3CH3_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM3_CH3)
#define DMAMAP_DMA12_TIM3CH4_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM3_CH4)
#define DMAMAP_DMA12_TIM3CH4_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM3_CH4)
#define DMAMAP_DMA12_TIM3UP_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM3_UP)
#define DMAMAP_DMA12_TIM3UP_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM3_UP)
#define DMAMAP_DMA12_TIM3TRIG_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM3_TRIG)
#define DMAMAP_DMA12_TIM3TRIG_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM3_TRIG)
#define DMAMAP_DMA12_TIM4CH1_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM4_CH1)
#define DMAMAP_DMA12_TIM4CH1_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM4_CH1)
#define DMAMAP_DMA12_TIM4CH2_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM4_CH2)
#define DMAMAP_DMA12_TIM4CH2_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM4_CH2)
#define DMAMAP_DMA12_TIM4CH3_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM4_CH3)
#define DMAMAP_DMA12_TIM4CH3_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM4_CH3)
#define DMAMAP_DMA12_TIM4CH4_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM4_CH4)
#define DMAMAP_DMA12_TIM4CH4_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM4_CH4)
#define DMAMAP_DMA12_TIM4UP_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM4_UP)
#define DMAMAP_DMA12_TIM4UP_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM4_UP)
#define DMAMAP_DMA12_TIM5CH1_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM5_CH1)
#define DMAMAP_DMA12_TIM5CH1_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM5_CH1)
#define DMAMAP_DMA12_TIM5CH2_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM5_CH2)
#define DMAMAP_DMA12_TIM5CH2_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM5_CH2)
#define DMAMAP_DMA12_TIM5CH3_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM5_CH3)
#define DMAMAP_DMA12_TIM5CH3_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM5_CH3)
#define DMAMAP_DMA12_TIM5CH4_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM5_CH4)
#define DMAMAP_DMA12_TIM5CH4_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM5_CH4)
#define DMAMAP_DMA12_TIM5UP_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM5_UP)
#define DMAMAP_DMA12_TIM5UP_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM5_UP)
#define DMAMAP_DMA12_TIM5TRIG_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM5_TRIG)
#define DMAMAP_DMA12_TIM5TRIG_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM5_TRIG)
#define DMAMAP_DMA12_TIM15CH1_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM15_CH1)
#define DMAMAP_DMA12_TIM15CH1_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM15_CH1)
#define DMAMAP_DMA12_TIM15UP_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM15_UP)
#define DMAMAP_DMA12_TIM15UP_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM15_UP)
#define DMAMAP_DMA12_TIM15TRIG_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM15_TRIG)
#define DMAMAP_DMA12_TIM15TRIG_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM15_TRIG)
#define DMAMAP_DMA12_TIM16CH1_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM16_CH1)
#define DMAMAP_DMA12_TIM16CH1_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM16_CH1)
#define DMAMAP_DMA12_TIM16UP_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM16_UP)
#define DMAMAP_DMA12_TIM16UP_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM16_UP)
#define DMAMAP_DMA12_TIM17CH1_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM17_CH1)
#define DMAMAP_DMA12_TIM17CH1_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM17_CH1)
#define DMAMAP_DMA12_TIM17UP_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM17_UP)
#define DMAMAP_DMA12_TIM17UP_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM17_UP)
#define DMAMAP_DMA12_TIM20CH1_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM20_CH1)
#define DMAMAP_DMA12_TIM20CH1_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM20_CH1)
#define DMAMAP_DMA12_TIM20CH2_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM20_CH2)
#define DMAMAP_DMA12_TIM20CH2_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM20_CH2)
#define DMAMAP_DMA12_TIM20CH3_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM20_CH3)
#define DMAMAP_DMA12_TIM20CH3_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM20_CH3)
#define DMAMAP_DMA12_TIM20CH4_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM20_CH4)
#define DMAMAP_DMA12_TIM20CH4_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM20_CH4)
#define DMAMAP_DMA12_TIM20UP_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM20_UP)
#define DMAMAP_DMA12_TIM20UP_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM20_UP)
#define DMAMAP_DMA12_AESIN_0 DMAMAP_MAP(DMA1, DMAMUX1_AES_IN)
#define DMAMAP_DMA12_AESIN_1 DMAMAP_MAP(DMA2, DMAMUX1_AES_IN)
#define DMAMAP_DMA12_AESOUT_0 DMAMAP_MAP(DMA1, DMAMUX1_AES_OUT)
#define DMAMAP_DMA12_AESOUT_1 DMAMAP_MAP(DMA2, DMAMUX1_AES_OUT)
#define DMAMAP_DMA12_TIM20TRIG_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM20_TRIG)
#define DMAMAP_DMA12_TIM20TRIG_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM20_TRIG)
#define DMAMAP_DMA12_TIM20COM_0 DMAMAP_MAP(DMA1, DMAMUX1_TIM20_COM)
#define DMAMAP_DMA12_TIM20COM_1 DMAMAP_MAP(DMA2, DMAMUX1_TIM20_COM)
#define DMAMAP_DMA12_HRTIM1M_0 DMAMAP_MAP(DMA1, DMAMUX1_HRTIM1_M)
#define DMAMAP_DMA12_HRTIM1M_1 DMAMAP_MAP(DMA2, DMAMUX1_HRTIM1_M)
#define DMAMAP_DMA12_HRTIM1A_0 DMAMAP_MAP(DMA1, DMAMUX1_HRTIM1_A)
#define DMAMAP_DMA12_HRTIM1A_1 DMAMAP_MAP(DMA2, DMAMUX1_HRTIM1_A)
#define DMAMAP_DMA12_HRTIM1B_0 DMAMAP_MAP(DMA1, DMAMUX1_HRTIM1_B)
#define DMAMAP_DMA12_HRTIM1B_1 DMAMAP_MAP(DMA2, DMAMUX1_HRTIM1_B)
#define DMAMAP_DMA12_HRTIM1C_0 DMAMAP_MAP(DMA1, DMAMUX1_HRTIM1_C)
#define DMAMAP_DMA12_HRTIM1C_1 DMAMAP_MAP(DMA2, DMAMUX1_HRTIM1_C)
#define DMAMAP_DMA12_HRTIM1D_0 DMAMAP_MAP(DMA1, DMAMUX1_HRTIM1_D)
#define DMAMAP_DMA12_HRTIM1D_1 DMAMAP_MAP(DMA2, DMAMUX1_HRTIM1_D)
#define DMAMAP_DMA12_HRTIM1E_0 DMAMAP_MAP(DMA1, DMAMUX1_HRTIM1_E)
#define DMAMAP_DMA12_HRTIM1E_1 DMAMAP_MAP(DMA2, DMAMUX1_HRTIM1_E)
#define DMAMAP_DMA12_HRTIM1F_0 DMAMAP_MAP(DMA1, DMAMUX1_HRTIM1_F)
#define DMAMAP_DMA12_HRTIM1F_1 DMAMAP_MAP(DMA2, DMAMUX1_HRTIM1_F)
#define DMAMAP_DMA12_DAC3CH1_0 DMAMAP_MAP(DMA1, DMAMUX1_DAC3_CH1)
#define DMAMAP_DMA12_DAC3CH1_1 DMAMAP_MAP(DMA2, DMAMUX1_DAC3_CH1)
#define DMAMAP_DMA12_DAC3CH2_0 DMAMAP_MAP(DMA1, DMAMUX1_DAC3_CH2)
#define DMAMAP_DMA12_DAC3CH2_1 DMAMAP_MAP(DMA2, DMAMUX1_DAC3_CH2)
#define DMAMAP_DMA12_DAC4CH1_0 DMAMAP_MAP(DMA1, DMAMUX1_DAC4_CH1)
#define DMAMAP_DMA12_DAC4CH1_1 DMAMAP_MAP(DMA2, DMAMUX1_DAC4_CH1)
#define DMAMAP_DMA12_DAC4CH2_0 DMAMAP_MAP(DMA1, DMAMUX1_DAC4_CH2)
#define DMAMAP_DMA12_DAC4CH2_1 DMAMAP_MAP(DMA2, DMAMUX1_DAC4_CH2)
#define DMAMAP_DMA12_SPI4RX_0 DMAMAP_MAP(DMA1, DMAMUX1_SPI4_RX)
#define DMAMAP_DMA12_SPI4RX_1 DMAMAP_MAP(DMA2, DMAMUX1_SPI4_RX)
#define DMAMAP_DMA12_SPI4TX_0 DMAMAP_MAP(DMA1, DMAMUX1_SPI4_TX)
#define DMAMAP_DMA12_SPI4TX_1 DMAMAP_MAP(DMA2, DMAMUX1_SPI4_TX)
#define DMAMAP_DMA12_SAI1A_0 DMAMAP_MAP(DMA1, DMAMUX1_SAI1_A)
#define DMAMAP_DMA12_SAI1A_1 DMAMAP_MAP(DMA2, DMAMUX1_SAI1_A)
#define DMAMAP_DMA12_SAI1B_0 DMAMAP_MAP(DMA1, DMAMUX1_SAI1_B)
#define DMAMAP_DMA12_SAI1B_1 DMAMAP_MAP(DMA2, DMAMUX1_SAI1_B)
#define DMAMAP_DMA12_FMACREAD_0 DMAMAP_MAP(DMA1, DMAMUX1_FMAC_READ)
#define DMAMAP_DMA12_FMACREAD_1 DMAMAP_MAP(DMA2, DMAMUX1_FMAC_READ)
#define DMAMAP_DMA12_FMACWRITE_0 DMAMAP_MAP(DMA1, DMAMUX1_FMAC_WRITE)
#define DMAMAP_DMA12_FMACWRITE_1 DMAMAP_MAP(DMA2, DMAMUX1_FMAC_WRITE)
#define DMAMAP_DMA12_CORDICREAD_0 DMAMAP_MAP(DMA1, DMAMUX1_CORDIC_READ)
#define DMAMAP_DMA12_CORDICREAD_1 DMAMAP_MAP(DMA2, DMAMUX1_CORDIC_READ)
#define DMAMAP_DMA12_CORDICWRITE_0 DMAMAP_MAP(DMA1, DMAMUX1_CORDIC_WRITE)
#define DMAMAP_DMA12_CORDICWRITE_1 DMAMAP_MAP(DMA2, DMAMUX1_CORDIC_WRITE)
#define DMAMAP_DMA12_UCPD1RX_0 DMAMAP_MAP(DMA1, DMAMUX1_UCPD1_RX)
#define DMAMAP_DMA12_UCPD1RX_1 DMAMAP_MAP(DMA2, DMAMUX1_UCPD1_RX)
#define DMAMAP_DMA12_UCPD1TX_0 DMAMAP_MAP(DMA1, DMAMUX1_UCPD1_TX)
#define DMAMAP_DMA12_UCPD1TX_1 DMAMAP_MAP(DMA2, DMAMUX1_UCPD1_TX)
#endif /* __ARCH_ARM_SRC_STM32_HARDWARE_STM32G4XXXX_DMAMUX_H */
| 73.232323 | 99 | 0.683 |
b13839021bbbf66f2b64ccde68c5820b69d89101 | 8,193 | h | C | controller/lib/include/audio_unit_descriptor_response.h | RikusW/avdecc-lib | eb73e2a1151920d954443425ba67adfe1d8d9819 | [
"MIT"
] | 57 | 2015-01-20T23:09:18.000Z | 2021-08-03T16:22:40.000Z | controller/lib/include/audio_unit_descriptor_response.h | Avnu/avdecc-lib | eb73e2a1151920d954443425ba67adfe1d8d9819 | [
"MIT"
] | 67 | 2015-01-15T13:21:36.000Z | 2021-03-31T15:31:17.000Z | controller/lib/include/audio_unit_descriptor_response.h | Avnu/avdecc-lib | eb73e2a1151920d954443425ba67adfe1d8d9819 | [
"MIT"
] | 27 | 2015-01-22T11:55:40.000Z | 2021-08-17T02:23:56.000Z | /*
* Licensed under the MIT License (MIT)
*
* Copyright (c) 2014 AudioScience Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 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.
*/
/**
* audio_unit_descriptor_response.h
*
* Public AUDIO_UNIT descriptor response interface class
* The AUDIO UNIT descriptor describes an AUDIO UNIT within the AVDECC Entity. An Audio Unit
* represents a single audio clock domain.
*/
#pragma once
#include <stdint.h>
#include "avdecc-lib_build.h"
#include "descriptor_response_base.h"
namespace avdecc_lib
{
class audio_unit_descriptor_response : public virtual descriptor_response_base
{
public:
virtual ~audio_unit_descriptor_response(){};
///
/// \return The localized string reference pointing to the localized descriptor name.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL localized_description() = 0;
///
/// \return The descriptor index of the Clock Domain descriptor describing the clock domain for the Audio Unit.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL clock_domain_index() = 0;
///
/// \return The number of Input Stream Ports used by this Audio Unit.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL number_of_stream_input_ports() = 0;
///
/// \return The index of the first Stream Port Input descriptor.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL base_stream_input_port() = 0;
///
/// \return The number of Output Stream Ports used by this Audio Unit.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL number_of_stream_output_ports() = 0;
///
/// \return The index of the first Stream Port Output descriptor.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL base_stream_output_port() = 0;
///
/// \return The number of external Input Ports used by this Audio Unit.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL number_of_external_input_ports() = 0;
///
/// \return The index of the first External Port Input descriptor.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL base_external_input_port() = 0;
///
/// \return The number of external Output Ports used by this Audio Unit.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL number_of_external_output_ports() = 0;
///
/// \return The index of the first External Port Output descriptor.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL base_external_output_port() = 0;
///
/// \return The number of internal Input Ports used by this Audio Unit.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL number_of_internal_input_ports() = 0;
///
/// \return The index of the first input Internal JACK INPUT and Internal Port Input descriptors.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL base_internal_input_port() = 0;
///
/// \return The number of internal Output Ports used by this Audio Unit.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL number_of_internal_output_ports() = 0;
///
/// \return The index of the first output Internal JACK OUTPUT and Internal Port Output descriptors.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL base_internal_output_port() = 0;
///
/// \return The number of controls within this Audio Unit.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL number_of_controls() = 0;
///
/// \return The index of the first Control descriptor.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL base_control() = 0;
///
/// \return The number of signal selectors within this Audio Unit.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL number_of_signal_selectors() = 0;
///
/// \return The index of the first Signal Selector descriptor.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL base_signal_selector() = 0;
///
/// \return The number of mixers within this Audio Unit.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL number_of_mixers() = 0;
///
/// \return The index of the first Mixer descriptor.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL base_mixer() = 0;
///
/// \return The number of matrices within this Audio Unit.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL number_of_matrices() = 0;
///
/// \return The index of the first Matrix descriptor.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL base_matrix() = 0;
///
/// \return The number of splitters within this Audio Unit.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL number_of_splitters() = 0;
///
/// \return The index of the first Signal Splitter descriptor.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL base_splitter() = 0;
///
/// \return The number of combiners within this Audio Unit.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL number_of_combiners() = 0;
///
/// \return index of the first Signal Combiner descriptor.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL base_combiner() = 0;
///
/// \return The number of demultiplexers within this Audio Unit.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL number_of_demultiplexers() = 0;
///
/// \return The index of the first Signal Demultiplexer descriptor.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL base_demultiplexer() = 0;
///
/// \return The number of multiplexers within this Audio Unit.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL number_of_multiplexers() = 0;
///
/// \return The index of the first Multiplexer descriptor..
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL base_multiplexer() = 0;
///
/// \return The number of transcoders within this Audio Unit.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL number_of_transcoders() = 0;
///
/// \return The index of the first Signal Transcoder descriptor.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL base_transcoder() = 0;
///
/// \return The number of control blocks within this Audio Unit.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL number_of_control_blocks() = 0;
///
/// \return The index of the first Control Block descriptor.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL base_control_block() = 0;
///
/// \return The current sampling rate of this Audio Unit.
///
AVDECC_CONTROLLER_LIB32_API virtual uint32_t STDCALL current_sampling_rate() = 0;
///
/// \return The corresponding sampling rate by index of this Audio Unit.
///
AVDECC_CONTROLLER_LIB32_API virtual uint32_t STDCALL get_sampling_rate_by_index(size_t sampling_rate_index) = 0;
///
/// \return The number of sample rates. The maximum value is 91 for this version of AEM.
///
AVDECC_CONTROLLER_LIB32_API virtual uint16_t STDCALL sampling_rates_count() = 0;
};
}
| 35.621739 | 116 | 0.715733 |
7f6c9b0fad0566e8f85988fe25cbfbc7e4055203 | 1,857 | h | C | usr/src/test/crypto-tests/tests/modes/aes/cmac/aes_cmac.h | AsahiOS/gate | 283d47da4e17a5871d9d575e7ffb81e8f6c52e51 | [
"MIT"
] | null | null | null | usr/src/test/crypto-tests/tests/modes/aes/cmac/aes_cmac.h | AsahiOS/gate | 283d47da4e17a5871d9d575e7ffb81e8f6c52e51 | [
"MIT"
] | null | null | null | usr/src/test/crypto-tests/tests/modes/aes/cmac/aes_cmac.h | AsahiOS/gate | 283d47da4e17a5871d9d575e7ffb81e8f6c52e51 | [
"MIT"
] | 1 | 2020-12-30T00:04:16.000Z | 2020-12-30T00:04:16.000Z | /*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*/
/*
* Copyright 2015 Nexenta Systems, Inc. All rights reserved.
*/
#ifndef _AES_CMAC_H
#define _AES_CMAC_H
#ifdef __cplusplus
extern "C" {
#endif
/*
* Test Vectors
* RFC4493
*/
static uint8_t CMAC_0[AES_BLOCK_LEN] = {
0xbb, 0x1d, 0x69, 0x29, 0xe9, 0x59, 0x37, 0x28,
0x7f, 0xa3, 0x7d, 0x12, 0x9b, 0x75, 0x67, 0x46
};
static uint8_t CMAC_16[AES_BLOCK_LEN] = {
0x07, 0x0a, 0x16, 0xb4, 0x6b, 0x4d, 0x41, 0x44,
0xf7, 0x9b, 0xdd, 0x9d, 0xd0, 0x4a, 0x28, 0x7c
};
static uint8_t CMAC_40[AES_BLOCK_LEN] = {
0xdf, 0xa6, 0x67, 0x47, 0xde, 0x9a, 0xe6, 0x30,
0x30, 0xca, 0x32, 0x61, 0x14, 0x97, 0xc8, 0x27
};
static uint8_t CMAC_64[AES_BLOCK_LEN] = {
0x51, 0xf0, 0xbe, 0xbf, 0x7e, 0x3b, 0x9d, 0x92,
0xfc, 0x49, 0x74, 0x17, 0x79, 0x36, 0x3c, 0xfe
};
uint8_t M[64] = {
0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10
};
uint8_t keytest[16] = {
0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c
};
uint8_t *RES[] = {
CMAC_0, CMAC_16, CMAC_40, CMAC_64
};
size_t DATALEN[] = {
0, 16, 40, 64
};
#ifdef __cplusplus
}
#endif
#endif /* _AES_CMAC_H */
| 25.438356 | 69 | 0.674744 |
cfae911d06560fb3a930d2d0042913288e7a42c7 | 2,742 | h | C | vpr7_x2p/vpr/SRC/fpga_spice/clb_pin_remap/post_place_timing.h | ganeshgore/OpenFPGA | e2e4a9287ddd3f88ee6d436fa4b7e616bcd20390 | [
"MIT"
] | 1 | 2019-10-11T09:21:34.000Z | 2019-10-11T09:21:34.000Z | vpr7_x2p/vpr/SRC/fpga_spice/clb_pin_remap/post_place_timing.h | ganeshgore/OpenFPGA | e2e4a9287ddd3f88ee6d436fa4b7e616bcd20390 | [
"MIT"
] | null | null | null | vpr7_x2p/vpr/SRC/fpga_spice/clb_pin_remap/post_place_timing.h | ganeshgore/OpenFPGA | e2e4a9287ddd3f88ee6d436fa4b7e616bcd20390 | [
"MIT"
] | null | null | null |
void load_post_place_net_delay(float** net_delay,
int n_blks,
t_block* blk,
int n_nets,
t_net* nets,
t_det_routing_arch det_routing_arch,
t_segment_inf* segment_inf,
t_timing_inf timing_inf,
int num_directs,
t_direct_inf* directs);
float estimate_post_place_one_net_sink_delay(int net_index,
int n_blks,
t_block* blk,
int src_blk_index,
int des_blk_index,
t_det_routing_arch det_routing_arch,
t_segment_inf* segment_inf,
t_timing_inf timing_inf,
int num_directs,
t_direct_inf* directs);
float esti_pin2pin_one_net_delay(t_block src_blk,
int src_pin_side,
int src_pin_index,
t_block des_blk,
int des_pin_side,
int des_pin_index,
t_det_routing_arch det_routing_arch,
t_segment_inf* segment_inf,
t_timing_inf timing_inf,
int num_directs,
t_direct_inf* directs);
void load_expected_remapped_net_delay(float** net_delay,
int n_blks,
t_block* blk,
int n_nets,
t_net* nets,
t_det_routing_arch det_routing_arch,
t_segment_inf* segment_inf,
t_timing_inf timing_inf,
int num_directs,
t_direct_inf* directs);
float esti_distance_num_seg_delay(int distance,
int num_segment,
t_segment_inf* segment_inf,
int allow_long_segment);
float esti_one_segment_net_delay(int distance, t_segment_inf segment_inf);
float get_crossing_penalty(int num_sinks);
| 49.854545 | 95 | 0.383297 |
cfd93e31f68900796a5f7b936556f1ce21e8b602 | 22,816 | c | C | release/src-rt-6.x.4708/linux/linux-2.6.36/drivers/char/tty_ldisc.c | afeng11/tomato-arm | 1ca18a88480b34fd495e683d849f46c2d47bb572 | [
"FSFAP"
] | 4 | 2017-05-17T11:27:04.000Z | 2020-05-24T07:23:26.000Z | release/src-rt-6.x.4708/linux/linux-2.6.36/drivers/char/tty_ldisc.c | afeng11/tomato-arm | 1ca18a88480b34fd495e683d849f46c2d47bb572 | [
"FSFAP"
] | 1 | 2018-08-21T03:43:09.000Z | 2018-08-21T03:43:09.000Z | release/src-rt-6.x.4708/linux/linux-2.6.36/drivers/char/tty_ldisc.c | afeng11/tomato-arm | 1ca18a88480b34fd495e683d849f46c2d47bb572 | [
"FSFAP"
] | 5 | 2017-10-11T08:09:11.000Z | 2020-10-14T04:10:13.000Z | #include <linux/types.h>
#include <linux/major.h>
#include <linux/errno.h>
#include <linux/signal.h>
#include <linux/fcntl.h>
#include <linux/sched.h>
#include <linux/interrupt.h>
#include <linux/tty.h>
#include <linux/tty_driver.h>
#include <linux/tty_flip.h>
#include <linux/devpts_fs.h>
#include <linux/file.h>
#include <linux/console.h>
#include <linux/timer.h>
#include <linux/ctype.h>
#include <linux/kd.h>
#include <linux/mm.h>
#include <linux/string.h>
#include <linux/slab.h>
#include <linux/poll.h>
#include <linux/proc_fs.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/wait.h>
#include <linux/bitops.h>
#include <linux/delay.h>
#include <linux/seq_file.h>
#include <linux/uaccess.h>
#include <asm/system.h>
#include <linux/kbd_kern.h>
#include <linux/vt_kern.h>
#include <linux/selection.h>
#include <linux/smp_lock.h> /* For the moment */
#include <linux/kmod.h>
#include <linux/nsproxy.h>
/*
* This guards the refcounted line discipline lists. The lock
* must be taken with irqs off because there are hangup path
* callers who will do ldisc lookups and cannot sleep.
*/
static DEFINE_SPINLOCK(tty_ldisc_lock);
static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait);
static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_idle);
/* Line disc dispatch table */
static struct tty_ldisc_ops *tty_ldiscs[NR_LDISCS];
static inline struct tty_ldisc *get_ldisc(struct tty_ldisc *ld)
{
if (ld)
atomic_inc(&ld->users);
return ld;
}
static void put_ldisc(struct tty_ldisc *ld)
{
unsigned long flags;
if (WARN_ON_ONCE(!ld))
return;
/*
* If this is the last user, free the ldisc, and
* release the ldisc ops.
*
* We really want an "atomic_dec_and_lock_irqsave()",
* but we don't have it, so this does it by hand.
*/
local_irq_save(flags);
if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
struct tty_ldisc_ops *ldo = ld->ops;
ldo->refcount--;
module_put(ldo->owner);
spin_unlock_irqrestore(&tty_ldisc_lock, flags);
kfree(ld);
return;
}
local_irq_restore(flags);
wake_up(&tty_ldisc_idle);
}
/**
* tty_register_ldisc - install a line discipline
* @disc: ldisc number
* @new_ldisc: pointer to the ldisc object
*
* Installs a new line discipline into the kernel. The discipline
* is set up as unreferenced and then made available to the kernel
* from this point onwards.
*
* Locking:
* takes tty_ldisc_lock to guard against ldisc races
*/
int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
{
unsigned long flags;
int ret = 0;
if (disc < N_TTY || disc >= NR_LDISCS)
return -EINVAL;
spin_lock_irqsave(&tty_ldisc_lock, flags);
tty_ldiscs[disc] = new_ldisc;
new_ldisc->num = disc;
new_ldisc->refcount = 0;
spin_unlock_irqrestore(&tty_ldisc_lock, flags);
return ret;
}
EXPORT_SYMBOL(tty_register_ldisc);
/**
* tty_unregister_ldisc - unload a line discipline
* @disc: ldisc number
* @new_ldisc: pointer to the ldisc object
*
* Remove a line discipline from the kernel providing it is not
* currently in use.
*
* Locking:
* takes tty_ldisc_lock to guard against ldisc races
*/
int tty_unregister_ldisc(int disc)
{
unsigned long flags;
int ret = 0;
if (disc < N_TTY || disc >= NR_LDISCS)
return -EINVAL;
spin_lock_irqsave(&tty_ldisc_lock, flags);
if (tty_ldiscs[disc]->refcount)
ret = -EBUSY;
else
tty_ldiscs[disc] = NULL;
spin_unlock_irqrestore(&tty_ldisc_lock, flags);
return ret;
}
EXPORT_SYMBOL(tty_unregister_ldisc);
static struct tty_ldisc_ops *get_ldops(int disc)
{
unsigned long flags;
struct tty_ldisc_ops *ldops, *ret;
spin_lock_irqsave(&tty_ldisc_lock, flags);
ret = ERR_PTR(-EINVAL);
ldops = tty_ldiscs[disc];
if (ldops) {
ret = ERR_PTR(-EAGAIN);
if (try_module_get(ldops->owner)) {
ldops->refcount++;
ret = ldops;
}
}
spin_unlock_irqrestore(&tty_ldisc_lock, flags);
return ret;
}
static void put_ldops(struct tty_ldisc_ops *ldops)
{
unsigned long flags;
spin_lock_irqsave(&tty_ldisc_lock, flags);
ldops->refcount--;
module_put(ldops->owner);
spin_unlock_irqrestore(&tty_ldisc_lock, flags);
}
/**
* tty_ldisc_get - take a reference to an ldisc
* @disc: ldisc number
*
* Takes a reference to a line discipline. Deals with refcounts and
* module locking counts. Returns NULL if the discipline is not available.
* Returns a pointer to the discipline and bumps the ref count if it is
* available
*
* Locking:
* takes tty_ldisc_lock to guard against ldisc races
*/
static struct tty_ldisc *tty_ldisc_get(int disc)
{
struct tty_ldisc *ld;
struct tty_ldisc_ops *ldops;
if (disc < N_TTY || disc >= NR_LDISCS)
return ERR_PTR(-EINVAL);
/*
* Get the ldisc ops - we may need to request them to be loaded
* dynamically and try again.
*/
ldops = get_ldops(disc);
if (IS_ERR(ldops)) {
request_module("tty-ldisc-%d", disc);
ldops = get_ldops(disc);
if (IS_ERR(ldops))
return ERR_CAST(ldops);
}
ld = kmalloc(sizeof(struct tty_ldisc), GFP_KERNEL);
if (ld == NULL) {
put_ldops(ldops);
return ERR_PTR(-ENOMEM);
}
ld->ops = ldops;
atomic_set(&ld->users, 1);
return ld;
}
static void *tty_ldiscs_seq_start(struct seq_file *m, loff_t *pos)
{
return (*pos < NR_LDISCS) ? pos : NULL;
}
static void *tty_ldiscs_seq_next(struct seq_file *m, void *v, loff_t *pos)
{
(*pos)++;
return (*pos < NR_LDISCS) ? pos : NULL;
}
static void tty_ldiscs_seq_stop(struct seq_file *m, void *v)
{
}
static int tty_ldiscs_seq_show(struct seq_file *m, void *v)
{
int i = *(loff_t *)v;
struct tty_ldisc_ops *ldops;
ldops = get_ldops(i);
if (IS_ERR(ldops))
return 0;
seq_printf(m, "%-10s %2d\n", ldops->name ? ldops->name : "???", i);
put_ldops(ldops);
return 0;
}
static const struct seq_operations tty_ldiscs_seq_ops = {
.start = tty_ldiscs_seq_start,
.next = tty_ldiscs_seq_next,
.stop = tty_ldiscs_seq_stop,
.show = tty_ldiscs_seq_show,
};
static int proc_tty_ldiscs_open(struct inode *inode, struct file *file)
{
return seq_open(file, &tty_ldiscs_seq_ops);
}
const struct file_operations tty_ldiscs_proc_fops = {
.owner = THIS_MODULE,
.open = proc_tty_ldiscs_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
/**
* tty_ldisc_assign - set ldisc on a tty
* @tty: tty to assign
* @ld: line discipline
*
* Install an instance of a line discipline into a tty structure. The
* ldisc must have a reference count above zero to ensure it remains.
* The tty instance refcount starts at zero.
*
* Locking:
* Caller must hold references
*/
static void tty_ldisc_assign(struct tty_struct *tty, struct tty_ldisc *ld)
{
tty->ldisc = ld;
}
/**
* tty_ldisc_try - internal helper
* @tty: the tty
*
* Make a single attempt to grab and bump the refcount on
* the tty ldisc. Return 0 on failure or 1 on success. This is
* used to implement both the waiting and non waiting versions
* of tty_ldisc_ref
*
* Locking: takes tty_ldisc_lock
*/
static struct tty_ldisc *tty_ldisc_try(struct tty_struct *tty)
{
unsigned long flags;
struct tty_ldisc *ld;
spin_lock_irqsave(&tty_ldisc_lock, flags);
ld = NULL;
if (test_bit(TTY_LDISC, &tty->flags))
ld = get_ldisc(tty->ldisc);
spin_unlock_irqrestore(&tty_ldisc_lock, flags);
return ld;
}
/**
* tty_ldisc_ref_wait - wait for the tty ldisc
* @tty: tty device
*
* Dereference the line discipline for the terminal and take a
* reference to it. If the line discipline is in flux then
* wait patiently until it changes.
*
* Note: Must not be called from an IRQ/timer context. The caller
* must also be careful not to hold other locks that will deadlock
* against a discipline change, such as an existing ldisc reference
* (which we check for)
*
* Locking: call functions take tty_ldisc_lock
*/
struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty)
{
struct tty_ldisc *ld;
/* wait_event is a macro */
wait_event(tty_ldisc_wait, (ld = tty_ldisc_try(tty)) != NULL);
return ld;
}
EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait);
/**
* tty_ldisc_ref - get the tty ldisc
* @tty: tty device
*
* Dereference the line discipline for the terminal and take a
* reference to it. If the line discipline is in flux then
* return NULL. Can be called from IRQ and timer functions.
*
* Locking: called functions take tty_ldisc_lock
*/
struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty)
{
return tty_ldisc_try(tty);
}
EXPORT_SYMBOL_GPL(tty_ldisc_ref);
/**
* tty_ldisc_deref - free a tty ldisc reference
* @ld: reference to free up
*
* Undoes the effect of tty_ldisc_ref or tty_ldisc_ref_wait. May
* be called in IRQ context.
*
* Locking: takes tty_ldisc_lock
*/
void tty_ldisc_deref(struct tty_ldisc *ld)
{
put_ldisc(ld);
}
EXPORT_SYMBOL_GPL(tty_ldisc_deref);
static inline void tty_ldisc_put(struct tty_ldisc *ld)
{
put_ldisc(ld);
}
/**
* tty_ldisc_enable - allow ldisc use
* @tty: terminal to activate ldisc on
*
* Set the TTY_LDISC flag when the line discipline can be called
* again. Do necessary wakeups for existing sleepers. Clear the LDISC
* changing flag to indicate any ldisc change is now over.
*
* Note: nobody should set the TTY_LDISC bit except via this function.
* Clearing directly is allowed.
*/
void tty_ldisc_enable(struct tty_struct *tty)
{
set_bit(TTY_LDISC, &tty->flags);
clear_bit(TTY_LDISC_CHANGING, &tty->flags);
wake_up(&tty_ldisc_wait);
}
/**
* tty_ldisc_flush - flush line discipline queue
* @tty: tty
*
* Flush the line discipline queue (if any) for this tty. If there
* is no line discipline active this is a no-op.
*/
void tty_ldisc_flush(struct tty_struct *tty)
{
struct tty_ldisc *ld = tty_ldisc_ref(tty);
if (ld) {
if (ld->ops->flush_buffer)
ld->ops->flush_buffer(tty);
tty_ldisc_deref(ld);
}
tty_buffer_flush(tty);
}
EXPORT_SYMBOL_GPL(tty_ldisc_flush);
/**
* tty_set_termios_ldisc - set ldisc field
* @tty: tty structure
* @num: line discipline number
*
* This is probably overkill for real world processors but
* they are not on hot paths so a little discipline won't do
* any harm.
*
* Locking: takes termios_mutex
*/
static void tty_set_termios_ldisc(struct tty_struct *tty, int num)
{
mutex_lock(&tty->termios_mutex);
tty->termios->c_line = num;
mutex_unlock(&tty->termios_mutex);
}
/**
* tty_ldisc_open - open a line discipline
* @tty: tty we are opening the ldisc on
* @ld: discipline to open
*
* A helper opening method. Also a convenient debugging and check
* point.
*
* Locking: always called with BTM already held.
*/
static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld)
{
WARN_ON(test_and_set_bit(TTY_LDISC_OPEN, &tty->flags));
if (ld->ops->open) {
int ret;
/* BTM here locks versus a hangup event */
WARN_ON(!tty_locked());
ret = ld->ops->open(tty);
if (ret)
clear_bit(TTY_LDISC_OPEN, &tty->flags);
return ret;
}
return 0;
}
/**
* tty_ldisc_close - close a line discipline
* @tty: tty we are opening the ldisc on
* @ld: discipline to close
*
* A helper close method. Also a convenient debugging and check
* point.
*/
static void tty_ldisc_close(struct tty_struct *tty, struct tty_ldisc *ld)
{
WARN_ON(!test_bit(TTY_LDISC_OPEN, &tty->flags));
clear_bit(TTY_LDISC_OPEN, &tty->flags);
if (ld->ops->close)
ld->ops->close(tty);
}
/**
* tty_ldisc_restore - helper for tty ldisc change
* @tty: tty to recover
* @old: previous ldisc
*
* Restore the previous line discipline or N_TTY when a line discipline
* change fails due to an open error
*/
static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old)
{
char buf[64];
struct tty_ldisc *new_ldisc;
int r;
/* There is an outstanding reference here so this is safe */
old = tty_ldisc_get(old->ops->num);
WARN_ON(IS_ERR(old));
tty_ldisc_assign(tty, old);
tty_set_termios_ldisc(tty, old->ops->num);
if (tty_ldisc_open(tty, old) < 0) {
tty_ldisc_put(old);
/* This driver is always present */
new_ldisc = tty_ldisc_get(N_TTY);
if (IS_ERR(new_ldisc))
panic("n_tty: get");
tty_ldisc_assign(tty, new_ldisc);
tty_set_termios_ldisc(tty, N_TTY);
r = tty_ldisc_open(tty, new_ldisc);
if (r < 0)
panic("Couldn't open N_TTY ldisc for "
"%s --- error %d.",
tty_name(tty, buf), r);
}
}
/**
* tty_ldisc_halt - shut down the line discipline
* @tty: tty device
*
* Shut down the line discipline and work queue for this tty device.
* The TTY_LDISC flag being cleared ensures no further references can
* be obtained while the delayed work queue halt ensures that no more
* data is fed to the ldisc.
*
* You need to do a 'flush_scheduled_work()' (outside the ldisc_mutex)
* in order to make sure any currently executing ldisc work is also
* flushed.
*/
static int tty_ldisc_halt(struct tty_struct *tty)
{
clear_bit(TTY_LDISC, &tty->flags);
return cancel_delayed_work_sync(&tty->buf.work);
}
/**
* tty_ldisc_wait_idle - wait for the ldisc to become idle
* @tty: tty to wait for
*
* Wait for the line discipline to become idle. The discipline must
* have been halted for this to guarantee it remains idle.
*/
static int tty_ldisc_wait_idle(struct tty_struct *tty)
{
int ret;
ret = wait_event_interruptible_timeout(tty_ldisc_idle,
atomic_read(&tty->ldisc->users) == 1, 5 * HZ);
if (ret < 0)
return ret;
return ret > 0 ? 0 : -EBUSY;
}
/**
* tty_set_ldisc - set line discipline
* @tty: the terminal to set
* @ldisc: the line discipline
*
* Set the discipline of a tty line. Must be called from a process
* context. The ldisc change logic has to protect itself against any
* overlapping ldisc change (including on the other end of pty pairs),
* the close of one side of a tty/pty pair, and eventually hangup.
*
* Locking: takes tty_ldisc_lock, termios_mutex
*/
int tty_set_ldisc(struct tty_struct *tty, int ldisc)
{
int retval;
struct tty_ldisc *o_ldisc, *new_ldisc;
int work, o_work = 0;
struct tty_struct *o_tty;
new_ldisc = tty_ldisc_get(ldisc);
if (IS_ERR(new_ldisc))
return PTR_ERR(new_ldisc);
tty_lock();
/*
* We need to look at the tty locking here for pty/tty pairs
* when both sides try to change in parallel.
*/
o_tty = tty->link; /* o_tty is the pty side or NULL */
/*
* Check the no-op case
*/
if (tty->ldisc->ops->num == ldisc) {
tty_unlock();
tty_ldisc_put(new_ldisc);
return 0;
}
tty_unlock();
/*
* Problem: What do we do if this blocks ?
* We could deadlock here
*/
tty_wait_until_sent(tty, 0);
tty_lock();
mutex_lock(&tty->ldisc_mutex);
/*
* We could be midstream of another ldisc change which has
* dropped the lock during processing. If so we need to wait.
*/
while (test_bit(TTY_LDISC_CHANGING, &tty->flags)) {
mutex_unlock(&tty->ldisc_mutex);
tty_unlock();
wait_event(tty_ldisc_wait,
test_bit(TTY_LDISC_CHANGING, &tty->flags) == 0);
tty_lock();
mutex_lock(&tty->ldisc_mutex);
}
set_bit(TTY_LDISC_CHANGING, &tty->flags);
/*
* No more input please, we are switching. The new ldisc
* will update this value in the ldisc open function
*/
tty->receive_room = 0;
o_ldisc = tty->ldisc;
tty_unlock();
/*
* Make sure we don't change while someone holds a
* reference to the line discipline. The TTY_LDISC bit
* prevents anyone taking a reference once it is clear.
* We need the lock to avoid racing reference takers.
*
* We must clear the TTY_LDISC bit here to avoid a livelock
* with a userspace app continually trying to use the tty in
* parallel to the change and re-referencing the tty.
*/
work = tty_ldisc_halt(tty);
if (o_tty)
o_work = tty_ldisc_halt(o_tty);
/*
* Wait for ->hangup_work and ->buf.work handlers to terminate.
* We must drop the mutex here in case a hangup is also in process.
*/
mutex_unlock(&tty->ldisc_mutex);
flush_scheduled_work();
retval = tty_ldisc_wait_idle(tty);
tty_lock();
mutex_lock(&tty->ldisc_mutex);
/* handle wait idle failure locked */
if (retval) {
tty_ldisc_put(new_ldisc);
goto enable;
}
if (test_bit(TTY_HUPPED, &tty->flags)) {
/* We were raced by the hangup method. It will have stomped
the ldisc data and closed the ldisc down */
clear_bit(TTY_LDISC_CHANGING, &tty->flags);
mutex_unlock(&tty->ldisc_mutex);
tty_ldisc_put(new_ldisc);
tty_unlock();
return -EIO;
}
/* Shutdown the current discipline. */
tty_ldisc_close(tty, o_ldisc);
/* Now set up the new line discipline. */
tty_ldisc_assign(tty, new_ldisc);
tty_set_termios_ldisc(tty, ldisc);
retval = tty_ldisc_open(tty, new_ldisc);
if (retval < 0) {
/* Back to the old one or N_TTY if we can't */
tty_ldisc_put(new_ldisc);
tty_ldisc_restore(tty, o_ldisc);
}
/* At this point we hold a reference to the new ldisc and a
a reference to the old ldisc. If we ended up flipping back
to the existing ldisc we have two references to it */
if (tty->ldisc->ops->num != o_ldisc->ops->num && tty->ops->set_ldisc)
tty->ops->set_ldisc(tty);
tty_ldisc_put(o_ldisc);
enable:
/*
* Allow ldisc referencing to occur again
*/
tty_ldisc_enable(tty);
if (o_tty)
tty_ldisc_enable(o_tty);
/* Restart the work queue in case no characters kick it off. Safe if
already running */
if (work)
schedule_delayed_work(&tty->buf.work, 1);
if (o_work)
schedule_delayed_work(&o_tty->buf.work, 1);
mutex_unlock(&tty->ldisc_mutex);
tty_unlock();
return retval;
}
/**
* tty_reset_termios - reset terminal state
* @tty: tty to reset
*
* Restore a terminal to the driver default state.
*/
static void tty_reset_termios(struct tty_struct *tty)
{
mutex_lock(&tty->termios_mutex);
*tty->termios = tty->driver->init_termios;
tty->termios->c_ispeed = tty_termios_input_baud_rate(tty->termios);
tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios);
mutex_unlock(&tty->termios_mutex);
}
/**
* tty_ldisc_reinit - reinitialise the tty ldisc
* @tty: tty to reinit
* @ldisc: line discipline to reinitialize
*
* Switch the tty to a line discipline and leave the ldisc
* state closed
*/
static int tty_ldisc_reinit(struct tty_struct *tty, int ldisc)
{
struct tty_ldisc *ld = tty_ldisc_get(ldisc);
if (IS_ERR(ld))
return -1;
tty_ldisc_close(tty, tty->ldisc);
tty_ldisc_put(tty->ldisc);
tty->ldisc = NULL;
/*
* Switch the line discipline back
*/
tty_ldisc_assign(tty, ld);
tty_set_termios_ldisc(tty, ldisc);
return 0;
}
/**
* tty_ldisc_hangup - hangup ldisc reset
* @tty: tty being hung up
*
* Some tty devices reset their termios when they receive a hangup
* event. In that situation we must also switch back to N_TTY properly
* before we reset the termios data.
*
* Locking: We can take the ldisc mutex as the rest of the code is
* careful to allow for this.
*
* In the pty pair case this occurs in the close() path of the
* tty itself so we must be careful about locking rules.
*/
void tty_ldisc_hangup(struct tty_struct *tty)
{
struct tty_ldisc *ld;
int reset = tty->driver->flags & TTY_DRIVER_RESET_TERMIOS;
int err = 0;
ld = tty_ldisc_ref(tty);
if (ld != NULL) {
/* We may have no line discipline at this point */
if (ld->ops->flush_buffer)
ld->ops->flush_buffer(tty);
tty_driver_flush_buffer(tty);
if ((test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) &&
ld->ops->write_wakeup)
ld->ops->write_wakeup(tty);
if (ld->ops->hangup)
ld->ops->hangup(tty);
tty_ldisc_deref(ld);
}
wake_up_interruptible_poll(&tty->write_wait, POLLOUT);
wake_up_interruptible_poll(&tty->read_wait, POLLIN);
/*
* Shutdown the current line discipline, and reset it to
* N_TTY if need be.
*
* Avoid racing set_ldisc or tty_ldisc_release
*/
mutex_lock(&tty->ldisc_mutex);
/*
* this is like tty_ldisc_halt, but we need to give up
* the BTM before calling cancel_delayed_work_sync,
* which may need to wait for another function taking the BTM
*/
clear_bit(TTY_LDISC, &tty->flags);
tty_unlock();
cancel_delayed_work_sync(&tty->buf.work);
mutex_unlock(&tty->ldisc_mutex);
tty_lock();
mutex_lock(&tty->ldisc_mutex);
if (tty->ldisc) { /* Not yet closed */
if (reset == 0) {
if (!tty_ldisc_reinit(tty, tty->termios->c_line))
err = tty_ldisc_open(tty, tty->ldisc);
else
err = 1;
}
/* If the re-open fails or we reset then go to N_TTY. The
N_TTY open cannot fail */
if (reset || err) {
BUG_ON(tty_ldisc_reinit(tty, N_TTY));
WARN_ON(tty_ldisc_open(tty, tty->ldisc));
}
tty_ldisc_enable(tty);
}
mutex_unlock(&tty->ldisc_mutex);
if (reset)
tty_reset_termios(tty);
}
/**
* tty_ldisc_setup - open line discipline
* @tty: tty being shut down
* @o_tty: pair tty for pty/tty pairs
*
* Called during the initial open of a tty/pty pair in order to set up the
* line disciplines and bind them to the tty. This has no locking issues
* as the device isn't yet active.
*/
int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty)
{
struct tty_ldisc *ld = tty->ldisc;
int retval;
retval = tty_ldisc_open(tty, ld);
if (retval)
return retval;
if (o_tty) {
retval = tty_ldisc_open(o_tty, o_tty->ldisc);
if (retval) {
tty_ldisc_close(tty, ld);
return retval;
}
tty_ldisc_enable(o_tty);
}
tty_ldisc_enable(tty);
return 0;
}
/**
* tty_ldisc_release - release line discipline
* @tty: tty being shut down
* @o_tty: pair tty for pty/tty pairs
*
* Called during the final close of a tty/pty pair in order to shut down
* the line discpline layer. On exit the ldisc assigned is N_TTY and the
* ldisc has not been opened.
*/
void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty)
{
/*
* Prevent flush_to_ldisc() from rescheduling the work for later. Then
* kill any delayed work. As this is the final close it does not
* race with the set_ldisc code path.
*/
tty_unlock();
tty_ldisc_halt(tty);
flush_scheduled_work();
tty_lock();
mutex_lock(&tty->ldisc_mutex);
/*
* Now kill off the ldisc
*/
tty_ldisc_close(tty, tty->ldisc);
tty_ldisc_put(tty->ldisc);
/* Force an oops if we mess this up */
tty->ldisc = NULL;
/* Ensure the next open requests the N_TTY ldisc */
tty_set_termios_ldisc(tty, N_TTY);
mutex_unlock(&tty->ldisc_mutex);
/* This will need doing differently if we need to lock */
if (o_tty)
tty_ldisc_release(o_tty, NULL);
/* And the memory resources remaining (buffers, termios) will be
disposed of when the kref hits zero */
}
/**
* tty_ldisc_init - ldisc setup for new tty
* @tty: tty being allocated
*
* Set up the line discipline objects for a newly allocated tty. Note that
* the tty structure is not completely set up when this call is made.
*/
void tty_ldisc_init(struct tty_struct *tty)
{
struct tty_ldisc *ld = tty_ldisc_get(N_TTY);
if (IS_ERR(ld))
panic("n_tty: init_tty");
tty_ldisc_assign(tty, ld);
}
void tty_ldisc_begin(void)
{
/* Setup the default TTY line discipline. */
(void) tty_register_ldisc(N_TTY, &tty_ldisc_N_TTY);
}
| 24.27234 | 76 | 0.709897 |
9ac9ee043076b828ed3ab5d8f811dafd086ff479 | 4,871 | c | C | src/dynarray.c | pengowray/nothing | b81bb5fc7f9fcb2c53b858873ec9c9600284a8f2 | [
"MIT"
] | null | null | null | src/dynarray.c | pengowray/nothing | b81bb5fc7f9fcb2c53b858873ec9c9600284a8f2 | [
"MIT"
] | null | null | null | src/dynarray.c | pengowray/nothing | b81bb5fc7f9fcb2c53b858873ec9c9600284a8f2 | [
"MIT"
] | null | null | null | #include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "system/stacktrace.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
#include "dynarray.h"
#define DYNARRAY_INIT_CAPACITY 8
struct Dynarray
{
Lt *lt;
size_t element_size;
size_t capacity;
size_t count;
char *data;
};
Dynarray *create_dynarray(size_t element_size)
{
Lt *lt = create_lt();
Dynarray *dynarray = PUSH_LT(lt, nth_calloc(1, sizeof(Dynarray)), free);
if (dynarray == NULL) {
RETURN_LT(lt, NULL);
}
dynarray->lt = lt;
dynarray->element_size = element_size;
dynarray->capacity = DYNARRAY_INIT_CAPACITY;
dynarray->count = 0;
dynarray->data = PUSH_LT(lt, nth_calloc(DYNARRAY_INIT_CAPACITY, element_size), free);
if (dynarray->data == NULL) {
RETURN_LT(lt, NULL);
}
return dynarray;
}
void destroy_dynarray(Dynarray *dynarray)
{
trace_assert(dynarray);
RETURN_LT0(dynarray->lt);
}
void *dynarray_pointer_at(Dynarray *dynarray, size_t index) {
trace_assert(index < dynarray->count);
return dynarray->data + index * dynarray->element_size;
}
size_t dynarray_count(const Dynarray *dynarray)
{
trace_assert(dynarray);
return dynarray->count;
}
void *dynarray_data(Dynarray *dynarray)
{
trace_assert(dynarray);
return dynarray->data;
}
void dynarray_clear(Dynarray *dynarray)
{
trace_assert(dynarray);
dynarray->count = 0;
}
static
int dynarray_grow(Dynarray *dynarray)
{
if (dynarray->count < dynarray->capacity) {
return 0;
}
void *new_data = nth_realloc(
dynarray->data,
dynarray->capacity * dynarray->element_size * 2);
if (new_data == NULL) {
return -1;
}
dynarray->data = REPLACE_LT(dynarray->lt, dynarray->data, new_data);
if (dynarray->data == NULL) {
return -1;
}
dynarray->capacity *= 2;
return 0;
}
int dynarray_push(Dynarray *dynarray, const void *element)
{
trace_assert(dynarray);
trace_assert(element);
if (dynarray_grow(dynarray) < 0) {
return -1;
}
memcpy(
(char*) dynarray->data + dynarray->count * dynarray->element_size,
element,
dynarray->element_size);
dynarray->count++;
return 0;
}
bool dynarray_contains(const Dynarray *dynarray,
const void *element)
{
trace_assert(dynarray);
trace_assert(element);
for (size_t i = 0; i < dynarray->count; ++i) {
if (memcmp((const char*)dynarray->data + i * dynarray->element_size,
(const char*)element,
dynarray->element_size) == 0) {
return true;
}
}
return false;
}
void dynarray_delete_at(Dynarray *dynarray, size_t index)
{
trace_assert(dynarray);
trace_assert(index < dynarray->count);
memmove(
dynarray->data + index * dynarray->element_size,
dynarray->data + (index + 1) * dynarray->element_size,
dynarray->element_size * (dynarray->count - index - 1));
dynarray->count--;
}
void dynarray_insert_before(Dynarray *dynarray, size_t index, void *element)
{
trace_assert(dynarray);
trace_assert(element);
trace_assert(index <= dynarray->count);
dynarray_grow(dynarray);
memmove(
dynarray->data + (index + 1) * dynarray->element_size,
dynarray->data + index * dynarray->element_size,
dynarray->element_size * (dynarray->count - index));
memcpy(
dynarray->data + index * dynarray->element_size,
element,
dynarray->element_size);
dynarray->count++;
}
int dynarray_push_empty(Dynarray *dynarray)
{
trace_assert(dynarray);
if (dynarray_grow(dynarray) < 0) {
return -1;
}
memset(
(char*) dynarray->data + dynarray->count * dynarray->element_size,
0,
dynarray->element_size);
dynarray->count++;
return 0;
}
// TODO(#980): dynarray_push and dynarray_push_empty have duplicate codez
void dynarray_pop(Dynarray *dynarray, void *element)
{
trace_assert(dynarray);
trace_assert(dynarray->count > 0);
dynarray->count--;
if (element) {
memcpy(
element,
dynarray->data + dynarray->count * dynarray->element_size,
dynarray->element_size);
}
}
void dynarray_replace_at(Dynarray *dynarray, size_t index, void *element)
{
trace_assert(dynarray);
trace_assert(element);
trace_assert(index < dynarray->count);
memcpy(
dynarray->data + index * dynarray->element_size,
element,
dynarray->element_size);
}
void dynarray_copy_to(Dynarray *dynarray, void *dest, size_t index)
{
trace_assert(dynarray);
trace_assert(dest);
trace_assert(index < dynarray->count);
memcpy(dest, dynarray->data + index * dynarray->element_size, dynarray->element_size);
}
| 22.242009 | 90 | 0.640115 |
36eb06250c9293e5a3b43d700633f859949bc324 | 315 | h | C | include/ilc/passes/ionir/ionir_logger_pass.h | ronthecookie/ilc | 4e2f78bd39da0497bddf58b6783b4a3b3489a2cf | [
"Unlicense"
] | 2 | 2020-08-20T15:01:13.000Z | 2020-08-20T15:58:23.000Z | include/ilc/passes/ionir/ionir_logger_pass.h | ionlang/onyx | 4e2f78bd39da0497bddf58b6783b4a3b3489a2cf | [
"Unlicense"
] | 4 | 2019-12-26T02:50:38.000Z | 2020-10-16T01:15:05.000Z | include/ilc/passes/ionir/ionir_logger_pass.h | ionlang/onyx | 4e2f78bd39da0497bddf58b6783b4a3b3489a2cf | [
"Unlicense"
] | 2 | 2020-10-01T15:33:30.000Z | 2020-10-12T15:41:02.000Z | #pragma once
#include <ionir/passes/pass.h>
namespace ilc {
struct IonIrLoggerPass : ionir::Pass {
IONSHARED_PASS_ID;
explicit IonIrLoggerPass(
ionshared::Ptr<ionshared::PassContext> context
);
void visit(ionshared::Ptr<ionir::Construct> node) override;
};
}
| 19.6875 | 67 | 0.638095 |
327349ea86c813aecd4959a5ed7098fe55d6e399 | 228 | h | C | unit_tests/cpp_classes/cpp_stub_classes.h | SoapyMan/oolua | 9d25a865b05bbb6aaff56726b46e5b746572e490 | [
"MIT"
] | 4 | 2018-12-19T09:30:24.000Z | 2021-06-26T05:38:11.000Z | unit_tests/cpp_classes/cpp_stub_classes.h | SoapyMan/oolua | 9d25a865b05bbb6aaff56726b46e5b746572e490 | [
"MIT"
] | null | null | null | unit_tests/cpp_classes/cpp_stub_classes.h | SoapyMan/oolua | 9d25a865b05bbb6aaff56726b46e5b746572e490 | [
"MIT"
] | 2 | 2017-03-28T18:38:30.000Z | 2018-10-17T19:01:05.000Z | #ifndef CPP_STUB_CLASSES_OOLUA_H_
# define CPP_STUB_CLASSES_OOLUA_H_
/**[UsedAsMinimalClass]*/
struct Stub1 {};
/**[UsedAsMinimalClass]*/
struct Stub2 {};
struct Stub3 {};
struct InvalidStub {};
struct Return_double{};
#endif
| 17.538462 | 34 | 0.754386 |
c5e4ab34845b2c2804040e8c4457a1894fd6b33f | 2,334 | h | C | src/tomcrypt/headers/tomcrypt_misc.h | vbogolepov/srp-binding | 002bd52eb96d19c723227415179cc24107f20791 | [
"MIT"
] | null | null | null | src/tomcrypt/headers/tomcrypt_misc.h | vbogolepov/srp-binding | 002bd52eb96d19c723227415179cc24107f20791 | [
"MIT"
] | null | null | null | src/tomcrypt/headers/tomcrypt_misc.h | vbogolepov/srp-binding | 002bd52eb96d19c723227415179cc24107f20791 | [
"MIT"
] | null | null | null | /* ---- LTC_BASE64 Routines ---- */
#ifdef LTC_BASE64
int base64_encode(const unsigned char *in, unsigned long len,
unsigned char *out, unsigned long *outlen);
int base64_decode(const unsigned char *in, unsigned long len,
unsigned char *out, unsigned long *outlen);
#endif
#ifdef LTC_BASE64_URL
int base64url_encode(const unsigned char *in, unsigned long len,
unsigned char *out, unsigned long *outlen);
int base64url_decode(const unsigned char *in, unsigned long len,
unsigned char *out, unsigned long *outlen);
#endif
/* ===> LTC_HKDF -- RFC5869 HMAC-based Key Derivation Function <=== */
#ifdef LTC_HKDF
int hkdf_test(void);
int hkdf_extract(int hash_idx,
const unsigned char *salt, unsigned long saltlen,
const unsigned char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen);
int hkdf_expand(int hash_idx,
const unsigned char *info, unsigned long infolen,
const unsigned char *in, unsigned long inlen,
unsigned char *out, unsigned long outlen);
int hkdf(int hash_idx,
const unsigned char *salt, unsigned long saltlen,
const unsigned char *info, unsigned long infolen,
const unsigned char *in, unsigned long inlen,
unsigned char *out, unsigned long outlen);
#endif /* LTC_HKDF */
/* ---- MEM routines ---- */
int mem_neq(const void *a, const void *b, size_t len);
void zeromem(volatile void *dst, size_t len);
void burn_stack(unsigned long len);
const char *error_to_string(int err);
extern const char *crypt_build_settings;
/* ---- HMM ---- */
int crypt_fsa(void *mp, ...);
/* ---- Dynamic language support ---- */
int crypt_get_constant(const char* namein, int *valueout);
int crypt_list_all_constants(char *names_list, unsigned int *names_list_size);
int crypt_get_size(const char* namein, unsigned int *sizeout);
int crypt_list_all_sizes(char *names_list, unsigned int *names_list_size);
#ifdef LTM_DESC
void init_LTM(void);
#endif
#ifdef TFM_DESC
void init_TFM(void);
#endif
/* *** use of GMP is untested ***
#ifdef GMP_DESC
void init_GMP(void);
#endif
*/
/* $Source$ */
/* $Revision$ */
/* $Date$ */
| 30.710526 | 78 | 0.646958 |
65e00f943405820e37ef98f42941456cda5704a4 | 2,288 | h | C | SlidingTiles/src/Tiles/Bread.h | Pharap/SlidingTiles | e9a479d4f70fd6344cf5005ca2c80da12a306743 | [
"Apache-2.0"
] | null | null | null | SlidingTiles/src/Tiles/Bread.h | Pharap/SlidingTiles | e9a479d4f70fd6344cf5005ca2c80da12a306743 | [
"Apache-2.0"
] | null | null | null | SlidingTiles/src/Tiles/Bread.h | Pharap/SlidingTiles | e9a479d4f70fd6344cf5005ca2c80da12a306743 | [
"Apache-2.0"
] | null | null | null | #pragma once
#include <stdint.h>
#include <avr/pgmspace.h>
namespace Tiles
{
constexpr uint8_t breadWidth = 16;
constexpr uint8_t breadHeight = 16;
constexpr uint8_t bread[] PROGMEM
{
// Dimensions
breadWidth, breadHeight,
// Frame 0 - Bread_0x0
0x00, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xBF, 0xDF, 0xEF,
// Frame 1 - Bread_0x1
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0x7E, 0x7E, 0x7E, 0xBE, 0xBE, 0xBE, 0xBE, 0xBE, 0xBE, 0xBE, 0xBE,
0xF7, 0xFB, 0xFD, 0xFE, 0xFE, 0xFF, 0xFB, 0xF5, 0xF5, 0xED, 0xED, 0xDB, 0xDB, 0xDB, 0xB7, 0xB7,
// Frame 2 - Bread_0x2
0x7E, 0x7E, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xAA, 0x56, 0x00,
0x6F, 0x6F, 0x9E, 0xFE, 0xFD, 0xFB, 0xC7, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAA, 0x55, 0x00,
// Frame 3 - Bread_1x0
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x8F, 0xF3, 0xFC, 0xFF, 0xFF, 0xFF, 0xFD,
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0xF8, 0xFF, 0xFF, 0xFD, 0xFA, 0xF6, 0xF6, 0xEE,
// Frame 4 - Bread_1x1
0xFA, 0xFA, 0xF6, 0xF6, 0xF6, 0xEE, 0xDD, 0xDD, 0xBB, 0xBB, 0xB7, 0x77, 0x6F, 0x9F, 0xFF, 0xFF,
0xEE, 0xED, 0xDD, 0xDD, 0xBB, 0xB7, 0xB7, 0xAF, 0xDF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0x7F, 0xBF,
// Frame 5 - Bread_1x2
0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xAF, 0x15, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAA, 0x55, 0x00,
0x5F, 0xAF, 0xD7, 0xEB, 0xF5, 0xF8, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAA, 0x55, 0x00,
// Frame 6 - Bread_2x0
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF3, 0xEF, 0xDF, 0xBF, 0xBF, 0x7F, 0x7F, 0x3F,
0x00, 0x3F, 0x5F, 0x3F, 0x5F, 0x3F, 0x5F, 0x3F, 0x5F, 0x3F, 0x5F, 0x3F, 0x5F, 0x3F, 0x5F, 0x3F,
// Frame 7 - Bread_2x1
0x5F, 0x2F, 0x5F, 0x2F, 0x57, 0x2F, 0x97, 0xAB, 0xD7, 0xCB, 0xE5, 0xEA, 0xF5, 0xFA, 0xFD, 0xFE,
0x5F, 0x3F, 0x5F, 0x3F, 0x5F, 0x3F, 0x5F, 0x3F, 0x5F, 0x3F, 0x5F, 0x3F, 0x5F, 0x3F, 0x5F, 0x3F,
// Frame 8 - Bread_2x2
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAA, 0x55, 0x00,
0x5F, 0x3F, 0x5F, 0x3F, 0x5F, 0x3F, 0x5F, 0x3F, 0x5F, 0x3F, 0x5F, 0x3F, 0x5F, 0x2A, 0x55, 0x00,
};
} | 44 | 98 | 0.638112 |
d0809f074e1f6a5a1df5f765e3657b19a01e9261 | 445 | c | C | workspace/uclibc-ng-master/libc/sysdeps/linux/common/pipe.c | maydali28/toolchain-cross-compile | 254cfed3074532ff01c63259b4ea43b1cdf8b968 | [
"MIT"
] | null | null | null | workspace/uclibc-ng-master/libc/sysdeps/linux/common/pipe.c | maydali28/toolchain-cross-compile | 254cfed3074532ff01c63259b4ea43b1cdf8b968 | [
"MIT"
] | null | null | null | workspace/uclibc-ng-master/libc/sysdeps/linux/common/pipe.c | maydali28/toolchain-cross-compile | 254cfed3074532ff01c63259b4ea43b1cdf8b968 | [
"MIT"
] | null | null | null | /*
* pipe() for uClibc
*
* Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
*
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
#include <sys/syscall.h>
#include <unistd.h>
#if defined __NR_pipe2 && !defined __NR_pipe
int pipe(int filedes[2])
{
return pipe2(filedes, 0);
}
/* If both are defined then use the pipe syscall */
#else
_syscall1(int, pipe, int *, filedes)
#endif
libc_hidden_def(pipe)
| 19.347826 | 74 | 0.698876 |
d0b7c559aa0cb8d4134c9f8f44e22b420fbf5fed | 3,269 | h | C | pfring-framework/userland/c++/PFring.h | refraction-networking/tapdance | 39262efa194b520f3187ad98cab8efb953eccf39 | [
"Apache-2.0"
] | 106 | 2017-08-03T21:32:43.000Z | 2022-03-24T06:25:58.000Z | pfring-framework/userland/c++/PFring.h | refraction-routing/tapdance | 39262efa194b520f3187ad98cab8efb953eccf39 | [
"Apache-2.0"
] | 1 | 2017-07-26T20:21:50.000Z | 2017-07-26T20:21:50.000Z | pfring-framework/userland/c++/PFring.h | refraction-networking/tapdance | 39262efa194b520f3187ad98cab8efb953eccf39 | [
"Apache-2.0"
] | 20 | 2017-08-21T04:28:04.000Z | 2021-09-01T21:04:38.000Z | /*
*
* (C) 2007-12 - Luca Deri <deri@ntop.org>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef PFRING_H
#define PFRING_H
extern "C" {
#define HAVE_PF_RING
#include "pcap-int.h"
#define HAVE_PCAP
#include "pfring.h"
}
class PFring {
private:
pfring *ring;
u_int snaplen;
char *device_name;
public:
PFring(char *device, u_int snaplen, u_int flags = 0);
~PFring();
/* Cluster */
inline int set_cluster(u_int clusterId)
{ return pfring_set_cluster(ring, clusterId, cluster_round_robin); };
inline int remove_from_cluster()
{ return pfring_remove_from_cluster(ring); };
/* Channel */
inline int set_channel_id(short channelId)
{ return pfring_set_channel_id(ring, channelId); };
/* Read Packets */
bool wait_for_packets(int msec = -1 /* -1 == infinite */);
int get_next_packet(struct pfring_pkthdr *hdr, const u_char *pkt, u_int pkt_len);
int get_next_packet_zc(struct pfring_pkthdr *hdr, const u_char **pkt);
/* Filtering */
int add_bpf_filter(char *the_filter);
inline int add_filtering_rule(filtering_rule* the_rule)
{ return pfring_add_filtering_rule(ring, the_rule); };
inline int remove_filtering_rule(u_int16_t rule_id)
{ return pfring_remove_filtering_rule(ring, rule_id); };
inline int toggle_filtering_policy(bool rules_default_accept_policy)
{ return pfring_toggle_filtering_policy(ring, rules_default_accept_policy ? 1 : 0); };
inline int add_hash_filtering_rule(hash_filtering_rule *rule)
{ return pfring_handle_hash_filtering_rule(ring, rule, 1); };
inline int remove_hash_filtering_rule(hash_filtering_rule *rule)
{ return pfring_handle_hash_filtering_rule(ring, rule, 0); };
/* Stats */
inline int get_stats(pfring_stat *stats)
{ return pfring_stats(ring, stats); };
inline int get_filtering_rule_stats(u_int16_t rule_id, char *stats, u_int *stats_len)
{ return pfring_get_filtering_rule_stats(ring, rule_id, stats, stats_len); };
inline int get_hash_filtering_rule_stats(hash_filtering_rule* rule, char *stats, u_int *stats_len)
{ return pfring_get_hash_filtering_rule_stats(ring, rule, stats, stats_len); };
/* Utils */
inline char* get_device_name() { return device_name; };
inline int enable_ring() { return pfring_enable_ring(ring); };
inline int set_sampling_rate(u_int32_t rate /* 1 = no sampling */)
{ return pfring_set_sampling_rate(ring, rate); };
inline int get_version(u_int32_t *version)
{ return pfring_version(ring, version); };
inline int get_socket_id() { return ring->fd; };
};
#endif /* PFRING_H */
| 36.322222 | 100 | 0.731722 |
655a8bca18ec05d3c65f290e33ca426f5e31c494 | 3,305 | c | C | cbench/indirect_jump/tailcall_reuse_multithreading.c | vul337/cfi-eval | 7d7801cf44cc650127d692c2a7222434375ac6aa | [
"Apache-2.0"
] | 16 | 2020-11-17T08:17:10.000Z | 2022-03-16T07:47:44.000Z | cbench/indirect_jump/tailcall_reuse_multithreading.c | vul337/cfi-eval | 7d7801cf44cc650127d692c2a7222434375ac6aa | [
"Apache-2.0"
] | null | null | null | cbench/indirect_jump/tailcall_reuse_multithreading.c | vul337/cfi-eval | 7d7801cf44cc650127d692c2a7222434375ac6aa | [
"Apache-2.0"
] | 4 | 2020-12-13T10:44:30.000Z | 2021-12-20T13:34:37.000Z | #include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
typedef int (*SameTypeFunc_)(int, int);
typedef void (*DiffRetFunc_)(int, int);
typedef int (*DiffArgFunc_)(int, float);
typedef int (*MoreArgFunc_)(int, int, int);
typedef int (*LessArgFunc_)(void);
typedef int (*VoidArgFunc_)(int);
int SameTypeFunc1(int a, int b) {
printf("In %s \n", __FUNCTION__);
return 0;
}
int SameTypeFunc2(int a, int b) {
printf("In %s \n", __FUNCTION__);
return 0;
}
void DiffRetFunc1(int a, int b) { printf("In %s \n", __FUNCTION__); }
void DiffRetFunc2(int a, int b) { printf("In %s \n", __FUNCTION__); }
int DiffArgFunc1(int a, float b) {
printf("In %s \n", __FUNCTION__);
return 0;
}
int DiffArgFunc2(int a, float b) {
printf("In %s \n", __FUNCTION__);
return 0;
}
int MoreArgFunc1(int a, int b, int c) {
printf("In %s \n", __FUNCTION__);
return 0;
}
int MoreArgFunc2(int a, int b, int c) {
printf("In %s \n", __FUNCTION__);
return 0;
}
int LessArgFunc1(int a) {
printf("In %s \n", __FUNCTION__);
return 0;
}
int LessArgFunc2(int a) {
printf("In %s \n", __FUNCTION__);
return 0;
}
int VoidArgFunc1(void) {
printf("In %s \n", __FUNCTION__);
return 0;
}
int VoidArgFunc2(void) {
printf("In %s \n", __FUNCTION__);
return 0;
}
int Foo(int a, int b) {
printf("In %s\n", __FUNCTION__);
return 1;
}
int Bar(int a, int b) {
printf("In %s\n", __FUNCTION__);
return 0;
}
struct FuncPtr {
SameTypeFunc_ correct_func[1];
SameTypeFunc_ same_type_func[1];
DiffArgFunc_ diff_arg_func[1];
DiffRetFunc_ diff_ret_func[1];
MoreArgFunc_ more_arg_func[1];
LessArgFunc_ less_arg_func[1];
VoidArgFunc_ void_arg_func[1];
};
// the struct aligns the function pointer arrays
// so indexing past the end will reliably call working function pointers
static struct FuncPtr fptr1 = {
.correct_func = {Foo},
.same_type_func = {SameTypeFunc1},
.diff_arg_func = {DiffArgFunc1},
.diff_ret_func = {DiffRetFunc1},
.more_arg_func = {MoreArgFunc1},
.less_arg_func = {LessArgFunc1},
.void_arg_func = {VoidArgFunc1},
};
static struct FuncPtr fptr2 = {
.correct_func = {Bar},
.same_type_func = {SameTypeFunc2},
.diff_arg_func = {DiffArgFunc2},
.diff_ret_func = {DiffRetFunc2},
.more_arg_func = {MoreArgFunc2},
.less_arg_func = {LessArgFunc2},
.void_arg_func = {VoidArgFunc2},
};
int idx;
int Excute(void) {
printf("Calling a function:\n");
scanf("%d", &idx);
sleep(3);
return fptr1.correct_func[idx](idx, idx);
}
void *UseIdx(void *args) {
if (Excute())
printf("success exit\n");
}
void *IncreaseIdx(void *args) {
sleep(1);
printf("plz input index:\n");
scanf("%d", &idx);
}
int main(int argc, const char *argv[]) {
printf("0: the correct function\n");
printf("1-6: out of bound access inside the same object\n");
printf("\tthe correct function: %p\n", (void *)fptr1.correct_func);
printf("let test the out of bound access inside the other object\n");
printf("\tthe same-type function infptr2: %p\n", (void *)fptr2.correct_func);
printf("The bar-based offset is sequentially increased by 1-6\n");
pthread_t a, b;
pthread_create(&a, NULL, UseIdx, NULL);
pthread_create(&b, NULL, IncreaseIdx, NULL);
pthread_join(a, NULL);
pthread_join(b, NULL);
// Excute(argv);
return 0;
}
| 23.776978 | 79 | 0.667474 |
658b7537060be6124b4f2bf022ea5e53b2a24405 | 771 | h | C | src/examples/08-instancing/mesh.h | m-decoster/glExamples | b8d330e27150a97e193f65bfe8a422d3420082ba | [
"MIT"
] | 16 | 2015-10-14T10:23:19.000Z | 2022-03-23T09:48:11.000Z | src/examples/08-instancing/mesh.h | m-decoster/glExamples | b8d330e27150a97e193f65bfe8a422d3420082ba | [
"MIT"
] | null | null | null | src/examples/08-instancing/mesh.h | m-decoster/glExamples | b8d330e27150a97e193f65bfe8a422d3420082ba | [
"MIT"
] | 7 | 2017-09-11T20:47:57.000Z | 2021-05-22T11:17:54.000Z | #ifndef MESH_HEADER
#define MESH_HEADER
#include "../common/util.h"
#include <glm/glm.hpp>
#include <vector>
/*
* The changes to this class include:
* the render code will now use glDrawElementsInstanced;
* there is a setInstances method that allows us to set the different model matrices;
* we no longer need getModelMatrix(), so it has been removed;
* there is a new field numMeshes that indicates the number of instances;
* we no longer store the individual positions for this example, so that has been removed too
*/
class Mesh
{
public:
Mesh();
~Mesh();
bool load(const char* fileName);
void setInstances(int numMeshes, std::vector<glm::mat4> models);
void render();
private:
int numIndices, numMeshes;
GLuint vao;
};
#endif
| 23.363636 | 93 | 0.715953 |
437adb3d2c387569be3e4283d9ce9c74801cd282 | 1,401 | h | C | src/CompoundCollisionAlgorithm.h | AndresTraks/BulletSharp | c277666667f91c58191f4cfa97f117053de679ef | [
"MIT"
] | 245 | 2015-01-02T14:11:26.000Z | 2022-03-18T08:56:36.000Z | src/CompoundCollisionAlgorithm.h | AndresTraks/BulletSharp | c277666667f91c58191f4cfa97f117053de679ef | [
"MIT"
] | 50 | 2015-01-04T22:32:21.000Z | 2021-06-08T20:26:24.000Z | src/CompoundCollisionAlgorithm.h | AndresTraks/BulletSharp | c277666667f91c58191f4cfa97f117053de679ef | [
"MIT"
] | 69 | 2015-04-03T15:38:44.000Z | 2022-01-20T14:27:30.000Z | #pragma once
#include "ActivatingCollisionAlgorithm.h"
#include "CollisionCreateFunc.h"
namespace BulletSharp
{
ref class CollisionAlgorithmConstructionInfo;
ref class CollisionObjectWrapper;
ref class CollisionShape;
public delegate bool CompoundChildShapePairCallback(CollisionShape^ pShape0, CollisionShape^ pShape);
public ref class CompoundCollisionAlgorithm : ActivatingCollisionAlgorithm
{
public:
ref class CreateFunc : CollisionAlgorithmCreateFunc
{
internal:
CreateFunc(btCompoundCollisionAlgorithm::CreateFunc* native);
public:
CreateFunc();
};
ref class SwappedCreateFunc : CollisionAlgorithmCreateFunc
{
internal:
SwappedCreateFunc(btCompoundCollisionAlgorithm::SwappedCreateFunc* native);
public:
SwappedCreateFunc();
};
internal:
static CompoundChildShapePairCallback^ _compoundChildShapePairCallback;
CompoundCollisionAlgorithm(btCompoundCollisionAlgorithm* native);
public:
CompoundCollisionAlgorithm(CollisionAlgorithmConstructionInfo^ ci, CollisionObjectWrapper^ body0Wrap,
CollisionObjectWrapper^ body1Wrap, bool isSwapped);
CollisionAlgorithm^ GetChildAlgorithm(int n);
static property CompoundChildShapePairCallback^ CompoundChildShapePairCallback
{
::CompoundChildShapePairCallback^ get();
void set(::CompoundChildShapePairCallback^ value);
}
};
};
| 26.433962 | 104 | 0.779443 |
4e0abb24d4c3f70e05512d96fba4356b5d5e3252 | 1,585 | h | C | src/bracketedLog.h | massimo-marino/cpp-utilities | d1ae012415751e4334a2275e64feeb13e8ba10aa | [
"MIT"
] | null | null | null | src/bracketedLog.h | massimo-marino/cpp-utilities | d1ae012415751e4334a2275e64feeb13e8ba10aa | [
"MIT"
] | null | null | null | src/bracketedLog.h | massimo-marino/cpp-utilities | d1ae012415751e4334a2275e64feeb13e8ba10aa | [
"MIT"
] | null | null | null | //
// bracketedLog.h
//
// Created by massimo on 2/8/19.
//
#pragma once
#include <iostream>
////////////////////////////////////////////////////////////////////////////////
class bracketedLog final
{
public:
explicit
bracketedLog(const std::string& funcName, std::ostream& os = std::cout) noexcept
: funcName_(funcName),
os_(os)
{
os_ << "[ "
<< funcName_
<< " started ]"
<< std::endl;
}
explicit
bracketedLog(const std::string& funcName,
const std::string& fileName,
const unsigned int numLine,
std::ostream& os = std::cout) noexcept
: funcName_(funcName),
os_ (os)
{
os_ << "[ "
<< fileName << ":"
<< funcName_ << "@"
<< numLine
<< " started ]"
<< std::endl;
}
~bracketedLog()
{
os_ << "[ "
<< funcName_
<< " ended ]"
<< std::endl;
}
bracketedLog() = delete;
bracketedLog(const bracketedLog& rhs) = delete;
bracketedLog& operator=(const bracketedLog& rhs) = delete;
bracketedLog(bracketedLog&& rhs) = delete;
bracketedLog& operator=(bracketedLog&& rhs) = delete;
// we don't want these objects allocated on the heap
void* operator new(std::size_t) = delete;
void* operator new[](std::size_t) = delete;
void operator delete(void*) = delete;
void operator delete[](void*) = delete;
private:
std::string funcName_ {};
std::ostream& os_ {std::cout};
}; // class bracketedLog
#define BL bracketedLog bl(__func__)
#define BLFL bracketedLog bl(__func__, __FILE__, __LINE__)
| 22.971014 | 82 | 0.561514 |
084422f02f8a2968fe88f2f34ef64336ed9f0e6c | 25,109 | h | C | private/windows/media/avi/inc/mediaman.h | King0987654/windows2000 | 01f9c2e62c4289194e33244aade34b7d19e7c9b8 | [
"MIT"
] | 17 | 2020-11-13T13:42:52.000Z | 2021-09-16T09:13:13.000Z | multimedia/media/avi/inc/mediaman.h | sancho1952007/Windows-Server-2003 | 5c6fe3db626b63a384230a1aa6b92ac416b0765f | [
"Unlicense"
] | 2 | 2020-10-19T08:02:06.000Z | 2020-10-19T08:23:18.000Z | multimedia/media/avi/inc/mediaman.h | sancho1952007/Windows-Server-2003 | 5c6fe3db626b63a384230a1aa6b92ac416b0765f | [
"Unlicense"
] | 14 | 2019-01-16T01:01:23.000Z | 2022-02-20T15:54:27.000Z | /* MEDIAMAN.H
*
* Public header for the MMSys media element manager DLL
*
* include after windows.h
*
*/
#ifndef _MEDMAN_H_
#define _MEDMAN_H_
/*************** MEDIAMAN TYPES ****************/
typedef DWORD MEDID;
typedef WORD MEDGID;
typedef DWORD FOURCC;
typedef FOURCC MEDTYPE;
typedef WORD MEDMSG;
typedef WORD MEDUSER;
/*************** MEDINFO INSTANCE BLOCK ****************/
/*
* Resource instance structure, passed around as MEDINFO.
* This structure definition may change, DO NOT DEPEND ON IT, but
* use access macros defined below instead!!
*/
typedef struct _MedInfoStruct {
DWORD wFlags; // maybe duplicate fpEnt flags
WORD wAccessCount;
WORD wLockCount;
DWORD dwAccessRet;
DWORD dwLockRet;
char achInst[2];
} MedInfoStruct;
typedef MedInfoStruct FAR *MEDINFO;
/* Instance data access macros */
#define medInfoInstance(medinfo) ((LPSTR) &((medinfo)->achInst[0]))
#define medInfoAccessCount(medinfo) ((medinfo)->wAccessCount)
#define medInfoLockCount(medinfo) ((medinfo)->wLockCount)
#define medInfoLockRead(medinfo) ((medinfo)->wFlags & 0x0800)
#define medInfoLockWrite(medinfo) ((medinfo)->wFlags & 0x0400)
#define MedInfoInstance(medinfo) medInfoInstance(medinfo)
#define MedInfoAccessCount(medinfo) medInfoAccessCount(medinfo)
#define MedInfoLockCount(medinfo) medInfoLockCount(medinfo)
#define MedInfoLockRead(medinfo) medInfoLockRead(medinfo)
#define MedInfoLockWrite(medinfo) medInfoLockWrite(medinfo)
/********** RESOURCE HANDLER DECLARATION *************/
typedef DWORD (FAR PASCAL MedHandler)
(MEDID medid, MEDMSG medmsg, MEDINFO medinfo,
LONG lParam1, LONG lParam2);
typedef MedHandler FAR *FPMedHandler;
/* Logical resource handler messages */
#define MED_INIT 0x0010
#define MED_UNLOAD 0x0011
#define MED_LOCK 0x0012
#define MED_UNLOCK 0x0013
#define MED_EXPEL 0x0014
#define MED_DESTROY 0x0015
#define MED_CREATE 0x0016
#define MED_TYPEINIT 0x0020
#define MED_TYPEUNLOAD 0x0021
#define MED_SETPHYSICAL 0x0022
#define MED_COPY 0x0023
#define MED_NEWNAME 0x0024
#define MED_PAINT 0x002A
#define MED_REALIZEPALETTE 0x002B
#define MED_GETPAINTCAPS 0x002C
#define MED_GETCLIPBOARDDATA 0x002D
/* PaintCaps flags */
#define MMC_PALETTEINFO 0x0001
#define MMC_BOUNDRECT 0x0002
#define MMC_CLIPFORMAT 0x0003
/* Paint message flags */
#define MMP_NORMPAL 0x0000
#define MMP_NOPALETTE 0x0001
#define MMP_PALBACKGROUND 0x0002
#define MMP_SHRINKTOFIT 0x0010
#define MMP_DSTANDSRCRECTS 0x0020
/* Load/Save messages */
#define MED_GETLOADPARAM 0x0030
#define MED_PRELOAD 0x0031
#define MED_LOAD 0x0032
#define MED_POSTLOAD 0x0033
#define MED_FREELOADPARAM 0x0034
#define MED_GETSAVEPARAM 0x0035
#define MED_PRESAVE 0x0036
#define MED_SAVE 0x0037
#define MED_POSTSAVE 0x0038
#define MED_FREESAVEPARAM 0x0039
/* Sent to resource users */
#define MED_CHANGE 0x0060
/* Messages sent to MedDiskInfoCallback */
#define MED_DISKCBBEGIN 0x0065
#define MED_DISKCBUPDATE 0x0066
#define MED_DISKCBEND 0x0067
#define MED_DISKCBNEWCONV 0x0068
/* Minimum value available for type-defined messages */
#define MED_USER 0x0200
/***************** RESOURCE LOAD/SAVE *******************/
typedef struct _MedDisk {
WORD wFlags;
DWORD dwMessageData;
DWORD dwRetVal;
DWORD dwInstance1;
DWORD dwInstance2;
DWORD dwParam1;
DWORD dwParam2;
DWORD dwCbInstance1;
DWORD dwCbInstance2;
HWND hwndParentWindow;
MEDID medid;
DWORD dwReserved1;
DWORD dwReserved2;
DWORD dwReserved3;
DWORD dwReserved4;
} MedDisk;
typedef MedDisk FAR *FPMedDisk;
typedef MedDisk NEAR *NPMedDisk;
/* Flags for wFlags field */
#define MEDF_DISKSAVE 0x0001 // save taking place
#define MEDF_DISKLOAD 0x0002 // load taking place
#define MEDF_DISKVERIFY 0x0004 // verify the file format on load
typedef HANDLE HMEDIABATCH;
/* Macros to check status of load/save */
#define medIsDiskVerify(FPDISK) \
(((FPMedDisk) (FPDISK))->wFlags & MEDF_DISKVERIFY)
#define medIsDiskLoad(FPDISK) \
(((FPMedDisk) (FPDISK))->wFlags & MEDF_DISKLOAD)
#define medIsDiskSave(FPDISK) \
(((FPMedDisk) (FPDISK))->wFlags & MEDF_DISKSAVE)
/* Values returned by physical handlers to MED_LOAD & MED_SAVE messages */
#define MEDF_OK 1
#define MEDF_ABORT 2
#define MEDF_ERROR 3
#define MEDF_BADFORMAT 4
#define MEDF_NOTPROCESSED 0L
/* Callback type used for information on disk save/load status */
typedef WORD (FAR PASCAL MedDiskInfoCallback)
(WORD wmsg, FPMedDisk fpDisk, LONG lParam,
WORD wPercentDone, LPSTR lpszTextStatus);
typedef MedDiskInfoCallback FAR *FPMedDiskInfoCallback;
/* Functions used by info callbacks */
void FAR PASCAL medDiskCancel(FPMedDisk fpDisk);
WORD FAR PASCAL medUpdateProgress(FPMedDisk fpDisk,
WORD wPercentDone, LPSTR lpszTextStatus);
/************* LOGICAL I/O ROUTINES *****************/
typedef struct _MedReturn {
MEDID medid;
DWORD dwReturn;
} MedReturn;
typedef MedReturn FAR *FPMedReturn;
WORD FAR PASCAL medSave(MEDID medid, LONG lParam,
BOOL fYield, FPMedDiskInfoCallback lpfnCb,
LONG lParamCb);
WORD FAR PASCAL medSaveAs(MEDID medid, FPMedReturn medReturn,
LPSTR lpszName, LONG lParam, BOOL fYield,
FPMedDiskInfoCallback lpfnCb, LONG lParamCb);
WORD FAR PASCAL medAccess(MEDID medid, LONG lParam,
FPMedReturn medReturn, BOOL fYield,
FPMedDiskInfoCallback lpfnCb, LONG lParamCb);
void FAR PASCAL medRelease(MEDID medid, LONG lParam);
DWORD FAR PASCAL medLock(MEDID medid, WORD wFlags, LONG lParam);
void FAR PASCAL medUnlock(MEDID medid, WORD wFlags,
DWORD dwChangeInfo, LONG lParam);
DWORD FAR PASCAL medSendMessage(MEDID medid, MEDMSG medmsg,
LONG lParam1, LONG lParam2);
DWORD FAR PASCAL medSendPhysMessage(MEDID medid, MEDMSG medmsg,
LONG lParam1, LONG lParam2);
BOOL FAR PASCAL medCreate(FPMedReturn medReturn,
MEDTYPE medtype, LONG lParam);
BOOL FAR PASCAL medIsDirty(MEDID medid);
BOOL FAR PASCAL medSetDirty(MEDID medid, BOOL fDirty);
WORD FAR PASCAL medIsAccessed(MEDID medid);
BOOL FAR PASCAL medIsShared(MEDID medid);
MEDINFO FAR PASCAL medGetMedinfo(MEDID medid);
BOOL FAR PASCAL medReleaseResinfo(MEDID medid, MEDINFO medinfo);
DWORD FAR PASCAL medSendPhysTypeMsg(MEDID medid, MEDTYPE medTypePhysical,
MEDMSG medmsg, LONG lParam1, LONG lParam2);
typedef struct _MedAccessStruct {
MEDID medid;
LONG lParamLoad;
BOOL fYield;
HWND hwndParent;
FPMedDiskInfoCallback lpfnCb;
LONG lParamCb;
DWORD dwReturn;
} MedAccessStruct;
typedef MedAccessStruct FAR *FPMedAccessStruct;
WORD FAR PASCAL medAccessIndirect(FPMedAccessStruct fpAccess, WORD wSize);
typedef struct _MedSaveStruct {
MEDID medid;
LONG lParamSave;
BOOL fYield;
HWND hwndParent;
FPMedDiskInfoCallback lpfnCb;
LONG lParamCb;
LPSTR lpszNewName;
MEDID medidReturn;
DWORD dwReturn;
} MedSaveStruct;
typedef MedSaveStruct FAR *FPMedSaveStruct;
WORD FAR PASCAL medSaveIndirect(FPMedSaveStruct fpSave, WORD wSize);
WORD FAR PASCAL medSaveAsIndirect(FPMedSaveStruct fpSave, WORD wSize);
/*
* BATCH CONVERSION
*/
WORD FAR PASCAL medAccessBatch(HMEDIABATCH hmedBatch, FPMedReturn medReturn,
BOOL fYield, WORD wFlags);
WORD FAR PASCAL medSaveBatch(HMEDIABATCH hmedBatch, BOOL fYield);
WORD FAR PASCAL medSaveAsBatch(HMEDIABATCH hmedBatch, MEDID medidExisting,
LPSTR lpszName, FPMedReturn medReturn,
BOOL fYield, WORD wResetFlags);
HMEDIABATCH FAR PASCAL medAllocBatchBuffer(MEDID medid, HWND hwnd,
WORD wFlags, BOOL fLoad, DWORD dwMsgData,
FPMedDiskInfoCallback lpfnCb, LONG lParamCb);
BOOL FAR PASCAL medResetBatchBuffer(HMEDIABATCH hmedbatch, MEDID medid,
WORD wFlags);
BOOL FAR PASCAL medFreeBatchBuffer(HMEDIABATCH hmedbatch);
#define MEDBATCH_RESETUPDATECB 0x0001
/* Flags for medLock */
#define MEDF_READ 0x0001
#define MEDF_WRITE 0x0002
/* Flags for medUnlock */
#define MEDF_CHANGED 0x0004
#define MEDF_NOCHANGE 0x0000
/**************** RESOURCE USER ******************/
MEDUSER FAR PASCAL medRegisterUser(HWND hWnd, DWORD dwInst);
void FAR PASCAL medUnregisterUser(MEDUSER meduser);
void FAR PASCAL medSendUserMessage(MEDID medid, MEDMSG medmsg, LONG lParam);
BOOL FAR PASCAL medRegisterUsage(MEDID medid, MEDUSER meduser);
BOOL FAR PASCAL medUnregisterUsage(MEDID medid, MEDUSER meduser);
typedef struct _MedUserMsgInfo {
MEDID medid;
LONG lParam;
MEDINFO medinfo;
DWORD dwInst;
} MedUserMsgInfo;
typedef MedUserMsgInfo FAR *FPMedUserMsgInfo;
#ifndef MM_MEDNOTIFY
#define MM_MEDNOTIFY 0x3BA
#endif
// obsolete but still required by bitedit and paledit
typedef DWORD (FAR PASCAL MedUser)
(MEDID medid, MEDMSG medmsg, MEDINFO medinfo,
LONG lParam, DWORD dwInst);
typedef MedUser FAR *FPMedUser;
MEDUSER FAR PASCAL medRegisterCallback(FPMedUser lpfnUser, DWORD dwInst);
/**************** TYPE TABLE *****************/
typedef struct _MedTypeInfo {
BOOL fValid; // Is this entry valid?
WORD wFlags; // type flags
MEDTYPE medtype; // the type id
FPMedHandler lpfnHandler; // handler function for this type
WORD wInstanceSize; // the byte count of instance data
WORD wRefcount; // reference count on this type
} MedTypeInfo;
typedef MedTypeInfo FAR *FPMedTypeInfo;
/* Flags to medRegisterType */
#define MEDTYPE_LOGICAL 0x0001
#define MEDTYPE_PHYSICAL 0x0002
/* Type creation macros */
#define medMEDTYPE( ch0, ch1, ch2, ch3 ) \
( (DWORD)(BYTE)(ch0) | ( (DWORD)(BYTE)(ch1) << 8 ) | \
( (DWORD)(BYTE)(ch2) << 16 ) | ( (DWORD)(BYTE)(ch3) << 24 ) )
#define medFOURCC( ch0, ch1, ch2, ch3 ) \
( (DWORD)(BYTE)(ch0) | ( (DWORD)(BYTE)(ch1) << 8 ) | \
( (DWORD)(BYTE)(ch2) << 16 ) | ( (DWORD)(BYTE)(ch3) << 24 ) )
BOOL FAR PASCAL medRegisterType(MEDTYPE medtype, FPMedHandler lpfnHandler,
WORD wFlags);
BOOL FAR PASCAL medUnregisterType(MEDTYPE medtype);
BOOL FAR PASCAL medGetTypeInfo(MEDTYPE medtype, FPMedTypeInfo fpInfo);
WORD FAR PASCAL medIterTypes(WORD wIndex, FPMedTypeInfo fpInfo);
FOURCC FAR PASCAL medStringToFourCC(LPSTR lpszString);
void FAR PASCAL medFourCCToString( FOURCC fcc, LPSTR lpszString);
MEDTYPE FAR PASCAL medGetLogicalType(MEDID medid);
MEDTYPE FAR PASCAL medGetPhysicalType(MEDID medid);
BOOL FAR PASCAL medSetPhysicalType(MEDID medid, MEDTYPE medtype);
/************* MISC FUNCTIONS *****************/
WORD FAR PASCAL medGetErrorText(DWORD wErrno, LPSTR lpszBuf, WORD wSize);
DWORD FAR PASCAL medGetError(void);
void FAR PASCAL medSetExtError(WORD wErrno, HANDLE hInst);
BOOL FAR PASCAL medClientInit(void);
BOOL FAR PASCAL medClientExit(void);
HANDLE FAR PASCAL medLoadHandlerDLL(LPSTR lpszDLLName);
BOOL FAR PASCAL medUnloadHandlerDLL(HANDLE hModule);
/************* RESOURCE LOCATION *****************/
MEDID FAR PASCAL medLocate(LPSTR lpszMedName, MEDTYPE medtype,
WORD wFlags, LPSTR lpszMedPath);
MEDID FAR PASCAL medSubLocate(MEDID medidParent, MEDTYPE medtype,
DWORD dwOffset, DWORD dwSize);
HANDLE FAR PASCAL medGetAliases(MEDID medid);
/* Flags for medLocate */
#define MEDF_LOCATE 0x0001
#define MEDF_MAKEFILE 0x0002
#define MEDF_MEMORYFILE 0x0004
#define MEDF_NONSHARED 0x0008
typedef struct _MedMemoryFileStruct {
LPSTR lpszBuf;
DWORD dwSize;
} MedMemoryFile;
typedef MedMemoryFile FAR *FPMedMemoryFile;
typedef struct _MedFileInfo {
WORD wFlags;
WORD wFilesysType;
MEDID medidParent;
DWORD dwSize;
DWORD dwOffset;
/* Information on memory file system */
LPSTR lpszMemory;
DWORD dwMemSize;
} MedFileInfo;
typedef MedFileInfo FAR *FPMedFileInfo;
#define MEDFILE_SUBELEMENT 0x01
#define MEDFILE_NONSHARED 0x02
BOOL FAR PASCAL medGetFileInfo(MEDID medid, FPMedFileInfo fpInfo, WORD wSize);
WORD FAR PASCAL medGetFileName(MEDID medid, LPSTR lpszBuf, WORD wBufSize);
#define MEDNAME_ERROR 0
#define MEDNAME_DYNAMIC 1
#define MEDNAME_MEMORY 2
#define MEDNAME_FILE 3
/***************************************
*
* MEDIAMAN DLL ERROR MESSAGES
*
* Should be less than 0x200.
*
***************************************/
#define MMERR_NOERROR 0x0000
#define MMERR_TYPELISTMEM 0x0001
#define MMERR_BADHANDLER 0x0002
#define MMERR_TYPELISTDUPL 0x0003
#define MMERR_INVALIDTYPE 0x0004
#define MMERR_TYPEREFNOTZERO 0x0005
#define MMERR_WRONGHANDLERTYPE 0x0006
#define MMERR_GROUPTABLEMEMORY 0x0010
#define MMERR_GROUPSTRUCTMEMORY 0x0011
#define MMERR_GROUPSTRINGTABLE 0x0012
#define MMERR_GROUPENTRYTABLE 0x0013
#define MMERR_USERTABLEMEMORY 0x0014
#define RMERR_INVALIDMEDUSER 0x0015
#define MMERR_GLOBALUSERMEMORY 0x0016
#define MMERR_INVALIDSUBPARENT 0x0030
#define MMERR_NOFILEEXISTS 0x0031
#define MMERR_LOGONNAMESPACE 0x0040
#define MMERR_FILENAMESTEP 0x0041
#define MMERR_MEDNOTACCESSED 0x0042
#define MMERR_UNNAMEDELEMENT 0x0043
#define MMERR_DISKOPABORT 0x0044
#define MMERR_NOTCORRECTFILE 0x0045
#define MMERR_COPYFAILED 0x0046
#define MMERR_DISKOPINPROGRESS 0x0047
#define MMERR_MEMORY 0x0048
#define MMERR_READOFWRITELOCKED 0x00E0
#define MMERR_WRITEOFWRITELOCKED 0x00E1
#define MMERR_INVALIDDLLNAME 0x00F0
#define MMERR_COULDNOTLOADDLL 0x00F1
#define MMERR_BADLIBINIT 0x00F2
#define MMERR_INVALIDMODULE 0x00F3
#define MMERR_UNKNOWN 0x0100
#define MMERR_HMEDREAD 0x0101
#define MMERR_HMEDWRITE 0x0102
#define MMERR_HMEDGET 0x0103
#define MMERR_HMEDPUT 0x0104
#define MMERR_HMEDCLOSE 0x0105
#define MMERR_HMEDFIND 0x0106
#define MMERR_HMEDFINDANY 0x0107
#define MMERR_HMEDUNGET 0x0108
#define MMERR_HMEDALLOC 0x0109
#define MMERR_HMEDLOCK 0x010a
#define MMERR_GETFILEINFO 0x010b
#define MMERR_HMEDASCEND 0x010c
#define MMERR_STACKASCEND 0x010d
#define MMERR_HMEDDESCEND 0x010e
#define MMERR_DESCENDSPACE 0x010f
#define MMERR_DESCENDGET 0x0110
#define MMERR_STACKDESCEND 0x0111
#define MMERR_HMEDRESIZE 0x0112
#define MMERR_STACKRESIZE 0x0113
#define MMERR_HMEDCREATE 0x0114
#define MMERR_STACKCREATE 0x0115
#define MMERR_CREATESPACE 0x0116
#define MMERR_CREATEPUT 0x0117
#define MMERR_HMEDSIZE 0x0118
#define MMERR_HMEDLEVEL 0x0119
#define MMERR_HMEDCKID 0x011a
#define RMERR_MEDIDOPEN 0x011b
#define MMERR_WRITEONLY 0x011c
#define MMERR_READONLY 0x011d
#define MMERR_PREVERROR 0x011e
#define MMERR_EOF 0x011f
#define MMERR_BEGIN 0x0120
#define MMERR_IOERROR 0x0121
#define MMERR_UNGETROOM 0x0122
#define MMERR_GETFILENAME 0x0123
#define MMERR_FINDFIRST 0x0124
#define MMERR_OPEN 0x0125
#define MMERR_SEEKINIT 0x0126
#define MMERR_HMEDSEEK 0x0127
#define MMERR_READ 0x0128
#define MMERR_HMEDCFOPEN 0x0129
#define MMERR_MEDGCFCLOSE 0x0130
#define MMERR_WRITE 0x0131
#define MMERR_MAXERROR 0x0200
/***************************************
*
* MEDIAMAN PHYSICAL IO DEFINITIONS
*
***************************************/
typedef FOURCC CKID;
typedef FOURCC FORMTYPE;
typedef DWORD CKSIZE;
/*
* RIFF stack elements
*/
typedef int RIFFSTACKPLACE;
typedef void huge * HPVOID;
typedef struct riff_stack_element {
CKID nID; /* TOS current chunk id */
CKSIZE cbSize; /* TOS current chunk size */
LONG nOffset; /* Stacked nOffset for prev chunk */
LONG nEnd; /* Stacked nEnd for prev chunk */
WORD info; /* Stacked info for prev chunk */
} RIFFSTACKELEM;
typedef RIFFSTACKELEM FAR * FPRIFFSTACKELEM;
/*
* Storage System Handler routine type definition
*/
typedef LONG (FAR PASCAL MIOHANDLER) \
(struct medElement far * hMed, WORD wFlags, \
DWORD lParam1, DWORD lParam2 );
typedef MIOHANDLER FAR * FPMIOHANDLER;
#define MEDIO_DOS_STORAGE 0
#define MEDIO_MEM_STORAGE 1
#define MEDIO_CF_STORAGE 2
/*
* Handle to Resource ( once opened )
*/
typedef struct medElement {
LONG lData1; /* data 1 2 and 3 sections hold */
LONG lData2; /* info specific to the storage system */
LONG lData3; /* eg the dos file handle for dos files */
MEDID medid; /* medid opened */
HANDLE hMem; /* handle to the memory of the HMED */
FPMIOHANDLER fpfnHandler; /* storage system handler */
LONG nInitOffset; /* for sub-resources - offset of start */
LONG nOffset; /* for riff offset start of chunk to start */
/* NOTE nOffset doesn't include nInitOffset */
LONG nCurrent; /* offset of end of current buffer */
LONG nEnd; /* offset of end of current chunk/file */
LONG nLeft; /* space in buff from eof(chunk) to buffend */
LONG nGet; /* number of chars left to read in buff */
LONG nPut; /* number of chars left to write in buff */
/* NOTE nGet, nPut are mutually exclusive */
LONG nSize; /* size of information read into buffer */
LONG nUnGet; /* num of chars ungotten before buff start */
WORD flags; /* RIOF_ info 'temperary' like error */
WORD info; /* RIOI_ info 'permanent' eg. extendable*/
LPSTR fpchPlace; /* place to get/put next char in buffer */
LPSTR fpchMax; /* max position of Place - for seek, unget */
LONG cbBuffer; /* the full buffer size */
RIFFSTACKPLACE nRiffTop; /* current top of riff stack, -1 is nothing */
FPRIFFSTACKELEM fpRiffStack;
/* FP into the data to for Riff Stack */
/* riff stack index top by nRiffTop */
LPSTR fpchBuffer; /* FP into the data for the Buffer */
char data[1]; /* the actual buffer */
} MIOELEMENT;
typedef MIOELEMENT FAR * HMED;
/*
* HMED flags 'temporary' info
*/
#define MIOF_OK 0 /* no info */
#define MIOF_EOF 1 /* have reached eof (or end of chunk) */
#define MIOF_READING 2 /* info has been read into buffer */
#define MIOF_WRITING 4 /* info has been written to buffer */
#define MIOF_UNGET 8 /* have ungotten before buff start */
#define MIOF_ERROR 16 /* have gotten some form of error */
#define MIOF_BUFF_EOF 64 /* EOF at buffer end */
#define MIOF_BUFF_ERROR 128 /* error at buffer end or 'fatal' error */
/* fatal as in can not do any more IO */
/* unlike the error you get for */
/* trying to unget too many chars */
#define MIOF_AFTERCURR 256 /* the characters in the buffer are located */
/* after the hMed->nCurrent */
/*
* HMED info 'permanent' info
*/
#define MIOI_NOTHING 0 /* no info */
#define MIOI_RESIZED 32 /* This chunk has been resized */
/* possibly fix the size on ascend */
#define MIOI_AUTOSIZED 64 /* This chunk has been created */
/* fix the size on ascend */
#define MIOI_BYTESWAPPED 128 /* riff chunk sizes are byteswapped */
#define MIOI_EXTENDABLE 256 /* the resource is extendable */
/* unlike riff chunks */
/*
* Return values
*/
#define MED_EOF (-1) /* universal something wrong return */
/*
* Resource mode to open resource as
*/
#define MOP_READ 0
#define MOP_WRITE 1
#define MOP_READ_WRITE 2
#define MOP_PRELOAD 0x0008
#define MOP_CREATE 0x0010
#define MOP_ZEROBUFFER 0x0100
/* CLOSE return flags */
#define MCERR_OK 0x0000
#define MCERR_UNSPECIFIC 0x0001
#define MCERR_FLUSH 0x0002
#define MCERR_STORAGE 0x0004
/*
* seek flags
*/
#define MOPS_SET 1
#define MOPS_CUR 2
#define MOPS_END 4
#define MOPS_NONLOCAL 128
#define MOPS_EXTEND 64
/*
* Resize Chunk Flags
*/
#define MOPRC_AUTOSIZE 1
/*
* FUNCTION API's
*/
/* normal IO */
HMED FAR PASCAL medOpen( MEDID id, WORD wMode, WORD wSize );
WORD FAR PASCAL medClose( HMED hMed );
LONG FAR PASCAL medRead( HMED hMed, HPVOID hpBuffer, LONG lBytes );
LONG FAR PASCAL medWrite( HMED hMed, HPVOID hpBuffer, LONG lBytes );
LONG FAR PASCAL medSeek( HMED hMed, LONG lOffset, WORD wOrigin );
/* RIFF */
BOOL FAR PASCAL medAscend( HMED hMed );
CKID FAR PASCAL medDescend( HMED hMed );
CKID FAR PASCAL medCreateChunk(HMED hMed, CKID ckid, DWORD dwCkSize);
BOOL FAR PASCAL medResizeChunk(HMED hMed, DWORD dwCkSize, WORD wFlags);
int FAR PASCAL medGetChunkLevel( HMED hMed );
CKID FAR PASCAL medGetChunkID( HMED hMed );
CKSIZE FAR PASCAL medGetChunkSize( HMED hMed );
BOOL FAR PASCAL medFindAnyChunk( HMED hMed, CKID FAR * ackid );
BOOL FAR PASCAL medFindChunk( HMED hMed, CKID id );
LONG FAR PASCAL medGetSwapWORD( HMED hMed );
/*
* FUNCTIONs used in macros and such
*/
LONG FAR PASCAL medIOFillBuff( HMED hMed, int size );
LONG FAR PASCAL medIOFlushBuff( HMED hMed, DWORD dwElem, int size );
BOOL FAR PASCAL medFlush( HMED hMed );
LONG FAR PASCAL medUnGet( HMED hMed, DWORD dwElem, int size );
/*
* MACRO API's autodocked in riomac.d
*/
/* RIFF stuff */
#define medFCC3( fcc ) ( (BYTE)( (fcc & 0xFF000000) >> 24 ) )
#define medFCC2( fcc ) ( (BYTE)( (fcc & 0x00FF0000) >> 16 ) )
#define medFCC1( fcc ) ( (BYTE)( (fcc & 0x0000FF00) >> 8 ) )
#define medFCC0( fcc ) ( (BYTE)(fcc & 0x000000FF) )
/* constant RIFF chunk id */
#define ckidRIFF medFOURCC( 'R', 'I', 'F', 'F' )
/* lets the user set and check if the file is byteswapped */
#define medGetByteSwapped( hMed ) ( (hMed)->info & MIOI_BYTESWAPPED )
#define medSetByteSwapped( hMed, fVal ) ( (hMed)->info = ( fVal ? \
( (hMed)->info | MIOI_BYTESWAPPED ) : \
~((~((hMed)->info))|MIOI_BYTESWAPPED) ) )
#define medHMEDtoMEDID( hMed ) ( (hMed)->medid )
/*
* UnGet Get and Put of BYTE WORD and DWORD and ByteSwapped versions
* NOTE the ByteSwap function is in WINCOM and so WINCOM.H must be included
* before the RESIO.H
*/
#define medUnGetBYTE( hMed, ch ) ( (int)(medUnGet( hMed,(DWORD)ch,1 ) ) )
#define medUnGetWORD( hMed, w ) ( (LONG)(medUnGet( hMed,(DWORD)w,2 ) ) )
#define medUnGetDWORD( hMed, dw ) ( (LONG)(medUnGet( hMed,(DWORD)dw,4) ) )
#define medUnGetSwapWORD(hMed,w) ( medUnGetWORD( hMed, \
ByteSwapWORD((WORD)w) ) )
#define medUnGetSwapDWORD(hMed,dw) ( medUnGetDWORD( hMed, \
ByteSwapDWORD((DWORD)dw) ) )
#define medUnGetOpSwapWORD( hMed, w ) ( medGetByteSwapped( hMed ) ? \
medUnGetSwapWORD( hMed, w ) : \
medUnGetWORD( hMed, w ) )
#define medUnGetOpSwapDWORD( hMed, dw ) ( medGetByteSwapped( hMed ) ? \
medUnGetSwapDWORD( hMed, dw ) : \
medUnGetDWORD( hMed, dw ) )
#define medGetBYTE( hMed ) ( (--((hMed)->nGet) >= 0) ? \
(int)(BYTE)*(((hMed)->fpchPlace)++) : \
(int)(medIOFillBuff( hMed, 1 )) )
#define medPutBYTE( hMed, ch ) ( (--((hMed)->nPut) >= 0) ? \
(int)(BYTE)((*(((hMed)->fpchPlace)++)) = (BYTE)ch) : \
(int)(medIOFlushBuff(hMed,(DWORD)ch,1)) )
/* note in the following macros we want to advance the fpchPlace */
/* by the size after we get the value of it. To do this we typecast */
/* them to int ( or long ) and add the size ( += size ) and then */
/* subtract 4 so the value used is not incremented yet */
#define medGetWORD( hMed ) ( (((hMed)->nGet -= 2) >= 0) ? \
(long)*((WORD FAR *)((((LONG)((hMed)->fpchPlace))+=2)-2)) : \
(long)(medIOFillBuff( hMed, 2 )) )
#define medPutWORD( hMed, w ) ( (((hMed)->nPut -= 2) >= 0) ? \
(long)((*((WORD FAR *)((((LONG)((hMed)->fpchPlace))+=2)-2)))=(WORD)w) :\
(long)(medIOFlushBuff( hMed, (DWORD)w, 2 )) )
#define medPutSwapWORD( hMed, w ) ( medPutWORD(hMed,ByteSwapWORD((WORD)w)) )
#define medGetOpSwapWORD( hMed ) ( medGetByteSwapped( hMed ) ? \
medGetSwapWORD( hMed ) : \
medGetWORD( hMed ) )
#define medPutOpSwapWORD( hMed, w ) ( medGetByteSwapped( hMed ) ? \
medPutSwapWORD( hMed, w ) : \
medPutWORD( hMed, w ) )
#define medGetDWORD( hMed ) ( (((hMed)->nGet -= 4) >= 0) ? \
(long)*((DWORD FAR *)((((LONG)((hMed)->fpchPlace))+=4)-4)) : \
(long)(medIOFillBuff( hMed, 4 )) )
#define medPutDWORD( hMed, dw ) ( (((hMed)->nPut -= 4) >= 0) ? \
(long)((*((DWORD FAR *)((((LONG)((hMed)->fpchPlace))+=4)-4)))=(DWORD)dw): \
(long)(medIOFlushBuff( hMed, (DWORD)dw, 4 )) )
#define medGetSwapDWORD(hMed) (ByteSwapDWORD((DWORD)medGetDWORD(hMed)))
#define medPutSwapDWORD(hMed,dw) (medPutDWORD(hMed,ByteSwapDWORD((DWORD)dw)))
#define medGetOpSwapDWORD( hMed ) ( medGetByteSwapped( hMed ) ? \
medGetSwapDWORD( hMed ) : \
medGetDWORD( hMed ) )
#define medPutOpSwapDWORD( hMed, dw ) ( medGetByteSwapped( hMed ) ? \
medPutSwapDWORD( hMed, dw ) : \
medPutDWORD( hMed, dw ) )
/* for RIFF, read the FORMTYPE */
#define medReadFormHeader( hMed ) medGetDWORD( hMed )
#define medWriteFormHeader( hMed, formtype ) medPutDWORD( hMed, formtype )
#define medGetFOURCC( hMed ) medGetDWORD( hMed )
#define medPutFOURCC( hMed, fcc ) medPutDWORD( hMed, fcc )
/* ERROR and EOF checks */
#define medGetIOError( hMed ) ( (hMed)->flags & MIOF_ERROR )
#define medGetIOEOF( hMed ) ( (hMed)->flags & MIOF_EOF )
#endif /* _MEDMAN_H_ */
| 31.38625 | 80 | 0.695567 |
d6e7e68e7851174d53a9b0ea393a44848e2b2ad6 | 186 | c | C | bucket_CF/lua53/patches/patch-src__liolib.c | jrmarino/ravensource | 91d599fd1f2af55270258d15e72c62774f36033e | [
"FTL"
] | 17 | 2017-04-22T21:53:52.000Z | 2021-01-21T16:57:55.000Z | bucket_CF/lua53/patches/patch-src__liolib.c | jrmarino/ravensource | 91d599fd1f2af55270258d15e72c62774f36033e | [
"FTL"
] | 186 | 2017-09-12T20:46:52.000Z | 2021-11-27T18:15:14.000Z | bucket_CF/lua53/patches/patch-src__liolib.c | jrmarino/ravensource | 91d599fd1f2af55270258d15e72c62774f36033e | [
"FTL"
] | 74 | 2017-09-06T14:48:01.000Z | 2021-08-28T02:48:27.000Z | --- src/liolib.c.orig 2020-09-14 15:34:00 UTC
+++ src/liolib.c
@@ -16,6 +16,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include "lua.h"
| 16.909091 | 45 | 0.607527 |
03ec4c66555889a7ab8be590c975ebb05e178dae | 77 | h | C | modulo4/ex15a/ex15.h | jpvacorreia/ARQCP_ISEP | 60974b1e45f5d9b6a105075b08c14eb47dd58288 | [
"MIT"
] | null | null | null | modulo4/ex15a/ex15.h | jpvacorreia/ARQCP_ISEP | 60974b1e45f5d9b6a105075b08c14eb47dd58288 | [
"MIT"
] | null | null | null | modulo4/ex15a/ex15.h | jpvacorreia/ARQCP_ISEP | 60974b1e45f5d9b6a105075b08c14eb47dd58288 | [
"MIT"
] | 3 | 2019-11-01T20:56:30.000Z | 2020-11-17T17:21:25.000Z | #ifndef ASM_H
#define ASM_H
int greater_date(int date1, int date2);
#endif
| 11 | 39 | 0.753247 |
8605e44a6ba5c2611ad889e97006fe4d2e5b7926 | 5,004 | c | C | libxc-4.2.3/src/maple2c/lda_c_hl.c | rdietric/lsms | 8d0d5f01186abf9a1cc54db3f97f9934b422cf92 | [
"BSD-3-Clause"
] | 16 | 2018-04-03T15:35:47.000Z | 2022-03-01T03:19:23.000Z | libxc-4.2.3/src/maple2c/lda_c_hl.c | rdietric/lsms | 8d0d5f01186abf9a1cc54db3f97f9934b422cf92 | [
"BSD-3-Clause"
] | 8 | 2019-07-30T13:59:18.000Z | 2022-03-31T17:43:35.000Z | libxc-4.2.3/src/maple2c/lda_c_hl.c | rdietric/lsms | 8d0d5f01186abf9a1cc54db3f97f9934b422cf92 | [
"BSD-3-Clause"
] | 9 | 2018-06-30T00:30:48.000Z | 2022-01-31T09:14:29.000Z | /*
This file was generated automatically with ../scripts/maple2c.pl.
Do not edit this file directly as it can be overwritten!!
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
Maple version : Maple 2016 (X86 64 LINUX)
Maple source : ../maple/lda_c_hl.mpl
Type of functional: work_lda
*/
static void
func0(const xc_func_type *p, xc_lda_work_t *r)
{
double t1, t2, t3, t4, t5, t6, t7, t9;
double t12, t13, t15, t17, t25, t27, t28, t44;
double t46, t47, t48, t49;
lda_c_hl_params *params;
assert(p->params != NULL);
params = (lda_c_hl_params * )(p->params);
t1 = params->c[0];
t2 = r->rs * r->rs;
t3 = t2 * r->rs;
t4 = params->r[0];
t5 = t4 * t4;
t6 = t5 * t4;
t7 = 0.1e1 / t6;
t9 = t3 * t7 + 0.1e1;
t12 = 0.1e1 + 0.1e1 / r->rs * t4;
t13 = log(t12);
t15 = 0.1e1 / t5;
t17 = 0.1e1 / t4;
r->f = -t1 * (t9 * t13 - t2 * t15 + r->rs * t17 / 0.2e1 - 0.1e1 / 0.3e1);
if(r->order < 1) return;
t25 = 0.1e1 / t2;
t27 = 0.1e1 / t12;
t28 = t4 * t27;
r->dfdrs = -t1 * (0.3e1 * t2 * t7 * t13 - t9 * t25 * t28 - 0.2e1 * r->rs * t15 + t17 / 0.2e1);
if(r->order < 2) return;
t44 = t2 * t2;
t46 = t9 / t44;
t47 = t12 * t12;
t48 = 0.1e1 / t47;
t49 = t5 * t48;
r->d2fdrs2 = -t1 * (0.6e1 * r->rs * t7 * t13 - 0.6e1 * t15 * t27 + 0.2e1 * t9 / t3 * t28 - t46 * t49 - 0.2e1 * t15);
if(r->order < 3) return;
r->d3fdrs3 = -t1 * (0.6e1 * t7 * t13 - 0.9e1 * t17 * t48 * t25 - 0.6e1 * t46 * t28 + 0.6e1 * t9 / t44 / r->rs * t49 - 0.2e1 * t9 / t44 / t2 * t6 / t47 / t12);
if(r->order < 4) return;
}
static void
func1(const xc_func_type *p, xc_lda_work_t *r)
{
double t1, t2, t3, t4, t5, t6, t7, t9;
double t10, t12, t13, t15, t17, t21, t22, t23;
double t25, t26, t29, t32, t33, t34, t35, t36;
double t37, t38, t40, t42, t43, t45, t47, t52;
double t57, t59, t60, t66, t71, t72, t79, t83;
double t89, t93, t94, t95, t96, t97, t98, t102;
double t111, t112, t113, t114, t119, t121, t123, t127;
double t136, t141, t149;
lda_c_hl_params *params;
assert(p->params != NULL);
params = (lda_c_hl_params * )(p->params);
t1 = params->c[0];
t2 = r->rs * r->rs;
t3 = t2 * r->rs;
t4 = params->r[0];
t5 = t4 * t4;
t6 = t5 * t4;
t7 = 0.1e1 / t6;
t9 = t3 * t7 + 0.1e1;
t10 = 0.1e1 / r->rs;
t12 = t10 * t4 + 0.1e1;
t13 = log(t12);
t15 = 0.1e1 / t5;
t17 = 0.1e1 / t4;
t21 = t1 * (t9 * t13 - t2 * t15 + r->rs * t17 / 0.2e1 - 0.1e1 / 0.3e1);
t22 = 0.1e1 + r->z;
t23 = cbrt(t22);
t25 = 0.1e1 - r->z;
t26 = cbrt(t25);
t29 = M_CBRT2;
t32 = 0.1e1 / (0.2e1 * t29 - 0.2e1);
t33 = (t23 * t22 + t26 * t25 - 0.2e1) * t32;
t34 = params->c[1];
t35 = params->r[1];
t36 = t35 * t35;
t37 = t36 * t35;
t38 = 0.1e1 / t37;
t40 = t3 * t38 + 0.1e1;
t42 = t10 * t35 + 0.1e1;
t43 = log(t42);
t45 = 0.1e1 / t36;
t47 = 0.1e1 / t35;
t52 = -t34 * (t40 * t43 - t2 * t45 + r->rs * t47 / 0.2e1 - 0.1e1 / 0.3e1) + t21;
r->f = t33 * t52 - t21;
if(r->order < 1) return;
t57 = 0.1e1 / t2;
t59 = 0.1e1 / t12;
t60 = t4 * t59;
t66 = t1 * (0.3e1 * t2 * t7 * t13 - t9 * t57 * t60 - 0.2e1 * r->rs * t15 + t17 / 0.2e1);
t71 = 0.1e1 / t42;
t72 = t35 * t71;
t79 = -t34 * (0.3e1 * t2 * t38 * t43 - t40 * t57 * t72 - 0.2e1 * r->rs * t45 + t47 / 0.2e1) + t66;
r->dfdrs = t33 * t79 - t66;
t83 = (0.4e1 / 0.3e1 * t23 - 0.4e1 / 0.3e1 * t26) * t32;
r->dfdz = t83 * t52;
if(r->order < 2) return;
t89 = 0.1e1 / t3;
t93 = t2 * t2;
t94 = 0.1e1 / t93;
t95 = t9 * t94;
t96 = t12 * t12;
t97 = 0.1e1 / t96;
t98 = t5 * t97;
t102 = t1 * (0.6e1 * r->rs * t7 * t13 + 0.2e1 * t9 * t89 * t60 - 0.6e1 * t15 * t59 - t95 * t98 - 0.2e1 * t15);
t111 = t40 * t94;
t112 = t42 * t42;
t113 = 0.1e1 / t112;
t114 = t36 * t113;
t119 = -t34 * (0.6e1 * r->rs * t38 * t43 + 0.2e1 * t40 * t89 * t72 - t111 * t114 - 0.6e1 * t45 * t71 - 0.2e1 * t45) + t102;
r->d2fdrs2 = t33 * t119 - t102;
r->d2fdrsz = t83 * t79;
t121 = t23 * t23;
t123 = t26 * t26;
t127 = (0.4e1 / 0.9e1 / t121 + 0.4e1 / 0.9e1 / t123) * t32;
r->d2fdz2 = t127 * t52;
if(r->order < 3) return;
t136 = 0.1e1 / t93 / r->rs;
t141 = 0.1e1 / t93 / t2;
t149 = t1 * (0.6e1 * t7 * t13 - 0.9e1 * t17 * t97 * t57 - 0.6e1 * t95 * t60 + 0.6e1 * t9 * t136 * t98 - 0.2e1 * t9 * t141 * t6 / t96 / t12);
r->d3fdrs3 = -t149 + t33 * (-t34 * (0.6e1 * t38 * t43 - 0.9e1 * t47 * t113 * t57 - 0.6e1 * t111 * t72 + 0.6e1 * t40 * t136 * t114 - 0.2e1 * t40 * t141 * t37 / t112 / t42) + t149);
r->d3fdrs2z = t83 * t119;
r->d3fdrsz2 = t127 * t79;
r->d3fdz3 = (-0.8e1 / 0.27e2 / t121 / t22 + 0.8e1 / 0.27e2 / t123 / t25) * t32 * t52;
if(r->order < 4) return;
}
void
xc_lda_c_hl_func(const xc_func_type *p, xc_lda_work_t *r)
{
if(p->nspin == XC_UNPOLARIZED)
func0(p, r);
else
func1(p, r);
}
#define maple2c_order 3
#define maple2c_func xc_lda_c_hl_func
| 28.271186 | 181 | 0.531575 |
2fffbdd93add33af853ead38abdffad47a8b216a | 82 | h | C | Pod/Classes/Projection/MOBProjectionEPSG2123.h | jkdubr/Proj4 | dcdf91821720b90423e7d6774d14948d165fbb12 | [
"MIT"
] | 3 | 2015-01-29T15:53:20.000Z | 2019-03-06T03:36:56.000Z | Pod/Classes/Projection/MOBProjectionEPSG2123.h | jkdubr/Proj4 | dcdf91821720b90423e7d6774d14948d165fbb12 | [
"MIT"
] | 1 | 2016-01-12T13:53:40.000Z | 2016-01-12T13:53:40.000Z | Pod/Classes/Projection/MOBProjectionEPSG2123.h | jkdubr/Proj4 | dcdf91821720b90423e7d6774d14948d165fbb12 | [
"MIT"
] | null | null | null | #import "MOBProjection.h"
@interface MOBProjectionEPSG2123 : MOBProjection
@end
| 13.666667 | 48 | 0.804878 |
ea8f596cb94c2e37c1f695727bcabfb9e06297ee | 709 | c | C | hw6/0716061_hw6d.c | TheLurkingCat/Introduction-to-Computers-and-Programming | 5c9716fdf6c8e86b9e79545cdc751e03485c3e06 | [
"MIT"
] | null | null | null | hw6/0716061_hw6d.c | TheLurkingCat/Introduction-to-Computers-and-Programming | 5c9716fdf6c8e86b9e79545cdc751e03485c3e06 | [
"MIT"
] | null | null | null | hw6/0716061_hw6d.c | TheLurkingCat/Introduction-to-Computers-and-Programming | 5c9716fdf6c8e86b9e79545cdc751e03485c3e06 | [
"MIT"
] | null | null | null | #include <stdio.h>
#include <stdlib.h>
#define swap(X, Y) \
(X) ^= (Y); \
(Y) ^= (X); \
(X) ^= (Y);
/* Input : integer n
* Output : how many way to climb n stairs
*/
int climbStairs(int n) {
/* O(n) */
int a = 1, b = 2, c = 4, i;
switch (n) {
case 0:
return 0;
case 1:
return 1;
case 2:
return 2;
case 3:
return 4;
default:
for (i = 3; i < n; i++) {
swap(a, b);
swap(b, c);
c += a + b;
}
return c;
}
}
int main() {
int n;
scanf("%d", &n);
printf("%d", climbStairs(n));
return 0;
} | 18.657895 | 43 | 0.358251 |
d98bc16e2cf3213bbe33b0c79fea10d6c92ac17a | 218 | c | C | app/out_html5/out/h3d/impl/_GlDriver/CompiledProgram.c | Lerg/hashlink-emscripten | 8f5c28a879c78f275fcbc482e1c5f86c08dbe72e | [
"MIT"
] | 1 | 2021-10-03T16:34:38.000Z | 2021-10-03T16:34:38.000Z | app/out_html5/out/h3d/impl/_GlDriver/CompiledProgram.c | Lerg/hashlink-emscripten | 8f5c28a879c78f275fcbc482e1c5f86c08dbe72e | [
"MIT"
] | null | null | null | app/out_html5/out/h3d/impl/_GlDriver/CompiledProgram.c | Lerg/hashlink-emscripten | 8f5c28a879c78f275fcbc482e1c5f86c08dbe72e | [
"MIT"
] | null | null | null | // Generated by HLC 4.2.1 (HL v4)
#define HLC_BOOT
#include <hlc.h>
#include <h3d/impl/_GlDriver/CompiledProgram.h>
void h3d_impl__GlDriver_CompiledProgram_new(h3d__impl___GlDriver__CompiledProgram r0) {
return;
}
| 21.8 | 87 | 0.788991 |
b314101237fe224de97632f94b0637db5d32c5be | 8,936 | c | C | drivers/vfio/mdev/mdev_core.c | jainsakshi2395/linux | 7ccb860232bb83fb60cd6bcf5aaf0c008d903acb | [
"Linux-OpenIB"
] | 44 | 2022-03-16T08:32:31.000Z | 2022-03-31T16:02:35.000Z | drivers/vfio/mdev/mdev_core.c | jainsakshi2395/linux | 7ccb860232bb83fb60cd6bcf5aaf0c008d903acb | [
"Linux-OpenIB"
] | 1 | 2021-01-27T01:29:47.000Z | 2021-01-27T01:29:47.000Z | drivers/vfio/mdev/mdev_core.c | jainsakshi2395/linux | 7ccb860232bb83fb60cd6bcf5aaf0c008d903acb | [
"Linux-OpenIB"
] | 18 | 2022-03-19T04:41:04.000Z | 2022-03-31T03:32:12.000Z | // SPDX-License-Identifier: GPL-2.0-only
/*
* Mediated device Core Driver
*
* Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
* Author: Neo Jia <cjia@nvidia.com>
* Kirti Wankhede <kwankhede@nvidia.com>
*/
#include <linux/module.h>
#include <linux/device.h>
#include <linux/slab.h>
#include <linux/uuid.h>
#include <linux/sysfs.h>
#include <linux/mdev.h>
#include "mdev_private.h"
#define DRIVER_VERSION "0.1"
#define DRIVER_AUTHOR "NVIDIA Corporation"
#define DRIVER_DESC "Mediated device Core Driver"
static LIST_HEAD(parent_list);
static DEFINE_MUTEX(parent_list_lock);
static struct class_compat *mdev_bus_compat_class;
static LIST_HEAD(mdev_list);
static DEFINE_MUTEX(mdev_list_lock);
struct device *mdev_parent_dev(struct mdev_device *mdev)
{
return mdev->type->parent->dev;
}
EXPORT_SYMBOL(mdev_parent_dev);
/*
* Return the index in supported_type_groups that this mdev_device was created
* from.
*/
unsigned int mdev_get_type_group_id(struct mdev_device *mdev)
{
return mdev->type->type_group_id;
}
EXPORT_SYMBOL(mdev_get_type_group_id);
/*
* Used in mdev_type_attribute sysfs functions to return the index in the
* supported_type_groups that the sysfs is called from.
*/
unsigned int mtype_get_type_group_id(struct mdev_type *mtype)
{
return mtype->type_group_id;
}
EXPORT_SYMBOL(mtype_get_type_group_id);
/*
* Used in mdev_type_attribute sysfs functions to return the parent struct
* device
*/
struct device *mtype_get_parent_dev(struct mdev_type *mtype)
{
return mtype->parent->dev;
}
EXPORT_SYMBOL(mtype_get_parent_dev);
/* Should be called holding parent_list_lock */
static struct mdev_parent *__find_parent_device(struct device *dev)
{
struct mdev_parent *parent;
list_for_each_entry(parent, &parent_list, next) {
if (parent->dev == dev)
return parent;
}
return NULL;
}
void mdev_release_parent(struct kref *kref)
{
struct mdev_parent *parent = container_of(kref, struct mdev_parent,
ref);
struct device *dev = parent->dev;
kfree(parent);
put_device(dev);
}
/* Caller must hold parent unreg_sem read or write lock */
static void mdev_device_remove_common(struct mdev_device *mdev)
{
struct mdev_parent *parent = mdev->type->parent;
int ret;
mdev_remove_sysfs_files(mdev);
device_del(&mdev->dev);
lockdep_assert_held(&parent->unreg_sem);
if (parent->ops->remove) {
ret = parent->ops->remove(mdev);
if (ret)
dev_err(&mdev->dev, "Remove failed: err=%d\n", ret);
}
/* Balances with device_initialize() */
put_device(&mdev->dev);
}
static int mdev_device_remove_cb(struct device *dev, void *data)
{
struct mdev_device *mdev = mdev_from_dev(dev);
if (mdev)
mdev_device_remove_common(mdev);
return 0;
}
/*
* mdev_register_device : Register a device
* @dev: device structure representing parent device.
* @ops: Parent device operation structure to be registered.
*
* Add device to list of registered parent devices.
* Returns a negative value on error, otherwise 0.
*/
int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops)
{
int ret;
struct mdev_parent *parent;
char *env_string = "MDEV_STATE=registered";
char *envp[] = { env_string, NULL };
/* check for mandatory ops */
if (!ops || !ops->supported_type_groups)
return -EINVAL;
if (!ops->device_driver && (!ops->create || !ops->remove))
return -EINVAL;
dev = get_device(dev);
if (!dev)
return -EINVAL;
mutex_lock(&parent_list_lock);
/* Check for duplicate */
parent = __find_parent_device(dev);
if (parent) {
parent = NULL;
ret = -EEXIST;
goto add_dev_err;
}
parent = kzalloc(sizeof(*parent), GFP_KERNEL);
if (!parent) {
ret = -ENOMEM;
goto add_dev_err;
}
kref_init(&parent->ref);
init_rwsem(&parent->unreg_sem);
parent->dev = dev;
parent->ops = ops;
if (!mdev_bus_compat_class) {
mdev_bus_compat_class = class_compat_register("mdev_bus");
if (!mdev_bus_compat_class) {
ret = -ENOMEM;
goto add_dev_err;
}
}
ret = parent_create_sysfs_files(parent);
if (ret)
goto add_dev_err;
ret = class_compat_create_link(mdev_bus_compat_class, dev, NULL);
if (ret)
dev_warn(dev, "Failed to create compatibility class link\n");
list_add(&parent->next, &parent_list);
mutex_unlock(&parent_list_lock);
dev_info(dev, "MDEV: Registered\n");
kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
return 0;
add_dev_err:
mutex_unlock(&parent_list_lock);
if (parent)
mdev_put_parent(parent);
else
put_device(dev);
return ret;
}
EXPORT_SYMBOL(mdev_register_device);
/*
* mdev_unregister_device : Unregister a parent device
* @dev: device structure representing parent device.
*
* Remove device from list of registered parent devices. Give a chance to free
* existing mediated devices for given device.
*/
void mdev_unregister_device(struct device *dev)
{
struct mdev_parent *parent;
char *env_string = "MDEV_STATE=unregistered";
char *envp[] = { env_string, NULL };
mutex_lock(&parent_list_lock);
parent = __find_parent_device(dev);
if (!parent) {
mutex_unlock(&parent_list_lock);
return;
}
dev_info(dev, "MDEV: Unregistering\n");
list_del(&parent->next);
mutex_unlock(&parent_list_lock);
down_write(&parent->unreg_sem);
class_compat_remove_link(mdev_bus_compat_class, dev, NULL);
device_for_each_child(dev, NULL, mdev_device_remove_cb);
parent_remove_sysfs_files(parent);
up_write(&parent->unreg_sem);
mdev_put_parent(parent);
/* We still have the caller's reference to use for the uevent */
kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
}
EXPORT_SYMBOL(mdev_unregister_device);
static void mdev_device_release(struct device *dev)
{
struct mdev_device *mdev = to_mdev_device(dev);
/* Pairs with the get in mdev_device_create() */
kobject_put(&mdev->type->kobj);
mutex_lock(&mdev_list_lock);
list_del(&mdev->next);
mutex_unlock(&mdev_list_lock);
dev_dbg(&mdev->dev, "MDEV: destroying\n");
kfree(mdev);
}
int mdev_device_create(struct mdev_type *type, const guid_t *uuid)
{
int ret;
struct mdev_device *mdev, *tmp;
struct mdev_parent *parent = type->parent;
struct mdev_driver *drv = parent->ops->device_driver;
mutex_lock(&mdev_list_lock);
/* Check for duplicate */
list_for_each_entry(tmp, &mdev_list, next) {
if (guid_equal(&tmp->uuid, uuid)) {
mutex_unlock(&mdev_list_lock);
return -EEXIST;
}
}
mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
if (!mdev) {
mutex_unlock(&mdev_list_lock);
return -ENOMEM;
}
device_initialize(&mdev->dev);
mdev->dev.parent = parent->dev;
mdev->dev.bus = &mdev_bus_type;
mdev->dev.release = mdev_device_release;
mdev->dev.groups = parent->ops->mdev_attr_groups;
mdev->type = type;
/* Pairs with the put in mdev_device_release() */
kobject_get(&type->kobj);
guid_copy(&mdev->uuid, uuid);
list_add(&mdev->next, &mdev_list);
mutex_unlock(&mdev_list_lock);
ret = dev_set_name(&mdev->dev, "%pUl", uuid);
if (ret)
goto out_put_device;
/* Check if parent unregistration has started */
if (!down_read_trylock(&parent->unreg_sem)) {
ret = -ENODEV;
goto out_put_device;
}
if (parent->ops->create) {
ret = parent->ops->create(mdev);
if (ret)
goto out_unlock;
}
ret = device_add(&mdev->dev);
if (ret)
goto out_remove;
if (!drv)
drv = &vfio_mdev_driver;
ret = device_driver_attach(&drv->driver, &mdev->dev);
if (ret)
goto out_del;
ret = mdev_create_sysfs_files(mdev);
if (ret)
goto out_del;
mdev->active = true;
dev_dbg(&mdev->dev, "MDEV: created\n");
up_read(&parent->unreg_sem);
return 0;
out_del:
device_del(&mdev->dev);
out_remove:
if (parent->ops->remove)
parent->ops->remove(mdev);
out_unlock:
up_read(&parent->unreg_sem);
out_put_device:
put_device(&mdev->dev);
return ret;
}
int mdev_device_remove(struct mdev_device *mdev)
{
struct mdev_device *tmp;
struct mdev_parent *parent = mdev->type->parent;
mutex_lock(&mdev_list_lock);
list_for_each_entry(tmp, &mdev_list, next) {
if (tmp == mdev)
break;
}
if (tmp != mdev) {
mutex_unlock(&mdev_list_lock);
return -ENODEV;
}
if (!mdev->active) {
mutex_unlock(&mdev_list_lock);
return -EAGAIN;
}
mdev->active = false;
mutex_unlock(&mdev_list_lock);
/* Check if parent unregistration has started */
if (!down_read_trylock(&parent->unreg_sem))
return -ENODEV;
mdev_device_remove_common(mdev);
up_read(&parent->unreg_sem);
return 0;
}
static int __init mdev_init(void)
{
int rc;
rc = mdev_bus_register();
if (rc)
return rc;
rc = mdev_register_driver(&vfio_mdev_driver);
if (rc)
goto err_bus;
return 0;
err_bus:
mdev_bus_unregister();
return rc;
}
static void __exit mdev_exit(void)
{
mdev_unregister_driver(&vfio_mdev_driver);
if (mdev_bus_compat_class)
class_compat_unregister(mdev_bus_compat_class);
mdev_bus_unregister();
}
subsys_initcall(mdev_init)
module_exit(mdev_exit)
MODULE_VERSION(DRIVER_VERSION);
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION(DRIVER_DESC);
| 22.118812 | 79 | 0.728402 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.