hexsha stringlengths 40 40 | size int64 7 1.05M | ext stringclasses 13 values | lang stringclasses 1 value | max_stars_repo_path stringlengths 4 269 | max_stars_repo_name stringlengths 5 109 | max_stars_repo_head_hexsha stringlengths 40 40 | max_stars_repo_licenses listlengths 1 9 | max_stars_count int64 1 191k ⌀ | max_stars_repo_stars_event_min_datetime stringlengths 24 24 ⌀ | max_stars_repo_stars_event_max_datetime stringlengths 24 24 ⌀ | max_issues_repo_path stringlengths 4 269 | max_issues_repo_name stringlengths 5 116 | max_issues_repo_head_hexsha stringlengths 40 40 | max_issues_repo_licenses listlengths 1 9 | max_issues_count int64 1 48.5k ⌀ | 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 4 269 | max_forks_repo_name stringlengths 5 116 | max_forks_repo_head_hexsha stringlengths 40 40 | max_forks_repo_licenses listlengths 1 9 | max_forks_count int64 1 105k ⌀ | max_forks_repo_forks_event_min_datetime stringlengths 24 24 ⌀ | max_forks_repo_forks_event_max_datetime stringlengths 24 24 ⌀ | content stringlengths 7 1.05M | avg_line_length float64 1.21 330k | max_line_length int64 6 990k | alphanum_fraction float64 0.01 0.99 | author_id stringlengths 2 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
4d0c73022fef67c16d3d3c9df859a479c89e6cfd | 16,321 | cpp | C++ | src/peco/net/utils.cpp | littlepush/libpeco | c0ca92ddb7a70cd8183ade1ee0ec57fd534e280e | [
"MIT"
] | 1 | 2020-04-14T06:31:56.000Z | 2020-04-14T06:31:56.000Z | src/peco/net/utils.cpp | littlepush/libpeco | c0ca92ddb7a70cd8183ade1ee0ec57fd534e280e | [
"MIT"
] | null | null | null | src/peco/net/utils.cpp | littlepush/libpeco | c0ca92ddb7a70cd8183ade1ee0ec57fd534e280e | [
"MIT"
] | null | null | null | /*
utils.cpp
libpeco
2022-02-17
Push Chen
*/
/*
MIT License
Copyright (c) 2019 Push Chen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "peco/net/utils.h"
#include "peco/utils.h"
#if PECO_TARGET_LINUX
#include <endian.h>
#elif PECO_TARGET_APPLE
#include <libkern/OSByteOrder.h>
#include <machine/endian.h>
#else
// Windows?
#endif
#if !PECO_TARGET_WIN
#include <fcntl.h>
#include <sys/un.h>
#endif
namespace peco {
namespace net_utils {
uint16_t h2n(uint16_t v) { return htons(v); }
uint32_t h2n(uint32_t v) { return htonl(v); }
uint64_t h2n(uint64_t v) {
#if PECO_TARGET_OPENOS
return htobe64(v);
#else
return htonll(v);
#endif
}
float h2n(float v) {
uint32_t *_iv = (uint32_t *)(&v);
uint32_t _nv = h2n(*_iv);
uint32_t *_pnv = &_nv;
return *(float *)_pnv;
}
double h2n(double v) {
uint64_t *_iv = (uint64_t *)(&v);
uint64_t _nv = h2n(*_iv);
uint64_t *_pnv = &_nv;
return *(double *)_pnv;
}
uint16_t n2h(uint16_t v) { return ntohs(v); }
uint32_t n2h(uint32_t v) { return ntohl(v); }
uint64_t n2h(uint64_t v) {
#if PECO_TARGET_OPENOS
return be64toh(v);
#else
return ntohll(v);
#endif
}
float n2h(float v) {
uint32_t *_iv = (uint32_t *)(&v);
uint32_t _nv = n2h(*_iv);
uint32_t *_pnv = &_nv;
return *(float *)_pnv;
}
double n2h(double v) {
uint64_t *_iv = (uint64_t *)(&v);
uint64_t _nv = n2h(*_iv);
uint64_t *_pnv = &_nv;
return *(double *)_pnv;
}
// Convert host endian to little endian
#if PECO_TARGET_OPENOS
uint16_t h2le(uint16_t v) { return htole16(v); }
uint32_t h2le(uint32_t v) { return htole32(v); }
uint64_t h2le(uint64_t v) { return htole64(v); }
#elif PECO_TARGET_APPLE
uint16_t h2le(uint16_t v) { return OSSwapHostToLittleInt16(v); }
uint32_t h2le(uint32_t v) { return OSSwapHostToLittleInt32(v); }
uint64_t h2le(uint64_t v) { return OSSwapHostToLittleInt64(v); }
#else // Windows
uint16_t h2le(uint16_t v) { return v; }
uint32_t h2le(uint32_t v) { return v; }
uint64_t h2le(uint64_t v) { return v; }
#endif
float h2le(float v) {
uint32_t *_iv = (uint32_t *)(&v);
uint32_t _lev = h2le(*_iv);
uint32_t *_plev = &_lev;
return *(float *)_plev;
}
double h2le(double v) {
uint64_t *_iv = (uint64_t *)(&v);
uint64_t _lev = h2le(*_iv);
uint64_t *_plev = &_lev;
return *(double *)_plev;
}
// Little Endian to Host
#if PECO_TARGET_OPENOS
uint16_t le2h(uint16_t v) { return le16toh(v); }
uint32_t le2h(uint32_t v) { return le32toh(v); }
uint64_t le2h(uint64_t v) { return le64toh(v); }
#elif PECO_TARGET_APPLE
uint16_t le2h(uint16_t v) { return OSSwapLittleToHostInt16(v); }
uint32_t le2h(uint32_t v) { return OSSwapLittleToHostInt32(v); }
uint64_t le2h(uint64_t v) { return OSSwapLittleToHostInt64(v); }
#else // Windows
uint16_t le2h(uint16_t v) { return v; }
uint32_t le2h(uint32_t v) { return v; }
uint64_t le2h(uint64_t v) { return v; }
#endif
float le2h(float v) {
uint32_t *_iv = (uint32_t *)(&v);
uint32_t _lev = le2h(*_iv);
uint32_t *_plev = &_lev;
return *(float *)_plev;
}
double le2h(double v) {
uint64_t *_iv = (uint64_t *)(&v);
uint64_t _lev = le2h(*_iv);
uint64_t *_plev = &_lev;
return *(double *)_plev;
}
// Convert host endian to big endian
#if PECO_TARGET_OPENOS
uint16_t h2be(uint16_t v) { return htobe16(v); }
uint32_t h2be(uint32_t v) { return htobe32(v); }
uint64_t h2be(uint64_t v) { return htobe64(v); }
#elif PECO_TARGET_APPLE
uint16_t h2be(uint16_t v) { return OSSwapHostToBigInt16(v); }
uint32_t h2be(uint32_t v) { return OSSwapHostToBigInt32(v); }
uint64_t h2be(uint64_t v) { return OSSwapHostToBigInt64(v); }
#else
#if defined(_MSC_VER)
uint16_t h2be(uint16_t v) { return _byteswap_ushort(v); }
uint32_t h2be(uint32_t v) { return _byteswap_ulong(v); }
uint64_t h2be(uint64_t v) { return _byteswap_uint64(v); }
#elif PECO_USE_GNU
uint16_t h2be(uint16_t v) { return __builtin_bswap16(v); }
uint32_t h2be(uint32_t v) { return __builtin_bswap32(v); }
uint64_t h2be(uint64_t v) { return __builtin_bswap64(v); }
#endif
#endif
float h2be(float v) {
uint32_t *_iv = (uint32_t *)(&v);
uint32_t _lev = h2be(*_iv);
uint32_t *_plev = &_lev;
return *(float *)_plev;
}
double h2be(double v) {
uint64_t *_iv = (uint64_t *)(&v);
uint64_t _lev = h2be(*_iv);
uint64_t *_plev = &_lev;
return *(double *)_plev;
}
// Big Endian to Host
#if PECO_TARGET_OPENOS
uint16_t be2h(uint16_t v) { return be16toh(v); }
uint32_t be2h(uint32_t v) { return be32toh(v); }
uint64_t be2h(uint64_t v) { return be64toh(v); }
#elif PECO_TARGET_APPLE
uint16_t be2h(uint16_t v) { return OSSwapBigToHostInt16(v); }
uint32_t be2h(uint32_t v) { return OSSwapBigToHostInt32(v); }
uint64_t be2h(uint64_t v) { return OSSwapBigToHostInt64(v); }
#else
#if defined(_MSC_VER)
uint16_t be2h(uint16_t v) { return _byteswap_ushort(v); }
uint32_t be2h(uint32_t v) { return _byteswap_ulong(v); }
uint64_t be2h(uint64_t v) { return _byteswap_uint64(v); }
#elif PECO_USE_GNU
uint16_t be2h(uint16_t v) { return __builtin_bswap16(v); }
uint32_t be2h(uint32_t v) { return __builtin_bswap32(v); }
uint64_t be2h(uint64_t v) { return __builtin_bswap64(v); }
#endif
#endif
float be2h(float v) {
uint32_t *_iv = (uint32_t *)(&v);
uint32_t _lev = be2h(*_iv);
uint32_t *_plev = &_lev;
return *(float *)_plev;
}
double be2h(double v) {
uint64_t *_iv = (uint64_t *)(&v);
uint64_t _lev = be2h(*_iv);
uint64_t *_plev = &_lev;
return *(double *)_plev;
}
// Get localhost's computer name on LAN
const std::string &hostname() {
static std::string _hn;
if (_hn.size() == 0) {
char __hostname[256] = {0};
if (gethostname(__hostname, 256) == -1) {
_hn = __hostname;
}
}
return _hn;
}
// Get peer info from a socket
peer_t socket_peerinfo(const SOCKET_T hSo) {
if (SOCKET_NOT_VALIDATE(hSo))
return peer_t::nan;
struct sockaddr_in _addr;
socklen_t _addrLen = sizeof(_addr);
memset(&_addr, 0, sizeof(_addr));
if (0 == getpeername(hSo, (struct sockaddr *)&_addr, &_addrLen)) {
return peer_t(_addr);
}
return peer_t::nan;
}
// Get local socket's port
uint16_t localport(const SOCKET_T hSo) {
if (SOCKET_NOT_VALIDATE(hSo))
return 0;
struct sockaddr_in _addr;
socklen_t _addrLen = sizeof(_addr);
memset(&_addr, 0, sizeof(_addr));
if (0 == getsockname(hSo, (struct sockaddr *)&_addr, &_addrLen)) {
return ntohs(_addr.sin_port);
}
return 0;
}
// Get the socket type
SocketType socktype(SOCKET_T hSo) {
// Get the type
struct sockaddr _addr;
socklen_t _len = sizeof(_addr);
getsockname(hSo, &_addr, &_len);
// Check un first
uint16_t _sfamily = ((struct sockaddr_un *)(&_addr))->sun_family;
if (_sfamily == AF_UNIX || _sfamily == AF_LOCAL) {
return kSocketTypeUnixDomain;
} else {
int _type;
_len = sizeof(_type);
getsockopt(hSo, SOL_SOCKET, SO_TYPE, (char *)&_type, (socklen_t *)&_len);
if (_type == SOCK_STREAM) {
return kSocketTypeTCP;
} else {
return kSocketTypeUDP;
}
}
}
// Set the linger time for a socket
// I strong suggest not to change this value unless you
// know what you are doing
bool lingertime(SOCKET_T hSo, bool onoff, unsigned timeout) {
if (SOCKET_NOT_VALIDATE(hSo))
return false;
struct linger _sol = {(onoff ? 1 : 0), (int)timeout};
return (setsockopt(hSo, SOL_SOCKET, SO_LINGER, &_sol, sizeof(_sol)) == 0);
}
// Set Current socket reusable or not
bool reusable(SOCKET_T hSo, bool reusable) {
if (SOCKET_NOT_VALIDATE(hSo))
return false;
int _reused = reusable ? 1 : 0;
bool _r = setsockopt(hSo, SOL_SOCKET, SO_REUSEADDR, (const char *)&_reused,
sizeof(int)) != -1;
if (!_r) {
log::warning << "Warning: cannot set the socket as reusable." << std::endl;
}
return _r;
}
// Make current socket keep alive
bool keepalive(SOCKET_T hSo, bool keepalive) {
if (SOCKET_NOT_VALIDATE(hSo))
return false;
int _keepalive = keepalive ? 1 : 0;
return setsockopt(hSo, SOL_SOCKET, SO_KEEPALIVE, (const char *)&_keepalive,
sizeof(int));
}
bool __setINetNonblocking(SOCKET_T hSo, bool nonblocking) {
if (SOCKET_NOT_VALIDATE(hSo))
return false;
unsigned long _u = (nonblocking ? 1 : 0);
bool _r = SO_NETWORK_IOCTL_CALL(hSo, FIONBIO, &_u) >= 0;
if (!_r) {
log::warning << "Warning: cannot change the nonblocking flag of socket."
<< std::endl;
}
return _r;
}
bool __setUDSNonblocking(SOCKET_T hSo, bool nonblocking) {
// Set NonBlocking
int _f = fcntl(hSo, F_GETFL, NULL);
if (_f < 0) {
log::warning << "Warning: cannot get UDS socket file info." << std::endl;
return false;
}
if (nonblocking) {
_f |= O_NONBLOCK;
} else {
_f &= (~O_NONBLOCK);
}
if (fcntl(hSo, F_SETFL, _f) < 0) {
log::warning
<< "Warning: failed to change the nonblocking flag of UDS socket."
<< std::endl;
return false;
}
return true;
}
// Make a socket to be nonblocking
bool nonblocking(SOCKET_T hSo, bool nonblocking) {
if (SOCKET_NOT_VALIDATE(hSo))
return false;
uint32_t _st = socktype(hSo);
if (_st == kSocketTypeUnixDomain)
return __setUDSNonblocking(hSo, nonblocking);
else
return __setINetNonblocking(hSo, nonblocking);
}
bool nodelay(SOCKET_T hSo, bool nodelay) {
if (SOCKET_NOT_VALIDATE(hSo))
return false;
if (socktype(hSo) != kSocketTypeTCP)
return true;
// Try to set as tcp-nodelay
int _flag = nodelay ? 1 : 0;
bool _r = (setsockopt(hSo, IPPROTO_TCP, TCP_NODELAY, (const char *)&_flag,
sizeof(int)) != -1);
if (!_r) {
log::warning << "Warning: cannot set the socket to be tcp-nodelay"
<< std::endl;
}
return _r;
}
// Set the socket's buffer size
bool buffersize(SOCKET_T hSo, uint32_t rmem, uint32_t wmem) {
if (SOCKET_NOT_VALIDATE(hSo))
return false;
if (rmem != 0) {
setsockopt(hSo, SOL_SOCKET, SO_RCVBUF, (char *)&rmem, sizeof(rmem));
}
if (wmem != 0) {
setsockopt(hSo, SOL_SOCKET, SO_SNDBUF, (char *)&wmem, sizeof(wmem));
}
return true;
}
// Check if a socket has data to read
bool has_data_pending(SOCKET_T hSo) {
if (SOCKET_NOT_VALIDATE(hSo))
return false;
fd_set _fs;
FD_ZERO(&_fs);
FD_SET(hSo, &_fs);
int _ret = 0;
struct timeval _tv = {0, 0};
do {
FD_ZERO(&_fs);
FD_SET(hSo, &_fs);
_ret = ::select(hSo + 1, &_fs, NULL, NULL, &_tv);
} while (_ret < 0 && errno == EINTR);
// Try to peek
if (_ret <= 0) return false;
_ret = recv(hSo, NULL, 0, MSG_PEEK);
// If _ret < 0, means recv an error signal
return (_ret > 0);
}
// Check if a socket has buffer to write
bool has_buffer_outgoing(SOCKET_T hSo) {
if (SOCKET_NOT_VALIDATE(hSo))
return false;
fd_set _fs;
int _ret = 0;
struct timeval _tv = {0, 0};
do {
FD_ZERO(&_fs);
FD_SET(hSo, &_fs);
_ret = ::select(hSo + 1, NULL, &_fs, NULL, &_tv);
} while (_ret < 0 && errno == EINTR);
return (_ret > 0);
}
// Create Socket Handler
SOCKET_T create_socket(SocketType sock_type) {
SOCKET_T _so = INVALIDATE_SOCKET;
if (sock_type == kSocketTypeTCP) {
_so = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
} else if (sock_type == kSocketTypeUDP) {
_so = ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
} else if (sock_type == kSocketTypeUnixDomain) {
_so = ::socket(AF_UNIX, SOCK_STREAM, 0);
} else {
log::error << "Error: Cannot create new socket with unknow type <"
<< sock_type << ">" << std::endl;
return _so;
}
if (SOCKET_NOT_VALIDATE(_so)) {
log::error << "Error: Failed to create socket with type <" << sock_type
<< ">" << std::endl;
return _so;
}
// Set the socket to be nonblocking;
nonblocking(_so, true);
nodelay(_so, true);
reusable(_so, true);
keepalive(_so, true);
return _so;
}
// Read Data From a socket
size_t read(SOCKET_T hSo, char *buffer, size_t length,
std::function<int(SOCKET_T, char *, size_t)> f) {
if (SOCKET_NOT_VALIDATE(hSo))
return 0;
size_t BUF_SIZE = length;
size_t _received = 0;
size_t _leftspace = BUF_SIZE;
do {
int _retCode = f(hSo, buffer + _received, _leftspace);
if (_retCode < 0) {
if (errno == EINTR)
continue; // Signal 7, retry
if (errno == EAGAIN || errno == EWOULDBLOCK) {
// No more incoming data in this socket's cache
return _received;
}
log::error << "Error: failed to receive data on socket(" << hSo << "), "
<< ::strerror(errno) << std::endl;
return 0;
} else if (_retCode == 0) {
return 0;
} else {
_received += _retCode;
_leftspace -= _retCode;
}
} while (_leftspace > 0);
return _received;
}
bool read(std::string& buffer,
SOCKET_T hSo, std::function<int(SOCKET_T, char *, size_t)> f,
uint32_t max_buffer_size) {
if (SOCKET_NOT_VALIDATE(hSo))
return false;
bool _hasLimit = (max_buffer_size != 0);
size_t BUF_SIZE = (_hasLimit ? max_buffer_size : 1024); // 1KB
std::string _buffer(BUF_SIZE, '\0');
//_buffer.resize(BUF_SIZE);
size_t _received = 0;
size_t _leftspace = BUF_SIZE;
do {
int _retCode = f(hSo, &_buffer[0] + _received, _leftspace);
if (_retCode < 0) {
if (errno == EINTR)
continue; // signal 7, retry
if (errno == EAGAIN || errno == EWOULDBLOCK) {
// No more data on a non-blocking socket
_buffer.resize(_received);
break;
}
// Other error
_buffer.resize(0);
log::error << "Error: Failed to receive data on socket(" << hSo << ", "
<< ::strerror(errno) << std::endl;
return false;
} else if (_retCode == 0) {
// Peer Close
_buffer.resize(0);
return false;
} else {
_received += _retCode;
_leftspace -= _retCode;
if (_leftspace > 0) {
// Unfull
_buffer.resize(_received);
break;
} else {
// If has limit, and left space is zero,
// which means the data size has reach
// the limit and we should not read any more
// data from the socket this time.
if (_hasLimit)
break;
// Otherwise, try to double the buffer
// The buffer is full, try to double the buffer and try again
if (BUF_SIZE * 2 <= _buffer.max_size()) {
BUF_SIZE *= 2;
} else if (BUF_SIZE < _buffer.max_size()) {
BUF_SIZE = _buffer.max_size();
} else {
break; // direct return, wait for next read.
}
// Resize the buffer and try to read again
_leftspace = BUF_SIZE - _received;
_buffer.resize(BUF_SIZE);
}
}
} while (true);
buffer = std::move(_buffer);
return true;
}
// Write Data to a socket
int write(SOCKET_T hSo, const char *data, size_t data_lenth,
std::function<int(SOCKET_T, const char *, size_t)> f) {
size_t _sent = 0;
while (_sent < data_lenth) {
int _ret = f(hSo, data + _sent, data_lenth - _sent);
if (_ret < 0) {
if (ENOBUFS == errno || EAGAIN == errno || EWOULDBLOCK == errno) {
// No buf
break;
} else {
log::warning << "Failed to send data on socket(" << hSo << "), "
<< ::strerror(errno) << std::endl;
return _ret;
}
} else if (_ret == 0) {
break;
} else {
_sent += _ret;
}
}
return (int)_sent;
}
} // namespace net_utils
} // namespace peco
// Push Chen
| 28.533217 | 79 | 0.650818 | littlepush |
4d0f14fa29ac19f33da798f7a7884ac3909d5d09 | 1,116 | cpp | C++ | 6. Heaps/buildHeap_in_O(N).cpp | suraj0803/DSA | 6ea21e452d7662e2351ee2a7b0415722e1bbf094 | [
"MIT"
] | null | null | null | 6. Heaps/buildHeap_in_O(N).cpp | suraj0803/DSA | 6ea21e452d7662e2351ee2a7b0415722e1bbf094 | [
"MIT"
] | null | null | null | 6. Heaps/buildHeap_in_O(N).cpp | suraj0803/DSA | 6ea21e452d7662e2351ee2a7b0415722e1bbf094 | [
"MIT"
] | null | null | null | #include<iostream>
#include<vector>
using namespace std;
void print(vector<int> v){
for(int x:v){
cout<<x<<" ";
}
cout<<endl;
}
bool minHeap = false;
bool compare(int a, int b){
if(minHeap){
return a<b;
}
else{
return a>b;
}
}
int heapify(vector<int> &v, int index)
{
int left = 2*index;
int right = 2*index+1;
int min_index = index;
int last = v.size()-1;
if(left <= last and compare(v[left],v[index])){
min_index = left;
}
if(right <= last and compare(v[right],v[index])){
min_index = right;
}
if(min_index!=index){
swap(v[index],v[min_index]);
heapify(v,min_index);
}
}
void buildHeap(vector<int> &v)
{
for(int i=(v.size()-1/2); i>=1; i--){// start from 1st non leaves and then heapify
// root node is fixed
heapify(v,i);
}
int main()
{
vector<int> v{-1,10,20,5,6,18,9,4};// 0th index is blocked so starting from index 1
print(v);
buildHeap(v);
print(v);
return 0;
} | 18 | 88 | 0.512545 | suraj0803 |
4d1419b88b24596be819e55615be446ece598eca | 11,137 | cpp | C++ | kernel/platform/pc64/src/init/LoadRootsrv.cpp | tristanseifert/kush-os | 1ffd595aae8f3dc880e798eff72365b8b6c631f0 | [
"0BSD"
] | 4 | 2021-06-22T20:52:30.000Z | 2022-02-04T00:19:44.000Z | kernel/platform/pc64/src/init/LoadRootsrv.cpp | tristanseifert/kush-os | 1ffd595aae8f3dc880e798eff72365b8b6c631f0 | [
"0BSD"
] | null | null | null | kernel/platform/pc64/src/init/LoadRootsrv.cpp | tristanseifert/kush-os | 1ffd595aae8f3dc880e798eff72365b8b6c631f0 | [
"0BSD"
] | null | null | null | #include "tar.h"
#include "elf.h"
#include <platform.h>
#include <log.h>
#include <runtime/SmartPointers.h>
#include <mem/PhysicalAllocator.h>
#include <sched/Scheduler.h>
#include <sched/Task.h>
#include <sched/Thread.h>
#include <vm/Map.h>
#include <vm/MapEntry.h>
#include <bootboot.h>
extern "C" BOOTBOOT bootboot;
using namespace platform;
// output logs about setting up the root server environment
#define LOG_SETUP 0
/// VM address at which the init bundle is mapped in the task
constexpr static const uintptr_t kInitBundleVmAddr = 0x690000000;
/// Name of root server binary in initrd
static const char *kRootSrvName = "rootsrv\0";
constexpr static const size_t kRootSrvNameLen = 8;
static void RootSrvEntry(const uintptr_t);
static void MapInitBundle();
static bool FindRootsrvFile(void* &outPtr, size_t &outLength);
static uintptr_t ValidateSrvElf(void *elfBase, const size_t elfSize);
static uintptr_t MapSrvSegments(const uintptr_t, void *elfBase, const size_t elfSize);
static void AllocSrvStack(const uintptr_t, const uintptr_t);
/**
* Loads the root server binary from the ramdisk.
*/
rt::SharedPtr<sched::Task> platform::InitRootsrv() {
// create the task
auto task = sched::Task::alloc();
REQUIRE(task, "failed to allocate rootsrv task");
task->setName("rootsrv");
task->setCritical(true);
#if LOG_SETUP
log("created rootsrv task: %p $%016llx'h", static_cast<void *>(task), task->handle);
#endif
// create the main thread
auto main = sched::Thread::userThread(task, &RootSrvEntry);
main->kernelMode = false;
main->setName("Main");
#if LOG_SETUP
log("rootsrv thread: $%p $%p'h", static_cast<void *>(main), main->handle);
#endif
// done
task->launch();
return task;
}
/**
* Main entry point for the root server
*
* Map the init bundle -- an USTAR file -- into the task's address space, and attempt to find in
* it the ELF for the root server. Once we've located it, create mappings that contain the ELF's
* .text and .data segments, and allocate a .bss, and stack.
*
* When complete, we'll set up for an userspace return to the entry point of the ELF.
*
* The temporary mappings are at fixed locations; be sure that the actual ELF load addresses do
* not overlap with these ranges.
*/
static void RootSrvEntry(const uintptr_t) {
void *elfBase = nullptr;
size_t elfLength = 0;
// this is usally handled by the syscall
auto thread = sched::Thread::current();
arch::TaskWillStart(thread->task);
// map the init bundle; find the root server file
MapInitBundle();
if(!FindRootsrvFile(elfBase, elfLength)) {
panic("failed to find rootsrv");
}
const auto diff = reinterpret_cast<uintptr_t>(elfBase) - kInitBundleVmAddr;
const auto elfPhys = bootboot.initrd_ptr + diff;
#if LOG_SETUP
log("rootsrv ELF at %p (phys %p off %p %p) len %u", elfBase, elfPhys, diff, bootboot.initrd_ptr, elfLength);
#endif
// create segments for ELF
const auto entry = ValidateSrvElf(elfBase, elfLength);
MapSrvSegments(elfPhys, elfBase, elfLength);
#if LOG_SETUP
log("rootsrv entry: %p (file at %p len %u)", entry, elfBase, elfLength);
#endif
// set up a 128K stack
constexpr static const uintptr_t kStackTop = 0x7fff80000000;
constexpr static const uintptr_t kStackBottom = 0x7fff80008000;
AllocSrvStack(kStackTop, (kStackBottom - kStackTop));
// XXX: offset from stack is to allow us to pop off the task info ptr (which is null)
reinterpret_cast<uintptr_t *>(kStackBottom)[-1] = 0;
// we've finished setup; jump to the server code
#if LOG_SETUP
log("going to: %p (stack %p)", entry, kStackBottom);
#endif
sched::Thread::current()->returnToUser(entry, kStackBottom - sizeof(uintptr_t));
}
/**
* Validates the loaded ELF. This ensures:
*
* - The file is actually an ELF.
* - It is a statically linked binary.
*/
static uintptr_t ValidateSrvElf(void *elfBase, const size_t elfSize) {
REQUIRE(elfSize > sizeof(Elf64_Ehdr), "ELF too small: %u", elfSize);
int err;
const auto hdr = reinterpret_cast<Elf64_Ehdr *>(elfBase);
// check the magic value (and also the class, data and version)
static const uint8_t kElfIdent[7] = {
// ELF magic
0x7F, 0x45, 0x4C, 0x46,
// 64-bit class
0x02,
// data encoding: little endian
0x01,
// SysV ABI
0x01
};
err = memcmp(kElfIdent, hdr->ident, 7);
REQUIRE(!err, "invalid ELF ident");
// ensure header version and some other flags
REQUIRE(hdr->version == 1, "invalid ELF header version %d", hdr->version);
REQUIRE(hdr->type == 2, "rootsrv invalid binary type: %d", hdr->type);
REQUIRE(hdr->machine == 62, "rootsrv invalid machine type: %d", hdr->machine); // EM_X86_64
// ensure the program and section headers are in bounds
REQUIRE((hdr->secHdrOff + (hdr->numSecHdr * hdr->secHdrSize)) <= elfSize, "%s headers extend past end of file", "section");
REQUIRE((hdr->progHdrOff + (hdr->numProgHdr * hdr->progHdrSize)) <= elfSize, "%s headers extend past end of file", "program");
REQUIRE(hdr->progHdrSize >= sizeof(Elf64_Phdr), "invalid phdr size: %u", hdr->progHdrSize);
// return entry point address
return hdr->entryAddr;
}
/**
* Reads the ELF program headers to determine which file backed sections need to be loaded.
*
* For this to work, all loadabale sections in the file _must_ be aligned to a page size bound; the
* linker scripts the C library provides for static binaries should ensure this.
*
* This should take care of both the rwdata (.data) and zero-initialized (.bss) sections of the
* file; they're combined into one program header entry. (These we cannot direct map; instead we
* just copy the data from the initial mapping.)
*
* @return Entry point address
*/
static uintptr_t MapSrvSegments(const uintptr_t elfPhys, void *elfBase, const size_t elfSize) {
int err;
const auto hdr = reinterpret_cast<Elf64_Ehdr *>(elfBase);
const auto pageSz = arch_page_size();
auto vm = sched::Task::current()->vm;
// get location of program headers
const auto pHdr = reinterpret_cast<Elf64_Phdr *>(reinterpret_cast<uintptr_t>(elfBase)
+ hdr->progHdrOff);
// parse each of the program headers
for(size_t i = 0; i < hdr->numProgHdr; i++) {
// ignore all non-load program headers
auto &p = pHdr[i];
if(p.type != PT_LOAD) continue;
// convert the program header flags into a VM protection mode
auto flags = vm::MapMode::ACCESS_USER;
if(p.flags & PF_EXECUTABLE) {
flags |= vm::MapMode::EXECUTE;
}
if(p.flags & PF_READ) {
flags |= vm::MapMode::READ;
}
if(p.flags & PF_WRITE) {
REQUIRE((p.flags & PF_EXECUTABLE) == 0, "cannot map page as WX");
flags |= vm::MapMode::WRITE;
}
// allocate the required pages
const size_t numPages = ((p.memBytes + pageSz - 1) / pageSz);
for(size_t i = 0; i < numPages; i++) {
// allocate the physical page
const auto page = mem::PhysicalAllocator::alloc();
REQUIRE(page, "failed to allocate physical page");
// insert mapping and zero it
const auto vmAddr = p.virtAddr + (i * pageSz);
err = vm->add(page, pageSz, vmAddr, flags);
REQUIRE(!err, "failed to map root server program segment %u: %d", i, err);
memset(reinterpret_cast<void *>(vmAddr), 0, pageSz);
}
// copy the data from the file
void *fileOff = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(elfBase)
+ p.fileOff);
memcpy(reinterpret_cast<void *>(p.virtAddr), fileOff, p.fileBytes);
#if LOG_SETUP
log("phdr %u: allocated %d pages, copied $%x from file off $%x (len $%x) vm %08x", i,
numPages, p.fileBytes, p.fileOff, p.memBytes, p.virtAddr);
#endif
}
// fish out the entry point address
return hdr->entryAddr;
}
/**
* Allocates a stack for the root server.
*
* @note Top address must be page aligned; length must be a page multiple.
*/
static void AllocSrvStack(const uintptr_t top, const uintptr_t length) {
int err;
const auto pageSz = arch_page_size();
const auto numPages = length / pageSz;
// map each page to some anon memory
auto vm = sched::Task::current()->vm;
for(size_t i = 0; i < numPages; i++) {
// allocate the physical page
const auto page = mem::PhysicalAllocator::alloc();
REQUIRE(page, "failed to allocate physical page");
// insert mapping and zero it
const auto vmAddr = top + (i * pageSz);
err = vm->add(page, pageSz, vmAddr, vm::MapMode::ACCESS_USER | vm::MapMode::kKernelRW);
memset(reinterpret_cast<void *>(vmAddr), 0, pageSz);
}
}
/**
* Adds a read-only mapping of the init bundle into the address space of the init task.
*/
static void MapInitBundle() {
int err;
// calculate the number of pages
const auto pageSz = arch_page_size();
const size_t numPages = ((bootboot.initrd_size + pageSz - 1) / pageSz);
// create an allocation
auto task = sched::Task::current();
auto vm = task->vm;
auto entry = vm::MapEntry::makePhys(bootboot.initrd_ptr, numPages * pageSz,
vm::MappingFlags::Read);
#if LOG_SETUP
log("Mapped init bundle: phys %p len %u bytes to %p", bootboot.initrd_ptr,
bootboot.initrd_size, kInitBundleVmAddr);
#endif
err = vm->add(entry, task, kInitBundleVmAddr);
REQUIRE(!err, "failed to map root server init bundle: %d", err);
}
/**
* Helper method to convert an octal string to a binary number.
*/
static size_t Oct2Bin(const char *str, size_t size) {
size_t n = 0;
auto c = str;
while (size-- > 0) {
n *= 8;
n += *c - '0';
c++;
}
return n;
}
/**
* Searches the init bundle (which is assumed to be a tar file) for the root server binary.
*
* @param outPtr Virtual memory address of root server binary, if found
* @param outLength Length of the root server binary, if found
* @return Whether the binary was located
*/
static bool FindRootsrvFile(void* &outPtr, size_t &outLength) {
auto read = reinterpret_cast<uint8_t *>(kInitBundleVmAddr);
const auto bundleEnd = kInitBundleVmAddr + bootboot.initrd_size;
// iterate until we find the right header
while((reinterpret_cast<uintptr_t>(read) + 512) < bundleEnd &&
!memcmp(read + 257, TMAGIC, 5)) {
// get the size of this header and entry
auto hdr = reinterpret_cast<struct posix_header *>(read);
const auto size = Oct2Bin(hdr->size, 11);
// compare filename
if(!memcmp(hdr->name, kRootSrvName, kRootSrvNameLen)) {
outLength = size;
outPtr = read + 512; // XXX: is this block size _always_ 512?
return true;
}
// advance to next entry
read += (((size + 511) / 512) + 1) * 512;
}
return false;
}
| 32.852507 | 130 | 0.652779 | tristanseifert |
4d18095825a90b5f380a9e80b607b58587b2bdd4 | 604 | cpp | C++ | CF/1614.cpp | jawahiir98/CP | a32566554949cd12a62151f90ac3b82b67275cac | [
"MIT"
] | null | null | null | CF/1614.cpp | jawahiir98/CP | a32566554949cd12a62151f90ac3b82b67275cac | [
"MIT"
] | null | null | null | CF/1614.cpp | jawahiir98/CP | a32566554949cd12a62151f90ac3b82b67275cac | [
"MIT"
] | null | null | null | /*
/\ In The Name Of Allah /\
Author : Jawahiir Nabhan
*/
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
const char nl = '\n';
int main()
{
int T; cin>> T;
while(T--)
{
int N,l,r,k; cin>> N >> l >> r >> k;
vector <int> a(N);
for(int i = 0;i < N;i++) cin>> a[i];
sort(a.begin(), a.end());
int cnt = 0;
for(int i = 0;i < N;i++){
if(a[i] >= l && a[i] <= r && a[i] <= k){
cnt += 1;
k -= a[i];
}
}
cout<< cnt << nl;
}
}
| 20.133333 | 52 | 0.390728 | jawahiir98 |
4d18363789494a9ef59749044f51c4b812584f2e | 450 | cpp | C++ | src/app.cpp | ShaderKitty/geodesuka | 1578f2fe3e5a7102d2e314406c89a48132a71675 | [
"MIT"
] | 3 | 2021-08-07T15:11:35.000Z | 2021-11-17T18:59:45.000Z | src/app.cpp | ShaderKitty/geodesuka | 1578f2fe3e5a7102d2e314406c89a48132a71675 | [
"MIT"
] | null | null | null | src/app.cpp | ShaderKitty/geodesuka | 1578f2fe3e5a7102d2e314406c89a48132a71675 | [
"MIT"
] | null | null | null | #include <geodesuka/engine.h>
#include <geodesuka/core/app.h>
namespace geodesuka::core {
app::app(engine* aEngine, int argc, char* argv[]) {
this->Engine = aEngine;
}
// This is used engine side to generate thread for Application.
void app::run() {
// App is now ready to be run.
this->ExitApp.store(false);
// Initializes game loop.
this->gameloop();
// Forces all threads to finish.
this->Engine->Shutdown.store(true);
}
}
| 20.454545 | 64 | 0.673333 | ShaderKitty |
4d1ad0332c11dc690a87a9178325e4946dd8226f | 1,193 | cpp | C++ | 12085 Mobile Casanova.cpp | zihadboss/UVA-Solutions | 020fdcb09da79dc0a0411b04026ce3617c09cd27 | [
"Apache-2.0"
] | 86 | 2016-01-20T11:36:50.000Z | 2022-03-06T19:43:14.000Z | 12085 Mobile Casanova.cpp | Mehedishihab/UVA-Solutions | 474fe3d9d9ba574b97fd40ca5abb22ada95654a1 | [
"Apache-2.0"
] | null | null | null | 12085 Mobile Casanova.cpp | Mehedishihab/UVA-Solutions | 474fe3d9d9ba574b97fd40ca5abb22ada95654a1 | [
"Apache-2.0"
] | 113 | 2015-12-04T06:40:57.000Z | 2022-02-11T02:14:28.000Z | #include <iostream>
using namespace std;
unsigned int numbers[100005];
int main()
{
int N, T = 1;
while (cin >> N, N)
{
for (int i = 0; i < N; ++i)
cin >> numbers[i];
numbers[N] = 0; // Never common with the one before it
cout << "Case " << T++ << ":\n";
for (int i = 0; i < N; ++i)
{
if (numbers[i] + 1 != numbers[i + 1])
cout << '0' << numbers[i] << '\n';
else
{
cout << '0' << numbers[i] << '-';
int subsequent = i + 1;
for (; numbers[subsequent] + 1 == numbers[subsequent + 1]; ++subsequent)
;
unsigned int start = numbers[i], end = numbers[subsequent];
//cout << "\nS: " << start << ' ' << end << '\n';
unsigned int mod = 10;
while (start - (start % mod) != end - (end % mod))
mod *= 10;
//cout << "Mod: " << mod << '\n';
cout << (end % mod) << '\n';
i = subsequent;
}
}
cout << '\n';
}
} | 27.744186 | 88 | 0.352054 | zihadboss |
4d1ea956eaaea5c6e3865e987283b15556b26719 | 1,009 | hpp | C++ | test/comparison/earcut.hpp | pboyer/earcut.hpp | 4ad849c1eb3fa850465f6a14ba31fe03de714538 | [
"ISC"
] | 16 | 2020-12-27T16:38:06.000Z | 2022-03-19T23:29:50.000Z | test/comparison/earcut.hpp | pboyer/earcut.hpp | 4ad849c1eb3fa850465f6a14ba31fe03de714538 | [
"ISC"
] | null | null | null | test/comparison/earcut.hpp | pboyer/earcut.hpp | 4ad849c1eb3fa850465f6a14ba31fe03de714538 | [
"ISC"
] | null | null | null | #pragma once
#include <mapbox/earcut.hpp>
#include <array>
#include <memory>
#include <vector>
template <typename Coord, typename Polygon>
class EarcutTesselator {
public:
using Vertex = std::array<Coord, 2>;
using Vertices = std::vector<Vertex>;
EarcutTesselator(const Polygon &polygon_)
: polygon(polygon_)
{
for (const auto& ring : polygon_) {
for (const auto& vertex : ring) {
vertices_.emplace_back(Vertex {{ Coord(std::get<0>(vertex)),
Coord(std::get<1>(vertex)) }});
}
}
}
EarcutTesselator & operator=(const EarcutTesselator&) = delete;
void run() {
indices_ = mapbox::earcut(polygon);
}
std::vector<uint32_t> const& indices() const {
return indices_;
}
Vertices const& vertices() const {
return vertices_;
}
private:
const Polygon &polygon;
Vertices vertices_;
std::vector<uint32_t> indices_;
};
| 22.931818 | 80 | 0.582755 | pboyer |
4d270d8fceded650098263a5ff502d5ac9d11ddf | 2,962 | hpp | C++ | ishtar/include/emit/TypeName.hpp | Djelnar/mana_lang | a50feb48bd4c7a7a321bd5f28e382cbad0c6ef09 | [
"MIT"
] | null | null | null | ishtar/include/emit/TypeName.hpp | Djelnar/mana_lang | a50feb48bd4c7a7a321bd5f28e382cbad0c6ef09 | [
"MIT"
] | null | null | null | ishtar/include/emit/TypeName.hpp | Djelnar/mana_lang | a50feb48bd4c7a7a321bd5f28e382cbad0c6ef09 | [
"MIT"
] | null | null | null | #pragma once
#include <string>
#include <fmt/format.h>
#include "compatibility.types.hpp"
#include "utils/string.split.hpp"
#include "utils/string.replace.hpp"
#include <map>
using namespace std;
struct TypeName;
static map<tuple<int, int, int>, TypeName*>* __TypeName_cache = nullptr;
struct TypeName
{
wstring FullName;
[[nodiscard]] wstring get_name() const noexcept(false)
{
auto results = split(FullName, '/');
auto result = results[results.size() - 1];
results.clear();
return result;
}
[[nodiscard]] wstring get_namespace() const noexcept(false)
{
auto rd = split(FullName, '%');
auto& target = rd.at(1);
return replace_string(target, get_name(), L"");
}
[[nodiscard]] wstring get_assembly_name() const noexcept(false)
{
auto splited = split(FullName, '%');
return splited.at(0);
}
TypeName(const wstring& a, const wstring& n, const wstring& c) noexcept(true)
{
FullName = a + L"%" + c + L"/" + n;
}
TypeName(const wstring& fullName) noexcept(true)
{
FullName = fullName;
}
[[nodiscard]] static TypeName* construct(
const int asmIdx,
const int nameIdx,
const int namespaceIdx,
GetConstByIndexDelegate* m) noexcept(true)
{
if (__TypeName_cache == nullptr)
__TypeName_cache = new map<tuple<int, int, int>, TypeName*>();
auto key = make_tuple(asmIdx, nameIdx, namespaceIdx);
if (__TypeName_cache->contains(key))
return __TypeName_cache->at(key);
auto* result = new TypeName(m->operator()(asmIdx), m->operator()(nameIdx), m->operator()(namespaceIdx));
__TypeName_cache->insert({key, result});
return result;
}
static void Validate(TypeName* name) noexcept(false)
{
//if (!name->FullName.starts_with(L"global::"))
// throw InvalidFormatException(fmt::format(L"TypeName '{0}' has invalid. [name is not start with global::]", name->FullName));
}
};
template<> struct equality<TypeName*> {
static bool equal(TypeName* l, TypeName* r) {
return wcscmp(l->FullName.c_str(), r->FullName.c_str()) == 0;
}
};
template <> struct fmt::formatter<TypeName>: formatter<string_view> {
template <typename FormatContext>
auto format(TypeName c, FormatContext& ctx) {
return formatter<string_view>::format(c.FullName, ctx);
}
};
template <> struct fmt::formatter<TypeName*>: formatter<string_view> {
template <typename FormatContext>
auto format(TypeName* c, FormatContext& ctx) {
return formatter<string_view>::format(c->FullName, ctx);
}
};
TypeName* readTypeName(uint32_t** ip, GetConstByIndexDelegate* m)
{
++(*ip);
const auto asmIdx = READ32((*ip));
++(*ip);
const auto nameIdx = READ32((*ip));
++(*ip);
const auto nsIdx = READ32((*ip));
++(*ip);
return TypeName::construct(asmIdx, nameIdx, nsIdx, m);
} | 29.326733 | 138 | 0.630655 | Djelnar |
4d28deb35221698a4eb4c16efc6fd23df8704f25 | 94,063 | cc | C++ | 0012_Integer_to_Roman/0012.cc | LuciusKyle/LeetCode | 66c9090e5244b10eca0be50398764da2b4b48a6c | [
"Apache-2.0"
] | null | null | null | 0012_Integer_to_Roman/0012.cc | LuciusKyle/LeetCode | 66c9090e5244b10eca0be50398764da2b4b48a6c | [
"Apache-2.0"
] | null | null | null | 0012_Integer_to_Roman/0012.cc | LuciusKyle/LeetCode | 66c9090e5244b10eca0be50398764da2b4b48a6c | [
"Apache-2.0"
] | null | null | null |
// Symbol Value
// I 1
// V 5
// X 10
// L 50
// C 100
// D 500
// M 1000
#include <assert.h>
#include <array>
#include <string>
#include <fstream>
using std::string;
char cheat_chart[][16] = { "","I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII", "XIII", "XIV", "XV", "XVI", "XVII", "XVIII", "XIX", "XX", "XXI", "XXII", "XXIII", "XXIV", "XXV", "XXVI", "XXVII", "XXVIII", "XXIX", "XXX", "XXXI", "XXXII", "XXXIII", "XXXIV", "XXXV", "XXXVI", "XXXVII", "XXXVIII", "XXXIX", "XL", "XLI", "XLII", "XLIII", "XLIV", "XLV", "XLVI", "XLVII", "XLVIII", "XLIX", "L", "LI", "LII", "LIII", "LIV", "LV", "LVI", "LVII", "LVIII", "LIX", "LX", "LXI", "LXII", "LXIII", "LXIV", "LXV", "LXVI", "LXVII", "LXVIII", "LXIX", "LXX", "LXXI", "LXXII", "LXXIII", "LXXIV", "LXXV", "LXXVI", "LXXVII", "LXXVIII", "LXXIX", "LXXX", "LXXXI", "LXXXII", "LXXXIII", "LXXXIV", "LXXXV", "LXXXVI", "LXXXVII", "LXXXVIII", "LXXXIX", "XC", "XCI", "XCII", "XCIII", "XCIV", "XCV", "XCVI", "XCVII", "XCVIII", "XCIX", "C",
"CI", "CII", "CIII", "CIV", "CV", "CVI", "CVII", "CVIII", "CIX", "CX", "CXI", "CXII", "CXIII", "CXIV", "CXV", "CXVI", "CXVII", "CXVIII", "CXIX", "CXX", "CXXI", "CXXII", "CXXIII", "CXXIV", "CXXV", "CXXVI", "CXXVII", "CXXVIII", "CXXIX", "CXXX", "CXXXI", "CXXXII", "CXXXIII", "CXXXIV", "CXXXV", "CXXXVI", "CXXXVII", "CXXXVIII", "CXXXIX", "CXL", "CXLI", "CXLII", "CXLIII", "CXLIV", "CXLV", "CXLVI", "CXLVII", "CXLVIII", "CXLIX", "CL", "CLI", "CLII", "CLIII", "CLIV", "CLV", "CLVI", "CLVII", "CLVIII", "CLIX", "CLX", "CLXI", "CLXII", "CLXIII", "CLXIV", "CLXV", "CLXVI", "CLXVII", "CLXVIII", "CLXIX", "CLXX", "CLXXI", "CLXXII", "CLXXIII", "CLXXIV", "CLXXV", "CLXXVI", "CLXXVII", "CLXXVIII", "CLXXIX", "CLXXX", "CLXXXI", "CLXXXII", "CLXXXIII", "CLXXXIV", "CLXXXV", "CLXXXVI", "CLXXXVII", "CLXXXVIII", "CLXXXIX", "CXC", "CXCI", "CXCII", "CXCIII", "CXCIV", "CXCV", "CXCVI", "CXCVII", "CXCVIII", "CXCIX", "CC",
"CCI", "CCII", "CCIII", "CCIV", "CCV", "CCVI", "CCVII", "CCVIII", "CCIX", "CCX", "CCXI", "CCXII", "CCXIII", "CCXIV", "CCXV", "CCXVI", "CCXVII", "CCXVIII", "CCXIX", "CCXX", "CCXXI", "CCXXII", "CCXXIII", "CCXXIV", "CCXXV", "CCXXVI", "CCXXVII", "CCXXVIII", "CCXXIX", "CCXXX", "CCXXXI", "CCXXXII", "CCXXXIII", "CCXXXIV", "CCXXXV", "CCXXXVI", "CCXXXVII", "CCXXXVIII", "CCXXXIX", "CCXL", "CCXLI", "CCXLII", "CCXLIII", "CCXLIV", "CCXLV", "CCXLVI", "CCXLVII", "CCXLVIII", "CCXLIX", "CCL", "CCLI", "CCLII", "CCLIII", "CCLIV", "CCLV", "CCLVI", "CCLVII", "CCLVIII", "CCLIX", "CCLX", "CCLXI", "CCLXII", "CCLXIII", "CCLXIV", "CCLXV", "CCLXVI", "CCLXVII", "CCLXVIII", "CCLXIX", "CCLXX", "CCLXXI", "CCLXXII", "CCLXXIII", "CCLXXIV", "CCLXXV", "CCLXXVI", "CCLXXVII", "CCLXXVIII", "CCLXXIX", "CCLXXX", "CCLXXXI", "CCLXXXII", "CCLXXXIII", "CCLXXXIV", "CCLXXXV", "CCLXXXVI", "CCLXXXVII", "CCLXXXVIII", "CCLXXXIX", "CCXC", "CCXCI", "CCXCII", "CCXCIII", "CCXCIV", "CCXCV", "CCXCVI", "CCXCVII", "CCXCVIII", "CCXCIX", "CCC",
"CCCI", "CCCII", "CCCIII", "CCCIV", "CCCV", "CCCVI", "CCCVII", "CCCVIII", "CCCIX", "CCCX", "CCCXI", "CCCXII", "CCCXIII", "CCCXIV", "CCCXV", "CCCXVI", "CCCXVII", "CCCXVIII", "CCCXIX", "CCCXX", "CCCXXI", "CCCXXII", "CCCXXIII", "CCCXXIV", "CCCXXV", "CCCXXVI", "CCCXXVII", "CCCXXVIII", "CCCXXIX", "CCCXXX", "CCCXXXI", "CCCXXXII", "CCCXXXIII", "CCCXXXIV", "CCCXXXV", "CCCXXXVI", "CCCXXXVII", "CCCXXXVIII", "CCCXXXIX", "CCCXL", "CCCXLI", "CCCXLII", "CCCXLIII", "CCCXLIV", "CCCXLV", "CCCXLVI", "CCCXLVII", "CCCXLVIII", "CCCXLIX", "CCCL", "CCCLI", "CCCLII", "CCCLIII", "CCCLIV", "CCCLV", "CCCLVI", "CCCLVII", "CCCLVIII", "CCCLIX", "CCCLX", "CCCLXI", "CCCLXII", "CCCLXIII", "CCCLXIV", "CCCLXV", "CCCLXVI", "CCCLXVII", "CCCLXVIII", "CCCLXIX", "CCCLXX", "CCCLXXI", "CCCLXXII", "CCCLXXIII", "CCCLXXIV", "CCCLXXV", "CCCLXXVI", "CCCLXXVII", "CCCLXXVIII", "CCCLXXIX", "CCCLXXX", "CCCLXXXI", "CCCLXXXII", "CCCLXXXIII", "CCCLXXXIV", "CCCLXXXV", "CCCLXXXVI", "CCCLXXXVII", "CCCLXXXVIII", "CCCLXXXIX", "CCCXC", "CCCXCI", "CCCXCII", "CCCXCIII", "CCCXCIV", "CCCXCV", "CCCXCVI", "CCCXCVII", "CCCXCVIII", "CCCXCIX", "CD",
"CDI", "CDII", "CDIII", "CDIV", "CDV", "CDVI", "CDVII", "CDVIII", "CDIX", "CDX", "CDXI", "CDXII", "CDXIII", "CDXIV", "CDXV", "CDXVI", "CDXVII", "CDXVIII", "CDXIX", "CDXX", "CDXXI", "CDXXII", "CDXXIII", "CDXXIV", "CDXXV", "CDXXVI", "CDXXVII", "CDXXVIII", "CDXXIX", "CDXXX", "CDXXXI", "CDXXXII", "CDXXXIII", "CDXXXIV", "CDXXXV", "CDXXXVI", "CDXXXVII", "CDXXXVIII", "CDXXXIX", "CDXL", "CDXLI", "CDXLII", "CDXLIII", "CDXLIV", "CDXLV", "CDXLVI", "CDXLVII", "CDXLVIII", "CDXLIX", "CDL", "CDLI", "CDLII", "CDLIII", "CDLIV", "CDLV", "CDLVI", "CDLVII", "CDLVIII", "CDLIX", "CDLX", "CDLXI", "CDLXII", "CDLXIII", "CDLXIV", "CDLXV", "CDLXVI", "CDLXVII", "CDLXVIII", "CDLXIX", "CDLXX", "CDLXXI", "CDLXXII", "CDLXXIII", "CDLXXIV", "CDLXXV", "CDLXXVI", "CDLXXVII", "CDLXXVIII", "CDLXXIX", "CDLXXX", "CDLXXXI", "CDLXXXII", "CDLXXXIII", "CDLXXXIV", "CDLXXXV", "CDLXXXVI", "CDLXXXVII", "CDLXXXVIII", "CDLXXXIX", "CDXC", "CDXCI", "CDXCII", "CDXCIII", "CDXCIV", "CDXCV", "CDXCVI", "CDXCVII", "CDXCVIII", "CDXCIX", "D",
"DI", "DII", "DIII", "DIV", "DV", "DVI", "DVII", "DVIII", "DIX", "DX", "DXI", "DXII", "DXIII", "DXIV", "DXV", "DXVI", "DXVII", "DXVIII", "DXIX", "DXX", "DXXI", "DXXII", "DXXIII", "DXXIV", "DXXV", "DXXVI", "DXXVII", "DXXVIII", "DXXIX", "DXXX", "DXXXI", "DXXXII", "DXXXIII", "DXXXIV", "DXXXV", "DXXXVI", "DXXXVII", "DXXXVIII", "DXXXIX", "DXL", "DXLI", "DXLII", "DXLIII", "DXLIV", "DXLV", "DXLVI", "DXLVII", "DXLVIII", "DXLIX", "DL", "DLI", "DLII", "DLIII", "DLIV", "DLV", "DLVI", "DLVII", "DLVIII", "DLIX", "DLX", "DLXI", "DLXII", "DLXIII", "DLXIV", "DLXV", "DLXVI", "DLXVII", "DLXVIII", "DLXIX", "DLXX", "DLXXI", "DLXXII", "DLXXIII", "DLXXIV", "DLXXV", "DLXXVI", "DLXXVII", "DLXXVIII", "DLXXIX", "DLXXX", "DLXXXI", "DLXXXII", "DLXXXIII", "DLXXXIV", "DLXXXV", "DLXXXVI", "DLXXXVII", "DLXXXVIII", "DLXXXIX", "DXC", "DXCI", "DXCII", "DXCIII", "DXCIV", "DXCV", "DXCVI", "DXCVII", "DXCVIII", "DXCIX", "DC",
"DCI", "DCII", "DCIII", "DCIV", "DCV", "DCVI", "DCVII", "DCVIII", "DCIX", "DCX", "DCXI", "DCXII", "DCXIII", "DCXIV", "DCXV", "DCXVI", "DCXVII", "DCXVIII", "DCXIX", "DCXX", "DCXXI", "DCXXII", "DCXXIII", "DCXXIV", "DCXXV", "DCXXVI", "DCXXVII", "DCXXVIII", "DCXXIX", "DCXXX", "DCXXXI", "DCXXXII", "DCXXXIII", "DCXXXIV", "DCXXXV", "DCXXXVI", "DCXXXVII", "DCXXXVIII", "DCXXXIX", "DCXL", "DCXLI", "DCXLII", "DCXLIII", "DCXLIV", "DCXLV", "DCXLVI", "DCXLVII", "DCXLVIII", "DCXLIX", "DCL", "DCLI", "DCLII", "DCLIII", "DCLIV", "DCLV", "DCLVI", "DCLVII", "DCLVIII", "DCLIX", "DCLX", "DCLXI", "DCLXII", "DCLXIII", "DCLXIV", "DCLXV", "DCLXVI", "DCLXVII", "DCLXVIII", "DCLXIX", "DCLXX", "DCLXXI", "DCLXXII", "DCLXXIII", "DCLXXIV", "DCLXXV", "DCLXXVI", "DCLXXVII", "DCLXXVIII", "DCLXXIX", "DCLXXX", "DCLXXXI", "DCLXXXII", "DCLXXXIII", "DCLXXXIV", "DCLXXXV", "DCLXXXVI", "DCLXXXVII", "DCLXXXVIII", "DCLXXXIX", "DCXC", "DCXCI", "DCXCII", "DCXCIII", "DCXCIV", "DCXCV", "DCXCVI", "DCXCVII", "DCXCVIII", "DCXCIX", "DCC",
"DCCI", "DCCII", "DCCIII", "DCCIV", "DCCV", "DCCVI", "DCCVII", "DCCVIII", "DCCIX", "DCCX", "DCCXI", "DCCXII", "DCCXIII", "DCCXIV", "DCCXV", "DCCXVI", "DCCXVII", "DCCXVIII", "DCCXIX", "DCCXX", "DCCXXI", "DCCXXII", "DCCXXIII", "DCCXXIV", "DCCXXV", "DCCXXVI", "DCCXXVII", "DCCXXVIII", "DCCXXIX", "DCCXXX", "DCCXXXI", "DCCXXXII", "DCCXXXIII", "DCCXXXIV", "DCCXXXV", "DCCXXXVI", "DCCXXXVII", "DCCXXXVIII", "DCCXXXIX", "DCCXL", "DCCXLI", "DCCXLII", "DCCXLIII", "DCCXLIV", "DCCXLV", "DCCXLVI", "DCCXLVII", "DCCXLVIII", "DCCXLIX", "DCCL", "DCCLI", "DCCLII", "DCCLIII", "DCCLIV", "DCCLV", "DCCLVI", "DCCLVII", "DCCLVIII", "DCCLIX", "DCCLX", "DCCLXI", "DCCLXII", "DCCLXIII", "DCCLXIV", "DCCLXV", "DCCLXVI", "DCCLXVII", "DCCLXVIII", "DCCLXIX", "DCCLXX", "DCCLXXI", "DCCLXXII", "DCCLXXIII", "DCCLXXIV", "DCCLXXV", "DCCLXXVI", "DCCLXXVII", "DCCLXXVIII", "DCCLXXIX", "DCCLXXX", "DCCLXXXI", "DCCLXXXII", "DCCLXXXIII", "DCCLXXXIV", "DCCLXXXV", "DCCLXXXVI", "DCCLXXXVII", "DCCLXXXVIII", "DCCLXXXIX", "DCCXC", "DCCXCI", "DCCXCII", "DCCXCIII", "DCCXCIV", "DCCXCV", "DCCXCVI", "DCCXCVII", "DCCXCVIII", "DCCXCIX", "DCCC",
"DCCCI", "DCCCII", "DCCCIII", "DCCCIV", "DCCCV", "DCCCVI", "DCCCVII", "DCCCVIII", "DCCCIX", "DCCCX", "DCCCXI", "DCCCXII", "DCCCXIII", "DCCCXIV", "DCCCXV", "DCCCXVI", "DCCCXVII", "DCCCXVIII", "DCCCXIX", "DCCCXX", "DCCCXXI", "DCCCXXII", "DCCCXXIII", "DCCCXXIV", "DCCCXXV", "DCCCXXVI", "DCCCXXVII", "DCCCXXVIII", "DCCCXXIX", "DCCCXXX", "DCCCXXXI", "DCCCXXXII", "DCCCXXXIII", "DCCCXXXIV", "DCCCXXXV", "DCCCXXXVI", "DCCCXXXVII", "DCCCXXXVIII", "DCCCXXXIX", "DCCCXL", "DCCCXLI", "DCCCXLII", "DCCCXLIII", "DCCCXLIV", "DCCCXLV", "DCCCXLVI", "DCCCXLVII", "DCCCXLVIII", "DCCCXLIX", "DCCCL", "DCCCLI", "DCCCLII", "DCCCLIII", "DCCCLIV", "DCCCLV", "DCCCLVI", "DCCCLVII", "DCCCLVIII", "DCCCLIX", "DCCCLX", "DCCCLXI", "DCCCLXII", "DCCCLXIII", "DCCCLXIV", "DCCCLXV", "DCCCLXVI", "DCCCLXVII", "DCCCLXVIII", "DCCCLXIX", "DCCCLXX", "DCCCLXXI", "DCCCLXXII", "DCCCLXXIII", "DCCCLXXIV", "DCCCLXXV", "DCCCLXXVI", "DCCCLXXVII", "DCCCLXXVIII", "DCCCLXXIX", "DCCCLXXX", "DCCCLXXXI", "DCCCLXXXII", "DCCCLXXXIII", "DCCCLXXXIV", "DCCCLXXXV", "DCCCLXXXVI", "DCCCLXXXVII", "DCCCLXXXVIII", "DCCCLXXXIX", "DCCCXC", "DCCCXCI", "DCCCXCII", "DCCCXCIII", "DCCCXCIV", "DCCCXCV", "DCCCXCVI", "DCCCXCVII", "DCCCXCVIII", "DCCCXCIX", "CM",
"CMI", "CMII", "CMIII", "CMIV", "CMV", "CMVI", "CMVII", "CMVIII", "CMIX", "CMX", "CMXI", "CMXII", "CMXIII", "CMXIV", "CMXV", "CMXVI", "CMXVII", "CMXVIII", "CMXIX", "CMXX", "CMXXI", "CMXXII", "CMXXIII", "CMXXIV", "CMXXV", "CMXXVI", "CMXXVII", "CMXXVIII", "CMXXIX", "CMXXX", "CMXXXI", "CMXXXII", "CMXXXIII", "CMXXXIV", "CMXXXV", "CMXXXVI", "CMXXXVII", "CMXXXVIII", "CMXXXIX", "CMXL", "CMXLI", "CMXLII", "CMXLIII", "CMXLIV", "CMXLV", "CMXLVI", "CMXLVII", "CMXLVIII", "CMXLIX", "CML", "CMLI", "CMLII", "CMLIII", "CMLIV", "CMLV", "CMLVI", "CMLVII", "CMLVIII", "CMLIX", "CMLX", "CMLXI", "CMLXII", "CMLXIII", "CMLXIV", "CMLXV", "CMLXVI", "CMLXVII", "CMLXVIII", "CMLXIX", "CMLXX", "CMLXXI", "CMLXXII", "CMLXXIII", "CMLXXIV", "CMLXXV", "CMLXXVI", "CMLXXVII", "CMLXXVIII", "CMLXXIX", "CMLXXX", "CMLXXXI", "CMLXXXII", "CMLXXXIII", "CMLXXXIV", "CMLXXXV", "CMLXXXVI", "CMLXXXVII", "CMLXXXVIII", "CMLXXXIX", "CMXC", "CMXCI", "CMXCII", "CMXCIII", "CMXCIV", "CMXCV", "CMXCVI", "CMXCVII", "CMXCVIII", "CMXCIX", "M",
"MI", "MII", "MIII", "MIV", "MV", "MVI", "MVII", "MVIII", "MIX", "MX", "MXI", "MXII", "MXIII", "MXIV", "MXV", "MXVI", "MXVII", "MXVIII", "MXIX", "MXX", "MXXI", "MXXII", "MXXIII", "MXXIV", "MXXV", "MXXVI", "MXXVII", "MXXVIII", "MXXIX", "MXXX", "MXXXI", "MXXXII", "MXXXIII", "MXXXIV", "MXXXV", "MXXXVI", "MXXXVII", "MXXXVIII", "MXXXIX", "MXL", "MXLI", "MXLII", "MXLIII", "MXLIV", "MXLV", "MXLVI", "MXLVII", "MXLVIII", "MXLIX", "ML", "MLI", "MLII", "MLIII", "MLIV", "MLV", "MLVI", "MLVII", "MLVIII", "MLIX", "MLX", "MLXI", "MLXII", "MLXIII", "MLXIV", "MLXV", "MLXVI", "MLXVII", "MLXVIII", "MLXIX", "MLXX", "MLXXI", "MLXXII", "MLXXIII", "MLXXIV", "MLXXV", "MLXXVI", "MLXXVII", "MLXXVIII", "MLXXIX", "MLXXX", "MLXXXI", "MLXXXII", "MLXXXIII", "MLXXXIV", "MLXXXV", "MLXXXVI", "MLXXXVII", "MLXXXVIII", "MLXXXIX", "MXC", "MXCI", "MXCII", "MXCIII", "MXCIV", "MXCV", "MXCVI", "MXCVII", "MXCVIII", "MXCIX", "MC",
"MCI", "MCII", "MCIII", "MCIV", "MCV", "MCVI", "MCVII", "MCVIII", "MCIX", "MCX", "MCXI", "MCXII", "MCXIII", "MCXIV", "MCXV", "MCXVI", "MCXVII", "MCXVIII", "MCXIX", "MCXX", "MCXXI", "MCXXII", "MCXXIII", "MCXXIV", "MCXXV", "MCXXVI", "MCXXVII", "MCXXVIII", "MCXXIX", "MCXXX", "MCXXXI", "MCXXXII", "MCXXXIII", "MCXXXIV", "MCXXXV", "MCXXXVI", "MCXXXVII", "MCXXXVIII", "MCXXXIX", "MCXL", "MCXLI", "MCXLII", "MCXLIII", "MCXLIV", "MCXLV", "MCXLVI", "MCXLVII", "MCXLVIII", "MCXLIX", "MCL", "MCLI", "MCLII", "MCLIII", "MCLIV", "MCLV", "MCLVI", "MCLVII", "MCLVIII", "MCLIX", "MCLX", "MCLXI", "MCLXII", "MCLXIII", "MCLXIV", "MCLXV", "MCLXVI", "MCLXVII", "MCLXVIII", "MCLXIX", "MCLXX", "MCLXXI", "MCLXXII", "MCLXXIII", "MCLXXIV", "MCLXXV", "MCLXXVI", "MCLXXVII", "MCLXXVIII", "MCLXXIX", "MCLXXX", "MCLXXXI", "MCLXXXII", "MCLXXXIII", "MCLXXXIV", "MCLXXXV", "MCLXXXVI", "MCLXXXVII", "MCLXXXVIII", "MCLXXXIX", "MCXC", "MCXCI", "MCXCII", "MCXCIII", "MCXCIV", "MCXCV", "MCXCVI", "MCXCVII", "MCXCVIII", "MCXCIX", "MCC",
"MCCI", "MCCII", "MCCIII", "MCCIV", "MCCV", "MCCVI", "MCCVII", "MCCVIII", "MCCIX", "MCCX", "MCCXI", "MCCXII", "MCCXIII", "MCCXIV", "MCCXV", "MCCXVI", "MCCXVII", "MCCXVIII", "MCCXIX", "MCCXX", "MCCXXI", "MCCXXII", "MCCXXIII", "MCCXXIV", "MCCXXV", "MCCXXVI", "MCCXXVII", "MCCXXVIII", "MCCXXIX", "MCCXXX", "MCCXXXI", "MCCXXXII", "MCCXXXIII", "MCCXXXIV", "MCCXXXV", "MCCXXXVI", "MCCXXXVII", "MCCXXXVIII", "MCCXXXIX", "MCCXL", "MCCXLI", "MCCXLII", "MCCXLIII", "MCCXLIV", "MCCXLV", "MCCXLVI", "MCCXLVII", "MCCXLVIII", "MCCXLIX", "MCCL", "MCCLI", "MCCLII", "MCCLIII", "MCCLIV", "MCCLV", "MCCLVI", "MCCLVII", "MCCLVIII", "MCCLIX", "MCCLX", "MCCLXI", "MCCLXII", "MCCLXIII", "MCCLXIV", "MCCLXV", "MCCLXVI", "MCCLXVII", "MCCLXVIII", "MCCLXIX", "MCCLXX", "MCCLXXI", "MCCLXXII", "MCCLXXIII", "MCCLXXIV", "MCCLXXV", "MCCLXXVI", "MCCLXXVII", "MCCLXXVIII", "MCCLXXIX", "MCCLXXX", "MCCLXXXI", "MCCLXXXII", "MCCLXXXIII", "MCCLXXXIV", "MCCLXXXV", "MCCLXXXVI", "MCCLXXXVII", "MCCLXXXVIII", "MCCLXXXIX", "MCCXC", "MCCXCI", "MCCXCII", "MCCXCIII", "MCCXCIV", "MCCXCV", "MCCXCVI", "MCCXCVII", "MCCXCVIII", "MCCXCIX", "MCCC",
"MCCCI", "MCCCII", "MCCCIII", "MCCCIV", "MCCCV", "MCCCVI", "MCCCVII", "MCCCVIII", "MCCCIX", "MCCCX", "MCCCXI", "MCCCXII", "MCCCXIII", "MCCCXIV", "MCCCXV", "MCCCXVI", "MCCCXVII", "MCCCXVIII", "MCCCXIX", "MCCCXX", "MCCCXXI", "MCCCXXII", "MCCCXXIII", "MCCCXXIV", "MCCCXXV", "MCCCXXVI", "MCCCXXVII", "MCCCXXVIII", "MCCCXXIX", "MCCCXXX", "MCCCXXXI", "MCCCXXXII", "MCCCXXXIII", "MCCCXXXIV", "MCCCXXXV", "MCCCXXXVI", "MCCCXXXVII", "MCCCXXXVIII", "MCCCXXXIX", "MCCCXL", "MCCCXLI", "MCCCXLII", "MCCCXLIII", "MCCCXLIV", "MCCCXLV", "MCCCXLVI", "MCCCXLVII", "MCCCXLVIII", "MCCCXLIX", "MCCCL", "MCCCLI", "MCCCLII", "MCCCLIII", "MCCCLIV", "MCCCLV", "MCCCLVI", "MCCCLVII", "MCCCLVIII", "MCCCLIX", "MCCCLX", "MCCCLXI", "MCCCLXII", "MCCCLXIII", "MCCCLXIV", "MCCCLXV", "MCCCLXVI", "MCCCLXVII", "MCCCLXVIII", "MCCCLXIX", "MCCCLXX", "MCCCLXXI", "MCCCLXXII", "MCCCLXXIII", "MCCCLXXIV", "MCCCLXXV", "MCCCLXXVI", "MCCCLXXVII", "MCCCLXXVIII", "MCCCLXXIX", "MCCCLXXX", "MCCCLXXXI", "MCCCLXXXII", "MCCCLXXXIII", "MCCCLXXXIV", "MCCCLXXXV", "MCCCLXXXVI", "MCCCLXXXVII", "MCCCLXXXVIII", "MCCCLXXXIX", "MCCCXC", "MCCCXCI", "MCCCXCII", "MCCCXCIII", "MCCCXCIV", "MCCCXCV", "MCCCXCVI", "MCCCXCVII", "MCCCXCVIII", "MCCCXCIX", "MCD",
"MCDI", "MCDII", "MCDIII", "MCDIV", "MCDV", "MCDVI", "MCDVII", "MCDVIII", "MCDIX", "MCDX", "MCDXI", "MCDXII", "MCDXIII", "MCDXIV", "MCDXV", "MCDXVI", "MCDXVII", "MCDXVIII", "MCDXIX", "MCDXX", "MCDXXI", "MCDXXII", "MCDXXIII", "MCDXXIV", "MCDXXV", "MCDXXVI", "MCDXXVII", "MCDXXVIII", "MCDXXIX", "MCDXXX", "MCDXXXI", "MCDXXXII", "MCDXXXIII", "MCDXXXIV", "MCDXXXV", "MCDXXXVI", "MCDXXXVII", "MCDXXXVIII", "MCDXXXIX", "MCDXL", "MCDXLI", "MCDXLII", "MCDXLIII", "MCDXLIV", "MCDXLV", "MCDXLVI", "MCDXLVII", "MCDXLVIII", "MCDXLIX", "MCDL", "MCDLI", "MCDLII", "MCDLIII", "MCDLIV", "MCDLV", "MCDLVI", "MCDLVII", "MCDLVIII", "MCDLIX", "MCDLX", "MCDLXI", "MCDLXII", "MCDLXIII", "MCDLXIV", "MCDLXV", "MCDLXVI", "MCDLXVII", "MCDLXVIII", "MCDLXIX", "MCDLXX", "MCDLXXI", "MCDLXXII", "MCDLXXIII", "MCDLXXIV", "MCDLXXV", "MCDLXXVI", "MCDLXXVII", "MCDLXXVIII", "MCDLXXIX", "MCDLXXX", "MCDLXXXI", "MCDLXXXII", "MCDLXXXIII", "MCDLXXXIV", "MCDLXXXV", "MCDLXXXVI", "MCDLXXXVII", "MCDLXXXVIII", "MCDLXXXIX", "MCDXC", "MCDXCI", "MCDXCII", "MCDXCIII", "MCDXCIV", "MCDXCV", "MCDXCVI", "MCDXCVII", "MCDXCVIII", "MCDXCIX", "MD",
"MDI", "MDII", "MDIII", "MDIV", "MDV", "MDVI", "MDVII", "MDVIII", "MDIX", "MDX", "MDXI", "MDXII", "MDXIII", "MDXIV", "MDXV", "MDXVI", "MDXVII", "MDXVIII", "MDXIX", "MDXX", "MDXXI", "MDXXII", "MDXXIII", "MDXXIV", "MDXXV", "MDXXVI", "MDXXVII", "MDXXVIII", "MDXXIX", "MDXXX", "MDXXXI", "MDXXXII", "MDXXXIII", "MDXXXIV", "MDXXXV", "MDXXXVI", "MDXXXVII", "MDXXXVIII", "MDXXXIX", "MDXL", "MDXLI", "MDXLII", "MDXLIII", "MDXLIV", "MDXLV", "MDXLVI", "MDXLVII", "MDXLVIII", "MDXLIX", "MDL", "MDLI", "MDLII", "MDLIII", "MDLIV", "MDLV", "MDLVI", "MDLVII", "MDLVIII", "MDLIX", "MDLX", "MDLXI", "MDLXII", "MDLXIII", "MDLXIV", "MDLXV", "MDLXVI", "MDLXVII", "MDLXVIII", "MDLXIX", "MDLXX", "MDLXXI", "MDLXXII", "MDLXXIII", "MDLXXIV", "MDLXXV", "MDLXXVI", "MDLXXVII", "MDLXXVIII", "MDLXXIX", "MDLXXX", "MDLXXXI", "MDLXXXII", "MDLXXXIII", "MDLXXXIV", "MDLXXXV", "MDLXXXVI", "MDLXXXVII", "MDLXXXVIII", "MDLXXXIX", "MDXC", "MDXCI", "MDXCII", "MDXCIII", "MDXCIV", "MDXCV", "MDXCVI", "MDXCVII", "MDXCVIII", "MDXCIX", "MDC",
"MDCI", "MDCII", "MDCIII", "MDCIV", "MDCV", "MDCVI", "MDCVII", "MDCVIII", "MDCIX", "MDCX", "MDCXI", "MDCXII", "MDCXIII", "MDCXIV", "MDCXV", "MDCXVI", "MDCXVII", "MDCXVIII", "MDCXIX", "MDCXX", "MDCXXI", "MDCXXII", "MDCXXIII", "MDCXXIV", "MDCXXV", "MDCXXVI", "MDCXXVII", "MDCXXVIII", "MDCXXIX", "MDCXXX", "MDCXXXI", "MDCXXXII", "MDCXXXIII", "MDCXXXIV", "MDCXXXV", "MDCXXXVI", "MDCXXXVII", "MDCXXXVIII", "MDCXXXIX", "MDCXL", "MDCXLI", "MDCXLII", "MDCXLIII", "MDCXLIV", "MDCXLV", "MDCXLVI", "MDCXLVII", "MDCXLVIII", "MDCXLIX", "MDCL", "MDCLI", "MDCLII", "MDCLIII", "MDCLIV", "MDCLV", "MDCLVI", "MDCLVII", "MDCLVIII", "MDCLIX", "MDCLX", "MDCLXI", "MDCLXII", "MDCLXIII", "MDCLXIV", "MDCLXV", "MDCLXVI", "MDCLXVII", "MDCLXVIII", "MDCLXIX", "MDCLXX", "MDCLXXI", "MDCLXXII", "MDCLXXIII", "MDCLXXIV", "MDCLXXV", "MDCLXXVI", "MDCLXXVII", "MDCLXXVIII", "MDCLXXIX", "MDCLXXX", "MDCLXXXI", "MDCLXXXII", "MDCLXXXIII", "MDCLXXXIV", "MDCLXXXV", "MDCLXXXVI", "MDCLXXXVII", "MDCLXXXVIII", "MDCLXXXIX", "MDCXC", "MDCXCI", "MDCXCII", "MDCXCIII", "MDCXCIV", "MDCXCV", "MDCXCVI", "MDCXCVII", "MDCXCVIII", "MDCXCIX", "MDCC",
"MDCCI", "MDCCII", "MDCCIII", "MDCCIV", "MDCCV", "MDCCVI", "MDCCVII", "MDCCVIII", "MDCCIX", "MDCCX", "MDCCXI", "MDCCXII", "MDCCXIII", "MDCCXIV", "MDCCXV", "MDCCXVI", "MDCCXVII", "MDCCXVIII", "MDCCXIX", "MDCCXX", "MDCCXXI", "MDCCXXII", "MDCCXXIII", "MDCCXXIV", "MDCCXXV", "MDCCXXVI", "MDCCXXVII", "MDCCXXVIII", "MDCCXXIX", "MDCCXXX", "MDCCXXXI", "MDCCXXXII", "MDCCXXXIII", "MDCCXXXIV", "MDCCXXXV", "MDCCXXXVI", "MDCCXXXVII", "MDCCXXXVIII", "MDCCXXXIX", "MDCCXL", "MDCCXLI", "MDCCXLII", "MDCCXLIII", "MDCCXLIV", "MDCCXLV", "MDCCXLVI", "MDCCXLVII", "MDCCXLVIII", "MDCCXLIX", "MDCCL", "MDCCLI", "MDCCLII", "MDCCLIII", "MDCCLIV", "MDCCLV", "MDCCLVI", "MDCCLVII", "MDCCLVIII", "MDCCLIX", "MDCCLX", "MDCCLXI", "MDCCLXII", "MDCCLXIII", "MDCCLXIV", "MDCCLXV", "MDCCLXVI", "MDCCLXVII", "MDCCLXVIII", "MDCCLXIX", "MDCCLXX", "MDCCLXXI", "MDCCLXXII", "MDCCLXXIII", "MDCCLXXIV", "MDCCLXXV", "MDCCLXXVI", "MDCCLXXVII", "MDCCLXXVIII", "MDCCLXXIX", "MDCCLXXX", "MDCCLXXXI", "MDCCLXXXII", "MDCCLXXXIII", "MDCCLXXXIV", "MDCCLXXXV", "MDCCLXXXVI", "MDCCLXXXVII", "MDCCLXXXVIII", "MDCCLXXXIX", "MDCCXC", "MDCCXCI", "MDCCXCII", "MDCCXCIII", "MDCCXCIV", "MDCCXCV", "MDCCXCVI", "MDCCXCVII", "MDCCXCVIII", "MDCCXCIX", "MDCCC",
"MDCCCI", "MDCCCII", "MDCCCIII", "MDCCCIV", "MDCCCV", "MDCCCVI", "MDCCCVII", "MDCCCVIII", "MDCCCIX", "MDCCCX", "MDCCCXI", "MDCCCXII", "MDCCCXIII", "MDCCCXIV", "MDCCCXV", "MDCCCXVI", "MDCCCXVII", "MDCCCXVIII", "MDCCCXIX", "MDCCCXX", "MDCCCXXI", "MDCCCXXII", "MDCCCXXIII", "MDCCCXXIV", "MDCCCXXV", "MDCCCXXVI", "MDCCCXXVII", "MDCCCXXVIII", "MDCCCXXIX", "MDCCCXXX", "MDCCCXXXI", "MDCCCXXXII", "MDCCCXXXIII", "MDCCCXXXIV", "MDCCCXXXV", "MDCCCXXXVI", "MDCCCXXXVII", "MDCCCXXXVIII", "MDCCCXXXIX", "MDCCCXL", "MDCCCXLI", "MDCCCXLII", "MDCCCXLIII", "MDCCCXLIV", "MDCCCXLV", "MDCCCXLVI", "MDCCCXLVII", "MDCCCXLVIII", "MDCCCXLIX", "MDCCCL", "MDCCCLI", "MDCCCLII", "MDCCCLIII", "MDCCCLIV", "MDCCCLV", "MDCCCLVI", "MDCCCLVII", "MDCCCLVIII", "MDCCCLIX", "MDCCCLX", "MDCCCLXI", "MDCCCLXII", "MDCCCLXIII", "MDCCCLXIV", "MDCCCLXV", "MDCCCLXVI", "MDCCCLXVII", "MDCCCLXVIII", "MDCCCLXIX", "MDCCCLXX", "MDCCCLXXI", "MDCCCLXXII", "MDCCCLXXIII", "MDCCCLXXIV", "MDCCCLXXV", "MDCCCLXXVI", "MDCCCLXXVII", "MDCCCLXXVIII", "MDCCCLXXIX", "MDCCCLXXX", "MDCCCLXXXI", "MDCCCLXXXII", "MDCCCLXXXIII", "MDCCCLXXXIV", "MDCCCLXXXV", "MDCCCLXXXVI", "MDCCCLXXXVII", "MDCCCLXXXVIII", "MDCCCLXXXIX", "MDCCCXC", "MDCCCXCI", "MDCCCXCII", "MDCCCXCIII", "MDCCCXCIV", "MDCCCXCV", "MDCCCXCVI", "MDCCCXCVII", "MDCCCXCVIII", "MDCCCXCIX", "MCM",
"MCMI", "MCMII", "MCMIII", "MCMIV", "MCMV", "MCMVI", "MCMVII", "MCMVIII", "MCMIX", "MCMX", "MCMXI", "MCMXII", "MCMXIII", "MCMXIV", "MCMXV", "MCMXVI", "MCMXVII", "MCMXVIII", "MCMXIX", "MCMXX", "MCMXXI", "MCMXXII", "MCMXXIII", "MCMXXIV", "MCMXXV", "MCMXXVI", "MCMXXVII", "MCMXXVIII", "MCMXXIX", "MCMXXX", "MCMXXXI", "MCMXXXII", "MCMXXXIII", "MCMXXXIV", "MCMXXXV", "MCMXXXVI", "MCMXXXVII", "MCMXXXVIII", "MCMXXXIX", "MCMXL", "MCMXLI", "MCMXLII", "MCMXLIII", "MCMXLIV", "MCMXLV", "MCMXLVI", "MCMXLVII", "MCMXLVIII", "MCMXLIX", "MCML", "MCMLI", "MCMLII", "MCMLIII", "MCMLIV", "MCMLV", "MCMLVI", "MCMLVII", "MCMLVIII", "MCMLIX", "MCMLX", "MCMLXI", "MCMLXII", "MCMLXIII", "MCMLXIV", "MCMLXV", "MCMLXVI", "MCMLXVII", "MCMLXVIII", "MCMLXIX", "MCMLXX", "MCMLXXI", "MCMLXXII", "MCMLXXIII", "MCMLXXIV", "MCMLXXV", "MCMLXXVI", "MCMLXXVII", "MCMLXXVIII", "MCMLXXIX", "MCMLXXX", "MCMLXXXI", "MCMLXXXII", "MCMLXXXIII", "MCMLXXXIV", "MCMLXXXV", "MCMLXXXVI", "MCMLXXXVII", "MCMLXXXVIII", "MCMLXXXIX", "MCMXC", "MCMXCI", "MCMXCII", "MCMXCIII", "MCMXCIV", "MCMXCV", "MCMXCVI", "MCMXCVII", "MCMXCVIII", "MCMXCIX", "MM",
"MMI", "MMII", "MMIII", "MMIV", "MMV", "MMVI", "MMVII", "MMVIII", "MMIX", "MMX", "MMXI", "MMXII", "MMXIII", "MMXIV", "MMXV", "MMXVI", "MMXVII", "MMXVIII", "MMXIX", "MMXX", "MMXXI", "MMXXII", "MMXXIII", "MMXXIV", "MMXXV", "MMXXVI", "MMXXVII", "MMXXVIII", "MMXXIX", "MMXXX", "MMXXXI", "MMXXXII", "MMXXXIII", "MMXXXIV", "MMXXXV", "MMXXXVI", "MMXXXVII", "MMXXXVIII", "MMXXXIX", "MMXL", "MMXLI", "MMXLII", "MMXLIII", "MMXLIV", "MMXLV", "MMXLVI", "MMXLVII", "MMXLVIII", "MMXLIX", "MML", "MMLI", "MMLII", "MMLIII", "MMLIV", "MMLV", "MMLVI", "MMLVII", "MMLVIII", "MMLIX", "MMLX", "MMLXI", "MMLXII", "MMLXIII", "MMLXIV", "MMLXV", "MMLXVI", "MMLXVII", "MMLXVIII", "MMLXIX", "MMLXX", "MMLXXI", "MMLXXII", "MMLXXIII", "MMLXXIV", "MMLXXV", "MMLXXVI", "MMLXXVII", "MMLXXVIII", "MMLXXIX", "MMLXXX", "MMLXXXI", "MMLXXXII", "MMLXXXIII", "MMLXXXIV", "MMLXXXV", "MMLXXXVI", "MMLXXXVII", "MMLXXXVIII", "MMLXXXIX", "MMXC", "MMXCI", "MMXCII", "MMXCIII", "MMXCIV", "MMXCV", "MMXCVI", "MMXCVII", "MMXCVIII", "MMXCIX", "MMC",
"MMCI", "MMCII", "MMCIII", "MMCIV", "MMCV", "MMCVI", "MMCVII", "MMCVIII", "MMCIX", "MMCX", "MMCXI", "MMCXII", "MMCXIII", "MMCXIV", "MMCXV", "MMCXVI", "MMCXVII", "MMCXVIII", "MMCXIX", "MMCXX", "MMCXXI", "MMCXXII", "MMCXXIII", "MMCXXIV", "MMCXXV", "MMCXXVI", "MMCXXVII", "MMCXXVIII", "MMCXXIX", "MMCXXX", "MMCXXXI", "MMCXXXII", "MMCXXXIII", "MMCXXXIV", "MMCXXXV", "MMCXXXVI", "MMCXXXVII", "MMCXXXVIII", "MMCXXXIX", "MMCXL", "MMCXLI", "MMCXLII", "MMCXLIII", "MMCXLIV", "MMCXLV", "MMCXLVI", "MMCXLVII", "MMCXLVIII", "MMCXLIX", "MMCL", "MMCLI", "MMCLII", "MMCLIII", "MMCLIV", "MMCLV", "MMCLVI", "MMCLVII", "MMCLVIII", "MMCLIX", "MMCLX", "MMCLXI", "MMCLXII", "MMCLXIII", "MMCLXIV", "MMCLXV", "MMCLXVI", "MMCLXVII", "MMCLXVIII", "MMCLXIX", "MMCLXX", "MMCLXXI", "MMCLXXII", "MMCLXXIII", "MMCLXXIV", "MMCLXXV", "MMCLXXVI", "MMCLXXVII", "MMCLXXVIII", "MMCLXXIX", "MMCLXXX", "MMCLXXXI", "MMCLXXXII", "MMCLXXXIII", "MMCLXXXIV", "MMCLXXXV", "MMCLXXXVI", "MMCLXXXVII", "MMCLXXXVIII", "MMCLXXXIX", "MMCXC", "MMCXCI", "MMCXCII", "MMCXCIII", "MMCXCIV", "MMCXCV", "MMCXCVI", "MMCXCVII", "MMCXCVIII", "MMCXCIX", "MMCC",
"MMCCI", "MMCCII", "MMCCIII", "MMCCIV", "MMCCV", "MMCCVI", "MMCCVII", "MMCCVIII", "MMCCIX", "MMCCX", "MMCCXI", "MMCCXII", "MMCCXIII", "MMCCXIV", "MMCCXV", "MMCCXVI", "MMCCXVII", "MMCCXVIII", "MMCCXIX", "MMCCXX", "MMCCXXI", "MMCCXXII", "MMCCXXIII", "MMCCXXIV", "MMCCXXV", "MMCCXXVI", "MMCCXXVII", "MMCCXXVIII", "MMCCXXIX", "MMCCXXX", "MMCCXXXI", "MMCCXXXII", "MMCCXXXIII", "MMCCXXXIV", "MMCCXXXV", "MMCCXXXVI", "MMCCXXXVII", "MMCCXXXVIII", "MMCCXXXIX", "MMCCXL", "MMCCXLI", "MMCCXLII", "MMCCXLIII", "MMCCXLIV", "MMCCXLV", "MMCCXLVI", "MMCCXLVII", "MMCCXLVIII", "MMCCXLIX", "MMCCL", "MMCCLI", "MMCCLII", "MMCCLIII", "MMCCLIV", "MMCCLV", "MMCCLVI", "MMCCLVII", "MMCCLVIII", "MMCCLIX", "MMCCLX", "MMCCLXI", "MMCCLXII", "MMCCLXIII", "MMCCLXIV", "MMCCLXV", "MMCCLXVI", "MMCCLXVII", "MMCCLXVIII", "MMCCLXIX", "MMCCLXX", "MMCCLXXI", "MMCCLXXII", "MMCCLXXIII", "MMCCLXXIV", "MMCCLXXV", "MMCCLXXVI", "MMCCLXXVII", "MMCCLXXVIII", "MMCCLXXIX", "MMCCLXXX", "MMCCLXXXI", "MMCCLXXXII", "MMCCLXXXIII", "MMCCLXXXIV", "MMCCLXXXV", "MMCCLXXXVI", "MMCCLXXXVII", "MMCCLXXXVIII", "MMCCLXXXIX", "MMCCXC", "MMCCXCI", "MMCCXCII", "MMCCXCIII", "MMCCXCIV", "MMCCXCV", "MMCCXCVI", "MMCCXCVII", "MMCCXCVIII", "MMCCXCIX", "MMCCC",
"MMCCCI", "MMCCCII", "MMCCCIII", "MMCCCIV", "MMCCCV", "MMCCCVI", "MMCCCVII", "MMCCCVIII", "MMCCCIX", "MMCCCX", "MMCCCXI", "MMCCCXII", "MMCCCXIII", "MMCCCXIV", "MMCCCXV", "MMCCCXVI", "MMCCCXVII", "MMCCCXVIII", "MMCCCXIX", "MMCCCXX", "MMCCCXXI", "MMCCCXXII", "MMCCCXXIII", "MMCCCXXIV", "MMCCCXXV", "MMCCCXXVI", "MMCCCXXVII", "MMCCCXXVIII", "MMCCCXXIX", "MMCCCXXX", "MMCCCXXXI", "MMCCCXXXII", "MMCCCXXXIII", "MMCCCXXXIV", "MMCCCXXXV", "MMCCCXXXVI", "MMCCCXXXVII", "MMCCCXXXVIII", "MMCCCXXXIX", "MMCCCXL", "MMCCCXLI", "MMCCCXLII", "MMCCCXLIII", "MMCCCXLIV", "MMCCCXLV", "MMCCCXLVI", "MMCCCXLVII", "MMCCCXLVIII", "MMCCCXLIX", "MMCCCL", "MMCCCLI", "MMCCCLII", "MMCCCLIII", "MMCCCLIV", "MMCCCLV", "MMCCCLVI", "MMCCCLVII", "MMCCCLVIII", "MMCCCLIX", "MMCCCLX", "MMCCCLXI", "MMCCCLXII", "MMCCCLXIII", "MMCCCLXIV", "MMCCCLXV", "MMCCCLXVI", "MMCCCLXVII", "MMCCCLXVIII", "MMCCCLXIX", "MMCCCLXX", "MMCCCLXXI", "MMCCCLXXII", "MMCCCLXXIII", "MMCCCLXXIV", "MMCCCLXXV", "MMCCCLXXVI", "MMCCCLXXVII", "MMCCCLXXVIII", "MMCCCLXXIX", "MMCCCLXXX", "MMCCCLXXXI", "MMCCCLXXXII", "MMCCCLXXXIII", "MMCCCLXXXIV", "MMCCCLXXXV", "MMCCCLXXXVI", "MMCCCLXXXVII", "MMCCCLXXXVIII", "MMCCCLXXXIX", "MMCCCXC", "MMCCCXCI", "MMCCCXCII", "MMCCCXCIII", "MMCCCXCIV", "MMCCCXCV", "MMCCCXCVI", "MMCCCXCVII", "MMCCCXCVIII", "MMCCCXCIX", "MMCD",
"MMCDI", "MMCDII", "MMCDIII", "MMCDIV", "MMCDV", "MMCDVI", "MMCDVII", "MMCDVIII", "MMCDIX", "MMCDX", "MMCDXI", "MMCDXII", "MMCDXIII", "MMCDXIV", "MMCDXV", "MMCDXVI", "MMCDXVII", "MMCDXVIII", "MMCDXIX", "MMCDXX", "MMCDXXI", "MMCDXXII", "MMCDXXIII", "MMCDXXIV", "MMCDXXV", "MMCDXXVI", "MMCDXXVII", "MMCDXXVIII", "MMCDXXIX", "MMCDXXX", "MMCDXXXI", "MMCDXXXII", "MMCDXXXIII", "MMCDXXXIV", "MMCDXXXV", "MMCDXXXVI", "MMCDXXXVII", "MMCDXXXVIII", "MMCDXXXIX", "MMCDXL", "MMCDXLI", "MMCDXLII", "MMCDXLIII", "MMCDXLIV", "MMCDXLV", "MMCDXLVI", "MMCDXLVII", "MMCDXLVIII", "MMCDXLIX", "MMCDL", "MMCDLI", "MMCDLII", "MMCDLIII", "MMCDLIV", "MMCDLV", "MMCDLVI", "MMCDLVII", "MMCDLVIII", "MMCDLIX", "MMCDLX", "MMCDLXI", "MMCDLXII", "MMCDLXIII", "MMCDLXIV", "MMCDLXV", "MMCDLXVI", "MMCDLXVII", "MMCDLXVIII", "MMCDLXIX", "MMCDLXX", "MMCDLXXI", "MMCDLXXII", "MMCDLXXIII", "MMCDLXXIV", "MMCDLXXV", "MMCDLXXVI", "MMCDLXXVII", "MMCDLXXVIII", "MMCDLXXIX", "MMCDLXXX", "MMCDLXXXI", "MMCDLXXXII", "MMCDLXXXIII", "MMCDLXXXIV", "MMCDLXXXV", "MMCDLXXXVI", "MMCDLXXXVII", "MMCDLXXXVIII", "MMCDLXXXIX", "MMCDXC", "MMCDXCI", "MMCDXCII", "MMCDXCIII", "MMCDXCIV", "MMCDXCV", "MMCDXCVI", "MMCDXCVII", "MMCDXCVIII", "MMCDXCIX", "MMD",
"MMDI", "MMDII", "MMDIII", "MMDIV", "MMDV", "MMDVI", "MMDVII", "MMDVIII", "MMDIX", "MMDX", "MMDXI", "MMDXII", "MMDXIII", "MMDXIV", "MMDXV", "MMDXVI", "MMDXVII", "MMDXVIII", "MMDXIX", "MMDXX", "MMDXXI", "MMDXXII", "MMDXXIII", "MMDXXIV", "MMDXXV", "MMDXXVI", "MMDXXVII", "MMDXXVIII", "MMDXXIX", "MMDXXX", "MMDXXXI", "MMDXXXII", "MMDXXXIII", "MMDXXXIV", "MMDXXXV", "MMDXXXVI", "MMDXXXVII", "MMDXXXVIII", "MMDXXXIX", "MMDXL", "MMDXLI", "MMDXLII", "MMDXLIII", "MMDXLIV", "MMDXLV", "MMDXLVI", "MMDXLVII", "MMDXLVIII", "MMDXLIX", "MMDL", "MMDLI", "MMDLII", "MMDLIII", "MMDLIV", "MMDLV", "MMDLVI", "MMDLVII", "MMDLVIII", "MMDLIX", "MMDLX", "MMDLXI", "MMDLXII", "MMDLXIII", "MMDLXIV", "MMDLXV", "MMDLXVI", "MMDLXVII", "MMDLXVIII", "MMDLXIX", "MMDLXX", "MMDLXXI", "MMDLXXII", "MMDLXXIII", "MMDLXXIV", "MMDLXXV", "MMDLXXVI", "MMDLXXVII", "MMDLXXVIII", "MMDLXXIX", "MMDLXXX", "MMDLXXXI", "MMDLXXXII", "MMDLXXXIII", "MMDLXXXIV", "MMDLXXXV", "MMDLXXXVI", "MMDLXXXVII", "MMDLXXXVIII", "MMDLXXXIX", "MMDXC", "MMDXCI", "MMDXCII", "MMDXCIII", "MMDXCIV", "MMDXCV", "MMDXCVI", "MMDXCVII", "MMDXCVIII", "MMDXCIX", "MMDC",
"MMDCI", "MMDCII", "MMDCIII", "MMDCIV", "MMDCV", "MMDCVI", "MMDCVII", "MMDCVIII", "MMDCIX", "MMDCX", "MMDCXI", "MMDCXII", "MMDCXIII", "MMDCXIV", "MMDCXV", "MMDCXVI", "MMDCXVII", "MMDCXVIII", "MMDCXIX", "MMDCXX", "MMDCXXI", "MMDCXXII", "MMDCXXIII", "MMDCXXIV", "MMDCXXV", "MMDCXXVI", "MMDCXXVII", "MMDCXXVIII", "MMDCXXIX", "MMDCXXX", "MMDCXXXI", "MMDCXXXII", "MMDCXXXIII", "MMDCXXXIV", "MMDCXXXV", "MMDCXXXVI", "MMDCXXXVII", "MMDCXXXVIII", "MMDCXXXIX", "MMDCXL", "MMDCXLI", "MMDCXLII", "MMDCXLIII", "MMDCXLIV", "MMDCXLV", "MMDCXLVI", "MMDCXLVII", "MMDCXLVIII", "MMDCXLIX", "MMDCL", "MMDCLI", "MMDCLII", "MMDCLIII", "MMDCLIV", "MMDCLV", "MMDCLVI", "MMDCLVII", "MMDCLVIII", "MMDCLIX", "MMDCLX", "MMDCLXI", "MMDCLXII", "MMDCLXIII", "MMDCLXIV", "MMDCLXV", "MMDCLXVI", "MMDCLXVII", "MMDCLXVIII", "MMDCLXIX", "MMDCLXX", "MMDCLXXI", "MMDCLXXII", "MMDCLXXIII", "MMDCLXXIV", "MMDCLXXV", "MMDCLXXVI", "MMDCLXXVII", "MMDCLXXVIII", "MMDCLXXIX", "MMDCLXXX", "MMDCLXXXI", "MMDCLXXXII", "MMDCLXXXIII", "MMDCLXXXIV", "MMDCLXXXV", "MMDCLXXXVI", "MMDCLXXXVII", "MMDCLXXXVIII", "MMDCLXXXIX", "MMDCXC", "MMDCXCI", "MMDCXCII", "MMDCXCIII", "MMDCXCIV", "MMDCXCV", "MMDCXCVI", "MMDCXCVII", "MMDCXCVIII", "MMDCXCIX", "MMDCC",
"MMDCCI", "MMDCCII", "MMDCCIII", "MMDCCIV", "MMDCCV", "MMDCCVI", "MMDCCVII", "MMDCCVIII", "MMDCCIX", "MMDCCX", "MMDCCXI", "MMDCCXII", "MMDCCXIII", "MMDCCXIV", "MMDCCXV", "MMDCCXVI", "MMDCCXVII", "MMDCCXVIII", "MMDCCXIX", "MMDCCXX", "MMDCCXXI", "MMDCCXXII", "MMDCCXXIII", "MMDCCXXIV", "MMDCCXXV", "MMDCCXXVI", "MMDCCXXVII", "MMDCCXXVIII", "MMDCCXXIX", "MMDCCXXX", "MMDCCXXXI", "MMDCCXXXII", "MMDCCXXXIII", "MMDCCXXXIV", "MMDCCXXXV", "MMDCCXXXVI", "MMDCCXXXVII", "MMDCCXXXVIII", "MMDCCXXXIX", "MMDCCXL", "MMDCCXLI", "MMDCCXLII", "MMDCCXLIII", "MMDCCXLIV", "MMDCCXLV", "MMDCCXLVI", "MMDCCXLVII", "MMDCCXLVIII", "MMDCCXLIX", "MMDCCL", "MMDCCLI", "MMDCCLII", "MMDCCLIII", "MMDCCLIV", "MMDCCLV", "MMDCCLVI", "MMDCCLVII", "MMDCCLVIII", "MMDCCLIX", "MMDCCLX", "MMDCCLXI", "MMDCCLXII", "MMDCCLXIII", "MMDCCLXIV", "MMDCCLXV", "MMDCCLXVI", "MMDCCLXVII", "MMDCCLXVIII", "MMDCCLXIX", "MMDCCLXX", "MMDCCLXXI", "MMDCCLXXII", "MMDCCLXXIII", "MMDCCLXXIV", "MMDCCLXXV", "MMDCCLXXVI", "MMDCCLXXVII", "MMDCCLXXVIII", "MMDCCLXXIX", "MMDCCLXXX", "MMDCCLXXXI", "MMDCCLXXXII", "MMDCCLXXXIII", "MMDCCLXXXIV", "MMDCCLXXXV", "MMDCCLXXXVI", "MMDCCLXXXVII", "MMDCCLXXXVIII", "MMDCCLXXXIX", "MMDCCXC", "MMDCCXCI", "MMDCCXCII", "MMDCCXCIII", "MMDCCXCIV", "MMDCCXCV", "MMDCCXCVI", "MMDCCXCVII", "MMDCCXCVIII", "MMDCCXCIX", "MMDCCC",
"MMDCCCI", "MMDCCCII", "MMDCCCIII", "MMDCCCIV", "MMDCCCV", "MMDCCCVI", "MMDCCCVII", "MMDCCCVIII", "MMDCCCIX", "MMDCCCX", "MMDCCCXI", "MMDCCCXII", "MMDCCCXIII", "MMDCCCXIV", "MMDCCCXV", "MMDCCCXVI", "MMDCCCXVII", "MMDCCCXVIII", "MMDCCCXIX", "MMDCCCXX", "MMDCCCXXI", "MMDCCCXXII", "MMDCCCXXIII", "MMDCCCXXIV", "MMDCCCXXV", "MMDCCCXXVI", "MMDCCCXXVII", "MMDCCCXXVIII", "MMDCCCXXIX", "MMDCCCXXX", "MMDCCCXXXI", "MMDCCCXXXII", "MMDCCCXXXIII", "MMDCCCXXXIV", "MMDCCCXXXV", "MMDCCCXXXVI", "MMDCCCXXXVII", "MMDCCCXXXVIII", "MMDCCCXXXIX", "MMDCCCXL", "MMDCCCXLI", "MMDCCCXLII", "MMDCCCXLIII", "MMDCCCXLIV", "MMDCCCXLV", "MMDCCCXLVI", "MMDCCCXLVII", "MMDCCCXLVIII", "MMDCCCXLIX", "MMDCCCL", "MMDCCCLI", "MMDCCCLII", "MMDCCCLIII", "MMDCCCLIV", "MMDCCCLV", "MMDCCCLVI", "MMDCCCLVII", "MMDCCCLVIII", "MMDCCCLIX", "MMDCCCLX", "MMDCCCLXI", "MMDCCCLXII", "MMDCCCLXIII", "MMDCCCLXIV", "MMDCCCLXV", "MMDCCCLXVI", "MMDCCCLXVII", "MMDCCCLXVIII", "MMDCCCLXIX", "MMDCCCLXX", "MMDCCCLXXI", "MMDCCCLXXII", "MMDCCCLXXIII", "MMDCCCLXXIV", "MMDCCCLXXV", "MMDCCCLXXVI", "MMDCCCLXXVII", "MMDCCCLXXVIII", "MMDCCCLXXIX", "MMDCCCLXXX", "MMDCCCLXXXI", "MMDCCCLXXXII", "MMDCCCLXXXIII", "MMDCCCLXXXIV", "MMDCCCLXXXV", "MMDCCCLXXXVI", "MMDCCCLXXXVII", "MMDCCCLXXXVIII", "MMDCCCLXXXIX", "MMDCCCXC", "MMDCCCXCI", "MMDCCCXCII", "MMDCCCXCIII", "MMDCCCXCIV", "MMDCCCXCV", "MMDCCCXCVI", "MMDCCCXCVII", "MMDCCCXCVIII", "MMDCCCXCIX", "MMCM",
"MMCMI", "MMCMII", "MMCMIII", "MMCMIV", "MMCMV", "MMCMVI", "MMCMVII", "MMCMVIII", "MMCMIX", "MMCMX", "MMCMXI", "MMCMXII", "MMCMXIII", "MMCMXIV", "MMCMXV", "MMCMXVI", "MMCMXVII", "MMCMXVIII", "MMCMXIX", "MMCMXX", "MMCMXXI", "MMCMXXII", "MMCMXXIII", "MMCMXXIV", "MMCMXXV", "MMCMXXVI", "MMCMXXVII", "MMCMXXVIII", "MMCMXXIX", "MMCMXXX", "MMCMXXXI", "MMCMXXXII", "MMCMXXXIII", "MMCMXXXIV", "MMCMXXXV", "MMCMXXXVI", "MMCMXXXVII", "MMCMXXXVIII", "MMCMXXXIX", "MMCMXL", "MMCMXLI", "MMCMXLII", "MMCMXLIII", "MMCMXLIV", "MMCMXLV", "MMCMXLVI", "MMCMXLVII", "MMCMXLVIII", "MMCMXLIX", "MMCML", "MMCMLI", "MMCMLII", "MMCMLIII", "MMCMLIV", "MMCMLV", "MMCMLVI", "MMCMLVII", "MMCMLVIII", "MMCMLIX", "MMCMLX", "MMCMLXI", "MMCMLXII", "MMCMLXIII", "MMCMLXIV", "MMCMLXV", "MMCMLXVI", "MMCMLXVII", "MMCMLXVIII", "MMCMLXIX", "MMCMLXX", "MMCMLXXI", "MMCMLXXII", "MMCMLXXIII", "MMCMLXXIV", "MMCMLXXV", "MMCMLXXVI", "MMCMLXXVII", "MMCMLXXVIII", "MMCMLXXIX", "MMCMLXXX", "MMCMLXXXI", "MMCMLXXXII", "MMCMLXXXIII", "MMCMLXXXIV", "MMCMLXXXV", "MMCMLXXXVI", "MMCMLXXXVII", "MMCMLXXXVIII", "MMCMLXXXIX", "MMCMXC", "MMCMXCI", "MMCMXCII", "MMCMXCIII", "MMCMXCIV", "MMCMXCV", "MMCMXCVI", "MMCMXCVII", "MMCMXCVIII", "MMCMXCIX", "MMM",
"MMMI", "MMMII", "MMMIII", "MMMIV", "MMMV", "MMMVI", "MMMVII", "MMMVIII", "MMMIX", "MMMX", "MMMXI", "MMMXII", "MMMXIII", "MMMXIV", "MMMXV", "MMMXVI", "MMMXVII", "MMMXVIII", "MMMXIX", "MMMXX", "MMMXXI", "MMMXXII", "MMMXXIII", "MMMXXIV", "MMMXXV", "MMMXXVI", "MMMXXVII", "MMMXXVIII", "MMMXXIX", "MMMXXX", "MMMXXXI", "MMMXXXII", "MMMXXXIII", "MMMXXXIV", "MMMXXXV", "MMMXXXVI", "MMMXXXVII", "MMMXXXVIII", "MMMXXXIX", "MMMXL", "MMMXLI", "MMMXLII", "MMMXLIII", "MMMXLIV", "MMMXLV", "MMMXLVI", "MMMXLVII", "MMMXLVIII", "MMMXLIX", "MMML", "MMMLI", "MMMLII", "MMMLIII", "MMMLIV", "MMMLV", "MMMLVI", "MMMLVII", "MMMLVIII", "MMMLIX", "MMMLX", "MMMLXI", "MMMLXII", "MMMLXIII", "MMMLXIV", "MMMLXV", "MMMLXVI", "MMMLXVII", "MMMLXVIII", "MMMLXIX", "MMMLXX", "MMMLXXI", "MMMLXXII", "MMMLXXIII", "MMMLXXIV", "MMMLXXV", "MMMLXXVI", "MMMLXXVII", "MMMLXXVIII", "MMMLXXIX", "MMMLXXX", "MMMLXXXI", "MMMLXXXII", "MMMLXXXIII", "MMMLXXXIV", "MMMLXXXV", "MMMLXXXVI", "MMMLXXXVII", "MMMLXXXVIII", "MMMLXXXIX", "MMMXC", "MMMXCI", "MMMXCII", "MMMXCIII", "MMMXCIV", "MMMXCV", "MMMXCVI", "MMMXCVII", "MMMXCVIII", "MMMXCIX", "MMMC",
"MMMCI", "MMMCII", "MMMCIII", "MMMCIV", "MMMCV", "MMMCVI", "MMMCVII", "MMMCVIII", "MMMCIX", "MMMCX", "MMMCXI", "MMMCXII", "MMMCXIII", "MMMCXIV", "MMMCXV", "MMMCXVI", "MMMCXVII", "MMMCXVIII", "MMMCXIX", "MMMCXX", "MMMCXXI", "MMMCXXII", "MMMCXXIII", "MMMCXXIV", "MMMCXXV", "MMMCXXVI", "MMMCXXVII", "MMMCXXVIII", "MMMCXXIX", "MMMCXXX", "MMMCXXXI", "MMMCXXXII", "MMMCXXXIII", "MMMCXXXIV", "MMMCXXXV", "MMMCXXXVI", "MMMCXXXVII", "MMMCXXXVIII", "MMMCXXXIX", "MMMCXL", "MMMCXLI", "MMMCXLII", "MMMCXLIII", "MMMCXLIV", "MMMCXLV", "MMMCXLVI", "MMMCXLVII", "MMMCXLVIII", "MMMCXLIX", "MMMCL", "MMMCLI", "MMMCLII", "MMMCLIII", "MMMCLIV", "MMMCLV", "MMMCLVI", "MMMCLVII", "MMMCLVIII", "MMMCLIX", "MMMCLX", "MMMCLXI", "MMMCLXII", "MMMCLXIII", "MMMCLXIV", "MMMCLXV", "MMMCLXVI", "MMMCLXVII", "MMMCLXVIII", "MMMCLXIX", "MMMCLXX", "MMMCLXXI", "MMMCLXXII", "MMMCLXXIII", "MMMCLXXIV", "MMMCLXXV", "MMMCLXXVI", "MMMCLXXVII", "MMMCLXXVIII", "MMMCLXXIX", "MMMCLXXX", "MMMCLXXXI", "MMMCLXXXII", "MMMCLXXXIII", "MMMCLXXXIV", "MMMCLXXXV", "MMMCLXXXVI", "MMMCLXXXVII", "MMMCLXXXVIII", "MMMCLXXXIX", "MMMCXC", "MMMCXCI", "MMMCXCII", "MMMCXCIII", "MMMCXCIV", "MMMCXCV", "MMMCXCVI", "MMMCXCVII", "MMMCXCVIII", "MMMCXCIX", "MMMCC",
"MMMCCI", "MMMCCII", "MMMCCIII", "MMMCCIV", "MMMCCV", "MMMCCVI", "MMMCCVII", "MMMCCVIII", "MMMCCIX", "MMMCCX", "MMMCCXI", "MMMCCXII", "MMMCCXIII", "MMMCCXIV", "MMMCCXV", "MMMCCXVI", "MMMCCXVII", "MMMCCXVIII", "MMMCCXIX", "MMMCCXX", "MMMCCXXI", "MMMCCXXII", "MMMCCXXIII", "MMMCCXXIV", "MMMCCXXV", "MMMCCXXVI", "MMMCCXXVII", "MMMCCXXVIII", "MMMCCXXIX", "MMMCCXXX", "MMMCCXXXI", "MMMCCXXXII", "MMMCCXXXIII", "MMMCCXXXIV", "MMMCCXXXV", "MMMCCXXXVI", "MMMCCXXXVII", "MMMCCXXXVIII", "MMMCCXXXIX", "MMMCCXL", "MMMCCXLI", "MMMCCXLII", "MMMCCXLIII", "MMMCCXLIV", "MMMCCXLV", "MMMCCXLVI", "MMMCCXLVII", "MMMCCXLVIII", "MMMCCXLIX", "MMMCCL", "MMMCCLI", "MMMCCLII", "MMMCCLIII", "MMMCCLIV", "MMMCCLV", "MMMCCLVI", "MMMCCLVII", "MMMCCLVIII", "MMMCCLIX", "MMMCCLX", "MMMCCLXI", "MMMCCLXII", "MMMCCLXIII", "MMMCCLXIV", "MMMCCLXV", "MMMCCLXVI", "MMMCCLXVII", "MMMCCLXVIII", "MMMCCLXIX", "MMMCCLXX", "MMMCCLXXI", "MMMCCLXXII", "MMMCCLXXIII", "MMMCCLXXIV", "MMMCCLXXV", "MMMCCLXXVI", "MMMCCLXXVII", "MMMCCLXXVIII", "MMMCCLXXIX", "MMMCCLXXX", "MMMCCLXXXI", "MMMCCLXXXII", "MMMCCLXXXIII", "MMMCCLXXXIV", "MMMCCLXXXV", "MMMCCLXXXVI", "MMMCCLXXXVII", "MMMCCLXXXVIII", "MMMCCLXXXIX", "MMMCCXC", "MMMCCXCI", "MMMCCXCII", "MMMCCXCIII", "MMMCCXCIV", "MMMCCXCV", "MMMCCXCVI", "MMMCCXCVII", "MMMCCXCVIII", "MMMCCXCIX", "MMMCCC",
"MMMCCCI", "MMMCCCII", "MMMCCCIII", "MMMCCCIV", "MMMCCCV", "MMMCCCVI", "MMMCCCVII", "MMMCCCVIII", "MMMCCCIX", "MMMCCCX", "MMMCCCXI", "MMMCCCXII", "MMMCCCXIII", "MMMCCCXIV", "MMMCCCXV", "MMMCCCXVI", "MMMCCCXVII", "MMMCCCXVIII", "MMMCCCXIX", "MMMCCCXX", "MMMCCCXXI", "MMMCCCXXII", "MMMCCCXXIII", "MMMCCCXXIV", "MMMCCCXXV", "MMMCCCXXVI", "MMMCCCXXVII", "MMMCCCXXVIII", "MMMCCCXXIX", "MMMCCCXXX", "MMMCCCXXXI", "MMMCCCXXXII", "MMMCCCXXXIII", "MMMCCCXXXIV", "MMMCCCXXXV", "MMMCCCXXXVI", "MMMCCCXXXVII", "MMMCCCXXXVIII", "MMMCCCXXXIX", "MMMCCCXL", "MMMCCCXLI", "MMMCCCXLII", "MMMCCCXLIII", "MMMCCCXLIV", "MMMCCCXLV", "MMMCCCXLVI", "MMMCCCXLVII", "MMMCCCXLVIII", "MMMCCCXLIX", "MMMCCCL", "MMMCCCLI", "MMMCCCLII", "MMMCCCLIII", "MMMCCCLIV", "MMMCCCLV", "MMMCCCLVI", "MMMCCCLVII", "MMMCCCLVIII", "MMMCCCLIX", "MMMCCCLX", "MMMCCCLXI", "MMMCCCLXII", "MMMCCCLXIII", "MMMCCCLXIV", "MMMCCCLXV", "MMMCCCLXVI", "MMMCCCLXVII", "MMMCCCLXVIII", "MMMCCCLXIX", "MMMCCCLXX", "MMMCCCLXXI", "MMMCCCLXXII", "MMMCCCLXXIII", "MMMCCCLXXIV", "MMMCCCLXXV", "MMMCCCLXXVI", "MMMCCCLXXVII", "MMMCCCLXXVIII", "MMMCCCLXXIX", "MMMCCCLXXX", "MMMCCCLXXXI", "MMMCCCLXXXII", "MMMCCCLXXXIII", "MMMCCCLXXXIV", "MMMCCCLXXXV", "MMMCCCLXXXVI", "MMMCCCLXXXVII", "MMMCCCLXXXVIII", "MMMCCCLXXXIX", "MMMCCCXC", "MMMCCCXCI", "MMMCCCXCII", "MMMCCCXCIII", "MMMCCCXCIV", "MMMCCCXCV", "MMMCCCXCVI", "MMMCCCXCVII", "MMMCCCXCVIII", "MMMCCCXCIX", "MMMCD",
"MMMCDI", "MMMCDII", "MMMCDIII", "MMMCDIV", "MMMCDV", "MMMCDVI", "MMMCDVII", "MMMCDVIII", "MMMCDIX", "MMMCDX", "MMMCDXI", "MMMCDXII", "MMMCDXIII", "MMMCDXIV", "MMMCDXV", "MMMCDXVI", "MMMCDXVII", "MMMCDXVIII", "MMMCDXIX", "MMMCDXX", "MMMCDXXI", "MMMCDXXII", "MMMCDXXIII", "MMMCDXXIV", "MMMCDXXV", "MMMCDXXVI", "MMMCDXXVII", "MMMCDXXVIII", "MMMCDXXIX", "MMMCDXXX", "MMMCDXXXI", "MMMCDXXXII", "MMMCDXXXIII", "MMMCDXXXIV", "MMMCDXXXV", "MMMCDXXXVI", "MMMCDXXXVII", "MMMCDXXXVIII", "MMMCDXXXIX", "MMMCDXL", "MMMCDXLI", "MMMCDXLII", "MMMCDXLIII", "MMMCDXLIV", "MMMCDXLV", "MMMCDXLVI", "MMMCDXLVII", "MMMCDXLVIII", "MMMCDXLIX", "MMMCDL", "MMMCDLI", "MMMCDLII", "MMMCDLIII", "MMMCDLIV", "MMMCDLV", "MMMCDLVI", "MMMCDLVII", "MMMCDLVIII", "MMMCDLIX", "MMMCDLX", "MMMCDLXI", "MMMCDLXII", "MMMCDLXIII", "MMMCDLXIV", "MMMCDLXV", "MMMCDLXVI", "MMMCDLXVII", "MMMCDLXVIII", "MMMCDLXIX", "MMMCDLXX", "MMMCDLXXI", "MMMCDLXXII", "MMMCDLXXIII", "MMMCDLXXIV", "MMMCDLXXV", "MMMCDLXXVI", "MMMCDLXXVII", "MMMCDLXXVIII", "MMMCDLXXIX", "MMMCDLXXX", "MMMCDLXXXI", "MMMCDLXXXII", "MMMCDLXXXIII", "MMMCDLXXXIV", "MMMCDLXXXV", "MMMCDLXXXVI", "MMMCDLXXXVII", "MMMCDLXXXVIII", "MMMCDLXXXIX", "MMMCDXC", "MMMCDXCI", "MMMCDXCII", "MMMCDXCIII", "MMMCDXCIV", "MMMCDXCV", "MMMCDXCVI", "MMMCDXCVII", "MMMCDXCVIII", "MMMCDXCIX", "MMMD",
"MMMDI", "MMMDII", "MMMDIII", "MMMDIV", "MMMDV", "MMMDVI", "MMMDVII", "MMMDVIII", "MMMDIX", "MMMDX", "MMMDXI", "MMMDXII", "MMMDXIII", "MMMDXIV", "MMMDXV", "MMMDXVI", "MMMDXVII", "MMMDXVIII", "MMMDXIX", "MMMDXX", "MMMDXXI", "MMMDXXII", "MMMDXXIII", "MMMDXXIV", "MMMDXXV", "MMMDXXVI", "MMMDXXVII", "MMMDXXVIII", "MMMDXXIX", "MMMDXXX", "MMMDXXXI", "MMMDXXXII", "MMMDXXXIII", "MMMDXXXIV", "MMMDXXXV", "MMMDXXXVI", "MMMDXXXVII", "MMMDXXXVIII", "MMMDXXXIX", "MMMDXL", "MMMDXLI", "MMMDXLII", "MMMDXLIII", "MMMDXLIV", "MMMDXLV", "MMMDXLVI", "MMMDXLVII", "MMMDXLVIII", "MMMDXLIX", "MMMDL", "MMMDLI", "MMMDLII", "MMMDLIII", "MMMDLIV", "MMMDLV", "MMMDLVI", "MMMDLVII", "MMMDLVIII", "MMMDLIX", "MMMDLX", "MMMDLXI", "MMMDLXII", "MMMDLXIII", "MMMDLXIV", "MMMDLXV", "MMMDLXVI", "MMMDLXVII", "MMMDLXVIII", "MMMDLXIX", "MMMDLXX", "MMMDLXXI", "MMMDLXXII", "MMMDLXXIII", "MMMDLXXIV", "MMMDLXXV", "MMMDLXXVI", "MMMDLXXVII", "MMMDLXXVIII", "MMMDLXXIX", "MMMDLXXX", "MMMDLXXXI", "MMMDLXXXII", "MMMDLXXXIII", "MMMDLXXXIV", "MMMDLXXXV", "MMMDLXXXVI", "MMMDLXXXVII", "MMMDLXXXVIII", "MMMDLXXXIX", "MMMDXC", "MMMDXCI", "MMMDXCII", "MMMDXCIII", "MMMDXCIV", "MMMDXCV", "MMMDXCVI", "MMMDXCVII", "MMMDXCVIII", "MMMDXCIX", "MMMDC",
"MMMDCI", "MMMDCII", "MMMDCIII", "MMMDCIV", "MMMDCV", "MMMDCVI", "MMMDCVII", "MMMDCVIII", "MMMDCIX", "MMMDCX", "MMMDCXI", "MMMDCXII", "MMMDCXIII", "MMMDCXIV", "MMMDCXV", "MMMDCXVI", "MMMDCXVII", "MMMDCXVIII", "MMMDCXIX", "MMMDCXX", "MMMDCXXI", "MMMDCXXII", "MMMDCXXIII", "MMMDCXXIV", "MMMDCXXV", "MMMDCXXVI", "MMMDCXXVII", "MMMDCXXVIII", "MMMDCXXIX", "MMMDCXXX", "MMMDCXXXI", "MMMDCXXXII", "MMMDCXXXIII", "MMMDCXXXIV", "MMMDCXXXV", "MMMDCXXXVI", "MMMDCXXXVII", "MMMDCXXXVIII", "MMMDCXXXIX", "MMMDCXL", "MMMDCXLI", "MMMDCXLII", "MMMDCXLIII", "MMMDCXLIV", "MMMDCXLV", "MMMDCXLVI", "MMMDCXLVII", "MMMDCXLVIII", "MMMDCXLIX", "MMMDCL", "MMMDCLI", "MMMDCLII", "MMMDCLIII", "MMMDCLIV", "MMMDCLV", "MMMDCLVI", "MMMDCLVII", "MMMDCLVIII", "MMMDCLIX", "MMMDCLX", "MMMDCLXI", "MMMDCLXII", "MMMDCLXIII", "MMMDCLXIV", "MMMDCLXV", "MMMDCLXVI", "MMMDCLXVII", "MMMDCLXVIII", "MMMDCLXIX", "MMMDCLXX", "MMMDCLXXI", "MMMDCLXXII", "MMMDCLXXIII", "MMMDCLXXIV", "MMMDCLXXV", "MMMDCLXXVI", "MMMDCLXXVII", "MMMDCLXXVIII", "MMMDCLXXIX", "MMMDCLXXX", "MMMDCLXXXI", "MMMDCLXXXII", "MMMDCLXXXIII", "MMMDCLXXXIV", "MMMDCLXXXV", "MMMDCLXXXVI", "MMMDCLXXXVII", "MMMDCLXXXVIII", "MMMDCLXXXIX", "MMMDCXC", "MMMDCXCI", "MMMDCXCII", "MMMDCXCIII", "MMMDCXCIV", "MMMDCXCV", "MMMDCXCVI", "MMMDCXCVII", "MMMDCXCVIII", "MMMDCXCIX", "MMMDCC",
"MMMDCCI", "MMMDCCII", "MMMDCCIII", "MMMDCCIV", "MMMDCCV", "MMMDCCVI", "MMMDCCVII", "MMMDCCVIII", "MMMDCCIX", "MMMDCCX", "MMMDCCXI", "MMMDCCXII", "MMMDCCXIII", "MMMDCCXIV", "MMMDCCXV", "MMMDCCXVI", "MMMDCCXVII", "MMMDCCXVIII", "MMMDCCXIX", "MMMDCCXX", "MMMDCCXXI", "MMMDCCXXII", "MMMDCCXXIII", "MMMDCCXXIV", "MMMDCCXXV", "MMMDCCXXVI", "MMMDCCXXVII", "MMMDCCXXVIII", "MMMDCCXXIX", "MMMDCCXXX", "MMMDCCXXXI", "MMMDCCXXXII", "MMMDCCXXXIII", "MMMDCCXXXIV", "MMMDCCXXXV", "MMMDCCXXXVI", "MMMDCCXXXVII", "MMMDCCXXXVIII", "MMMDCCXXXIX", "MMMDCCXL", "MMMDCCXLI", "MMMDCCXLII", "MMMDCCXLIII", "MMMDCCXLIV", "MMMDCCXLV", "MMMDCCXLVI", "MMMDCCXLVII", "MMMDCCXLVIII", "MMMDCCXLIX", "MMMDCCL", "MMMDCCLI", "MMMDCCLII", "MMMDCCLIII", "MMMDCCLIV", "MMMDCCLV", "MMMDCCLVI", "MMMDCCLVII", "MMMDCCLVIII", "MMMDCCLIX", "MMMDCCLX", "MMMDCCLXI", "MMMDCCLXII", "MMMDCCLXIII", "MMMDCCLXIV", "MMMDCCLXV", "MMMDCCLXVI", "MMMDCCLXVII", "MMMDCCLXVIII", "MMMDCCLXIX", "MMMDCCLXX", "MMMDCCLXXI", "MMMDCCLXXII", "MMMDCCLXXIII", "MMMDCCLXXIV", "MMMDCCLXXV", "MMMDCCLXXVI", "MMMDCCLXXVII", "MMMDCCLXXVIII", "MMMDCCLXXIX", "MMMDCCLXXX", "MMMDCCLXXXI", "MMMDCCLXXXII", "MMMDCCLXXXIII", "MMMDCCLXXXIV", "MMMDCCLXXXV", "MMMDCCLXXXVI", "MMMDCCLXXXVII", "MMMDCCLXXXVIII", "MMMDCCLXXXIX", "MMMDCCXC", "MMMDCCXCI", "MMMDCCXCII", "MMMDCCXCIII", "MMMDCCXCIV", "MMMDCCXCV", "MMMDCCXCVI", "MMMDCCXCVII", "MMMDCCXCVIII", "MMMDCCXCIX", "MMMDCCC",
"MMMDCCCI", "MMMDCCCII", "MMMDCCCIII", "MMMDCCCIV", "MMMDCCCV", "MMMDCCCVI", "MMMDCCCVII", "MMMDCCCVIII", "MMMDCCCIX", "MMMDCCCX", "MMMDCCCXI", "MMMDCCCXII", "MMMDCCCXIII", "MMMDCCCXIV", "MMMDCCCXV", "MMMDCCCXVI", "MMMDCCCXVII", "MMMDCCCXVIII", "MMMDCCCXIX", "MMMDCCCXX", "MMMDCCCXXI", "MMMDCCCXXII", "MMMDCCCXXIII", "MMMDCCCXXIV", "MMMDCCCXXV", "MMMDCCCXXVI", "MMMDCCCXXVII", "MMMDCCCXXVIII", "MMMDCCCXXIX", "MMMDCCCXXX", "MMMDCCCXXXI", "MMMDCCCXXXII", "MMMDCCCXXXIII", "MMMDCCCXXXIV", "MMMDCCCXXXV", "MMMDCCCXXXVI", "MMMDCCCXXXVII", "MMMDCCCXXXVIII", "MMMDCCCXXXIX", "MMMDCCCXL", "MMMDCCCXLI", "MMMDCCCXLII", "MMMDCCCXLIII", "MMMDCCCXLIV", "MMMDCCCXLV", "MMMDCCCXLVI", "MMMDCCCXLVII", "MMMDCCCXLVIII", "MMMDCCCXLIX", "MMMDCCCL", "MMMDCCCLI", "MMMDCCCLII", "MMMDCCCLIII", "MMMDCCCLIV", "MMMDCCCLV", "MMMDCCCLVI", "MMMDCCCLVII", "MMMDCCCLVIII", "MMMDCCCLIX", "MMMDCCCLX", "MMMDCCCLXI", "MMMDCCCLXII", "MMMDCCCLXIII", "MMMDCCCLXIV", "MMMDCCCLXV", "MMMDCCCLXVI", "MMMDCCCLXVII", "MMMDCCCLXVIII", "MMMDCCCLXIX", "MMMDCCCLXX", "MMMDCCCLXXI", "MMMDCCCLXXII", "MMMDCCCLXXIII", "MMMDCCCLXXIV", "MMMDCCCLXXV", "MMMDCCCLXXVI", "MMMDCCCLXXVII", "MMMDCCCLXXVIII", "MMMDCCCLXXIX", "MMMDCCCLXXX", "MMMDCCCLXXXI", "MMMDCCCLXXXII", "MMMDCCCLXXXIII", "MMMDCCCLXXXIV", "MMMDCCCLXXXV", "MMMDCCCLXXXVI", "MMMDCCCLXXXVII", "MMMDCCCLXXXVIII", "MMMDCCCLXXXIX", "MMMDCCCXC", "MMMDCCCXCI", "MMMDCCCXCII", "MMMDCCCXCIII", "MMMDCCCXCIV", "MMMDCCCXCV", "MMMDCCCXCVI", "MMMDCCCXCVII", "MMMDCCCXCVIII", "MMMDCCCXCIX", "MMMCM",
"MMMCMI", "MMMCMII", "MMMCMIII", "MMMCMIV", "MMMCMV", "MMMCMVI", "MMMCMVII", "MMMCMVIII", "MMMCMIX", "MMMCMX", "MMMCMXI", "MMMCMXII", "MMMCMXIII", "MMMCMXIV", "MMMCMXV", "MMMCMXVI", "MMMCMXVII", "MMMCMXVIII", "MMMCMXIX", "MMMCMXX", "MMMCMXXI", "MMMCMXXII", "MMMCMXXIII", "MMMCMXXIV", "MMMCMXXV", "MMMCMXXVI", "MMMCMXXVII", "MMMCMXXVIII", "MMMCMXXIX", "MMMCMXXX", "MMMCMXXXI", "MMMCMXXXII", "MMMCMXXXIII", "MMMCMXXXIV", "MMMCMXXXV", "MMMCMXXXVI", "MMMCMXXXVII", "MMMCMXXXVIII", "MMMCMXXXIX", "MMMCMXL", "MMMCMXLI", "MMMCMXLII", "MMMCMXLIII", "MMMCMXLIV", "MMMCMXLV", "MMMCMXLVI", "MMMCMXLVII", "MMMCMXLVIII", "MMMCMXLIX", "MMMCML", "MMMCMLI", "MMMCMLII", "MMMCMLIII", "MMMCMLIV", "MMMCMLV", "MMMCMLVI", "MMMCMLVII", "MMMCMLVIII", "MMMCMLIX", "MMMCMLX", "MMMCMLXI", "MMMCMLXII", "MMMCMLXIII", "MMMCMLXIV", "MMMCMLXV", "MMMCMLXVI", "MMMCMLXVII", "MMMCMLXVIII", "MMMCMLXIX", "MMMCMLXX", "MMMCMLXXI", "MMMCMLXXII", "MMMCMLXXIII", "MMMCMLXXIV", "MMMCMLXXV", "MMMCMLXXVI", "MMMCMLXXVII", "MMMCMLXXVIII", "MMMCMLXXIX", "MMMCMLXXX", "MMMCMLXXXI", "MMMCMLXXXII", "MMMCMLXXXIII", "MMMCMLXXXIV", "MMMCMLXXXV", "MMMCMLXXXVI", "MMMCMLXXXVII", "MMMCMLXXXVIII", "MMMCMLXXXIX", "MMMCMXC", "MMMCMXCI", "MMMCMXCII", "MMMCMXCIII", "MMMCMXCIV", "MMMCMXCV", "MMMCMXCVI", "MMMCMXCVII", "MMMCMXCVIII", "MMMCMXCIX" };
const std::array<string, 4000> cheat_arr{ "","I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII", "XIII", "XIV", "XV", "XVI", "XVII", "XVIII", "XIX", "XX", "XXI", "XXII", "XXIII", "XXIV", "XXV", "XXVI", "XXVII", "XXVIII", "XXIX", "XXX", "XXXI", "XXXII", "XXXIII", "XXXIV", "XXXV", "XXXVI", "XXXVII", "XXXVIII", "XXXIX", "XL", "XLI", "XLII", "XLIII", "XLIV", "XLV", "XLVI", "XLVII", "XLVIII", "XLIX", "L", "LI", "LII", "LIII", "LIV", "LV", "LVI", "LVII", "LVIII", "LIX", "LX", "LXI", "LXII", "LXIII", "LXIV", "LXV", "LXVI", "LXVII", "LXVIII", "LXIX", "LXX", "LXXI", "LXXII", "LXXIII", "LXXIV", "LXXV", "LXXVI", "LXXVII", "LXXVIII", "LXXIX", "LXXX", "LXXXI", "LXXXII", "LXXXIII", "LXXXIV", "LXXXV", "LXXXVI", "LXXXVII", "LXXXVIII", "LXXXIX", "XC", "XCI", "XCII", "XCIII", "XCIV", "XCV", "XCVI", "XCVII", "XCVIII", "XCIX", "C",
"CI", "CII", "CIII", "CIV", "CV", "CVI", "CVII", "CVIII", "CIX", "CX", "CXI", "CXII", "CXIII", "CXIV", "CXV", "CXVI", "CXVII", "CXVIII", "CXIX", "CXX", "CXXI", "CXXII", "CXXIII", "CXXIV", "CXXV", "CXXVI", "CXXVII", "CXXVIII", "CXXIX", "CXXX", "CXXXI", "CXXXII", "CXXXIII", "CXXXIV", "CXXXV", "CXXXVI", "CXXXVII", "CXXXVIII", "CXXXIX", "CXL", "CXLI", "CXLII", "CXLIII", "CXLIV", "CXLV", "CXLVI", "CXLVII", "CXLVIII", "CXLIX", "CL", "CLI", "CLII", "CLIII", "CLIV", "CLV", "CLVI", "CLVII", "CLVIII", "CLIX", "CLX", "CLXI", "CLXII", "CLXIII", "CLXIV", "CLXV", "CLXVI", "CLXVII", "CLXVIII", "CLXIX", "CLXX", "CLXXI", "CLXXII", "CLXXIII", "CLXXIV", "CLXXV", "CLXXVI", "CLXXVII", "CLXXVIII", "CLXXIX", "CLXXX", "CLXXXI", "CLXXXII", "CLXXXIII", "CLXXXIV", "CLXXXV", "CLXXXVI", "CLXXXVII", "CLXXXVIII", "CLXXXIX", "CXC", "CXCI", "CXCII", "CXCIII", "CXCIV", "CXCV", "CXCVI", "CXCVII", "CXCVIII", "CXCIX", "CC",
"CCI", "CCII", "CCIII", "CCIV", "CCV", "CCVI", "CCVII", "CCVIII", "CCIX", "CCX", "CCXI", "CCXII", "CCXIII", "CCXIV", "CCXV", "CCXVI", "CCXVII", "CCXVIII", "CCXIX", "CCXX", "CCXXI", "CCXXII", "CCXXIII", "CCXXIV", "CCXXV", "CCXXVI", "CCXXVII", "CCXXVIII", "CCXXIX", "CCXXX", "CCXXXI", "CCXXXII", "CCXXXIII", "CCXXXIV", "CCXXXV", "CCXXXVI", "CCXXXVII", "CCXXXVIII", "CCXXXIX", "CCXL", "CCXLI", "CCXLII", "CCXLIII", "CCXLIV", "CCXLV", "CCXLVI", "CCXLVII", "CCXLVIII", "CCXLIX", "CCL", "CCLI", "CCLII", "CCLIII", "CCLIV", "CCLV", "CCLVI", "CCLVII", "CCLVIII", "CCLIX", "CCLX", "CCLXI", "CCLXII", "CCLXIII", "CCLXIV", "CCLXV", "CCLXVI", "CCLXVII", "CCLXVIII", "CCLXIX", "CCLXX", "CCLXXI", "CCLXXII", "CCLXXIII", "CCLXXIV", "CCLXXV", "CCLXXVI", "CCLXXVII", "CCLXXVIII", "CCLXXIX", "CCLXXX", "CCLXXXI", "CCLXXXII", "CCLXXXIII", "CCLXXXIV", "CCLXXXV", "CCLXXXVI", "CCLXXXVII", "CCLXXXVIII", "CCLXXXIX", "CCXC", "CCXCI", "CCXCII", "CCXCIII", "CCXCIV", "CCXCV", "CCXCVI", "CCXCVII", "CCXCVIII", "CCXCIX", "CCC",
"CCCI", "CCCII", "CCCIII", "CCCIV", "CCCV", "CCCVI", "CCCVII", "CCCVIII", "CCCIX", "CCCX", "CCCXI", "CCCXII", "CCCXIII", "CCCXIV", "CCCXV", "CCCXVI", "CCCXVII", "CCCXVIII", "CCCXIX", "CCCXX", "CCCXXI", "CCCXXII", "CCCXXIII", "CCCXXIV", "CCCXXV", "CCCXXVI", "CCCXXVII", "CCCXXVIII", "CCCXXIX", "CCCXXX", "CCCXXXI", "CCCXXXII", "CCCXXXIII", "CCCXXXIV", "CCCXXXV", "CCCXXXVI", "CCCXXXVII", "CCCXXXVIII", "CCCXXXIX", "CCCXL", "CCCXLI", "CCCXLII", "CCCXLIII", "CCCXLIV", "CCCXLV", "CCCXLVI", "CCCXLVII", "CCCXLVIII", "CCCXLIX", "CCCL", "CCCLI", "CCCLII", "CCCLIII", "CCCLIV", "CCCLV", "CCCLVI", "CCCLVII", "CCCLVIII", "CCCLIX", "CCCLX", "CCCLXI", "CCCLXII", "CCCLXIII", "CCCLXIV", "CCCLXV", "CCCLXVI", "CCCLXVII", "CCCLXVIII", "CCCLXIX", "CCCLXX", "CCCLXXI", "CCCLXXII", "CCCLXXIII", "CCCLXXIV", "CCCLXXV", "CCCLXXVI", "CCCLXXVII", "CCCLXXVIII", "CCCLXXIX", "CCCLXXX", "CCCLXXXI", "CCCLXXXII", "CCCLXXXIII", "CCCLXXXIV", "CCCLXXXV", "CCCLXXXVI", "CCCLXXXVII", "CCCLXXXVIII", "CCCLXXXIX", "CCCXC", "CCCXCI", "CCCXCII", "CCCXCIII", "CCCXCIV", "CCCXCV", "CCCXCVI", "CCCXCVII", "CCCXCVIII", "CCCXCIX", "CD",
"CDI", "CDII", "CDIII", "CDIV", "CDV", "CDVI", "CDVII", "CDVIII", "CDIX", "CDX", "CDXI", "CDXII", "CDXIII", "CDXIV", "CDXV", "CDXVI", "CDXVII", "CDXVIII", "CDXIX", "CDXX", "CDXXI", "CDXXII", "CDXXIII", "CDXXIV", "CDXXV", "CDXXVI", "CDXXVII", "CDXXVIII", "CDXXIX", "CDXXX", "CDXXXI", "CDXXXII", "CDXXXIII", "CDXXXIV", "CDXXXV", "CDXXXVI", "CDXXXVII", "CDXXXVIII", "CDXXXIX", "CDXL", "CDXLI", "CDXLII", "CDXLIII", "CDXLIV", "CDXLV", "CDXLVI", "CDXLVII", "CDXLVIII", "CDXLIX", "CDL", "CDLI", "CDLII", "CDLIII", "CDLIV", "CDLV", "CDLVI", "CDLVII", "CDLVIII", "CDLIX", "CDLX", "CDLXI", "CDLXII", "CDLXIII", "CDLXIV", "CDLXV", "CDLXVI", "CDLXVII", "CDLXVIII", "CDLXIX", "CDLXX", "CDLXXI", "CDLXXII", "CDLXXIII", "CDLXXIV", "CDLXXV", "CDLXXVI", "CDLXXVII", "CDLXXVIII", "CDLXXIX", "CDLXXX", "CDLXXXI", "CDLXXXII", "CDLXXXIII", "CDLXXXIV", "CDLXXXV", "CDLXXXVI", "CDLXXXVII", "CDLXXXVIII", "CDLXXXIX", "CDXC", "CDXCI", "CDXCII", "CDXCIII", "CDXCIV", "CDXCV", "CDXCVI", "CDXCVII", "CDXCVIII", "CDXCIX", "D",
"DI", "DII", "DIII", "DIV", "DV", "DVI", "DVII", "DVIII", "DIX", "DX", "DXI", "DXII", "DXIII", "DXIV", "DXV", "DXVI", "DXVII", "DXVIII", "DXIX", "DXX", "DXXI", "DXXII", "DXXIII", "DXXIV", "DXXV", "DXXVI", "DXXVII", "DXXVIII", "DXXIX", "DXXX", "DXXXI", "DXXXII", "DXXXIII", "DXXXIV", "DXXXV", "DXXXVI", "DXXXVII", "DXXXVIII", "DXXXIX", "DXL", "DXLI", "DXLII", "DXLIII", "DXLIV", "DXLV", "DXLVI", "DXLVII", "DXLVIII", "DXLIX", "DL", "DLI", "DLII", "DLIII", "DLIV", "DLV", "DLVI", "DLVII", "DLVIII", "DLIX", "DLX", "DLXI", "DLXII", "DLXIII", "DLXIV", "DLXV", "DLXVI", "DLXVII", "DLXVIII", "DLXIX", "DLXX", "DLXXI", "DLXXII", "DLXXIII", "DLXXIV", "DLXXV", "DLXXVI", "DLXXVII", "DLXXVIII", "DLXXIX", "DLXXX", "DLXXXI", "DLXXXII", "DLXXXIII", "DLXXXIV", "DLXXXV", "DLXXXVI", "DLXXXVII", "DLXXXVIII", "DLXXXIX", "DXC", "DXCI", "DXCII", "DXCIII", "DXCIV", "DXCV", "DXCVI", "DXCVII", "DXCVIII", "DXCIX", "DC",
"DCI", "DCII", "DCIII", "DCIV", "DCV", "DCVI", "DCVII", "DCVIII", "DCIX", "DCX", "DCXI", "DCXII", "DCXIII", "DCXIV", "DCXV", "DCXVI", "DCXVII", "DCXVIII", "DCXIX", "DCXX", "DCXXI", "DCXXII", "DCXXIII", "DCXXIV", "DCXXV", "DCXXVI", "DCXXVII", "DCXXVIII", "DCXXIX", "DCXXX", "DCXXXI", "DCXXXII", "DCXXXIII", "DCXXXIV", "DCXXXV", "DCXXXVI", "DCXXXVII", "DCXXXVIII", "DCXXXIX", "DCXL", "DCXLI", "DCXLII", "DCXLIII", "DCXLIV", "DCXLV", "DCXLVI", "DCXLVII", "DCXLVIII", "DCXLIX", "DCL", "DCLI", "DCLII", "DCLIII", "DCLIV", "DCLV", "DCLVI", "DCLVII", "DCLVIII", "DCLIX", "DCLX", "DCLXI", "DCLXII", "DCLXIII", "DCLXIV", "DCLXV", "DCLXVI", "DCLXVII", "DCLXVIII", "DCLXIX", "DCLXX", "DCLXXI", "DCLXXII", "DCLXXIII", "DCLXXIV", "DCLXXV", "DCLXXVI", "DCLXXVII", "DCLXXVIII", "DCLXXIX", "DCLXXX", "DCLXXXI", "DCLXXXII", "DCLXXXIII", "DCLXXXIV", "DCLXXXV", "DCLXXXVI", "DCLXXXVII", "DCLXXXVIII", "DCLXXXIX", "DCXC", "DCXCI", "DCXCII", "DCXCIII", "DCXCIV", "DCXCV", "DCXCVI", "DCXCVII", "DCXCVIII", "DCXCIX", "DCC",
"DCCI", "DCCII", "DCCIII", "DCCIV", "DCCV", "DCCVI", "DCCVII", "DCCVIII", "DCCIX", "DCCX", "DCCXI", "DCCXII", "DCCXIII", "DCCXIV", "DCCXV", "DCCXVI", "DCCXVII", "DCCXVIII", "DCCXIX", "DCCXX", "DCCXXI", "DCCXXII", "DCCXXIII", "DCCXXIV", "DCCXXV", "DCCXXVI", "DCCXXVII", "DCCXXVIII", "DCCXXIX", "DCCXXX", "DCCXXXI", "DCCXXXII", "DCCXXXIII", "DCCXXXIV", "DCCXXXV", "DCCXXXVI", "DCCXXXVII", "DCCXXXVIII", "DCCXXXIX", "DCCXL", "DCCXLI", "DCCXLII", "DCCXLIII", "DCCXLIV", "DCCXLV", "DCCXLVI", "DCCXLVII", "DCCXLVIII", "DCCXLIX", "DCCL", "DCCLI", "DCCLII", "DCCLIII", "DCCLIV", "DCCLV", "DCCLVI", "DCCLVII", "DCCLVIII", "DCCLIX", "DCCLX", "DCCLXI", "DCCLXII", "DCCLXIII", "DCCLXIV", "DCCLXV", "DCCLXVI", "DCCLXVII", "DCCLXVIII", "DCCLXIX", "DCCLXX", "DCCLXXI", "DCCLXXII", "DCCLXXIII", "DCCLXXIV", "DCCLXXV", "DCCLXXVI", "DCCLXXVII", "DCCLXXVIII", "DCCLXXIX", "DCCLXXX", "DCCLXXXI", "DCCLXXXII", "DCCLXXXIII", "DCCLXXXIV", "DCCLXXXV", "DCCLXXXVI", "DCCLXXXVII", "DCCLXXXVIII", "DCCLXXXIX", "DCCXC", "DCCXCI", "DCCXCII", "DCCXCIII", "DCCXCIV", "DCCXCV", "DCCXCVI", "DCCXCVII", "DCCXCVIII", "DCCXCIX", "DCCC",
"DCCCI", "DCCCII", "DCCCIII", "DCCCIV", "DCCCV", "DCCCVI", "DCCCVII", "DCCCVIII", "DCCCIX", "DCCCX", "DCCCXI", "DCCCXII", "DCCCXIII", "DCCCXIV", "DCCCXV", "DCCCXVI", "DCCCXVII", "DCCCXVIII", "DCCCXIX", "DCCCXX", "DCCCXXI", "DCCCXXII", "DCCCXXIII", "DCCCXXIV", "DCCCXXV", "DCCCXXVI", "DCCCXXVII", "DCCCXXVIII", "DCCCXXIX", "DCCCXXX", "DCCCXXXI", "DCCCXXXII", "DCCCXXXIII", "DCCCXXXIV", "DCCCXXXV", "DCCCXXXVI", "DCCCXXXVII", "DCCCXXXVIII", "DCCCXXXIX", "DCCCXL", "DCCCXLI", "DCCCXLII", "DCCCXLIII", "DCCCXLIV", "DCCCXLV", "DCCCXLVI", "DCCCXLVII", "DCCCXLVIII", "DCCCXLIX", "DCCCL", "DCCCLI", "DCCCLII", "DCCCLIII", "DCCCLIV", "DCCCLV", "DCCCLVI", "DCCCLVII", "DCCCLVIII", "DCCCLIX", "DCCCLX", "DCCCLXI", "DCCCLXII", "DCCCLXIII", "DCCCLXIV", "DCCCLXV", "DCCCLXVI", "DCCCLXVII", "DCCCLXVIII", "DCCCLXIX", "DCCCLXX", "DCCCLXXI", "DCCCLXXII", "DCCCLXXIII", "DCCCLXXIV", "DCCCLXXV", "DCCCLXXVI", "DCCCLXXVII", "DCCCLXXVIII", "DCCCLXXIX", "DCCCLXXX", "DCCCLXXXI", "DCCCLXXXII", "DCCCLXXXIII", "DCCCLXXXIV", "DCCCLXXXV", "DCCCLXXXVI", "DCCCLXXXVII", "DCCCLXXXVIII", "DCCCLXXXIX", "DCCCXC", "DCCCXCI", "DCCCXCII", "DCCCXCIII", "DCCCXCIV", "DCCCXCV", "DCCCXCVI", "DCCCXCVII", "DCCCXCVIII", "DCCCXCIX", "CM",
"CMI", "CMII", "CMIII", "CMIV", "CMV", "CMVI", "CMVII", "CMVIII", "CMIX", "CMX", "CMXI", "CMXII", "CMXIII", "CMXIV", "CMXV", "CMXVI", "CMXVII", "CMXVIII", "CMXIX", "CMXX", "CMXXI", "CMXXII", "CMXXIII", "CMXXIV", "CMXXV", "CMXXVI", "CMXXVII", "CMXXVIII", "CMXXIX", "CMXXX", "CMXXXI", "CMXXXII", "CMXXXIII", "CMXXXIV", "CMXXXV", "CMXXXVI", "CMXXXVII", "CMXXXVIII", "CMXXXIX", "CMXL", "CMXLI", "CMXLII", "CMXLIII", "CMXLIV", "CMXLV", "CMXLVI", "CMXLVII", "CMXLVIII", "CMXLIX", "CML", "CMLI", "CMLII", "CMLIII", "CMLIV", "CMLV", "CMLVI", "CMLVII", "CMLVIII", "CMLIX", "CMLX", "CMLXI", "CMLXII", "CMLXIII", "CMLXIV", "CMLXV", "CMLXVI", "CMLXVII", "CMLXVIII", "CMLXIX", "CMLXX", "CMLXXI", "CMLXXII", "CMLXXIII", "CMLXXIV", "CMLXXV", "CMLXXVI", "CMLXXVII", "CMLXXVIII", "CMLXXIX", "CMLXXX", "CMLXXXI", "CMLXXXII", "CMLXXXIII", "CMLXXXIV", "CMLXXXV", "CMLXXXVI", "CMLXXXVII", "CMLXXXVIII", "CMLXXXIX", "CMXC", "CMXCI", "CMXCII", "CMXCIII", "CMXCIV", "CMXCV", "CMXCVI", "CMXCVII", "CMXCVIII", "CMXCIX", "M",
"MI", "MII", "MIII", "MIV", "MV", "MVI", "MVII", "MVIII", "MIX", "MX", "MXI", "MXII", "MXIII", "MXIV", "MXV", "MXVI", "MXVII", "MXVIII", "MXIX", "MXX", "MXXI", "MXXII", "MXXIII", "MXXIV", "MXXV", "MXXVI", "MXXVII", "MXXVIII", "MXXIX", "MXXX", "MXXXI", "MXXXII", "MXXXIII", "MXXXIV", "MXXXV", "MXXXVI", "MXXXVII", "MXXXVIII", "MXXXIX", "MXL", "MXLI", "MXLII", "MXLIII", "MXLIV", "MXLV", "MXLVI", "MXLVII", "MXLVIII", "MXLIX", "ML", "MLI", "MLII", "MLIII", "MLIV", "MLV", "MLVI", "MLVII", "MLVIII", "MLIX", "MLX", "MLXI", "MLXII", "MLXIII", "MLXIV", "MLXV", "MLXVI", "MLXVII", "MLXVIII", "MLXIX", "MLXX", "MLXXI", "MLXXII", "MLXXIII", "MLXXIV", "MLXXV", "MLXXVI", "MLXXVII", "MLXXVIII", "MLXXIX", "MLXXX", "MLXXXI", "MLXXXII", "MLXXXIII", "MLXXXIV", "MLXXXV", "MLXXXVI", "MLXXXVII", "MLXXXVIII", "MLXXXIX", "MXC", "MXCI", "MXCII", "MXCIII", "MXCIV", "MXCV", "MXCVI", "MXCVII", "MXCVIII", "MXCIX", "MC",
"MCI", "MCII", "MCIII", "MCIV", "MCV", "MCVI", "MCVII", "MCVIII", "MCIX", "MCX", "MCXI", "MCXII", "MCXIII", "MCXIV", "MCXV", "MCXVI", "MCXVII", "MCXVIII", "MCXIX", "MCXX", "MCXXI", "MCXXII", "MCXXIII", "MCXXIV", "MCXXV", "MCXXVI", "MCXXVII", "MCXXVIII", "MCXXIX", "MCXXX", "MCXXXI", "MCXXXII", "MCXXXIII", "MCXXXIV", "MCXXXV", "MCXXXVI", "MCXXXVII", "MCXXXVIII", "MCXXXIX", "MCXL", "MCXLI", "MCXLII", "MCXLIII", "MCXLIV", "MCXLV", "MCXLVI", "MCXLVII", "MCXLVIII", "MCXLIX", "MCL", "MCLI", "MCLII", "MCLIII", "MCLIV", "MCLV", "MCLVI", "MCLVII", "MCLVIII", "MCLIX", "MCLX", "MCLXI", "MCLXII", "MCLXIII", "MCLXIV", "MCLXV", "MCLXVI", "MCLXVII", "MCLXVIII", "MCLXIX", "MCLXX", "MCLXXI", "MCLXXII", "MCLXXIII", "MCLXXIV", "MCLXXV", "MCLXXVI", "MCLXXVII", "MCLXXVIII", "MCLXXIX", "MCLXXX", "MCLXXXI", "MCLXXXII", "MCLXXXIII", "MCLXXXIV", "MCLXXXV", "MCLXXXVI", "MCLXXXVII", "MCLXXXVIII", "MCLXXXIX", "MCXC", "MCXCI", "MCXCII", "MCXCIII", "MCXCIV", "MCXCV", "MCXCVI", "MCXCVII", "MCXCVIII", "MCXCIX", "MCC",
"MCCI", "MCCII", "MCCIII", "MCCIV", "MCCV", "MCCVI", "MCCVII", "MCCVIII", "MCCIX", "MCCX", "MCCXI", "MCCXII", "MCCXIII", "MCCXIV", "MCCXV", "MCCXVI", "MCCXVII", "MCCXVIII", "MCCXIX", "MCCXX", "MCCXXI", "MCCXXII", "MCCXXIII", "MCCXXIV", "MCCXXV", "MCCXXVI", "MCCXXVII", "MCCXXVIII", "MCCXXIX", "MCCXXX", "MCCXXXI", "MCCXXXII", "MCCXXXIII", "MCCXXXIV", "MCCXXXV", "MCCXXXVI", "MCCXXXVII", "MCCXXXVIII", "MCCXXXIX", "MCCXL", "MCCXLI", "MCCXLII", "MCCXLIII", "MCCXLIV", "MCCXLV", "MCCXLVI", "MCCXLVII", "MCCXLVIII", "MCCXLIX", "MCCL", "MCCLI", "MCCLII", "MCCLIII", "MCCLIV", "MCCLV", "MCCLVI", "MCCLVII", "MCCLVIII", "MCCLIX", "MCCLX", "MCCLXI", "MCCLXII", "MCCLXIII", "MCCLXIV", "MCCLXV", "MCCLXVI", "MCCLXVII", "MCCLXVIII", "MCCLXIX", "MCCLXX", "MCCLXXI", "MCCLXXII", "MCCLXXIII", "MCCLXXIV", "MCCLXXV", "MCCLXXVI", "MCCLXXVII", "MCCLXXVIII", "MCCLXXIX", "MCCLXXX", "MCCLXXXI", "MCCLXXXII", "MCCLXXXIII", "MCCLXXXIV", "MCCLXXXV", "MCCLXXXVI", "MCCLXXXVII", "MCCLXXXVIII", "MCCLXXXIX", "MCCXC", "MCCXCI", "MCCXCII", "MCCXCIII", "MCCXCIV", "MCCXCV", "MCCXCVI", "MCCXCVII", "MCCXCVIII", "MCCXCIX", "MCCC",
"MCCCI", "MCCCII", "MCCCIII", "MCCCIV", "MCCCV", "MCCCVI", "MCCCVII", "MCCCVIII", "MCCCIX", "MCCCX", "MCCCXI", "MCCCXII", "MCCCXIII", "MCCCXIV", "MCCCXV", "MCCCXVI", "MCCCXVII", "MCCCXVIII", "MCCCXIX", "MCCCXX", "MCCCXXI", "MCCCXXII", "MCCCXXIII", "MCCCXXIV", "MCCCXXV", "MCCCXXVI", "MCCCXXVII", "MCCCXXVIII", "MCCCXXIX", "MCCCXXX", "MCCCXXXI", "MCCCXXXII", "MCCCXXXIII", "MCCCXXXIV", "MCCCXXXV", "MCCCXXXVI", "MCCCXXXVII", "MCCCXXXVIII", "MCCCXXXIX", "MCCCXL", "MCCCXLI", "MCCCXLII", "MCCCXLIII", "MCCCXLIV", "MCCCXLV", "MCCCXLVI", "MCCCXLVII", "MCCCXLVIII", "MCCCXLIX", "MCCCL", "MCCCLI", "MCCCLII", "MCCCLIII", "MCCCLIV", "MCCCLV", "MCCCLVI", "MCCCLVII", "MCCCLVIII", "MCCCLIX", "MCCCLX", "MCCCLXI", "MCCCLXII", "MCCCLXIII", "MCCCLXIV", "MCCCLXV", "MCCCLXVI", "MCCCLXVII", "MCCCLXVIII", "MCCCLXIX", "MCCCLXX", "MCCCLXXI", "MCCCLXXII", "MCCCLXXIII", "MCCCLXXIV", "MCCCLXXV", "MCCCLXXVI", "MCCCLXXVII", "MCCCLXXVIII", "MCCCLXXIX", "MCCCLXXX", "MCCCLXXXI", "MCCCLXXXII", "MCCCLXXXIII", "MCCCLXXXIV", "MCCCLXXXV", "MCCCLXXXVI", "MCCCLXXXVII", "MCCCLXXXVIII", "MCCCLXXXIX", "MCCCXC", "MCCCXCI", "MCCCXCII", "MCCCXCIII", "MCCCXCIV", "MCCCXCV", "MCCCXCVI", "MCCCXCVII", "MCCCXCVIII", "MCCCXCIX", "MCD",
"MCDI", "MCDII", "MCDIII", "MCDIV", "MCDV", "MCDVI", "MCDVII", "MCDVIII", "MCDIX", "MCDX", "MCDXI", "MCDXII", "MCDXIII", "MCDXIV", "MCDXV", "MCDXVI", "MCDXVII", "MCDXVIII", "MCDXIX", "MCDXX", "MCDXXI", "MCDXXII", "MCDXXIII", "MCDXXIV", "MCDXXV", "MCDXXVI", "MCDXXVII", "MCDXXVIII", "MCDXXIX", "MCDXXX", "MCDXXXI", "MCDXXXII", "MCDXXXIII", "MCDXXXIV", "MCDXXXV", "MCDXXXVI", "MCDXXXVII", "MCDXXXVIII", "MCDXXXIX", "MCDXL", "MCDXLI", "MCDXLII", "MCDXLIII", "MCDXLIV", "MCDXLV", "MCDXLVI", "MCDXLVII", "MCDXLVIII", "MCDXLIX", "MCDL", "MCDLI", "MCDLII", "MCDLIII", "MCDLIV", "MCDLV", "MCDLVI", "MCDLVII", "MCDLVIII", "MCDLIX", "MCDLX", "MCDLXI", "MCDLXII", "MCDLXIII", "MCDLXIV", "MCDLXV", "MCDLXVI", "MCDLXVII", "MCDLXVIII", "MCDLXIX", "MCDLXX", "MCDLXXI", "MCDLXXII", "MCDLXXIII", "MCDLXXIV", "MCDLXXV", "MCDLXXVI", "MCDLXXVII", "MCDLXXVIII", "MCDLXXIX", "MCDLXXX", "MCDLXXXI", "MCDLXXXII", "MCDLXXXIII", "MCDLXXXIV", "MCDLXXXV", "MCDLXXXVI", "MCDLXXXVII", "MCDLXXXVIII", "MCDLXXXIX", "MCDXC", "MCDXCI", "MCDXCII", "MCDXCIII", "MCDXCIV", "MCDXCV", "MCDXCVI", "MCDXCVII", "MCDXCVIII", "MCDXCIX", "MD",
"MDI", "MDII", "MDIII", "MDIV", "MDV", "MDVI", "MDVII", "MDVIII", "MDIX", "MDX", "MDXI", "MDXII", "MDXIII", "MDXIV", "MDXV", "MDXVI", "MDXVII", "MDXVIII", "MDXIX", "MDXX", "MDXXI", "MDXXII", "MDXXIII", "MDXXIV", "MDXXV", "MDXXVI", "MDXXVII", "MDXXVIII", "MDXXIX", "MDXXX", "MDXXXI", "MDXXXII", "MDXXXIII", "MDXXXIV", "MDXXXV", "MDXXXVI", "MDXXXVII", "MDXXXVIII", "MDXXXIX", "MDXL", "MDXLI", "MDXLII", "MDXLIII", "MDXLIV", "MDXLV", "MDXLVI", "MDXLVII", "MDXLVIII", "MDXLIX", "MDL", "MDLI", "MDLII", "MDLIII", "MDLIV", "MDLV", "MDLVI", "MDLVII", "MDLVIII", "MDLIX", "MDLX", "MDLXI", "MDLXII", "MDLXIII", "MDLXIV", "MDLXV", "MDLXVI", "MDLXVII", "MDLXVIII", "MDLXIX", "MDLXX", "MDLXXI", "MDLXXII", "MDLXXIII", "MDLXXIV", "MDLXXV", "MDLXXVI", "MDLXXVII", "MDLXXVIII", "MDLXXIX", "MDLXXX", "MDLXXXI", "MDLXXXII", "MDLXXXIII", "MDLXXXIV", "MDLXXXV", "MDLXXXVI", "MDLXXXVII", "MDLXXXVIII", "MDLXXXIX", "MDXC", "MDXCI", "MDXCII", "MDXCIII", "MDXCIV", "MDXCV", "MDXCVI", "MDXCVII", "MDXCVIII", "MDXCIX", "MDC",
"MDCI", "MDCII", "MDCIII", "MDCIV", "MDCV", "MDCVI", "MDCVII", "MDCVIII", "MDCIX", "MDCX", "MDCXI", "MDCXII", "MDCXIII", "MDCXIV", "MDCXV", "MDCXVI", "MDCXVII", "MDCXVIII", "MDCXIX", "MDCXX", "MDCXXI", "MDCXXII", "MDCXXIII", "MDCXXIV", "MDCXXV", "MDCXXVI", "MDCXXVII", "MDCXXVIII", "MDCXXIX", "MDCXXX", "MDCXXXI", "MDCXXXII", "MDCXXXIII", "MDCXXXIV", "MDCXXXV", "MDCXXXVI", "MDCXXXVII", "MDCXXXVIII", "MDCXXXIX", "MDCXL", "MDCXLI", "MDCXLII", "MDCXLIII", "MDCXLIV", "MDCXLV", "MDCXLVI", "MDCXLVII", "MDCXLVIII", "MDCXLIX", "MDCL", "MDCLI", "MDCLII", "MDCLIII", "MDCLIV", "MDCLV", "MDCLVI", "MDCLVII", "MDCLVIII", "MDCLIX", "MDCLX", "MDCLXI", "MDCLXII", "MDCLXIII", "MDCLXIV", "MDCLXV", "MDCLXVI", "MDCLXVII", "MDCLXVIII", "MDCLXIX", "MDCLXX", "MDCLXXI", "MDCLXXII", "MDCLXXIII", "MDCLXXIV", "MDCLXXV", "MDCLXXVI", "MDCLXXVII", "MDCLXXVIII", "MDCLXXIX", "MDCLXXX", "MDCLXXXI", "MDCLXXXII", "MDCLXXXIII", "MDCLXXXIV", "MDCLXXXV", "MDCLXXXVI", "MDCLXXXVII", "MDCLXXXVIII", "MDCLXXXIX", "MDCXC", "MDCXCI", "MDCXCII", "MDCXCIII", "MDCXCIV", "MDCXCV", "MDCXCVI", "MDCXCVII", "MDCXCVIII", "MDCXCIX", "MDCC",
"MDCCI", "MDCCII", "MDCCIII", "MDCCIV", "MDCCV", "MDCCVI", "MDCCVII", "MDCCVIII", "MDCCIX", "MDCCX", "MDCCXI", "MDCCXII", "MDCCXIII", "MDCCXIV", "MDCCXV", "MDCCXVI", "MDCCXVII", "MDCCXVIII", "MDCCXIX", "MDCCXX", "MDCCXXI", "MDCCXXII", "MDCCXXIII", "MDCCXXIV", "MDCCXXV", "MDCCXXVI", "MDCCXXVII", "MDCCXXVIII", "MDCCXXIX", "MDCCXXX", "MDCCXXXI", "MDCCXXXII", "MDCCXXXIII", "MDCCXXXIV", "MDCCXXXV", "MDCCXXXVI", "MDCCXXXVII", "MDCCXXXVIII", "MDCCXXXIX", "MDCCXL", "MDCCXLI", "MDCCXLII", "MDCCXLIII", "MDCCXLIV", "MDCCXLV", "MDCCXLVI", "MDCCXLVII", "MDCCXLVIII", "MDCCXLIX", "MDCCL", "MDCCLI", "MDCCLII", "MDCCLIII", "MDCCLIV", "MDCCLV", "MDCCLVI", "MDCCLVII", "MDCCLVIII", "MDCCLIX", "MDCCLX", "MDCCLXI", "MDCCLXII", "MDCCLXIII", "MDCCLXIV", "MDCCLXV", "MDCCLXVI", "MDCCLXVII", "MDCCLXVIII", "MDCCLXIX", "MDCCLXX", "MDCCLXXI", "MDCCLXXII", "MDCCLXXIII", "MDCCLXXIV", "MDCCLXXV", "MDCCLXXVI", "MDCCLXXVII", "MDCCLXXVIII", "MDCCLXXIX", "MDCCLXXX", "MDCCLXXXI", "MDCCLXXXII", "MDCCLXXXIII", "MDCCLXXXIV", "MDCCLXXXV", "MDCCLXXXVI", "MDCCLXXXVII", "MDCCLXXXVIII", "MDCCLXXXIX", "MDCCXC", "MDCCXCI", "MDCCXCII", "MDCCXCIII", "MDCCXCIV", "MDCCXCV", "MDCCXCVI", "MDCCXCVII", "MDCCXCVIII", "MDCCXCIX", "MDCCC",
"MDCCCI", "MDCCCII", "MDCCCIII", "MDCCCIV", "MDCCCV", "MDCCCVI", "MDCCCVII", "MDCCCVIII", "MDCCCIX", "MDCCCX", "MDCCCXI", "MDCCCXII", "MDCCCXIII", "MDCCCXIV", "MDCCCXV", "MDCCCXVI", "MDCCCXVII", "MDCCCXVIII", "MDCCCXIX", "MDCCCXX", "MDCCCXXI", "MDCCCXXII", "MDCCCXXIII", "MDCCCXXIV", "MDCCCXXV", "MDCCCXXVI", "MDCCCXXVII", "MDCCCXXVIII", "MDCCCXXIX", "MDCCCXXX", "MDCCCXXXI", "MDCCCXXXII", "MDCCCXXXIII", "MDCCCXXXIV", "MDCCCXXXV", "MDCCCXXXVI", "MDCCCXXXVII", "MDCCCXXXVIII", "MDCCCXXXIX", "MDCCCXL", "MDCCCXLI", "MDCCCXLII", "MDCCCXLIII", "MDCCCXLIV", "MDCCCXLV", "MDCCCXLVI", "MDCCCXLVII", "MDCCCXLVIII", "MDCCCXLIX", "MDCCCL", "MDCCCLI", "MDCCCLII", "MDCCCLIII", "MDCCCLIV", "MDCCCLV", "MDCCCLVI", "MDCCCLVII", "MDCCCLVIII", "MDCCCLIX", "MDCCCLX", "MDCCCLXI", "MDCCCLXII", "MDCCCLXIII", "MDCCCLXIV", "MDCCCLXV", "MDCCCLXVI", "MDCCCLXVII", "MDCCCLXVIII", "MDCCCLXIX", "MDCCCLXX", "MDCCCLXXI", "MDCCCLXXII", "MDCCCLXXIII", "MDCCCLXXIV", "MDCCCLXXV", "MDCCCLXXVI", "MDCCCLXXVII", "MDCCCLXXVIII", "MDCCCLXXIX", "MDCCCLXXX", "MDCCCLXXXI", "MDCCCLXXXII", "MDCCCLXXXIII", "MDCCCLXXXIV", "MDCCCLXXXV", "MDCCCLXXXVI", "MDCCCLXXXVII", "MDCCCLXXXVIII", "MDCCCLXXXIX", "MDCCCXC", "MDCCCXCI", "MDCCCXCII", "MDCCCXCIII", "MDCCCXCIV", "MDCCCXCV", "MDCCCXCVI", "MDCCCXCVII", "MDCCCXCVIII", "MDCCCXCIX", "MCM",
"MCMI", "MCMII", "MCMIII", "MCMIV", "MCMV", "MCMVI", "MCMVII", "MCMVIII", "MCMIX", "MCMX", "MCMXI", "MCMXII", "MCMXIII", "MCMXIV", "MCMXV", "MCMXVI", "MCMXVII", "MCMXVIII", "MCMXIX", "MCMXX", "MCMXXI", "MCMXXII", "MCMXXIII", "MCMXXIV", "MCMXXV", "MCMXXVI", "MCMXXVII", "MCMXXVIII", "MCMXXIX", "MCMXXX", "MCMXXXI", "MCMXXXII", "MCMXXXIII", "MCMXXXIV", "MCMXXXV", "MCMXXXVI", "MCMXXXVII", "MCMXXXVIII", "MCMXXXIX", "MCMXL", "MCMXLI", "MCMXLII", "MCMXLIII", "MCMXLIV", "MCMXLV", "MCMXLVI", "MCMXLVII", "MCMXLVIII", "MCMXLIX", "MCML", "MCMLI", "MCMLII", "MCMLIII", "MCMLIV", "MCMLV", "MCMLVI", "MCMLVII", "MCMLVIII", "MCMLIX", "MCMLX", "MCMLXI", "MCMLXII", "MCMLXIII", "MCMLXIV", "MCMLXV", "MCMLXVI", "MCMLXVII", "MCMLXVIII", "MCMLXIX", "MCMLXX", "MCMLXXI", "MCMLXXII", "MCMLXXIII", "MCMLXXIV", "MCMLXXV", "MCMLXXVI", "MCMLXXVII", "MCMLXXVIII", "MCMLXXIX", "MCMLXXX", "MCMLXXXI", "MCMLXXXII", "MCMLXXXIII", "MCMLXXXIV", "MCMLXXXV", "MCMLXXXVI", "MCMLXXXVII", "MCMLXXXVIII", "MCMLXXXIX", "MCMXC", "MCMXCI", "MCMXCII", "MCMXCIII", "MCMXCIV", "MCMXCV", "MCMXCVI", "MCMXCVII", "MCMXCVIII", "MCMXCIX", "MM",
"MMI", "MMII", "MMIII", "MMIV", "MMV", "MMVI", "MMVII", "MMVIII", "MMIX", "MMX", "MMXI", "MMXII", "MMXIII", "MMXIV", "MMXV", "MMXVI", "MMXVII", "MMXVIII", "MMXIX", "MMXX", "MMXXI", "MMXXII", "MMXXIII", "MMXXIV", "MMXXV", "MMXXVI", "MMXXVII", "MMXXVIII", "MMXXIX", "MMXXX", "MMXXXI", "MMXXXII", "MMXXXIII", "MMXXXIV", "MMXXXV", "MMXXXVI", "MMXXXVII", "MMXXXVIII", "MMXXXIX", "MMXL", "MMXLI", "MMXLII", "MMXLIII", "MMXLIV", "MMXLV", "MMXLVI", "MMXLVII", "MMXLVIII", "MMXLIX", "MML", "MMLI", "MMLII", "MMLIII", "MMLIV", "MMLV", "MMLVI", "MMLVII", "MMLVIII", "MMLIX", "MMLX", "MMLXI", "MMLXII", "MMLXIII", "MMLXIV", "MMLXV", "MMLXVI", "MMLXVII", "MMLXVIII", "MMLXIX", "MMLXX", "MMLXXI", "MMLXXII", "MMLXXIII", "MMLXXIV", "MMLXXV", "MMLXXVI", "MMLXXVII", "MMLXXVIII", "MMLXXIX", "MMLXXX", "MMLXXXI", "MMLXXXII", "MMLXXXIII", "MMLXXXIV", "MMLXXXV", "MMLXXXVI", "MMLXXXVII", "MMLXXXVIII", "MMLXXXIX", "MMXC", "MMXCI", "MMXCII", "MMXCIII", "MMXCIV", "MMXCV", "MMXCVI", "MMXCVII", "MMXCVIII", "MMXCIX", "MMC",
"MMCI", "MMCII", "MMCIII", "MMCIV", "MMCV", "MMCVI", "MMCVII", "MMCVIII", "MMCIX", "MMCX", "MMCXI", "MMCXII", "MMCXIII", "MMCXIV", "MMCXV", "MMCXVI", "MMCXVII", "MMCXVIII", "MMCXIX", "MMCXX", "MMCXXI", "MMCXXII", "MMCXXIII", "MMCXXIV", "MMCXXV", "MMCXXVI", "MMCXXVII", "MMCXXVIII", "MMCXXIX", "MMCXXX", "MMCXXXI", "MMCXXXII", "MMCXXXIII", "MMCXXXIV", "MMCXXXV", "MMCXXXVI", "MMCXXXVII", "MMCXXXVIII", "MMCXXXIX", "MMCXL", "MMCXLI", "MMCXLII", "MMCXLIII", "MMCXLIV", "MMCXLV", "MMCXLVI", "MMCXLVII", "MMCXLVIII", "MMCXLIX", "MMCL", "MMCLI", "MMCLII", "MMCLIII", "MMCLIV", "MMCLV", "MMCLVI", "MMCLVII", "MMCLVIII", "MMCLIX", "MMCLX", "MMCLXI", "MMCLXII", "MMCLXIII", "MMCLXIV", "MMCLXV", "MMCLXVI", "MMCLXVII", "MMCLXVIII", "MMCLXIX", "MMCLXX", "MMCLXXI", "MMCLXXII", "MMCLXXIII", "MMCLXXIV", "MMCLXXV", "MMCLXXVI", "MMCLXXVII", "MMCLXXVIII", "MMCLXXIX", "MMCLXXX", "MMCLXXXI", "MMCLXXXII", "MMCLXXXIII", "MMCLXXXIV", "MMCLXXXV", "MMCLXXXVI", "MMCLXXXVII", "MMCLXXXVIII", "MMCLXXXIX", "MMCXC", "MMCXCI", "MMCXCII", "MMCXCIII", "MMCXCIV", "MMCXCV", "MMCXCVI", "MMCXCVII", "MMCXCVIII", "MMCXCIX", "MMCC",
"MMCCI", "MMCCII", "MMCCIII", "MMCCIV", "MMCCV", "MMCCVI", "MMCCVII", "MMCCVIII", "MMCCIX", "MMCCX", "MMCCXI", "MMCCXII", "MMCCXIII", "MMCCXIV", "MMCCXV", "MMCCXVI", "MMCCXVII", "MMCCXVIII", "MMCCXIX", "MMCCXX", "MMCCXXI", "MMCCXXII", "MMCCXXIII", "MMCCXXIV", "MMCCXXV", "MMCCXXVI", "MMCCXXVII", "MMCCXXVIII", "MMCCXXIX", "MMCCXXX", "MMCCXXXI", "MMCCXXXII", "MMCCXXXIII", "MMCCXXXIV", "MMCCXXXV", "MMCCXXXVI", "MMCCXXXVII", "MMCCXXXVIII", "MMCCXXXIX", "MMCCXL", "MMCCXLI", "MMCCXLII", "MMCCXLIII", "MMCCXLIV", "MMCCXLV", "MMCCXLVI", "MMCCXLVII", "MMCCXLVIII", "MMCCXLIX", "MMCCL", "MMCCLI", "MMCCLII", "MMCCLIII", "MMCCLIV", "MMCCLV", "MMCCLVI", "MMCCLVII", "MMCCLVIII", "MMCCLIX", "MMCCLX", "MMCCLXI", "MMCCLXII", "MMCCLXIII", "MMCCLXIV", "MMCCLXV", "MMCCLXVI", "MMCCLXVII", "MMCCLXVIII", "MMCCLXIX", "MMCCLXX", "MMCCLXXI", "MMCCLXXII", "MMCCLXXIII", "MMCCLXXIV", "MMCCLXXV", "MMCCLXXVI", "MMCCLXXVII", "MMCCLXXVIII", "MMCCLXXIX", "MMCCLXXX", "MMCCLXXXI", "MMCCLXXXII", "MMCCLXXXIII", "MMCCLXXXIV", "MMCCLXXXV", "MMCCLXXXVI", "MMCCLXXXVII", "MMCCLXXXVIII", "MMCCLXXXIX", "MMCCXC", "MMCCXCI", "MMCCXCII", "MMCCXCIII", "MMCCXCIV", "MMCCXCV", "MMCCXCVI", "MMCCXCVII", "MMCCXCVIII", "MMCCXCIX", "MMCCC",
"MMCCCI", "MMCCCII", "MMCCCIII", "MMCCCIV", "MMCCCV", "MMCCCVI", "MMCCCVII", "MMCCCVIII", "MMCCCIX", "MMCCCX", "MMCCCXI", "MMCCCXII", "MMCCCXIII", "MMCCCXIV", "MMCCCXV", "MMCCCXVI", "MMCCCXVII", "MMCCCXVIII", "MMCCCXIX", "MMCCCXX", "MMCCCXXI", "MMCCCXXII", "MMCCCXXIII", "MMCCCXXIV", "MMCCCXXV", "MMCCCXXVI", "MMCCCXXVII", "MMCCCXXVIII", "MMCCCXXIX", "MMCCCXXX", "MMCCCXXXI", "MMCCCXXXII", "MMCCCXXXIII", "MMCCCXXXIV", "MMCCCXXXV", "MMCCCXXXVI", "MMCCCXXXVII", "MMCCCXXXVIII", "MMCCCXXXIX", "MMCCCXL", "MMCCCXLI", "MMCCCXLII", "MMCCCXLIII", "MMCCCXLIV", "MMCCCXLV", "MMCCCXLVI", "MMCCCXLVII", "MMCCCXLVIII", "MMCCCXLIX", "MMCCCL", "MMCCCLI", "MMCCCLII", "MMCCCLIII", "MMCCCLIV", "MMCCCLV", "MMCCCLVI", "MMCCCLVII", "MMCCCLVIII", "MMCCCLIX", "MMCCCLX", "MMCCCLXI", "MMCCCLXII", "MMCCCLXIII", "MMCCCLXIV", "MMCCCLXV", "MMCCCLXVI", "MMCCCLXVII", "MMCCCLXVIII", "MMCCCLXIX", "MMCCCLXX", "MMCCCLXXI", "MMCCCLXXII", "MMCCCLXXIII", "MMCCCLXXIV", "MMCCCLXXV", "MMCCCLXXVI", "MMCCCLXXVII", "MMCCCLXXVIII", "MMCCCLXXIX", "MMCCCLXXX", "MMCCCLXXXI", "MMCCCLXXXII", "MMCCCLXXXIII", "MMCCCLXXXIV", "MMCCCLXXXV", "MMCCCLXXXVI", "MMCCCLXXXVII", "MMCCCLXXXVIII", "MMCCCLXXXIX", "MMCCCXC", "MMCCCXCI", "MMCCCXCII", "MMCCCXCIII", "MMCCCXCIV", "MMCCCXCV", "MMCCCXCVI", "MMCCCXCVII", "MMCCCXCVIII", "MMCCCXCIX", "MMCD",
"MMCDI", "MMCDII", "MMCDIII", "MMCDIV", "MMCDV", "MMCDVI", "MMCDVII", "MMCDVIII", "MMCDIX", "MMCDX", "MMCDXI", "MMCDXII", "MMCDXIII", "MMCDXIV", "MMCDXV", "MMCDXVI", "MMCDXVII", "MMCDXVIII", "MMCDXIX", "MMCDXX", "MMCDXXI", "MMCDXXII", "MMCDXXIII", "MMCDXXIV", "MMCDXXV", "MMCDXXVI", "MMCDXXVII", "MMCDXXVIII", "MMCDXXIX", "MMCDXXX", "MMCDXXXI", "MMCDXXXII", "MMCDXXXIII", "MMCDXXXIV", "MMCDXXXV", "MMCDXXXVI", "MMCDXXXVII", "MMCDXXXVIII", "MMCDXXXIX", "MMCDXL", "MMCDXLI", "MMCDXLII", "MMCDXLIII", "MMCDXLIV", "MMCDXLV", "MMCDXLVI", "MMCDXLVII", "MMCDXLVIII", "MMCDXLIX", "MMCDL", "MMCDLI", "MMCDLII", "MMCDLIII", "MMCDLIV", "MMCDLV", "MMCDLVI", "MMCDLVII", "MMCDLVIII", "MMCDLIX", "MMCDLX", "MMCDLXI", "MMCDLXII", "MMCDLXIII", "MMCDLXIV", "MMCDLXV", "MMCDLXVI", "MMCDLXVII", "MMCDLXVIII", "MMCDLXIX", "MMCDLXX", "MMCDLXXI", "MMCDLXXII", "MMCDLXXIII", "MMCDLXXIV", "MMCDLXXV", "MMCDLXXVI", "MMCDLXXVII", "MMCDLXXVIII", "MMCDLXXIX", "MMCDLXXX", "MMCDLXXXI", "MMCDLXXXII", "MMCDLXXXIII", "MMCDLXXXIV", "MMCDLXXXV", "MMCDLXXXVI", "MMCDLXXXVII", "MMCDLXXXVIII", "MMCDLXXXIX", "MMCDXC", "MMCDXCI", "MMCDXCII", "MMCDXCIII", "MMCDXCIV", "MMCDXCV", "MMCDXCVI", "MMCDXCVII", "MMCDXCVIII", "MMCDXCIX", "MMD",
"MMDI", "MMDII", "MMDIII", "MMDIV", "MMDV", "MMDVI", "MMDVII", "MMDVIII", "MMDIX", "MMDX", "MMDXI", "MMDXII", "MMDXIII", "MMDXIV", "MMDXV", "MMDXVI", "MMDXVII", "MMDXVIII", "MMDXIX", "MMDXX", "MMDXXI", "MMDXXII", "MMDXXIII", "MMDXXIV", "MMDXXV", "MMDXXVI", "MMDXXVII", "MMDXXVIII", "MMDXXIX", "MMDXXX", "MMDXXXI", "MMDXXXII", "MMDXXXIII", "MMDXXXIV", "MMDXXXV", "MMDXXXVI", "MMDXXXVII", "MMDXXXVIII", "MMDXXXIX", "MMDXL", "MMDXLI", "MMDXLII", "MMDXLIII", "MMDXLIV", "MMDXLV", "MMDXLVI", "MMDXLVII", "MMDXLVIII", "MMDXLIX", "MMDL", "MMDLI", "MMDLII", "MMDLIII", "MMDLIV", "MMDLV", "MMDLVI", "MMDLVII", "MMDLVIII", "MMDLIX", "MMDLX", "MMDLXI", "MMDLXII", "MMDLXIII", "MMDLXIV", "MMDLXV", "MMDLXVI", "MMDLXVII", "MMDLXVIII", "MMDLXIX", "MMDLXX", "MMDLXXI", "MMDLXXII", "MMDLXXIII", "MMDLXXIV", "MMDLXXV", "MMDLXXVI", "MMDLXXVII", "MMDLXXVIII", "MMDLXXIX", "MMDLXXX", "MMDLXXXI", "MMDLXXXII", "MMDLXXXIII", "MMDLXXXIV", "MMDLXXXV", "MMDLXXXVI", "MMDLXXXVII", "MMDLXXXVIII", "MMDLXXXIX", "MMDXC", "MMDXCI", "MMDXCII", "MMDXCIII", "MMDXCIV", "MMDXCV", "MMDXCVI", "MMDXCVII", "MMDXCVIII", "MMDXCIX", "MMDC",
"MMDCI", "MMDCII", "MMDCIII", "MMDCIV", "MMDCV", "MMDCVI", "MMDCVII", "MMDCVIII", "MMDCIX", "MMDCX", "MMDCXI", "MMDCXII", "MMDCXIII", "MMDCXIV", "MMDCXV", "MMDCXVI", "MMDCXVII", "MMDCXVIII", "MMDCXIX", "MMDCXX", "MMDCXXI", "MMDCXXII", "MMDCXXIII", "MMDCXXIV", "MMDCXXV", "MMDCXXVI", "MMDCXXVII", "MMDCXXVIII", "MMDCXXIX", "MMDCXXX", "MMDCXXXI", "MMDCXXXII", "MMDCXXXIII", "MMDCXXXIV", "MMDCXXXV", "MMDCXXXVI", "MMDCXXXVII", "MMDCXXXVIII", "MMDCXXXIX", "MMDCXL", "MMDCXLI", "MMDCXLII", "MMDCXLIII", "MMDCXLIV", "MMDCXLV", "MMDCXLVI", "MMDCXLVII", "MMDCXLVIII", "MMDCXLIX", "MMDCL", "MMDCLI", "MMDCLII", "MMDCLIII", "MMDCLIV", "MMDCLV", "MMDCLVI", "MMDCLVII", "MMDCLVIII", "MMDCLIX", "MMDCLX", "MMDCLXI", "MMDCLXII", "MMDCLXIII", "MMDCLXIV", "MMDCLXV", "MMDCLXVI", "MMDCLXVII", "MMDCLXVIII", "MMDCLXIX", "MMDCLXX", "MMDCLXXI", "MMDCLXXII", "MMDCLXXIII", "MMDCLXXIV", "MMDCLXXV", "MMDCLXXVI", "MMDCLXXVII", "MMDCLXXVIII", "MMDCLXXIX", "MMDCLXXX", "MMDCLXXXI", "MMDCLXXXII", "MMDCLXXXIII", "MMDCLXXXIV", "MMDCLXXXV", "MMDCLXXXVI", "MMDCLXXXVII", "MMDCLXXXVIII", "MMDCLXXXIX", "MMDCXC", "MMDCXCI", "MMDCXCII", "MMDCXCIII", "MMDCXCIV", "MMDCXCV", "MMDCXCVI", "MMDCXCVII", "MMDCXCVIII", "MMDCXCIX", "MMDCC",
"MMDCCI", "MMDCCII", "MMDCCIII", "MMDCCIV", "MMDCCV", "MMDCCVI", "MMDCCVII", "MMDCCVIII", "MMDCCIX", "MMDCCX", "MMDCCXI", "MMDCCXII", "MMDCCXIII", "MMDCCXIV", "MMDCCXV", "MMDCCXVI", "MMDCCXVII", "MMDCCXVIII", "MMDCCXIX", "MMDCCXX", "MMDCCXXI", "MMDCCXXII", "MMDCCXXIII", "MMDCCXXIV", "MMDCCXXV", "MMDCCXXVI", "MMDCCXXVII", "MMDCCXXVIII", "MMDCCXXIX", "MMDCCXXX", "MMDCCXXXI", "MMDCCXXXII", "MMDCCXXXIII", "MMDCCXXXIV", "MMDCCXXXV", "MMDCCXXXVI", "MMDCCXXXVII", "MMDCCXXXVIII", "MMDCCXXXIX", "MMDCCXL", "MMDCCXLI", "MMDCCXLII", "MMDCCXLIII", "MMDCCXLIV", "MMDCCXLV", "MMDCCXLVI", "MMDCCXLVII", "MMDCCXLVIII", "MMDCCXLIX", "MMDCCL", "MMDCCLI", "MMDCCLII", "MMDCCLIII", "MMDCCLIV", "MMDCCLV", "MMDCCLVI", "MMDCCLVII", "MMDCCLVIII", "MMDCCLIX", "MMDCCLX", "MMDCCLXI", "MMDCCLXII", "MMDCCLXIII", "MMDCCLXIV", "MMDCCLXV", "MMDCCLXVI", "MMDCCLXVII", "MMDCCLXVIII", "MMDCCLXIX", "MMDCCLXX", "MMDCCLXXI", "MMDCCLXXII", "MMDCCLXXIII", "MMDCCLXXIV", "MMDCCLXXV", "MMDCCLXXVI", "MMDCCLXXVII", "MMDCCLXXVIII", "MMDCCLXXIX", "MMDCCLXXX", "MMDCCLXXXI", "MMDCCLXXXII", "MMDCCLXXXIII", "MMDCCLXXXIV", "MMDCCLXXXV", "MMDCCLXXXVI", "MMDCCLXXXVII", "MMDCCLXXXVIII", "MMDCCLXXXIX", "MMDCCXC", "MMDCCXCI", "MMDCCXCII", "MMDCCXCIII", "MMDCCXCIV", "MMDCCXCV", "MMDCCXCVI", "MMDCCXCVII", "MMDCCXCVIII", "MMDCCXCIX", "MMDCCC",
"MMDCCCI", "MMDCCCII", "MMDCCCIII", "MMDCCCIV", "MMDCCCV", "MMDCCCVI", "MMDCCCVII", "MMDCCCVIII", "MMDCCCIX", "MMDCCCX", "MMDCCCXI", "MMDCCCXII", "MMDCCCXIII", "MMDCCCXIV", "MMDCCCXV", "MMDCCCXVI", "MMDCCCXVII", "MMDCCCXVIII", "MMDCCCXIX", "MMDCCCXX", "MMDCCCXXI", "MMDCCCXXII", "MMDCCCXXIII", "MMDCCCXXIV", "MMDCCCXXV", "MMDCCCXXVI", "MMDCCCXXVII", "MMDCCCXXVIII", "MMDCCCXXIX", "MMDCCCXXX", "MMDCCCXXXI", "MMDCCCXXXII", "MMDCCCXXXIII", "MMDCCCXXXIV", "MMDCCCXXXV", "MMDCCCXXXVI", "MMDCCCXXXVII", "MMDCCCXXXVIII", "MMDCCCXXXIX", "MMDCCCXL", "MMDCCCXLI", "MMDCCCXLII", "MMDCCCXLIII", "MMDCCCXLIV", "MMDCCCXLV", "MMDCCCXLVI", "MMDCCCXLVII", "MMDCCCXLVIII", "MMDCCCXLIX", "MMDCCCL", "MMDCCCLI", "MMDCCCLII", "MMDCCCLIII", "MMDCCCLIV", "MMDCCCLV", "MMDCCCLVI", "MMDCCCLVII", "MMDCCCLVIII", "MMDCCCLIX", "MMDCCCLX", "MMDCCCLXI", "MMDCCCLXII", "MMDCCCLXIII", "MMDCCCLXIV", "MMDCCCLXV", "MMDCCCLXVI", "MMDCCCLXVII", "MMDCCCLXVIII", "MMDCCCLXIX", "MMDCCCLXX", "MMDCCCLXXI", "MMDCCCLXXII", "MMDCCCLXXIII", "MMDCCCLXXIV", "MMDCCCLXXV", "MMDCCCLXXVI", "MMDCCCLXXVII", "MMDCCCLXXVIII", "MMDCCCLXXIX", "MMDCCCLXXX", "MMDCCCLXXXI", "MMDCCCLXXXII", "MMDCCCLXXXIII", "MMDCCCLXXXIV", "MMDCCCLXXXV", "MMDCCCLXXXVI", "MMDCCCLXXXVII", "MMDCCCLXXXVIII", "MMDCCCLXXXIX", "MMDCCCXC", "MMDCCCXCI", "MMDCCCXCII", "MMDCCCXCIII", "MMDCCCXCIV", "MMDCCCXCV", "MMDCCCXCVI", "MMDCCCXCVII", "MMDCCCXCVIII", "MMDCCCXCIX", "MMCM",
"MMCMI", "MMCMII", "MMCMIII", "MMCMIV", "MMCMV", "MMCMVI", "MMCMVII", "MMCMVIII", "MMCMIX", "MMCMX", "MMCMXI", "MMCMXII", "MMCMXIII", "MMCMXIV", "MMCMXV", "MMCMXVI", "MMCMXVII", "MMCMXVIII", "MMCMXIX", "MMCMXX", "MMCMXXI", "MMCMXXII", "MMCMXXIII", "MMCMXXIV", "MMCMXXV", "MMCMXXVI", "MMCMXXVII", "MMCMXXVIII", "MMCMXXIX", "MMCMXXX", "MMCMXXXI", "MMCMXXXII", "MMCMXXXIII", "MMCMXXXIV", "MMCMXXXV", "MMCMXXXVI", "MMCMXXXVII", "MMCMXXXVIII", "MMCMXXXIX", "MMCMXL", "MMCMXLI", "MMCMXLII", "MMCMXLIII", "MMCMXLIV", "MMCMXLV", "MMCMXLVI", "MMCMXLVII", "MMCMXLVIII", "MMCMXLIX", "MMCML", "MMCMLI", "MMCMLII", "MMCMLIII", "MMCMLIV", "MMCMLV", "MMCMLVI", "MMCMLVII", "MMCMLVIII", "MMCMLIX", "MMCMLX", "MMCMLXI", "MMCMLXII", "MMCMLXIII", "MMCMLXIV", "MMCMLXV", "MMCMLXVI", "MMCMLXVII", "MMCMLXVIII", "MMCMLXIX", "MMCMLXX", "MMCMLXXI", "MMCMLXXII", "MMCMLXXIII", "MMCMLXXIV", "MMCMLXXV", "MMCMLXXVI", "MMCMLXXVII", "MMCMLXXVIII", "MMCMLXXIX", "MMCMLXXX", "MMCMLXXXI", "MMCMLXXXII", "MMCMLXXXIII", "MMCMLXXXIV", "MMCMLXXXV", "MMCMLXXXVI", "MMCMLXXXVII", "MMCMLXXXVIII", "MMCMLXXXIX", "MMCMXC", "MMCMXCI", "MMCMXCII", "MMCMXCIII", "MMCMXCIV", "MMCMXCV", "MMCMXCVI", "MMCMXCVII", "MMCMXCVIII", "MMCMXCIX", "MMM",
"MMMI", "MMMII", "MMMIII", "MMMIV", "MMMV", "MMMVI", "MMMVII", "MMMVIII", "MMMIX", "MMMX", "MMMXI", "MMMXII", "MMMXIII", "MMMXIV", "MMMXV", "MMMXVI", "MMMXVII", "MMMXVIII", "MMMXIX", "MMMXX", "MMMXXI", "MMMXXII", "MMMXXIII", "MMMXXIV", "MMMXXV", "MMMXXVI", "MMMXXVII", "MMMXXVIII", "MMMXXIX", "MMMXXX", "MMMXXXI", "MMMXXXII", "MMMXXXIII", "MMMXXXIV", "MMMXXXV", "MMMXXXVI", "MMMXXXVII", "MMMXXXVIII", "MMMXXXIX", "MMMXL", "MMMXLI", "MMMXLII", "MMMXLIII", "MMMXLIV", "MMMXLV", "MMMXLVI", "MMMXLVII", "MMMXLVIII", "MMMXLIX", "MMML", "MMMLI", "MMMLII", "MMMLIII", "MMMLIV", "MMMLV", "MMMLVI", "MMMLVII", "MMMLVIII", "MMMLIX", "MMMLX", "MMMLXI", "MMMLXII", "MMMLXIII", "MMMLXIV", "MMMLXV", "MMMLXVI", "MMMLXVII", "MMMLXVIII", "MMMLXIX", "MMMLXX", "MMMLXXI", "MMMLXXII", "MMMLXXIII", "MMMLXXIV", "MMMLXXV", "MMMLXXVI", "MMMLXXVII", "MMMLXXVIII", "MMMLXXIX", "MMMLXXX", "MMMLXXXI", "MMMLXXXII", "MMMLXXXIII", "MMMLXXXIV", "MMMLXXXV", "MMMLXXXVI", "MMMLXXXVII", "MMMLXXXVIII", "MMMLXXXIX", "MMMXC", "MMMXCI", "MMMXCII", "MMMXCIII", "MMMXCIV", "MMMXCV", "MMMXCVI", "MMMXCVII", "MMMXCVIII", "MMMXCIX", "MMMC",
"MMMCI", "MMMCII", "MMMCIII", "MMMCIV", "MMMCV", "MMMCVI", "MMMCVII", "MMMCVIII", "MMMCIX", "MMMCX", "MMMCXI", "MMMCXII", "MMMCXIII", "MMMCXIV", "MMMCXV", "MMMCXVI", "MMMCXVII", "MMMCXVIII", "MMMCXIX", "MMMCXX", "MMMCXXI", "MMMCXXII", "MMMCXXIII", "MMMCXXIV", "MMMCXXV", "MMMCXXVI", "MMMCXXVII", "MMMCXXVIII", "MMMCXXIX", "MMMCXXX", "MMMCXXXI", "MMMCXXXII", "MMMCXXXIII", "MMMCXXXIV", "MMMCXXXV", "MMMCXXXVI", "MMMCXXXVII", "MMMCXXXVIII", "MMMCXXXIX", "MMMCXL", "MMMCXLI", "MMMCXLII", "MMMCXLIII", "MMMCXLIV", "MMMCXLV", "MMMCXLVI", "MMMCXLVII", "MMMCXLVIII", "MMMCXLIX", "MMMCL", "MMMCLI", "MMMCLII", "MMMCLIII", "MMMCLIV", "MMMCLV", "MMMCLVI", "MMMCLVII", "MMMCLVIII", "MMMCLIX", "MMMCLX", "MMMCLXI", "MMMCLXII", "MMMCLXIII", "MMMCLXIV", "MMMCLXV", "MMMCLXVI", "MMMCLXVII", "MMMCLXVIII", "MMMCLXIX", "MMMCLXX", "MMMCLXXI", "MMMCLXXII", "MMMCLXXIII", "MMMCLXXIV", "MMMCLXXV", "MMMCLXXVI", "MMMCLXXVII", "MMMCLXXVIII", "MMMCLXXIX", "MMMCLXXX", "MMMCLXXXI", "MMMCLXXXII", "MMMCLXXXIII", "MMMCLXXXIV", "MMMCLXXXV", "MMMCLXXXVI", "MMMCLXXXVII", "MMMCLXXXVIII", "MMMCLXXXIX", "MMMCXC", "MMMCXCI", "MMMCXCII", "MMMCXCIII", "MMMCXCIV", "MMMCXCV", "MMMCXCVI", "MMMCXCVII", "MMMCXCVIII", "MMMCXCIX", "MMMCC",
"MMMCCI", "MMMCCII", "MMMCCIII", "MMMCCIV", "MMMCCV", "MMMCCVI", "MMMCCVII", "MMMCCVIII", "MMMCCIX", "MMMCCX", "MMMCCXI", "MMMCCXII", "MMMCCXIII", "MMMCCXIV", "MMMCCXV", "MMMCCXVI", "MMMCCXVII", "MMMCCXVIII", "MMMCCXIX", "MMMCCXX", "MMMCCXXI", "MMMCCXXII", "MMMCCXXIII", "MMMCCXXIV", "MMMCCXXV", "MMMCCXXVI", "MMMCCXXVII", "MMMCCXXVIII", "MMMCCXXIX", "MMMCCXXX", "MMMCCXXXI", "MMMCCXXXII", "MMMCCXXXIII", "MMMCCXXXIV", "MMMCCXXXV", "MMMCCXXXVI", "MMMCCXXXVII", "MMMCCXXXVIII", "MMMCCXXXIX", "MMMCCXL", "MMMCCXLI", "MMMCCXLII", "MMMCCXLIII", "MMMCCXLIV", "MMMCCXLV", "MMMCCXLVI", "MMMCCXLVII", "MMMCCXLVIII", "MMMCCXLIX", "MMMCCL", "MMMCCLI", "MMMCCLII", "MMMCCLIII", "MMMCCLIV", "MMMCCLV", "MMMCCLVI", "MMMCCLVII", "MMMCCLVIII", "MMMCCLIX", "MMMCCLX", "MMMCCLXI", "MMMCCLXII", "MMMCCLXIII", "MMMCCLXIV", "MMMCCLXV", "MMMCCLXVI", "MMMCCLXVII", "MMMCCLXVIII", "MMMCCLXIX", "MMMCCLXX", "MMMCCLXXI", "MMMCCLXXII", "MMMCCLXXIII", "MMMCCLXXIV", "MMMCCLXXV", "MMMCCLXXVI", "MMMCCLXXVII", "MMMCCLXXVIII", "MMMCCLXXIX", "MMMCCLXXX", "MMMCCLXXXI", "MMMCCLXXXII", "MMMCCLXXXIII", "MMMCCLXXXIV", "MMMCCLXXXV", "MMMCCLXXXVI", "MMMCCLXXXVII", "MMMCCLXXXVIII", "MMMCCLXXXIX", "MMMCCXC", "MMMCCXCI", "MMMCCXCII", "MMMCCXCIII", "MMMCCXCIV", "MMMCCXCV", "MMMCCXCVI", "MMMCCXCVII", "MMMCCXCVIII", "MMMCCXCIX", "MMMCCC",
"MMMCCCI", "MMMCCCII", "MMMCCCIII", "MMMCCCIV", "MMMCCCV", "MMMCCCVI", "MMMCCCVII", "MMMCCCVIII", "MMMCCCIX", "MMMCCCX", "MMMCCCXI", "MMMCCCXII", "MMMCCCXIII", "MMMCCCXIV", "MMMCCCXV", "MMMCCCXVI", "MMMCCCXVII", "MMMCCCXVIII", "MMMCCCXIX", "MMMCCCXX", "MMMCCCXXI", "MMMCCCXXII", "MMMCCCXXIII", "MMMCCCXXIV", "MMMCCCXXV", "MMMCCCXXVI", "MMMCCCXXVII", "MMMCCCXXVIII", "MMMCCCXXIX", "MMMCCCXXX", "MMMCCCXXXI", "MMMCCCXXXII", "MMMCCCXXXIII", "MMMCCCXXXIV", "MMMCCCXXXV", "MMMCCCXXXVI", "MMMCCCXXXVII", "MMMCCCXXXVIII", "MMMCCCXXXIX", "MMMCCCXL", "MMMCCCXLI", "MMMCCCXLII", "MMMCCCXLIII", "MMMCCCXLIV", "MMMCCCXLV", "MMMCCCXLVI", "MMMCCCXLVII", "MMMCCCXLVIII", "MMMCCCXLIX", "MMMCCCL", "MMMCCCLI", "MMMCCCLII", "MMMCCCLIII", "MMMCCCLIV", "MMMCCCLV", "MMMCCCLVI", "MMMCCCLVII", "MMMCCCLVIII", "MMMCCCLIX", "MMMCCCLX", "MMMCCCLXI", "MMMCCCLXII", "MMMCCCLXIII", "MMMCCCLXIV", "MMMCCCLXV", "MMMCCCLXVI", "MMMCCCLXVII", "MMMCCCLXVIII", "MMMCCCLXIX", "MMMCCCLXX", "MMMCCCLXXI", "MMMCCCLXXII", "MMMCCCLXXIII", "MMMCCCLXXIV", "MMMCCCLXXV", "MMMCCCLXXVI", "MMMCCCLXXVII", "MMMCCCLXXVIII", "MMMCCCLXXIX", "MMMCCCLXXX", "MMMCCCLXXXI", "MMMCCCLXXXII", "MMMCCCLXXXIII", "MMMCCCLXXXIV", "MMMCCCLXXXV", "MMMCCCLXXXVI", "MMMCCCLXXXVII", "MMMCCCLXXXVIII", "MMMCCCLXXXIX", "MMMCCCXC", "MMMCCCXCI", "MMMCCCXCII", "MMMCCCXCIII", "MMMCCCXCIV", "MMMCCCXCV", "MMMCCCXCVI", "MMMCCCXCVII", "MMMCCCXCVIII", "MMMCCCXCIX", "MMMCD",
"MMMCDI", "MMMCDII", "MMMCDIII", "MMMCDIV", "MMMCDV", "MMMCDVI", "MMMCDVII", "MMMCDVIII", "MMMCDIX", "MMMCDX", "MMMCDXI", "MMMCDXII", "MMMCDXIII", "MMMCDXIV", "MMMCDXV", "MMMCDXVI", "MMMCDXVII", "MMMCDXVIII", "MMMCDXIX", "MMMCDXX", "MMMCDXXI", "MMMCDXXII", "MMMCDXXIII", "MMMCDXXIV", "MMMCDXXV", "MMMCDXXVI", "MMMCDXXVII", "MMMCDXXVIII", "MMMCDXXIX", "MMMCDXXX", "MMMCDXXXI", "MMMCDXXXII", "MMMCDXXXIII", "MMMCDXXXIV", "MMMCDXXXV", "MMMCDXXXVI", "MMMCDXXXVII", "MMMCDXXXVIII", "MMMCDXXXIX", "MMMCDXL", "MMMCDXLI", "MMMCDXLII", "MMMCDXLIII", "MMMCDXLIV", "MMMCDXLV", "MMMCDXLVI", "MMMCDXLVII", "MMMCDXLVIII", "MMMCDXLIX", "MMMCDL", "MMMCDLI", "MMMCDLII", "MMMCDLIII", "MMMCDLIV", "MMMCDLV", "MMMCDLVI", "MMMCDLVII", "MMMCDLVIII", "MMMCDLIX", "MMMCDLX", "MMMCDLXI", "MMMCDLXII", "MMMCDLXIII", "MMMCDLXIV", "MMMCDLXV", "MMMCDLXVI", "MMMCDLXVII", "MMMCDLXVIII", "MMMCDLXIX", "MMMCDLXX", "MMMCDLXXI", "MMMCDLXXII", "MMMCDLXXIII", "MMMCDLXXIV", "MMMCDLXXV", "MMMCDLXXVI", "MMMCDLXXVII", "MMMCDLXXVIII", "MMMCDLXXIX", "MMMCDLXXX", "MMMCDLXXXI", "MMMCDLXXXII", "MMMCDLXXXIII", "MMMCDLXXXIV", "MMMCDLXXXV", "MMMCDLXXXVI", "MMMCDLXXXVII", "MMMCDLXXXVIII", "MMMCDLXXXIX", "MMMCDXC", "MMMCDXCI", "MMMCDXCII", "MMMCDXCIII", "MMMCDXCIV", "MMMCDXCV", "MMMCDXCVI", "MMMCDXCVII", "MMMCDXCVIII", "MMMCDXCIX", "MMMD",
"MMMDI", "MMMDII", "MMMDIII", "MMMDIV", "MMMDV", "MMMDVI", "MMMDVII", "MMMDVIII", "MMMDIX", "MMMDX", "MMMDXI", "MMMDXII", "MMMDXIII", "MMMDXIV", "MMMDXV", "MMMDXVI", "MMMDXVII", "MMMDXVIII", "MMMDXIX", "MMMDXX", "MMMDXXI", "MMMDXXII", "MMMDXXIII", "MMMDXXIV", "MMMDXXV", "MMMDXXVI", "MMMDXXVII", "MMMDXXVIII", "MMMDXXIX", "MMMDXXX", "MMMDXXXI", "MMMDXXXII", "MMMDXXXIII", "MMMDXXXIV", "MMMDXXXV", "MMMDXXXVI", "MMMDXXXVII", "MMMDXXXVIII", "MMMDXXXIX", "MMMDXL", "MMMDXLI", "MMMDXLII", "MMMDXLIII", "MMMDXLIV", "MMMDXLV", "MMMDXLVI", "MMMDXLVII", "MMMDXLVIII", "MMMDXLIX", "MMMDL", "MMMDLI", "MMMDLII", "MMMDLIII", "MMMDLIV", "MMMDLV", "MMMDLVI", "MMMDLVII", "MMMDLVIII", "MMMDLIX", "MMMDLX", "MMMDLXI", "MMMDLXII", "MMMDLXIII", "MMMDLXIV", "MMMDLXV", "MMMDLXVI", "MMMDLXVII", "MMMDLXVIII", "MMMDLXIX", "MMMDLXX", "MMMDLXXI", "MMMDLXXII", "MMMDLXXIII", "MMMDLXXIV", "MMMDLXXV", "MMMDLXXVI", "MMMDLXXVII", "MMMDLXXVIII", "MMMDLXXIX", "MMMDLXXX", "MMMDLXXXI", "MMMDLXXXII", "MMMDLXXXIII", "MMMDLXXXIV", "MMMDLXXXV", "MMMDLXXXVI", "MMMDLXXXVII", "MMMDLXXXVIII", "MMMDLXXXIX", "MMMDXC", "MMMDXCI", "MMMDXCII", "MMMDXCIII", "MMMDXCIV", "MMMDXCV", "MMMDXCVI", "MMMDXCVII", "MMMDXCVIII", "MMMDXCIX", "MMMDC",
"MMMDCI", "MMMDCII", "MMMDCIII", "MMMDCIV", "MMMDCV", "MMMDCVI", "MMMDCVII", "MMMDCVIII", "MMMDCIX", "MMMDCX", "MMMDCXI", "MMMDCXII", "MMMDCXIII", "MMMDCXIV", "MMMDCXV", "MMMDCXVI", "MMMDCXVII", "MMMDCXVIII", "MMMDCXIX", "MMMDCXX", "MMMDCXXI", "MMMDCXXII", "MMMDCXXIII", "MMMDCXXIV", "MMMDCXXV", "MMMDCXXVI", "MMMDCXXVII", "MMMDCXXVIII", "MMMDCXXIX", "MMMDCXXX", "MMMDCXXXI", "MMMDCXXXII", "MMMDCXXXIII", "MMMDCXXXIV", "MMMDCXXXV", "MMMDCXXXVI", "MMMDCXXXVII", "MMMDCXXXVIII", "MMMDCXXXIX", "MMMDCXL", "MMMDCXLI", "MMMDCXLII", "MMMDCXLIII", "MMMDCXLIV", "MMMDCXLV", "MMMDCXLVI", "MMMDCXLVII", "MMMDCXLVIII", "MMMDCXLIX", "MMMDCL", "MMMDCLI", "MMMDCLII", "MMMDCLIII", "MMMDCLIV", "MMMDCLV", "MMMDCLVI", "MMMDCLVII", "MMMDCLVIII", "MMMDCLIX", "MMMDCLX", "MMMDCLXI", "MMMDCLXII", "MMMDCLXIII", "MMMDCLXIV", "MMMDCLXV", "MMMDCLXVI", "MMMDCLXVII", "MMMDCLXVIII", "MMMDCLXIX", "MMMDCLXX", "MMMDCLXXI", "MMMDCLXXII", "MMMDCLXXIII", "MMMDCLXXIV", "MMMDCLXXV", "MMMDCLXXVI", "MMMDCLXXVII", "MMMDCLXXVIII", "MMMDCLXXIX", "MMMDCLXXX", "MMMDCLXXXI", "MMMDCLXXXII", "MMMDCLXXXIII", "MMMDCLXXXIV", "MMMDCLXXXV", "MMMDCLXXXVI", "MMMDCLXXXVII", "MMMDCLXXXVIII", "MMMDCLXXXIX", "MMMDCXC", "MMMDCXCI", "MMMDCXCII", "MMMDCXCIII", "MMMDCXCIV", "MMMDCXCV", "MMMDCXCVI", "MMMDCXCVII", "MMMDCXCVIII", "MMMDCXCIX", "MMMDCC",
"MMMDCCI", "MMMDCCII", "MMMDCCIII", "MMMDCCIV", "MMMDCCV", "MMMDCCVI", "MMMDCCVII", "MMMDCCVIII", "MMMDCCIX", "MMMDCCX", "MMMDCCXI", "MMMDCCXII", "MMMDCCXIII", "MMMDCCXIV", "MMMDCCXV", "MMMDCCXVI", "MMMDCCXVII", "MMMDCCXVIII", "MMMDCCXIX", "MMMDCCXX", "MMMDCCXXI", "MMMDCCXXII", "MMMDCCXXIII", "MMMDCCXXIV", "MMMDCCXXV", "MMMDCCXXVI", "MMMDCCXXVII", "MMMDCCXXVIII", "MMMDCCXXIX", "MMMDCCXXX", "MMMDCCXXXI", "MMMDCCXXXII", "MMMDCCXXXIII", "MMMDCCXXXIV", "MMMDCCXXXV", "MMMDCCXXXVI", "MMMDCCXXXVII", "MMMDCCXXXVIII", "MMMDCCXXXIX", "MMMDCCXL", "MMMDCCXLI", "MMMDCCXLII", "MMMDCCXLIII", "MMMDCCXLIV", "MMMDCCXLV", "MMMDCCXLVI", "MMMDCCXLVII", "MMMDCCXLVIII", "MMMDCCXLIX", "MMMDCCL", "MMMDCCLI", "MMMDCCLII", "MMMDCCLIII", "MMMDCCLIV", "MMMDCCLV", "MMMDCCLVI", "MMMDCCLVII", "MMMDCCLVIII", "MMMDCCLIX", "MMMDCCLX", "MMMDCCLXI", "MMMDCCLXII", "MMMDCCLXIII", "MMMDCCLXIV", "MMMDCCLXV", "MMMDCCLXVI", "MMMDCCLXVII", "MMMDCCLXVIII", "MMMDCCLXIX", "MMMDCCLXX", "MMMDCCLXXI", "MMMDCCLXXII", "MMMDCCLXXIII", "MMMDCCLXXIV", "MMMDCCLXXV", "MMMDCCLXXVI", "MMMDCCLXXVII", "MMMDCCLXXVIII", "MMMDCCLXXIX", "MMMDCCLXXX", "MMMDCCLXXXI", "MMMDCCLXXXII", "MMMDCCLXXXIII", "MMMDCCLXXXIV", "MMMDCCLXXXV", "MMMDCCLXXXVI", "MMMDCCLXXXVII", "MMMDCCLXXXVIII", "MMMDCCLXXXIX", "MMMDCCXC", "MMMDCCXCI", "MMMDCCXCII", "MMMDCCXCIII", "MMMDCCXCIV", "MMMDCCXCV", "MMMDCCXCVI", "MMMDCCXCVII", "MMMDCCXCVIII", "MMMDCCXCIX", "MMMDCCC",
"MMMDCCCI", "MMMDCCCII", "MMMDCCCIII", "MMMDCCCIV", "MMMDCCCV", "MMMDCCCVI", "MMMDCCCVII", "MMMDCCCVIII", "MMMDCCCIX", "MMMDCCCX", "MMMDCCCXI", "MMMDCCCXII", "MMMDCCCXIII", "MMMDCCCXIV", "MMMDCCCXV", "MMMDCCCXVI", "MMMDCCCXVII", "MMMDCCCXVIII", "MMMDCCCXIX", "MMMDCCCXX", "MMMDCCCXXI", "MMMDCCCXXII", "MMMDCCCXXIII", "MMMDCCCXXIV", "MMMDCCCXXV", "MMMDCCCXXVI", "MMMDCCCXXVII", "MMMDCCCXXVIII", "MMMDCCCXXIX", "MMMDCCCXXX", "MMMDCCCXXXI", "MMMDCCCXXXII", "MMMDCCCXXXIII", "MMMDCCCXXXIV", "MMMDCCCXXXV", "MMMDCCCXXXVI", "MMMDCCCXXXVII", "MMMDCCCXXXVIII", "MMMDCCCXXXIX", "MMMDCCCXL", "MMMDCCCXLI", "MMMDCCCXLII", "MMMDCCCXLIII", "MMMDCCCXLIV", "MMMDCCCXLV", "MMMDCCCXLVI", "MMMDCCCXLVII", "MMMDCCCXLVIII", "MMMDCCCXLIX", "MMMDCCCL", "MMMDCCCLI", "MMMDCCCLII", "MMMDCCCLIII", "MMMDCCCLIV", "MMMDCCCLV", "MMMDCCCLVI", "MMMDCCCLVII", "MMMDCCCLVIII", "MMMDCCCLIX", "MMMDCCCLX", "MMMDCCCLXI", "MMMDCCCLXII", "MMMDCCCLXIII", "MMMDCCCLXIV", "MMMDCCCLXV", "MMMDCCCLXVI", "MMMDCCCLXVII", "MMMDCCCLXVIII", "MMMDCCCLXIX", "MMMDCCCLXX", "MMMDCCCLXXI", "MMMDCCCLXXII", "MMMDCCCLXXIII", "MMMDCCCLXXIV", "MMMDCCCLXXV", "MMMDCCCLXXVI", "MMMDCCCLXXVII", "MMMDCCCLXXVIII", "MMMDCCCLXXIX", "MMMDCCCLXXX", "MMMDCCCLXXXI", "MMMDCCCLXXXII", "MMMDCCCLXXXIII", "MMMDCCCLXXXIV", "MMMDCCCLXXXV", "MMMDCCCLXXXVI", "MMMDCCCLXXXVII", "MMMDCCCLXXXVIII", "MMMDCCCLXXXIX", "MMMDCCCXC", "MMMDCCCXCI", "MMMDCCCXCII", "MMMDCCCXCIII", "MMMDCCCXCIV", "MMMDCCCXCV", "MMMDCCCXCVI", "MMMDCCCXCVII", "MMMDCCCXCVIII", "MMMDCCCXCIX", "MMMCM",
"MMMCMI", "MMMCMII", "MMMCMIII", "MMMCMIV", "MMMCMV", "MMMCMVI", "MMMCMVII", "MMMCMVIII", "MMMCMIX", "MMMCMX", "MMMCMXI", "MMMCMXII", "MMMCMXIII", "MMMCMXIV", "MMMCMXV", "MMMCMXVI", "MMMCMXVII", "MMMCMXVIII", "MMMCMXIX", "MMMCMXX", "MMMCMXXI", "MMMCMXXII", "MMMCMXXIII", "MMMCMXXIV", "MMMCMXXV", "MMMCMXXVI", "MMMCMXXVII", "MMMCMXXVIII", "MMMCMXXIX", "MMMCMXXX", "MMMCMXXXI", "MMMCMXXXII", "MMMCMXXXIII", "MMMCMXXXIV", "MMMCMXXXV", "MMMCMXXXVI", "MMMCMXXXVII", "MMMCMXXXVIII", "MMMCMXXXIX", "MMMCMXL", "MMMCMXLI", "MMMCMXLII", "MMMCMXLIII", "MMMCMXLIV", "MMMCMXLV", "MMMCMXLVI", "MMMCMXLVII", "MMMCMXLVIII", "MMMCMXLIX", "MMMCML", "MMMCMLI", "MMMCMLII", "MMMCMLIII", "MMMCMLIV", "MMMCMLV", "MMMCMLVI", "MMMCMLVII", "MMMCMLVIII", "MMMCMLIX", "MMMCMLX", "MMMCMLXI", "MMMCMLXII", "MMMCMLXIII", "MMMCMLXIV", "MMMCMLXV", "MMMCMLXVI", "MMMCMLXVII", "MMMCMLXVIII", "MMMCMLXIX", "MMMCMLXX", "MMMCMLXXI", "MMMCMLXXII", "MMMCMLXXIII", "MMMCMLXXIV", "MMMCMLXXV", "MMMCMLXXVI", "MMMCMLXXVII", "MMMCMLXXVIII", "MMMCMLXXIX", "MMMCMLXXX", "MMMCMLXXXI", "MMMCMLXXXII", "MMMCMLXXXIII", "MMMCMLXXXIV", "MMMCMLXXXV", "MMMCMLXXXVI", "MMMCMLXXXVII", "MMMCMLXXXVIII", "MMMCMLXXXIX", "MMMCMXC", "MMMCMXCI", "MMMCMXCII", "MMMCMXCIII", "MMMCMXCIV", "MMMCMXCV", "MMMCMXCVI", "MMMCMXCVII", "MMMCMXCVIII", "MMMCMXCIX" };
class Solution {
public:
string intToRoman(int num) { return cheat_chart[num]; }
};
class Solution00 {
public:
string intToRoman(int num) {
string str_rtn;
str_rtn.append(OneDigitIntToRaman<'M', '?', '?'>(num / 1000));
str_rtn.append(OneDigitIntToRaman<'C', 'D', 'M'>((num / 100) % 10));
str_rtn.append(OneDigitIntToRaman<'X', 'L', 'C'>((num / 10) % 10));
str_rtn += OneDigitIntToRaman<'I', 'V', 'X'>(num % 10);
return str_rtn;
}
private:
template <char ONE, char FIVE, char TEN>
string OneDigitIntToRaman(int num) {
assert(0 <= num && num < 10);
char rtn_val[][5] = {{},
{ONE},
{ONE, ONE},
{ONE, ONE, ONE},
{ONE, FIVE},
{FIVE},
{FIVE, ONE},
{FIVE, ONE, ONE},
{FIVE, ONE, ONE, ONE},
{ONE, TEN}};
return rtn_val[num];
}
};
int main00(void) {
Solution sln;
string rtn = sln.intToRoman(10);
assert(rtn == "X");
rtn = sln.intToRoman(58);
assert(rtn == "LVIII");
rtn = sln.intToRoman(1994);
assert(rtn == "MCMXCIV");
return 0;
}
int main(int argc, char const *argv[]) {
// Solution sln;
// std::ofstream file("out.file");
// for (int i = 1; i < 4000; ++i) {
// file << "\"" << sln.intToRoman(i) << "\", ";
// if(i%100==0) file<<'\n';
// }
// Solution sln;
// Solution00 sln0;
// for (int i = 1; i < 4000; ++i) {
// assert(sln.intToRoman(i) == sln0.intToRoman(i));
// }
size_t max = 0;
for (const auto &str : cheat_arr) {
if (max < str.size())
max = str.size();
}
return 0;
}
| 543.716763 | 1,498 | 0.648331 | LuciusKyle |
4d297430a48c4e706fb72fb72a3f98aebcd32ae8 | 16,035 | cpp | C++ | FGUI/widgets/form.cpp | Jacckii/fgui | 668d80b00c8c3e7908f5f67dd42260fe04ac01e4 | [
"MIT"
] | null | null | null | FGUI/widgets/form.cpp | Jacckii/fgui | 668d80b00c8c3e7908f5f67dd42260fe04ac01e4 | [
"MIT"
] | null | null | null | FGUI/widgets/form.cpp | Jacckii/fgui | 668d80b00c8c3e7908f5f67dd42260fe04ac01e4 | [
"MIT"
] | null | null | null | //
// FGUI - feature rich graphical user interface
//
// library includes
#include "form.hpp"
#include "groupbox.hpp"
namespace FGUI
{
void CForm::Render()
{
// handle input system
FGUI::INPUT.PullInput();
if (FGUI::INPUT.GetKeyPress(GetKey()))
{
// toggle main form on and off
SetState(!GetState());
}
// if the user toggles the main form
if (GetState())
{
// update main form
Update();
// handle main form movement
Movement();
// populate main form geometry
Geometry();
}
// iterate over child forms
for (const std::shared_ptr<FGUI::CForm>& childs : m_prgpForms)
{
if (FGUI::INPUT.GetKeyPress(childs->GetKey()))
{
// toggle child forms on and off
childs->SetState(!childs->GetState());
}
// if the user toggles a child form
if (childs->GetState())
{
// update child forms
childs->Update();
// handle child forms movement
childs->Movement();
// populate child forms geometry
childs->Geometry();
}
}
}
void CForm::SetState(bool onoff)
{
m_bIsOpened = onoff;
}
bool CForm::GetState()
{
return m_bIsOpened;
}
void CForm::AddForm(std::shared_ptr<FGUI::CForm> form)
{
if (!form)
{
return;
}
// populate the form container
m_prgpForms.emplace_back(form);
}
void CForm::AddTab(std::shared_ptr<FGUI::CTabs> tab)
{
if (!tab)
{
return;
}
// select the current tab being added (in case the form doesn't select one for us)
if (!m_prgpTabs.size())
{
m_pSelectedTab = tab;
}
// set parent form
tab->m_pParentForm = std::dynamic_pointer_cast<FGUI::CForm>(shared_from_this());
// populate the tab container
m_prgpTabs.emplace_back(tab);
}
void CForm::AddCallback(std::function<void()> callback)
{
m_fnctCallback = callback;
}
void CForm::SetKey(unsigned int key_code)
{
m_iKey = key_code;
}
void CForm::SetPosition(unsigned int x, unsigned int y)
{
m_ptPosition.m_iX = x;
m_ptPosition.m_iY = y;
}
void CForm::SetSize(unsigned int width, unsigned int height)
{
m_dmSize.m_iWidth = width;
m_dmSize.m_iHeight = height;
}
void CForm::SetSize(FGUI::DIMENSION size)
{
m_dmSize.m_iWidth = size.m_iWidth;
m_dmSize.m_iHeight = size.m_iHeight;
}
void CForm::SetTitle(std::string title)
{
m_strTitle = title;
}
void CForm::SetFlags(int flags)
{
m_nFlags = flags;
}
int CForm::GetKey()
{
return m_iKey;
}
std::string CForm::GetTitle()
{
return m_strTitle;
}
void CForm::SetFont(std::string family, int size, bool bold, int flags)
{
FGUI::RENDER.CreateFont(m_ulFont, family, size, flags, bold);
}
void CForm::SetFont(FGUI::WIDGET_FONT font)
{
FGUI::RENDER.CreateFont(m_ulFont, font.m_strFamily, font.m_iSize, font.m_nFlags, font.m_bBold);
}
FGUI::AREA CForm::GetWidgetArea()
{
// NOTE: if you plan to change the form design, make sure to edit this as well. (this is the area where widgets will be drawned)
return { m_ptPosition.m_iX + 10, m_ptPosition.m_iY + 75, m_dmSize.m_iWidth, m_dmSize.m_iHeight };
}
void CForm::SetFocusedWidget(std::shared_ptr<FGUI::CWidgets> widget)
{
m_pFocusedWidget = widget;
if (widget)
{
m_bIsFocusingOnWidget = true;
}
else
{
m_bIsFocusingOnWidget = false;
}
}
std::shared_ptr<FGUI::CWidgets> CForm::GetFocusedWidget()
{
return m_pFocusedWidget;
}
FGUI::FONT CForm::GetFont()
{
return m_ulFont;
}
bool CForm::GetFlags(FGUI::WIDGET_FLAG flags)
{
if (m_nFlags & static_cast<int>(flags))
{
return true;
}
return false;
}
FGUI::POINT CForm::GetPosition()
{
return m_ptPosition;
}
FGUI::DIMENSION CForm::GetSize()
{
return m_dmSize;
}
void CForm::Geometry()
{
// form body
FGUI::RENDER.Rectangle(m_ptPosition.m_iX, m_ptPosition.m_iY, m_dmSize.m_iWidth, m_dmSize.m_iHeight, { 45, 45, 45 });
FGUI::RENDER.Rectangle(m_ptPosition.m_iX + 1, m_ptPosition.m_iY + 31, m_dmSize.m_iWidth - 2, (m_dmSize.m_iHeight - 30) - 2, { 245, 245, 245 });
// form title
FGUI::RENDER.Text(m_ptPosition.m_iX + 10, m_ptPosition.m_iY + 10, m_ulFont, { 255, 255, 255 }, m_strTitle);
// widget area
FGUI::RENDER.Outline(m_ptPosition.m_iX + 10, (m_ptPosition.m_iY + 31) + 20 + 25, m_dmSize.m_iWidth - 20, (m_dmSize.m_iHeight - 31) - 60, { 195, 195, 195 });
// if the window has a function
if (m_fnctCallback)
{
// invoke function
m_fnctCallback();
}
// don't proceed if the form doesn't have any tabs
if (m_prgpTabs.empty())
{
return;
}
// tab buttons
for (std::size_t i = 0; i < m_prgpTabs.size(); i++)
{
// tab button area
FGUI::AREA arTabRegion = { (m_ptPosition.m_iX + 10) + (static_cast<int>(i) * 113), (m_ptPosition.m_iY + 31) + 20, 110, 25 };
if (FGUI::INPUT.IsCursorInArea(arTabRegion))
{
if (FGUI::INPUT.GetKeyPress(MOUSE_1))
{
// select tab
m_pSelectedTab = m_prgpTabs[i];
}
// unfocus widget
m_pFocusedWidget = nullptr;
}
// draw the buttons according to the tab state
if (m_pSelectedTab == m_prgpTabs[i])
{
FGUI::RENDER.Rectangle(arTabRegion.m_iLeft, arTabRegion.m_iTop - 5, arTabRegion.m_iRight, arTabRegion.m_iBottom + 5, { 45, 45, 45 });
FGUI::RENDER.Text(arTabRegion.m_iLeft + 20, arTabRegion.m_iTop + (arTabRegion.m_iBottom / 2) - 5, m_prgpTabs[i]->GetFont(), { 255, 255, 255 }, m_prgpTabs[i]->GetTitle());
}
else
{
FGUI::RENDER.Rectangle(arTabRegion.m_iLeft, arTabRegion.m_iTop, arTabRegion.m_iRight, arTabRegion.m_iBottom, { 45, 45, 45 });
FGUI::RENDER.Text(arTabRegion.m_iLeft + 20, arTabRegion.m_iTop + (arTabRegion.m_iBottom / 2) - 5, m_prgpTabs[i]->GetFont(), { 220, 220, 220 }, m_prgpTabs[i]->GetTitle());
}
}
// if the user selects a tab
if (m_pSelectedTab)
{
// this will tell the form to skip focused elements (so it can be drawned after all others)
bool bSkipWidget = false;
// this will hold the skipped element
std::shared_ptr<FGUI::CWidgets> pWidgetToSkip = nullptr;
// if the form is focusing on a widget
if (m_bIsFocusingOnWidget)
{
if (m_pFocusedWidget)
{
// assign the widget that will be skipped
pWidgetToSkip = m_pFocusedWidget;
// tell the form to skip this widget
bSkipWidget = true;
}
}
// if the tab doesn't have any widgets, don't proceed
if (m_pSelectedTab->m_prgpWidgets.empty())
{
return;
}
// iterate over the rest of the widgets
for (const std::shared_ptr<FGUI::CWidgets>& pWidgets : m_pSelectedTab->m_prgpWidgets)
{
// if the menu is having a widget skiped
if (bSkipWidget)
{
// check if the widget inside this iteration is not the one that will be skipped
if (pWidgetToSkip == pWidgets)
{
continue;
}
}
// check if widgets are unlocked (able to be drawned)
if (pWidgets && pWidgets->GetFlags(WIDGET_FLAG::DRAWABLE) && pWidgets->IsUnlocked())
{
// found groupbox
std::shared_ptr<FGUI::CGroupBox> pFoundGroupBox = nullptr;
if (pWidgets->GetType() != static_cast<int>(WIDGET_TYPE::GROUPBOX))
{
pFoundGroupBox = pWidgets->m_pParentGroupBox ? std::reinterpret_pointer_cast<FGUI::CGroupBox>(pWidgets->m_pParentGroupBox) : nullptr;
}
if (pFoundGroupBox)
{
// check if the groupbox has scrollbars enabled
if (pFoundGroupBox->GetScrollbarState())
{
// check if the skipped widgets are inside the boundaries of the groupbox
if ((pWidgets->GetAbsolutePosition().m_iY + pWidgets->GetSize().m_iHeight) <= (pFoundGroupBox->GetAbsolutePosition().m_iY + pFoundGroupBox->GetSize().m_iHeight)
&& (pWidgets->GetAbsolutePosition().m_iY >= pFoundGroupBox->GetAbsolutePosition().m_iY))
{
// draw other skipped widgets
pWidgets->Geometry();
}
}
else
{
// draw other widgets
pWidgets->Geometry();
}
}
else if (pWidgets->GetType() == static_cast<int>(WIDGET_TYPE::GROUPBOX) || pWidgets->GetType() == static_cast<int>(WIDGET_TYPE::COLORLIST) || pWidgets->GetType() == static_cast<int>(WIDGET_TYPE::IMAGE))
{
// draw widgets that needs to be outside of a groupbox
pWidgets->Geometry();
}
}
}
// now the form can draw skipped widgets
if (bSkipWidget)
{
if (pWidgetToSkip && pWidgetToSkip->GetFlags(WIDGET_FLAG::DRAWABLE) && pWidgetToSkip->IsUnlocked())
{
// found groupbox
std::shared_ptr<FGUI::CGroupBox> pFoundGroupBox = nullptr;
if (pWidgetToSkip->GetType() != static_cast<int>(WIDGET_TYPE::GROUPBOX))
{
pFoundGroupBox = pWidgetToSkip->m_pParentGroupBox ? std::reinterpret_pointer_cast<FGUI::CGroupBox>(pWidgetToSkip->m_pParentGroupBox) : nullptr;
}
if (pFoundGroupBox)
{
// check if the groupbox has scrollbars enabled
if (pFoundGroupBox->GetScrollbarState())
{
// check if the skipped widgets are inside the boundaries of the groupbox
if ((pWidgetToSkip->GetAbsolutePosition().m_iY + pWidgetToSkip->GetSize().m_iHeight) <= (pFoundGroupBox->GetAbsolutePosition().m_iY + pFoundGroupBox->GetSize().m_iHeight)
&& (pWidgetToSkip->GetAbsolutePosition().m_iY >= pFoundGroupBox->GetAbsolutePosition().m_iY))
{
// draw other skipped widgets
pWidgetToSkip->Geometry();
}
}
else
{
// draw other skipped widgets
pWidgetToSkip->Geometry();
}
}
else if (pWidgetToSkip->GetType() == static_cast<int>(WIDGET_TYPE::GROUPBOX) || pWidgetToSkip->GetType() == static_cast<int>(WIDGET_TYPE::COLORLIST))
{
// draw widgets that needs to be outside of a groupbox
pWidgetToSkip->Geometry();
}
}
}
}
}
void CForm::Update()
{
// don't do updates while the form is closed
if (!m_bIsOpened)
{
return;
}
// form flags
if (GetFlags(WIDGET_FLAG::FULLSCREEN))
{
// change form size
SetSize(FGUI::RENDER.GetScreenSize());
}
// check if the form received a click
bool bCheckWidgetClicks = false;
if (FGUI::INPUT.GetKeyPress(MOUSE_1))
{
// grab screen size
FGUI::DIMENSION dmScreenSize = FGUI::RENDER.GetScreenSize();
// get "clickable" area (you can limit this to the form boundaries instead of using the entire screen.)
FGUI::AREA arClickableRegion = { m_ptPosition.m_iX, m_ptPosition.m_iY, dmScreenSize.m_iWidth, dmScreenSize.m_iHeight };
if (FGUI::INPUT.IsCursorInArea(arClickableRegion))
{
// tell the form that it had received a click
bCheckWidgetClicks = true;
}
}
// if the form doesn't have a tab selected, don't proceed
if (!m_pSelectedTab)
{
return;
}
// if the tab doesn't have any widgets, don't proceed
if (m_pSelectedTab->m_prgpWidgets.empty())
{
return;
}
// this will tell the form to skip focused elements (so it can be drawned after all other's)
bool bSkipWidget = false;
// this will hold the skipped element
std::shared_ptr<FGUI::CWidgets> pWidgetToSkip = nullptr;
// handle updates on the focused widget first
if (m_bIsFocusingOnWidget)
{
if (m_pFocusedWidget)
{
// check if the focused widget is unlocked
if (m_pFocusedWidget->IsUnlocked())
{
// tell the form to skip this widget
bSkipWidget = true;
// assign the widget that will be skipped
pWidgetToSkip = m_pFocusedWidget;
// get focused widget area
FGUI::AREA arFocusedWidgetRegion = { pWidgetToSkip->GetAbsolutePosition().m_iX, pWidgetToSkip->GetAbsolutePosition().m_iY, pWidgetToSkip->GetSize().m_iWidth, pWidgetToSkip->GetSize().m_iHeight };
// update focused widget
pWidgetToSkip->Update();
// check if the focused widget can be clicked
if (pWidgetToSkip->GetFlags(WIDGET_FLAG::CLICKABLE) && FGUI::INPUT.IsCursorInArea(arFocusedWidgetRegion) && bCheckWidgetClicks)
{
// handle input of focused widgets
pWidgetToSkip->Input();
// unfocus this widget
SetFocusedWidget(nullptr);
// tell the form to look for another click
bCheckWidgetClicks = false;
}
}
}
}
// iterate over the rest of the widgets
for (const std::shared_ptr<FGUI::CWidgets>& pWidgets : m_pSelectedTab->m_prgpWidgets)
{
// check if the widgets are unlocked first
if (pWidgets->IsUnlocked())
{
// if the menu is having a widget skiped
if (bSkipWidget)
{
// check if the widget inside this iteration is not the one that will be skipped
if (pWidgetToSkip == pWidgets)
{
continue;
}
}
// found groupbox
std::shared_ptr<FGUI::CGroupBox> pFoundGroupBox = nullptr;
if (pWidgets->GetType() != static_cast<int>(WIDGET_TYPE::GROUPBOX))
{
pFoundGroupBox = pWidgets->m_pParentGroupBox ? std::reinterpret_pointer_cast<FGUI::CGroupBox>(pWidgets->m_pParentGroupBox) : nullptr;
}
// get the widget area
FGUI::AREA arWidgetRegion = { pWidgets->GetAbsolutePosition().m_iX, pWidgets->GetAbsolutePosition().m_iY, pWidgets->GetSize().m_iWidth, pWidgets->GetSize().m_iHeight };
if (pFoundGroupBox)
{
// check if the groupbox has scrollbars enabled
if (pFoundGroupBox->GetScrollbarState())
{
// check if the skipped widgets are inside the boundaries of the groupbox
if ((pWidgets->GetAbsolutePosition().m_iY + pWidgets->GetSize().m_iHeight) <= (pFoundGroupBox->GetAbsolutePosition().m_iY + pFoundGroupBox->GetSize().m_iHeight)
&& (pWidgets->GetAbsolutePosition().m_iY >= pFoundGroupBox->GetAbsolutePosition().m_iY))
{
// update widgets
pWidgets->Update();
// check if the widget can be clicked
if (pWidgets->GetFlags(WIDGET_FLAG::CLICKABLE) && FGUI::INPUT.IsCursorInArea(arWidgetRegion) && bCheckWidgetClicks)
{
// handle widget input
pWidgets->Input();
// tell the form to look for another click
bCheckWidgetClicks = false;
// focus widget
if (pWidgets->GetFlags(WIDGET_FLAG::FOCUSABLE))
{
SetFocusedWidget(pWidgets);
}
else
{
SetFocusedWidget(nullptr);
}
}
}
}
else
{
// update widgets
pWidgets->Update();
// check if the widget can be clicked
if (pWidgets->GetFlags(WIDGET_FLAG::CLICKABLE) && FGUI::INPUT.IsCursorInArea(arWidgetRegion) && bCheckWidgetClicks)
{
// handle widget input
pWidgets->Input();
// tell the form to look for another click
bCheckWidgetClicks = false;
// focus widget
if (pWidgets->GetFlags(WIDGET_FLAG::FOCUSABLE))
{
SetFocusedWidget(pWidgets);
}
else
{
SetFocusedWidget(nullptr);
}
}
}
}
else if (pWidgets->GetType() == static_cast<int>(WIDGET_TYPE::GROUPBOX) || pWidgets->GetType() == static_cast<int>(WIDGET_TYPE::COLORLIST))
{
// update widgets outside a groupbox
pWidgets->Update();
// check if the widgets can be clicked
if (pWidgets->GetFlags(WIDGET_FLAG::CLICKABLE) && FGUI::INPUT.IsCursorInArea(arWidgetRegion) && bCheckWidgetClicks)
{
// handle input
pWidgets->Input();
// tell the form to look for another click
bCheckWidgetClicks = false;
}
}
}
}
}
void CForm::Movement()
{
// don't handle movement while the form is closed
if (!m_bIsOpened)
{
return;
}
// form draggable area
FGUI::AREA arDraggableArea = { m_ptPosition.m_iX, m_ptPosition.m_iY, m_dmSize.m_iWidth, 30 };
if (FGUI::INPUT.IsCursorInArea(arDraggableArea))
{
if (FGUI::INPUT.GetKeyPress(MOUSE_1))
{
// drag form
m_bIsDragging = true;
}
}
// if the user started dragging the form
if (m_bIsDragging)
{
// get cursor position delta
FGUI::POINT ptCursorPosDelta = FGUI::INPUT.GetCursorPosDelta();
// move form
m_ptPosition.m_iX += ptCursorPosDelta.m_iX;
m_ptPosition.m_iY += ptCursorPosDelta.m_iY;
}
if (FGUI::INPUT.GetKeyRelease(MOUSE_1))
{
m_bIsDragging = false;
}
}
} // namespace FGUI | 26.115635 | 207 | 0.65488 | Jacckii |
4d2a1af1df214bd2662ea9af9f4330368f286590 | 5,329 | cpp | C++ | src/clReflectScan/Main.cpp | chip5441/clReflect | d366cced2fff9aefcfc5ec6a0c97ed6c827263eb | [
"MIT"
] | null | null | null | src/clReflectScan/Main.cpp | chip5441/clReflect | d366cced2fff9aefcfc5ec6a0c97ed6c827263eb | [
"MIT"
] | 1 | 2020-02-22T09:59:21.000Z | 2020-02-22T09:59:21.000Z | src/clReflectScan/Main.cpp | chip5441/clReflect | d366cced2fff9aefcfc5ec6a0c97ed6c827263eb | [
"MIT"
] | null | null | null |
//
// ===============================================================================
// clReflect
// -------------------------------------------------------------------------------
// Copyright (c) 2011-2012 Don Williamson & clReflect Authors (see AUTHORS file)
// Released under MIT License (see LICENSE file)
// ===============================================================================
//
#include "ClangFrontend.h"
#include "ASTConsumer.h"
#include "ReflectionSpecs.h"
#include "clReflectCore/Arguments.h"
#include "clReflectCore/Logging.h"
#include "clReflectCore/Database.h"
#include "clReflectCore/DatabaseTextSerialiser.h"
#include "clReflectCore/DatabaseBinarySerialiser.h"
#include "clang/AST/ASTContext.h"
#include <stdio.h>
#include <time.h>
namespace
{
bool FileExists(const char* filename)
{
// For now, just try to open the file
FILE* fp = fopen(filename, "r");
if (fp == 0)
{
return false;
}
fclose(fp);
return true;
}
bool EndsWith(const std::string& str, const std::string& end)
{
return str.rfind(end) == str.length() - end.length();
}
void WriteIncludedHeaders(const ClangParser& ast_parser, const char* outputfile, const char* input_filename)
{
std::vector< std::pair<ClangParser::HeaderType, std::string> > header_files;
ast_parser.GetIncludedFiles(header_files);
FILE* fp = fopen(outputfile, "wt");
// Print to output, noting that the source file will also be in the list
for (size_t i = 0; i < header_files.size(); i++)
{
if (header_files[i].second != input_filename)
{
fprintf(fp, "%c %s",
(header_files[i].first==ClangParser::HeaderType_User) ? 'u' : ( (header_files[i].first==ClangParser::HeaderType_System) ? 's' : 'e'),
header_files[i].second.c_str());
fprintf(fp, "\n");
}
}
fclose(fp);
}
void WriteDatabase(const cldb::Database& db, const std::string& filename)
{
if (EndsWith(filename, ".csv"))
{
cldb::WriteTextDatabase(filename.c_str(), db);
}
else
{
cldb::WriteBinaryDatabase(filename.c_str(), db);
}
}
void TestDBReadWrite(const cldb::Database& db)
{
cldb::WriteTextDatabase("output.csv", db);
cldb::WriteBinaryDatabase("output.bin", db);
cldb::Database indb_text;
cldb::ReadTextDatabase("output.csv", indb_text);
cldb::WriteTextDatabase("output2.csv", indb_text);
cldb::Database indb_bin;
cldb::ReadBinaryDatabase("output.bin", indb_bin);
cldb::WriteBinaryDatabase("output2.bin", indb_bin);
}
}
int main(int argc, const char* argv[])
{
float start = clock();
LOG_TO_STDOUT(main, ALL);
// Leave early if there aren't enough arguments
Arguments args(argc, argv);
if (args.Count() < 2)
{
LOG(main, ERROR, "Not enough arguments\n");
return 1;
}
// Does the input file exist?
const char* input_filename = argv[1];
if (!FileExists(input_filename))
{
LOG(main, ERROR, "Couldn't find the input file %s\n", input_filename);
return 1;
}
float prologue = clock();
// Parse the AST
ClangParser parser(args);
if (!parser.ParseAST(input_filename))
{
LOG(main, ERROR, "Errors parsing the AST\n");
return 1;
}
float parsing = clock();
// Gather reflection specs for the translation unit
clang::ASTContext& ast_context = parser.GetASTContext();
std::string spec_log = args.GetProperty("-spec_log");
ReflectionSpecs reflection_specs(args.Have("-reflect_specs_all"), spec_log);
reflection_specs.Gather(ast_context.getTranslationUnitDecl());
float specs = clock();
// On the second pass, build the reflection database
cldb::Database db;
db.AddBaseTypePrimitives();
std::string ast_log = args.GetProperty("-ast_log");
ASTConsumer ast_consumer(ast_context, db, reflection_specs, ast_log);
ast_consumer.WalkTranlationUnit(ast_context.getTranslationUnitDecl());
float build = clock();
// Add all the container specs
const ReflectionSpecContainer::MapType& container_specs = reflection_specs.GetContainerSpecs();
for (ReflectionSpecContainer::MapType::const_iterator i = container_specs.begin(); i != container_specs.end(); ++i)
{
const ReflectionSpecContainer& c = i->second;
db.AddContainerInfo(i->first, c.read_iterator_type, c.write_iterator_type, c.has_key);
}
// Write included header files if requested
std::string output_headers = args.GetProperty("-output_headers");
if (output_headers!="")
WriteIncludedHeaders(parser, output_headers.c_str(), input_filename);
// Write to a text/binary database depending upon extension
std::string output = args.GetProperty("-output");
if (output != "")
WriteDatabase(db, output);
float dbwrite = clock();
if (args.Have("-test_db"))
TestDBReadWrite(db);
float end = clock();
// Print some rough profiling info
if (args.Have("-timing"))
{
printf("Prologue: %.3f\n", (prologue - start) / CLOCKS_PER_SEC);
printf("Parsing: %.3f\n", (parsing - prologue) / CLOCKS_PER_SEC);
printf("Specs: %.3f\n", (specs - parsing) / CLOCKS_PER_SEC);
printf("Building: %.3f\n", (build - specs) / CLOCKS_PER_SEC);
printf("Database: %.3f\n", (dbwrite - build) / CLOCKS_PER_SEC);
printf("Total time: %.3f\n", (end - start) / CLOCKS_PER_SEC);
}
return 0;
}
| 28.497326 | 139 | 0.64346 | chip5441 |
4d2d672703c5773c83494c90ace77bba3c193a79 | 4,527 | hpp | C++ | include/Mahi/Gui/Transform.hpp | 1over/mahi-gui | a460f831d06746eb0e83555305a3eab174ee85b9 | [
"MIT"
] | 358 | 2020-03-22T05:30:25.000Z | 2022-03-29T13:20:18.000Z | include/Mahi/Gui/Transform.hpp | 1over/mahi-gui | a460f831d06746eb0e83555305a3eab174ee85b9 | [
"MIT"
] | 32 | 2020-03-25T13:16:28.000Z | 2022-02-07T21:58:41.000Z | include/Mahi/Gui/Transform.hpp | 1over/mahi-gui | a460f831d06746eb0e83555305a3eab174ee85b9 | [
"MIT"
] | 64 | 2020-03-22T16:56:59.000Z | 2022-03-19T13:50:18.000Z | // MIT License
//
// Copyright (c) 2020 Mechatronics and Haptic Interfaces Lab - Rice University
//
// 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.
//
// Author(s): Evan Pezent ([email protected])
//
// Adapted from: SFML - Simple and Fast Multimedia Library (license at bottom)
#pragma once
#include <Mahi/Gui/Rect.hpp>
#include <Mahi/Gui/Vec2.hpp>
namespace mahi {
namespace gui {
/// Encapsulates a 3x3 transformation matrix
class Transform {
public:
/// Default constructor
Transform();
/// Construct a transform from a 3x3 matrix
Transform(float a00, float a01, float a02,
float a10, float a11, float a12,
float a20, float a21, float a22);
/// Return the transform as a 4x4 matrix compatible with OpenGL
const float* matrix() const;
/// Return the inverse of the transform
Transform inverse() const;
/// Transform a 2D point
Vec2 transform(float x, float y) const;
/// Transform a 2D point
Vec2 transform(const Vec2& point) const;
/// Transform a rectangle
Rect transform(const Rect& rectangle) const;
/// Combine the current transform with another one
Transform& combine(const Transform& transform);
/// Combine the current transform with a translation
Transform& translate(float x, float y);
/// Combine the current transform with a translation
Transform& translate(const Vec2& offset);
/// Combine the current transform with a rotation
Transform& rotate(float angle);
/// Combine the current transform with a rotation
Transform& rotate(float angle, float centerX, float centerY);
/// Combine the current transform with a rotation
Transform& rotate(float angle, const Vec2& center);
/// Combine the current transform with a scaling
Transform& scale(float scaleX, float scaleY);
/// Combine the current transform with a scaling
Transform& scale(float scaleX, float scaleY, float centerX, float centerY);
/// Combine the current transform with a scaling
Transform& scale(const Vec2& factors);
/// Combine the current transform with a scaling
Transform& scale(const Vec2& factors, const Vec2& center);
public:
static const Transform Identity; ///< The identity transform
private:
float m_matrix[16]; ///< 4x4 matrix defining the transformation
};
/// Equivalent to calling Transform(left).combine(right).
Transform operator*(const Transform& left, const Transform& right);
/// Equivalent to calling left.combine(right).
Transform& operator*=(Transform& left, const Transform& right);
/// Equivalent to calling left.transform(right).
Vec2 operator*(const Transform& left, const Vec2& right);
/// Performs an element-wise comparison of the elements of the
/// left transform with the elements of the right transform.
bool operator==(const Transform& left, const Transform& right);
/// Equivalent to !(left == right).
bool operator!=(const Transform& left, const Transform& right);
} // namespace gui
} // namespace mahi
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2019 Laurent Gomila ([email protected])
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this
// software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
| 41.916667 | 91 | 0.726972 | 1over |
4d2de854dd84ca179d07c01cb4c557641fbd48ce | 1,125 | cpp | C++ | N0413-Arithmetic-Slices/solution1.cpp | loyio/leetcode | 366393c29a434a621592ef6674a45795a3086184 | [
"CC0-1.0"
] | null | null | null | N0413-Arithmetic-Slices/solution1.cpp | loyio/leetcode | 366393c29a434a621592ef6674a45795a3086184 | [
"CC0-1.0"
] | null | null | null | N0413-Arithmetic-Slices/solution1.cpp | loyio/leetcode | 366393c29a434a621592ef6674a45795a3086184 | [
"CC0-1.0"
] | 2 | 2022-01-25T05:31:31.000Z | 2022-02-26T07:22:23.000Z | //
// main.cpp
// LeetCode-Solution
//
// Created by Loyio Hex on 3/3/22.
//
#include <iostream>
#include <chrono>
#include <vector>
using namespace std;
using namespace std::chrono;
class Solution {
public:
int numberOfArithmeticSlices(vector<int>& nums) {
int len = nums.size();
if (len == 1) {
return 0;
}
int d = nums[0] - nums[1];
int t = 0, ans = 0;
for (int i = 2; i < len; ++i) {
if (nums[i - 1] - nums[i] == d) {
++t;
} else {
d = nums[i - 1] - nums[i];
t = 0;
}
ans += t;
}
return ans;
}
};
int main(int argc, const char * argv[]) {
auto start = high_resolution_clock::now();
// Main Start
vector<int> nums = {1,2,3,4};
Solution solution;
cout << solution.numberOfArithmeticSlices(nums);
// Main End
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
cout << endl << "Runnig time : " << duration.count() << "ms;" << endl;
return 0;
}
| 21.226415 | 74 | 0.503111 | loyio |
4d320cb4168e07c288fbf2ffe2ffa85908102660 | 3,339 | cpp | C++ | src/SSAO/GBuffer.cpp | fqhd/Sokuban | 1b41fb6c6e7c865447824eaffce0dff8c7efafa4 | [
"MIT"
] | 1 | 2021-11-17T07:52:45.000Z | 2021-11-17T07:52:45.000Z | src/SSAO/GBuffer.cpp | fqhd/Sokuban | 1b41fb6c6e7c865447824eaffce0dff8c7efafa4 | [
"MIT"
] | null | null | null | src/SSAO/GBuffer.cpp | fqhd/Sokuban | 1b41fb6c6e7c865447824eaffce0dff8c7efafa4 | [
"MIT"
] | null | null | null | #include "GBuffer.hpp"
void GBuffer::init(unsigned int width, unsigned int height){
glGenFramebuffers(1, &m_fboID);
glBindFramebuffer(GL_FRAMEBUFFER, m_fboID);
// - position color buffer
glGenTextures(1, &m_positionTextureID);
glBindTexture(GL_TEXTURE_2D, m_positionTextureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGB, GL_FLOAT, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_positionTextureID, 0);
glBindTexture(GL_TEXTURE_2D, 0);
// - normal color buffer
glGenTextures(1, &m_normalTextureID);
glBindTexture(GL_TEXTURE_2D, m_normalTextureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGB, GL_FLOAT, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, m_normalTextureID, 0);
glBindTexture(GL_TEXTURE_2D, 0);
// - color + specular color buffer
glGenTextures(1, &m_albedoTextureID);
glBindTexture(GL_TEXTURE_2D, m_albedoTextureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, m_albedoTextureID, 0);
glBindTexture(GL_TEXTURE_2D, 0);
// - tell OpenGL which color attachments we'll use (of this framebuffer) for rendering
unsigned int attachments[3] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };
glDrawBuffers(3, attachments);
//Depth buffer
glGenRenderbuffers(1, &m_rboID);
glBindRenderbuffer(GL_RENDERBUFFER, m_rboID);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_rboID);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE){
Utils::log("GBuffer: Failed to create Geomtry Buffer");
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void GBuffer::clear(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void GBuffer::bind(){
glBindFramebuffer(GL_FRAMEBUFFER, m_fboID);
}
void GBuffer::unbind(){
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void GBuffer::destroy(){
glDeleteTextures(1, &m_positionTextureID);
glDeleteTextures(1, &m_albedoTextureID);
glDeleteTextures(1, &m_normalTextureID);
glDeleteRenderbuffers(1, &m_rboID);
glDeleteFramebuffers(1, &m_fboID);
}
GLuint GBuffer::getPositionTextureID(){
return m_positionTextureID;
}
GLuint GBuffer::getNormalTextureID(){
return m_normalTextureID;
}
GLuint GBuffer::getAlbedoTextureID(){
return m_albedoTextureID;
}
| 37.1 | 105 | 0.758311 | fqhd |
2ec0117ea59b42bc7d14cf7d64aef029254fcde2 | 12,084 | cpp | C++ | runtime/qrt/internal_compiler/xacc_internal_compiler.cpp | vetter/qcor | 6f86835737277a26071593bb10dd8627c29d74a3 | [
"BSD-3-Clause"
] | 59 | 2019-08-22T18:40:38.000Z | 2022-03-09T04:12:42.000Z | runtime/qrt/internal_compiler/xacc_internal_compiler.cpp | vetter/qcor | 6f86835737277a26071593bb10dd8627c29d74a3 | [
"BSD-3-Clause"
] | 137 | 2019-09-13T15:50:18.000Z | 2021-12-06T14:19:46.000Z | runtime/qrt/internal_compiler/xacc_internal_compiler.cpp | vetter/qcor | 6f86835737277a26071593bb10dd8627c29d74a3 | [
"BSD-3-Clause"
] | 26 | 2019-07-08T17:30:35.000Z | 2021-12-03T16:24:12.000Z | /*******************************************************************************
* Copyright (c) 2018-, UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the MIT License
* which accompanies this distribution.
*
* Contributors:
* Alexander J. McCaskey - initial API and implementation
* Thien Nguyen - implementation
*******************************************************************************/
#include "xacc_internal_compiler.hpp"
#include "Instruction.hpp"
#include "Utils.hpp"
#include "heterogeneous.hpp"
#include "config_file_parser.hpp"
#include "xacc.hpp"
#include "xacc_service.hpp"
#include "InstructionIterator.hpp"
#include <CompositeInstruction.hpp>
#include <stdlib.h>
// Need to finalize the QuantumRuntime
#include "qrt.hpp"
namespace xacc {
namespace internal_compiler {
std::shared_ptr<Accelerator> qpu = nullptr;
std::shared_ptr<CompositeInstruction> lastCompiled = nullptr;
bool __execute = true;
std::vector<HeterogeneousMap> current_runtime_arguments = {};
void __set_verbose(bool v) { xacc::set_verbose(v); }
void compiler_InitializeXACC(const char *qpu_backend,
const std::vector<std::string> cmd_line_args) {
if (!xacc::isInitialized()) {
xacc::Initialize(cmd_line_args);
xacc::external::load_external_language_plugins();
auto at_exit = []() {
if (quantum::qrt_impl) quantum::qrt_impl->finalize();
xacc::Finalize();
};
atexit(at_exit);
}
setAccelerator(qpu_backend);
}
void compiler_InitializeXACC(const char *qpu_backend, int shots) {
if (!xacc::isInitialized()) {
xacc::Initialize();
xacc::external::load_external_language_plugins();
auto at_exit = []() {
if (quantum::qrt_impl) quantum::qrt_impl->finalize();
xacc::Finalize();
};
atexit(at_exit);
}
setAccelerator(qpu_backend, shots);
}
auto process_qpu_backend_str = [](const std::string &qpu_backend_str)
-> std::pair<std::string, HeterogeneousMap> {
bool has_extra_config = qpu_backend_str.find("[") != std::string::npos;
auto qpu_name =
(has_extra_config)
? qpu_backend_str.substr(0, qpu_backend_str.find_first_of("["))
: qpu_backend_str;
HeterogeneousMap options;
if (has_extra_config) {
auto first = qpu_backend_str.find_first_of("[");
auto second = qpu_backend_str.find_first_of("]");
auto qpu_config = qpu_backend_str.substr(first + 1, second - first - 1);
auto key_values = split(qpu_config, ',');
for (auto key_value : key_values) {
auto tmp = split(key_value, ':');
auto key = tmp[0];
auto value = tmp[1];
if (key == "qcor_qpu_config") {
// If the config is provided in a file:
// We could check for file extension here to
// determine a parsing plugin.
// Currently, we only support a simple key-value format (INI like).
// e.g.
// String like config:
// name=XACC
// Boolean configs
// true_val=true
// false_val=false
// Array/vector configs
// array=[1,2,3]
// array_double=[1.0,2.0,3.0]
auto parser = xacc::getService<ConfigFileParsingUtil>("ini");
options = parser->parse(value);
} else {
// check if int first, then double,
// finally just throw it in as a string
try {
auto i = std::stoi(value);
options.insert(key, i);
} catch (std::exception &e) {
try {
auto d = std::stod(value);
options.insert(key, d);
} catch (std::exception &e) {
options.insert(key, value);
}
}
}
}
}
return std::make_pair(qpu_name, options);
};
void setAccelerator(const char *qpu_backend) {
if (qpu) {
if (qpu_backend != qpu->name()) {
const auto [qpu_name, config] = process_qpu_backend_str(qpu_backend);
qpu = xacc::getAccelerator(qpu_name, config);
}
} else {
const auto [qpu_name, config] = process_qpu_backend_str(qpu_backend);
qpu = xacc::getAccelerator(qpu_name, config);
}
}
void setAccelerator(const char *qpu_backend, int shots) {
if (qpu) {
if (qpu_backend != qpu->name()) {
auto [qpu_name, config] = process_qpu_backend_str(qpu_backend);
config.insert("shots", shots);
qpu = xacc::getAccelerator(qpu_backend, config);
}
} else {
auto [qpu_name, config] = process_qpu_backend_str(qpu_backend);
config.insert("shots", shots);
qpu = xacc::getAccelerator(qpu_backend, {std::make_pair("shots", shots)});
}
}
std::shared_ptr<Accelerator> get_qpu() { return qpu; }
std::shared_ptr<CompositeInstruction> getLastCompiled() { return lastCompiled; }
// Map kernel source string representing a single
// kernel function to a single CompositeInstruction (src to IR)
std::shared_ptr<CompositeInstruction> compile(const char *compiler_name,
const char *kernel_src) {
auto compiler = xacc::getCompiler(compiler_name);
auto IR = compiler->compile(kernel_src, qpu);
auto program = IR->getComposites()[0];
lastCompiled = program;
return program;
}
std::shared_ptr<CompositeInstruction> getCompiled(const char *kernel_name) {
return xacc::hasCompiled(kernel_name) ? xacc::getCompiled(kernel_name)
: nullptr;
}
// Run quantum compilation routines on IR
void optimize(std::shared_ptr<CompositeInstruction> program,
const OptLevel opt) {
xacc::info("[InternalCompiler] Pre-optimization, circuit has " +
std::to_string(program->nInstructions()) + " instructions.");
if (opt == DEFAULT) {
auto optimizer = xacc::getIRTransformation("circuit-optimizer");
optimizer->apply(program, qpu);
} else {
xacc::error("Other Optimization Levels not yet supported.");
}
xacc::info("[InternalCompiler] Post-optimization, circuit has " +
std::to_string(program->nInstructions()) + " instructions.");
}
void execute(AcceleratorBuffer *buffer,
std::vector<std::shared_ptr<CompositeInstruction>> programs) {
qpu->execute(xacc::as_shared_ptr(buffer), programs);
}
// Execute on the specified QPU, persisting results to
// the provided buffer.
void execute(AcceleratorBuffer *buffer,
std::shared_ptr<CompositeInstruction> program,
double *parameters) {
std::shared_ptr<CompositeInstruction> program_as_shared;
if (parameters) {
std::vector<double> values(parameters, parameters + program->nVariables());
program = program->operator()(values);
}
auto buffer_as_shared = std::shared_ptr<AcceleratorBuffer>(
buffer, xacc::empty_delete<AcceleratorBuffer>());
qpu->execute(buffer_as_shared, program);
}
void execute(AcceleratorBuffer **buffers, const int nBuffers,
std::shared_ptr<CompositeInstruction> program,
double *parameters) {
// Should take vector of buffers, and we collapse them
// into a single unified buffer for execution, then set the
// measurement counts accordingly in postprocessing.
std::vector<AcceleratorBuffer *> bvec(buffers, buffers + nBuffers);
std::vector<std::string> buffer_names;
for (auto &a : bvec)
buffer_names.push_back(a->name());
// Do we have any unknown ancilla bits?
std::vector<std::string> possible_extra_buffers;
int possible_size = -1;
InstructionIterator it(program);
while (it.hasNext()) {
auto &next = *it.next();
auto bnames = next.getBufferNames();
for (auto &bb : bnames) {
if (!xacc::container::contains(buffer_names, bb) &&
!xacc::container::contains(possible_extra_buffers, bb)) {
// we have an unknown buffer with name bb, need to figure out its size
// too
possible_extra_buffers.push_back(bb);
}
}
}
for (auto &possible_buffer : possible_extra_buffers) {
std::set<std::size_t> sizes;
InstructionIterator it2(program);
while (it2.hasNext()) {
auto &next = *it2.next();
for (auto &bit : next.bits()) {
sizes.insert(bit);
}
}
auto size = *std::max_element(sizes.begin(), sizes.end());
auto extra = qalloc(size);
extra->setName(possible_buffer);
xacc::debug("[xacc_internal_compiler] Adding extra buffer " +
possible_buffer + " of size " + std::to_string(size));
bvec.push_back(extra.get());
}
// Merge the buffers. Keep track of buffer_name to shift in
// all bit indices operating on that buffer_name, a map of
// buffer names to the buffer ptr, and start a map to collect
// buffer names to measurement counts
int global_reg_size = 0;
std::map<std::string, int> shift_map;
std::vector<std::string> shift_map_names;
std::vector<int> shift_map_shifts;
std::map<std::string, AcceleratorBuffer *> buf_map;
std::map<std::string, std::map<std::string, int>> buf_counts;
for (auto &b : bvec) {
shift_map.insert({b->name(), global_reg_size});
shift_map_names.push_back(b->name());
shift_map_shifts.push_back(global_reg_size);
buf_map.insert({b->name(), b});
buf_counts.insert({b->name(), {}});
global_reg_size += b->size();
}
xacc::debug("[xacc_internal_compiler] Creating register of size " +
std::to_string(global_reg_size));
auto tmp = xacc::qalloc(global_reg_size);
// Update Program bit indices based on new global
// qubit register
InstructionIterator iter(program);
while (iter.hasNext()) {
auto &next = *iter.next();
std::vector<std::size_t> newBits;
int counter = 0;
for (auto &b : next.bits()) {
auto buffer_name = next.getBufferName(counter);
auto shift = shift_map[buffer_name];
newBits.push_back(b + shift);
counter++;
}
next.setBits(newBits);
// FIXME Update buffer_names here too
std::vector<std::string> unified_buf_names;
for (int j = 0; j < next.nRequiredBits(); j++) {
unified_buf_names.push_back("q");
}
next.setBufferNames(unified_buf_names);
}
std::vector<std::size_t> measure_idxs;
InstructionIterator iter2(program);
while (iter2.hasNext()) {
auto &next = *iter2.next();
if (next.name() == "Measure") {
measure_idxs.push_back(next.bits()[0]);
}
}
// Now execute using the global merged register
execute(tmp.get(), program, parameters);
// Take bit strings and map to buffer individual bit strings
for (auto &kv : tmp->getMeasurementCounts()) {
auto bitstring = kv.first;
// Some backends return bitstring of size = number of measures
// instead of size = global_reg_size, adjust if so
if (bitstring.size() == measure_idxs.size()) {
std::string tmps = "";
for (int j = 0; j < global_reg_size; j++)
tmps += "0";
for (int j = 0; j < measure_idxs.size(); j++) {
tmps[measure_idxs[j]] = bitstring[j];
}
bitstring = tmps;
}
// The following processing the bit string assuming LSB
if (qpu->getBitOrder() == Accelerator::BitOrder::MSB) {
std::reverse(bitstring.begin(), bitstring.end());
}
for (int j = 0; j < shift_map_names.size(); j++) {
auto shift = shift_map_shifts[j];
auto buff_name = shift_map_names[j];
auto buffer = buf_map[buff_name];
auto buffer_bitstring = bitstring.substr(shift, buffer->size());
if (qpu->getBitOrder() == Accelerator::BitOrder::MSB) {
std::reverse(buffer_bitstring.begin(), buffer_bitstring.end());
}
if (buf_counts[buff_name].count(buffer_bitstring)) {
buf_counts[buff_name][buffer_bitstring] += kv.second;
} else {
buf_counts[buff_name].insert({buffer_bitstring, kv.second});
}
}
}
for (auto &b : bvec) {
b->setMeasurements(buf_counts[b->name()]);
b->addExtraInfo("endianness",
qpu->getBitOrder() == Accelerator::BitOrder::LSB ? "lsb"
: "msb");
}
}
} // namespace internal_compiler
} // namespace xacc | 33.566667 | 81 | 0.638613 | vetter |
2ec02fda5fe7db14036fea086c6c492bcfbc1353 | 1,017 | cpp | C++ | programs/chapter_10/old/example_10_0/modules/pir/pir.cpp | epernia/arm_book | ffdd17618c2c7372cef338fc743f517bf6f0f42b | [
"BSD-3-Clause"
] | 2 | 2021-05-03T17:21:37.000Z | 2021-06-08T08:32:07.000Z | programs/chapter_10/old/example_10_0/modules/pir/pir.cpp | epernia/arm_book | ffdd17618c2c7372cef338fc743f517bf6f0f42b | [
"BSD-3-Clause"
] | null | null | null | programs/chapter_10/old/example_10_0/modules/pir/pir.cpp | epernia/arm_book | ffdd17618c2c7372cef338fc743f517bf6f0f42b | [
"BSD-3-Clause"
] | 2 | 2020-10-14T19:06:24.000Z | 2021-06-08T08:32:09.000Z | //=====[Libraries]=============================================================
#include "mbed.h"
#include "pir.h"
//=====[Declaration of private defines]======================================
//=====[Declaration of private data types]=====================================
//=====[Declaration and initialization of public global objects]===============
InterruptIn pir(PC_3);
DigitalOut pirOutput(PF_3);
//=====[Declaration of external public global variables]=======================
//=====[Declaration and initialization of public global variables]=============
//=====[Declaration and initialization of private global variables]============
//=====[Declarations (prototypes) of private functions]========================
void pirUpdate();
//=====[Implementations of public functions]===================================
void pirSensorInit()
{
pir.rise(&pirUpdate);
}
void pirUpdate()
{
pirOutput = !pirOutput;
}
//=====[Implementations of private functions]==================================
| 26.076923 | 79 | 0.496559 | epernia |
2ec12e9175f0a442ed2324081911c226e60a13f4 | 4,563 | cpp | C++ | src/hir_expand/erased_types.cpp | bjorn3/mrustc | 01f73e7894119405ab3f92b6191f044e491c9062 | [
"MIT"
] | 1,706 | 2015-01-18T11:01:10.000Z | 2022-03-31T00:31:54.000Z | src/hir_expand/erased_types.cpp | bjorn3/mrustc | 01f73e7894119405ab3f92b6191f044e491c9062 | [
"MIT"
] | 215 | 2015-03-26T10:31:36.000Z | 2022-03-13T02:04:13.000Z | src/hir_expand/erased_types.cpp | bjorn3/mrustc | 01f73e7894119405ab3f92b6191f044e491c9062 | [
"MIT"
] | 114 | 2015-03-26T10:29:02.000Z | 2022-03-21T20:59:37.000Z | /*
* MRustC - Rust Compiler
* - By John Hodge (Mutabah/thePowersGang)
*
* hir_expand/erased_types.cpp
* - HIR Expansion - Replace `impl Trait` with the real type
*/
#include <hir/visitor.hpp>
#include <hir/expr.hpp>
#include <hir_typeck/static.hpp>
#include <algorithm>
#include "main_bindings.hpp"
namespace {
class ExprVisitor_Extract:
public ::HIR::ExprVisitorDef
{
const StaticTraitResolve& m_resolve;
public:
ExprVisitor_Extract(const StaticTraitResolve& resolve):
m_resolve(resolve)
{
}
void visit_root(::HIR::ExprPtr& root)
{
root->visit(*this);
visit_type(root->m_res_type);
for(auto& ty : root.m_bindings)
visit_type(ty);
for(auto& ty : root.m_erased_types)
visit_type(ty);
}
void visit_node_ptr(::std::unique_ptr< ::HIR::ExprNode>& node_ptr) override {
assert(node_ptr);
node_ptr->visit(*this);
visit_type(node_ptr->m_res_type);
}
void visit_type(::HIR::TypeRef& ty) override
{
static Span sp;
if( ty.data().is_ErasedType() )
{
TRACE_FUNCTION_FR(ty, ty);
const auto& e = ty.data().as_ErasedType();
MonomorphState monomorph_cb;
auto val = m_resolve.get_value(sp, e.m_origin, monomorph_cb);
const auto& fcn = *val.as_Function();
const auto& erased_types = fcn.m_code.m_erased_types;
ASSERT_BUG(sp, e.m_index < erased_types.size(), "Erased type index out of range for " << e.m_origin << " - " << e.m_index << " >= " << erased_types.size());
const auto& tpl = erased_types[e.m_index];
auto new_ty = monomorph_cb.monomorph_type(sp, tpl);
m_resolve.expand_associated_types(sp, new_ty);
DEBUG("> " << ty << " => " << new_ty);
ty = mv$(new_ty);
// Recurse (TODO: Cleanly prevent infinite recursion - TRACE_FUNCTION does crude prevention)
visit_type(ty);
}
else
{
::HIR::ExprVisitorDef::visit_type(ty);
}
}
};
class OuterVisitor:
public ::HIR::Visitor
{
StaticTraitResolve m_resolve;
const ::HIR::ItemPath* m_fcn_path = nullptr;
public:
OuterVisitor(const ::HIR::Crate& crate):
m_resolve(crate)
{}
void visit_expr(::HIR::ExprPtr& exp) override
{
if( exp )
{
ExprVisitor_Extract ev(m_resolve);
ev.visit_root( exp );
}
}
void visit_function(::HIR::ItemPath p, ::HIR::Function& fcn) override
{
m_fcn_path = &p;
::HIR::Visitor::visit_function(p, fcn);
m_fcn_path = nullptr;
}
};
class OuterVisitor_Fixup:
public ::HIR::Visitor
{
StaticTraitResolve m_resolve;
public:
OuterVisitor_Fixup(const ::HIR::Crate& crate):
m_resolve(crate)
{}
void visit_type(::HIR::TypeRef& ty) override
{
static const Span sp;
if( ty.data().is_ErasedType() )
{
const auto& e = ty.data().as_ErasedType();
TRACE_FUNCTION_FR(ty, ty);
MonomorphState monomorph_cb;
auto val = m_resolve.get_value(sp, e.m_origin, monomorph_cb);
const auto& fcn = *val.as_Function();
const auto& erased_types = fcn.m_code.m_erased_types;
ASSERT_BUG(sp, e.m_index < erased_types.size(), "Erased type index out of range for " << e.m_origin << " - " << e.m_index << " >= " << erased_types.size());
const auto& tpl = erased_types[e.m_index];
auto new_ty = monomorph_cb.monomorph_type(sp, tpl);
DEBUG("> " << ty << " => " << new_ty);
ty = mv$(new_ty);
// Recurse (TODO: Cleanly prevent infinite recursion - TRACE_FUNCTION does crude prevention)
visit_type(ty);
}
else
{
::HIR::Visitor::visit_type(ty);
}
}
};
}
void HIR_Expand_ErasedType(::HIR::Crate& crate)
{
OuterVisitor ov(crate);
ov.visit_crate( crate );
OuterVisitor_Fixup ov_fix(crate);
ov_fix.visit_crate(crate);
}
| 30.218543 | 172 | 0.526846 | bjorn3 |
2ec2130a3012d5f534b52827cbebfd8040e4ea68 | 3,624 | cxx | C++ | reflow/dtls_wrapper/DtlsFactory.cxx | dulton/reSipServer | ac4241df81c1e3eef2e678271ffef4dda1fc6747 | [
"Apache-2.0"
] | 1 | 2019-04-15T14:10:58.000Z | 2019-04-15T14:10:58.000Z | reflow/dtls_wrapper/DtlsFactory.cxx | dulton/reSipServer | ac4241df81c1e3eef2e678271ffef4dda1fc6747 | [
"Apache-2.0"
] | null | null | null | reflow/dtls_wrapper/DtlsFactory.cxx | dulton/reSipServer | ac4241df81c1e3eef2e678271ffef4dda1fc6747 | [
"Apache-2.0"
] | 2 | 2019-10-31T09:11:09.000Z | 2021-09-17T01:00:49.000Z | #ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef USE_SSL
#include <cassert>
#include <iostream>
#include <rutil/ssl/OpenSSLInit.hxx>
#include <openssl/e_os2.h>
#include <openssl/rand.h>
#include <openssl/err.h>
#include <openssl/crypto.h>
#include <openssl/ssl.h>
#include "DtlsFactory.hxx"
#include "DtlsSocket.hxx"
using namespace dtls;
const char* DtlsFactory::DefaultSrtpProfile = "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32";
DtlsFactory::DtlsFactory(std::auto_ptr<DtlsTimerContext> tc,X509 *cert, EVP_PKEY *privkey):
mTimerContext(tc),
mCert(cert)
{
int r;
mContext=SSL_CTX_new(DTLSv1_method());
assert(mContext);
r=SSL_CTX_use_certificate(mContext, cert);
assert(r==1);
r=SSL_CTX_use_PrivateKey(mContext, privkey);
assert(r==1);
// Set SRTP profiles
r=SSL_CTX_set_tlsext_use_srtp(mContext, DefaultSrtpProfile);
assert(r==0);
}
DtlsFactory::~DtlsFactory()
{
SSL_CTX_free(mContext);
}
DtlsSocket*
DtlsFactory::createClient(std::auto_ptr<DtlsSocketContext> context)
{
return new DtlsSocket(context,this,DtlsSocket::Client);
}
DtlsSocket*
DtlsFactory::createServer(std::auto_ptr<DtlsSocketContext> context)
{
return new DtlsSocket(context,this,DtlsSocket::Server);
}
void
DtlsFactory::getMyCertFingerprint(char *fingerprint)
{
DtlsSocket::computeFingerprint(mCert,fingerprint);
}
void
DtlsFactory::setSrtpProfiles(const char *str)
{
int r;
r=SSL_CTX_set_tlsext_use_srtp(mContext,str);
assert(r==0);
}
void
DtlsFactory::setCipherSuites(const char *str)
{
int r;
r=SSL_CTX_set_cipher_list(mContext,str);
assert(r==1);
}
DtlsFactory::PacketType
DtlsFactory::demuxPacket(const unsigned char *data, unsigned int len)
{
assert(len>=1);
if((data[0]==0) || (data[0]==1))
return stun;
if((data[0]>=128) && (data[0]<=191))
return rtp;
if((data[0]>=20) && (data[0]<=64))
return dtls;
return unknown;
}
#endif //USE_SSL
/* ====================================================================
Copyright (c) 2007-2008, Eric Rescorla and Derek MacDonald
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. None of the contributors names may be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
==================================================================== */
| 26.452555 | 94 | 0.715232 | dulton |
2ec329002a0f52f0f7939833605fed1fad4d4a0d | 2,485 | cpp | C++ | test/op/Conv2DBackPropTest.cpp | z415073783/MNN | 62c5ca47964407508a5fa802582e648fc75eb0d9 | [
"Apache-2.0"
] | null | null | null | test/op/Conv2DBackPropTest.cpp | z415073783/MNN | 62c5ca47964407508a5fa802582e648fc75eb0d9 | [
"Apache-2.0"
] | 1 | 2021-09-07T09:13:03.000Z | 2021-09-07T09:13:03.000Z | test/op/Conv2DBackPropTest.cpp | z415073783/MNN | 62c5ca47964407508a5fa802582e648fc75eb0d9 | [
"Apache-2.0"
] | 1 | 2020-03-10T02:17:47.000Z | 2020-03-10T02:17:47.000Z | //
// Conv2DBackPropTest.cpp
// MNNTests
//
// Created by MNN on 2019/9/26.
// Copyright © 2018, Alibaba Group Holding Limited
//
#include "MNNTestSuite.h"
#include "Expr.hpp"
#include "ExprCreator.hpp"
#include "TestUtils.h"
using namespace MNN::Express;
class Conv2DBackPropTest : public MNNTestCase{
virtual ~Conv2DBackPropTest() = default;
virtual bool run(){
const float inputGradData[] = {
1., 1., 1.,
1., 1., 1.,
1., 1., 1
}; // 1x1x3x3
auto inputGrad = _Const(inputGradData, {1, 1, 3, 3}, NCHW);
inputGrad = _Convert(inputGrad, NC4HW4);
const float weightData[] = {
1., 1., 1.,
1., 1., 1.,
1., 1., 1.,
1., 1., 1.,
1., 1., 1.,
1., 1., 1.,
1., 1., 1.,
1., 1., 1.,
1., 1., 1.}; // 1x3x3x3
auto weight = _Const(weightData, {1,3,3,3}, NCHW);
auto bias = _Const(0., {1}, NCHW);
auto outputGrad = _Deconv(weight, bias, inputGrad);
outputGrad = _Convert(outputGrad, NCHW);
auto outputGradDim = outputGrad->getInfo()->dim;
const int outSize = outputGrad->getInfo()->size;
if(outputGrad->getInfo()->size != outSize){
return false;
}
const std::vector<int> expectedDim = {1,3,5,5};
if(!checkVector<int>(outputGradDim.data(), expectedDim.data(), 4, 0)){
MNN_ERROR("Conv2DBackProp shape test failed!\n");
return false;
}
const float expectedOutputGrad[] = {
1., 2., 3., 2., 1.,
2., 4., 6., 4., 2.,
3., 6., 9., 6., 3.,
2., 4., 6., 4., 2.,
1., 2., 3., 2., 1.,
1., 2., 3., 2., 1.,
2., 4., 6., 4., 2.,
3., 6., 9., 6., 3.,
2., 4., 6., 4., 2.,
1., 2., 3., 2., 1.,
1., 2., 3., 2., 1.,
2., 4., 6., 4., 2.,
3., 6., 9., 6., 3.,
2., 4., 6., 4., 2.,
1., 2., 3., 2., 1.};
auto outputGradData = outputGrad->readMap<float>();
if(!checkVector<float>(outputGradData, expectedOutputGrad, outSize, 0.01)){
MNN_ERROR("Conv2DBackProp test failed!\n");
return false;
}
return true;
}
};
MNNTestSuiteRegister(Conv2DBackPropTest, "op/Conv2DBackPropTest");
| 28.895349 | 83 | 0.452314 | z415073783 |
2ecb0e9f2302503b0c1a8944fbdaf30fe9cc14b5 | 7,820 | cpp | C++ | moai/src/zlcore/ZLFile.cpp | jjimenezg93/ai-pathfinding | e32ae8be30d3df21c7e64be987134049b585f1e6 | [
"MIT"
] | null | null | null | moai/src/zlcore/ZLFile.cpp | jjimenezg93/ai-pathfinding | e32ae8be30d3df21c7e64be987134049b585f1e6 | [
"MIT"
] | null | null | null | moai/src/zlcore/ZLFile.cpp | jjimenezg93/ai-pathfinding | e32ae8be30d3df21c7e64be987134049b585f1e6 | [
"MIT"
] | null | null | null | // Copyright (c) 2010-2011 Zipline Games, Inc. All Rights Reserved.
// http://getmoai.com
#include "pch.h"
#ifdef NACL
#include "NaClFile.h"
#endif
#include <zlcore/zl_util.h>
#include <zlcore/ZLFile.h>
#include <zlcore/ZLFileSystem.h>
#include <zlcore/ZLVirtualPath.h>
#include <zlcore/ZLZipStream.h>
#ifdef MOAI_COMPILER_MSVC
#include <Share.h>
#endif
using namespace std;
//================================================================//
// ZLFile
//================================================================//
//----------------------------------------------------------------//
void ZLFile::ClearError () {
if ( !this->mIsZip ) {
clearerr ( this->mPtr.mFile );
}
}
//----------------------------------------------------------------//
int ZLFile::Close () {
int result = 0;
if ( this->mIsZip ) {
if ( this->mPtr.mZip ) {
delete this->mPtr.mZip;
this->mPtr.mZip = 0;
}
}
else if ( this->mPtr.mFile ) {
result = fclose ( this->mPtr.mFile );
this->mPtr.mFile = 0;
}
return result;
}
//----------------------------------------------------------------//
int ZLFile::CloseProcess () {
FILE* stdFile = 0;
if ( !this->mIsZip ) {
stdFile = this->mPtr.mFile;
this->mPtr.mFile = 0;
}
#ifdef MOAI_OS_WINDOWS
return _pclose ( stdFile );
#else
return pclose ( stdFile );
#endif
}
//----------------------------------------------------------------//
int ZLFile::Flush () {
if ( !this->mIsZip ) {
return fflush ( this->mPtr.mFile );
}
return 0;
}
//----------------------------------------------------------------//
int ZLFile::GetChar () {
int result = EOF;
if ( this->mIsZip ) {
char c;
result = ( int )this->mPtr.mZip->Read ( &c, 1 );
if ( result == 1 ) {
result = c;
}
}
else {
result = fgetc ( this->mPtr.mFile );
}
return result;
}
//----------------------------------------------------------------//
int ZLFile::GetError () {
return ( this->mIsZip ) ? 0 : ferror ( this->mPtr.mFile ); // TODO: error flag for zip file
}
//----------------------------------------------------------------//
int ZLFile::GetFileNum () {
// TODO:
if ( !this->mIsZip ) {
return fileno ( this->mPtr.mFile );
}
return -1;
}
//----------------------------------------------------------------//
int ZLFile::GetPos ( fpos_t* position ) {
(( void )position );
assert ( 0 ); // not implemented
return -1;
}
//----------------------------------------------------------------//
char* ZLFile::GetString ( char* string, int length ) {
int i = 0;
int c = 0;
if ( this->mIsZip ) {
if ( length <= 1 ) return 0;
do {
c = this->GetChar ();
if ( c == ( int )EOF || c == ( int )NULL ) break;
string [ i++ ] = ( char )c;
if ( i >= length ) return 0;
} while ( c && ( c != '\n' ));
if ( i == 0 ) {
return 0;
}
string [ i ] = 0;
return string;
}
return fgets ( string, length, this->mPtr.mFile );
}
//----------------------------------------------------------------//
int ZLFile::IsEOF () {
return ( this->mIsZip ) ? this->mPtr.mZip->IsAtEnd () : feof ( this->mPtr.mFile );
}
//----------------------------------------------------------------//
int ZLFile::Open ( const char* filename, const char* mode ) {
ZLVirtualPath* mount;
string abspath = ZLFileSystem::Get ().GetAbsoluteFilePath ( filename );
filename = abspath.c_str ();
mount = ZLFileSystem::Get ().FindBestVirtualPath ( filename );
if ( mount ) {
if ( mode [ 0 ] == 'r' ) {
ZLZipStream* zipStream = 0;
filename = mount->GetLocalPath ( filename );
if ( filename ) {
zipStream = ZLZipStream::Open ( mount->mArchive, filename );
}
if ( zipStream ) {
this->mIsZip = 1;
this->mPtr.mZip = zipStream;
return 0;
}
}
}
else {
#ifdef MOAI_COMPILER_MSVC
FILE* stdFile = 0;
stdFile = _fsopen ( filename, mode, _SH_DENYNO );
#else
FILE* stdFile = fopen ( filename, mode );
#endif
if ( stdFile ) {
this->mPtr.mFile = stdFile;
return 0;
}
}
return -1;
}
//----------------------------------------------------------------//
int ZLFile::OpenProcess ( const char *command, const char *mode ) {
FILE* stdFile = 0;
#ifdef MOAI_OS_WINDOWS
stdFile = _popen ( command, mode );
#else
stdFile = popen ( command, mode );
#endif
if ( stdFile ) {
this->mPtr.mFile = stdFile;
return 0;
}
return -1;
}
//----------------------------------------------------------------//
int ZLFile::OpenTemp () {
this->mPtr.mFile = tmpfile ();
return this->mPtr.mFile ? 0 : -1;
}
//----------------------------------------------------------------//
int ZLFile::PutChar ( int c ) {
if ( !this->mIsZip ) {
return fputc ( c, this->mPtr.mFile );
}
return EOF;
}
//----------------------------------------------------------------//
int ZLFile::PutString ( const char* string ) {
if ( !this->mIsZip ) {
return fputs ( string, this->mPtr.mFile );
}
return EOF;
}
//----------------------------------------------------------------//
size_t ZLFile::Read ( void* buffer, size_t size, size_t count ) {
if ( this->mIsZip ) {
size_t result = ( size_t )this->mPtr.mZip->Read ( buffer, size * count );
return ( size_t )( result / size );
}
return fread ( buffer, size, count, this->mPtr.mFile );
}
//----------------------------------------------------------------//
int ZLFile::Reopen ( const char* filename, const char* mode ) {
if ( this->mIsZip ) {
this->Close ();
return this->Open ( filename, mode );
}
else {
FILE* stdFile = freopen ( filename, mode, this->mPtr.mFile );
if ( stdFile ) {
this->mPtr.mFile = stdFile;
return 0;
}
}
return -1;
}
//----------------------------------------------------------------//
int ZLFile::Seek ( long offset, int origin ) {
return ( this->mIsZip ) ? this->mPtr.mZip->Seek ( offset, origin ) : fseek ( this->mPtr.mFile, offset, origin );
}
//----------------------------------------------------------------//
void ZLFile::SetFile ( FILE* file ) {
this->Flush ();
this->mPtr.mFile = file;
this->mIsZip = false;
}
//----------------------------------------------------------------//
int ZLFile::SetPos ( const fpos_t * pos ) {
(( void )pos );
assert ( 0 ); // not implemented
return -1;
}
//----------------------------------------------------------------//
long ZLFile::Tell () {
return ( this->mIsZip ) ? ( long )this->mPtr.mZip->Tell () : ftell ( this->mPtr.mFile );
}
//----------------------------------------------------------------//
size_t ZLFile::Write ( const void* data, size_t size, size_t count ) {
if ( !this->mIsZip ) {
return fwrite ( data, size, count, this->mPtr.mFile );
}
return 0;
}
//----------------------------------------------------------------//
void ZLFile::SetBuf ( char* buffer ) {
if ( !this->mIsZip ) {
setbuf ( this->mPtr.mFile, buffer );
}
}
//----------------------------------------------------------------//
int ZLFile::SetVBuf ( char* buffer, int mode, size_t size ) {
if ( !this->mIsZip ) {
setvbuf ( this->mPtr.mFile, buffer, mode, size );
}
return 0;
}
//----------------------------------------------------------------//
int ZLFile::UnGetChar ( int character ) {
if ( this->mIsZip ) {
return this->mPtr.mZip->UnGetChar (( char )character ) ? EOF : 0;
}
return ungetc ( character, this->mPtr.mFile );
}
//----------------------------------------------------------------//
int ZLFile::VarPrintf ( const char* format, va_list arg ) {
if ( !this->mIsZip ) {
return vfprintf ( this->mPtr.mFile, format, arg );
}
return -1;
}
//----------------------------------------------------------------//
ZLFile::ZLFile () :
mIsZip ( false ) {
this->mPtr.mFile = 0;
this->mPtr.mZip = 0;
}
//----------------------------------------------------------------//
ZLFile::~ZLFile () {
this->Close ();
}
| 21.966292 | 113 | 0.438491 | jjimenezg93 |
2ed0eaef2a0c250f055097d9314285f0f213c6e5 | 3,752 | cpp | C++ | engine/src/Resources.cpp | CutiaGames/CutiaEngine | b81d9e7a01c7ec6f49d2a94df1a1976ac7634151 | [
"MIT"
] | 1 | 2018-05-11T04:11:27.000Z | 2018-05-11T04:11:27.000Z | engine/src/Resources.cpp | CutiaGames/CutiaEngine | b81d9e7a01c7ec6f49d2a94df1a1976ac7634151 | [
"MIT"
] | 8 | 2018-05-11T03:15:30.000Z | 2018-06-06T18:47:58.000Z | engine/src/Resources.cpp | CutiaGames/CutiaEngine | b81d9e7a01c7ec6f49d2a94df1a1976ac7634151 | [
"MIT"
] | 1 | 2018-05-11T16:28:17.000Z | 2018-05-11T16:28:17.000Z | #include "Resources.hpp"
#include "Game.hpp"
std::unordered_map<std::string, std::shared_ptr<SDL_Texture> > Resources::imageTable;
std::unordered_map<std::string, std::shared_ptr<Mix_Music> > Resources::musicTable;
std::unordered_map<std::string, std::shared_ptr<Mix_Chunk> > Resources::soundTable;
std::unordered_map<std::string, std::shared_ptr<TTF_Font> > Resources::fontTable;
void Resources::ClearAll()
{
ClearMusics();
ClearSounds();
ClearImages();
ClearFonts();
}
std::shared_ptr<SDL_Texture> Resources::GetImage(std::string file)
{
auto search = imageTable.find(file);
if(search != imageTable.end())
{
return search->second;
}
SDL_Texture* texture = IMG_LoadTexture(Game::GetInstance().GetRenderer(), file.c_str());
if(texture == nullptr)
{
printf("[ERROR] IMG_LoadTexture: %s\n", SDL_GetError());
return std::shared_ptr<SDL_Texture>(texture, [](SDL_Texture* texture) { SDL_DestroyTexture(texture); });
}
imageTable.insert({file, std::shared_ptr<SDL_Texture>(texture, [](SDL_Texture* texture) { SDL_DestroyTexture(texture); })});
return imageTable[file];
}
void Resources::ClearImages()
{
for(auto image: imageTable)
{
if(image.second.unique())
{
imageTable.erase(image.first);
}
}
imageTable.clear();
}
std::shared_ptr<Mix_Music> Resources::GetMusic(std::string file)
{
auto search = musicTable.find(file);
if(search != musicTable.end())
{
return search->second;
}
Mix_Music* music = Mix_LoadMUS(file.c_str());
if(music == nullptr)
{
printf("[ERROR] Mix_LoadMUS: %s\n", SDL_GetError());
return std::shared_ptr<Mix_Music>(music, [](Mix_Music* music) { Mix_FreeMusic(music); });
}
musicTable.insert({file, std::shared_ptr<Mix_Music>(music, [](Mix_Music* music) { Mix_FreeMusic(music); }) });
return musicTable[file];
}
void Resources::ClearMusics()
{
for(auto music: musicTable)
{
if(music.second.unique())
{
musicTable.erase(music.first);
}
}
musicTable.clear();
}
std::shared_ptr<Mix_Chunk> Resources::GetSound(std::string file)
{
auto search = soundTable.find(file);
if(search != soundTable.end())
{
return search->second;
}
Mix_Chunk* sound = Mix_LoadWAV(file.c_str());
if(sound == nullptr)
{
printf("[ERROR] Mix_LoadWAV: %s\n", SDL_GetError());
return std::shared_ptr<Mix_Chunk>(sound, [](Mix_Chunk* sound) {Mix_FreeChunk(sound);});
}
soundTable.insert({file, std::shared_ptr<Mix_Chunk>(sound, [](Mix_Chunk* sound) {Mix_FreeChunk(sound);}) });
return soundTable[file];
}
void Resources::ClearSounds()
{
for(auto sound: soundTable)
{
if(sound.second.unique())
{
soundTable.erase(sound.first);
}
}
soundTable.clear();
}
std::shared_ptr<TTF_Font> Resources::GetFont(std::string file, int ptsize)
{
std::string key = std::to_string(ptsize) + file;
auto search = fontTable.find(key);
if(search != fontTable.end())
{
return search->second;
}
TTF_Font* texture = TTF_OpenFont(file.c_str(), ptsize);
if(texture == nullptr)
{
printf("[ERROR] IMG_LoadTexture: %s\n", SDL_GetError());
return std::shared_ptr<TTF_Font>(texture, [](TTF_Font* font) { TTF_CloseFont(font); });
}
fontTable.insert({key, std::shared_ptr<TTF_Font>(texture, [](TTF_Font* font) { TTF_CloseFont(font); })});
return fontTable[key];
}
void Resources::ClearFonts()
{
for(auto font: fontTable)
{
if(font.second.unique())
{
fontTable.erase(font.first);
}
}
fontTable.clear();
}
| 25.52381 | 128 | 0.628465 | CutiaGames |
2ed5a119a57866d3d9245c88f8f3627f76a20b66 | 436 | cpp | C++ | src/sound/save_effect.cpp | Damdoshi/LibLapin | 800e0f17ed8f3c47797c48feea4c280bb0e4bdc9 | [
"BSD-3-Clause"
] | 38 | 2016-07-30T09:35:19.000Z | 2022-03-04T10:13:48.000Z | src/sound/save_effect.cpp | Elania-Marvers/LibLapin | 800e0f17ed8f3c47797c48feea4c280bb0e4bdc9 | [
"BSD-3-Clause"
] | 15 | 2017-02-12T19:20:52.000Z | 2021-06-09T09:30:52.000Z | src/sound/save_effect.cpp | Elania-Marvers/LibLapin | 800e0f17ed8f3c47797c48feea4c280bb0e4bdc9 | [
"BSD-3-Clause"
] | 12 | 2016-10-06T09:06:59.000Z | 2022-03-04T10:14:00.000Z | // Jason Brillante "Damdoshi"
// Hanged Bunny Studio 2014-2018
//
// Bibliotheque Lapin
#include <string.h>
#include "lapin_private.h"
#define PATTERN "%s -> %p"
bool bunny_save_effect(const t_bunny_effect *_eff,
const char *file)
{
struct bunny_effect *eff = (struct bunny_effect*)_eff;
if (bunny_compute_effect((t_bunny_effect*)_eff) == false)
return (false);
return (eff->effect->saveToFile(file));
}
| 20.761905 | 59 | 0.68578 | Damdoshi |
2ed73b79bc251975da43140d2079171c5afb7147 | 1,359 | hpp | C++ | include/eepp/graphics/fonthelper.hpp | dogtwelve/eepp | dd672ff0e108ae1e08449ca918dc144018fb4ba4 | [
"MIT"
] | null | null | null | include/eepp/graphics/fonthelper.hpp | dogtwelve/eepp | dd672ff0e108ae1e08449ca918dc144018fb4ba4 | [
"MIT"
] | null | null | null | include/eepp/graphics/fonthelper.hpp | dogtwelve/eepp | dd672ff0e108ae1e08449ca918dc144018fb4ba4 | [
"MIT"
] | null | null | null | #ifndef EE_GRAPHICSFONTHELPER_HPP
#define EE_GRAPHICSFONTHELPER_HPP
namespace EE { namespace Graphics {
enum EE_FONT_TYPE {
FONT_TYPE_TTF = 1,
FONT_TYPE_TEX = 2
};
enum EE_FONT_HALIGN {
FONT_DRAW_LEFT = (0 << 0),
FONT_DRAW_RIGHT = (1 << 0),
FONT_DRAW_CENTER = (2 << 0),
FONT_DRAW_HALIGN_MASK = (3 << 0)
};
enum EE_FONT_VALIGN {
FONT_DRAW_TOP = (0 << 2),
FONT_DRAW_BOTTOM = (1 << 2),
FONT_DRAW_MIDDLE = (2 << 2),
FONT_DRAW_VALIGN_MASK = (3 << 2)
};
inline Uint32 FontHAlignGet( Uint32 Flags ) {
return Flags & FONT_DRAW_HALIGN_MASK;
}
inline Uint32 FontVAlignGet( Uint32 Flags ) {
return Flags & FONT_DRAW_VALIGN_MASK;
}
#define FONT_DRAW_SHADOW (1 << 5)
#define FONT_DRAW_VERTICAL (1 << 6)
#define FONT_DRAW_ALIGN_MASK ( FONT_DRAW_VALIGN_MASK | FONT_DRAW_HALIGN_MASK )
/** Basic Glyph structure used by the engine */
struct eeGlyph {
Int32 MinX, MaxX, MinY, MaxY, Advance;
Uint16 CurX, CurY, CurW, CurH, GlyphH;
};
struct eeVertexCoords {
eeFloat TexCoords[2];
eeFloat Vertex[2];
};
struct eeTexCoords {
eeFloat TexCoords[8];
eeFloat Vertex[8];
};
typedef struct sFntHdrS {
Uint32 Magic;
Uint32 FirstChar;
Uint32 NumChars;
Uint32 Size;
Uint32 Height;
Int32 LineSkip;
Int32 Ascent;
Int32 Descent;
} sFntHdr;
#define EE_TTF_FONT_MAGIC ( ( 'E' << 0 ) | ( 'E' << 8 ) | ( 'F' << 16 ) | ( 'N' << 24 ) )
}}
#endif
| 19.414286 | 89 | 0.690213 | dogtwelve |
2ed7c5c100a54b741f94d33c79fe5394607caecb | 4,574 | cpp | C++ | llvm/3.4.2/llvm-3.4.2.src/lib/Support/StreamableMemoryObject.cpp | tangyibin/goblin-core | 1940db6e95908c81687b2b22ddd9afbc8db9cdfe | [
"BSD-3-Clause"
] | 36 | 2015-01-13T19:34:04.000Z | 2022-03-07T22:22:15.000Z | llvm/3.4.2/llvm-3.4.2.src/lib/Support/StreamableMemoryObject.cpp | tangyibin/goblin-core | 1940db6e95908c81687b2b22ddd9afbc8db9cdfe | [
"BSD-3-Clause"
] | 7 | 2015-10-20T19:05:01.000Z | 2021-11-13T14:55:47.000Z | llvm/3.4.2/llvm-3.4.2.src/lib/Support/StreamableMemoryObject.cpp | tangyibin/goblin-core | 1940db6e95908c81687b2b22ddd9afbc8db9cdfe | [
"BSD-3-Clause"
] | 18 | 2015-04-23T20:59:52.000Z | 2021-11-18T20:06:39.000Z | //===- StreamableMemoryObject.cpp - Streamable data interface -------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/Support/StreamableMemoryObject.h"
#include "llvm/Support/Compiler.h"
#include <cassert>
#include <cstring>
using namespace llvm;
namespace {
class RawMemoryObject : public StreamableMemoryObject {
public:
RawMemoryObject(const unsigned char *Start, const unsigned char *End) :
FirstChar(Start), LastChar(End) {
assert(LastChar >= FirstChar && "Invalid start/end range");
}
virtual uint64_t getBase() const LLVM_OVERRIDE { return 0; }
virtual uint64_t getExtent() const LLVM_OVERRIDE {
return LastChar - FirstChar;
}
virtual int readByte(uint64_t address, uint8_t* ptr) const LLVM_OVERRIDE;
virtual int readBytes(uint64_t address,
uint64_t size,
uint8_t *buf) const LLVM_OVERRIDE;
virtual const uint8_t *getPointer(uint64_t address,
uint64_t size) const LLVM_OVERRIDE;
virtual bool isValidAddress(uint64_t address) const LLVM_OVERRIDE {
return validAddress(address);
}
virtual bool isObjectEnd(uint64_t address) const LLVM_OVERRIDE {
return objectEnd(address);
}
private:
const uint8_t* const FirstChar;
const uint8_t* const LastChar;
// These are implemented as inline functions here to avoid multiple virtual
// calls per public function
bool validAddress(uint64_t address) const {
return static_cast<ptrdiff_t>(address) < LastChar - FirstChar;
}
bool objectEnd(uint64_t address) const {
return static_cast<ptrdiff_t>(address) == LastChar - FirstChar;
}
RawMemoryObject(const RawMemoryObject&) LLVM_DELETED_FUNCTION;
void operator=(const RawMemoryObject&) LLVM_DELETED_FUNCTION;
};
int RawMemoryObject::readByte(uint64_t address, uint8_t* ptr) const {
if (!validAddress(address)) return -1;
*ptr = *((uint8_t *)(uintptr_t)(address + FirstChar));
return 0;
}
int RawMemoryObject::readBytes(uint64_t address,
uint64_t size,
uint8_t *buf) const {
if (!validAddress(address) || !validAddress(address + size - 1)) return -1;
memcpy(buf, (uint8_t *)(uintptr_t)(address + FirstChar), size);
return size;
}
const uint8_t *RawMemoryObject::getPointer(uint64_t address,
uint64_t size) const {
return FirstChar + address;
}
} // anonymous namespace
namespace llvm {
// If the bitcode has a header, then its size is known, and we don't have to
// block until we actually want to read it.
bool StreamingMemoryObject::isValidAddress(uint64_t address) const {
if (ObjectSize && address < ObjectSize) return true;
return fetchToPos(address);
}
bool StreamingMemoryObject::isObjectEnd(uint64_t address) const {
if (ObjectSize) return address == ObjectSize;
fetchToPos(address);
return address == ObjectSize && address != 0;
}
uint64_t StreamingMemoryObject::getExtent() const {
if (ObjectSize) return ObjectSize;
size_t pos = BytesRead + kChunkSize;
// keep fetching until we run out of bytes
while (fetchToPos(pos)) pos += kChunkSize;
return ObjectSize;
}
int StreamingMemoryObject::readByte(uint64_t address, uint8_t* ptr) const {
if (!fetchToPos(address)) return -1;
*ptr = Bytes[address + BytesSkipped];
return 0;
}
int StreamingMemoryObject::readBytes(uint64_t address,
uint64_t size,
uint8_t *buf) const {
if (!fetchToPos(address + size - 1)) return -1;
memcpy(buf, &Bytes[address + BytesSkipped], size);
return 0;
}
bool StreamingMemoryObject::dropLeadingBytes(size_t s) {
if (BytesRead < s) return true;
BytesSkipped = s;
BytesRead -= s;
return false;
}
void StreamingMemoryObject::setKnownObjectSize(size_t size) {
ObjectSize = size;
Bytes.reserve(size);
}
StreamableMemoryObject *getNonStreamedMemoryObject(
const unsigned char *Start, const unsigned char *End) {
return new RawMemoryObject(Start, End);
}
StreamableMemoryObject::~StreamableMemoryObject() { }
StreamingMemoryObject::StreamingMemoryObject(DataStreamer *streamer) :
Bytes(kChunkSize), Streamer(streamer), BytesRead(0), BytesSkipped(0),
ObjectSize(0), EOFReached(false) {
BytesRead = streamer->GetBytes(&Bytes[0], kChunkSize);
}
}
| 32.211268 | 80 | 0.683428 | tangyibin |
2eda6038ee1087d5d26b3849f661f3ff8b17436c | 5,135 | cpp | C++ | test/test_inputmap.cpp | carlcc/gainput | 0d63da54e1c536295e39f360e883f6e5bb6a68d0 | [
"MIT"
] | 3,058 | 2017-10-03T01:33:22.000Z | 2022-03-30T22:04:23.000Z | test/test_inputmap.cpp | marcoesposito1988/gainput | a96e16dc873a62e0996a8ee27c85cad17f783110 | [
"MIT"
] | 157 | 2018-01-26T10:18:33.000Z | 2022-03-06T10:59:23.000Z | test/test_inputmap.cpp | marcoesposito1988/gainput | a96e16dc873a62e0996a8ee27c85cad17f783110 | [
"MIT"
] | 388 | 2017-12-21T10:52:32.000Z | 2022-03-31T18:25:49.000Z |
#include "catch.hpp"
#include <gainput/gainput.h>
using namespace gainput;
enum TestButtons
{
ButtonA,
ButtonStart = ButtonA,
ButtonB,
ButtonC,
ButtonD,
ButtonE,
ButtonF,
ButtonG,
ButtonCount
};
TEST_CASE("InputMap/create", "")
{
InputManager manager;
InputMap map(manager, "testmap");
REQUIRE(&manager == &map.GetManager());
REQUIRE(map.GetName());
REQUIRE(strcmp(map.GetName(), "testmap") == 0);
for (int b = ButtonStart; b < ButtonCount; ++b)
{
REQUIRE(!map.IsMapped(b));
}
InputMap map2(manager);
REQUIRE(!map2.GetName());
}
TEST_CASE("InputMap/map_bool", "")
{
InputManager manager;
const DeviceId keyboardId = manager.CreateDevice<InputDeviceKeyboard>();
const DeviceId mouseId = manager.CreateDevice<InputDeviceMouse>();
InputMap map(manager, "testmap");
REQUIRE(map.MapBool(ButtonA, keyboardId, KeyA));
REQUIRE(map.MapBool(ButtonA, keyboardId, KeyB));
REQUIRE(map.MapBool(ButtonA, keyboardId, KeyEscape));
REQUIRE(map.MapBool(ButtonA, mouseId, MouseButtonLeft));
REQUIRE(map.IsMapped(ButtonA));
REQUIRE(map.MapBool(ButtonB, keyboardId, KeyF2));
REQUIRE(map.MapBool(ButtonB, mouseId, MouseButtonLeft));
REQUIRE(map.IsMapped(ButtonB));
map.Clear();
for (int b = ButtonStart; b < ButtonCount; ++b)
{
REQUIRE(!map.IsMapped(b));
}
REQUIRE(map.MapBool(ButtonA, mouseId, MouseButtonRight));
REQUIRE(map.IsMapped(ButtonA));
map.Unmap(ButtonA);
REQUIRE(!map.IsMapped(ButtonA));
DeviceButtonSpec mappings[32];
REQUIRE(map.GetMappings(ButtonA, mappings, 32) == 0);
REQUIRE(map.MapBool(ButtonA, mouseId, MouseButtonMiddle));
REQUIRE(map.MapBool(ButtonA, keyboardId, KeyD));
REQUIRE(map.MapBool(ButtonD, keyboardId, KeyB));
REQUIRE(map.GetMappings(ButtonA, mappings, 32) == 2);
REQUIRE(mappings[0].deviceId == mouseId);
REQUIRE(mappings[0].buttonId == MouseButtonMiddle);
REQUIRE(mappings[1].deviceId == keyboardId);
REQUIRE(mappings[1].buttonId == KeyD);
char buf[32];
REQUIRE(map.GetUserButtonName(ButtonA, buf, 32));
REQUIRE(map.GetUserButtonId(mouseId, MouseButtonMiddle) == ButtonA);
REQUIRE(map.GetUserButtonId(keyboardId, KeyD) == ButtonA);
REQUIRE(map.GetUserButtonId(keyboardId, KeyB) == ButtonD);
}
TEST_CASE("InputMap/map_float", "")
{
InputManager manager;
const DeviceId keyboardId = manager.CreateDevice<InputDeviceKeyboard>();
const DeviceId mouseId = manager.CreateDevice<InputDeviceMouse>();
const DeviceId padId = manager.CreateDevice<InputDevicePad>();
InputMap map(manager, "testmap");
REQUIRE(map.MapFloat(ButtonA, keyboardId, KeyA));
REQUIRE(map.MapFloat(ButtonA, keyboardId, KeyB));
REQUIRE(map.MapFloat(ButtonA, keyboardId, KeyEscape));
REQUIRE(map.MapFloat(ButtonA, mouseId, MouseButtonLeft));
REQUIRE(map.MapFloat(ButtonA, mouseId, MouseAxisY));
REQUIRE(map.MapFloat(ButtonA, padId, PadButtonLeftStickX));
REQUIRE(map.IsMapped(ButtonA));
REQUIRE(map.MapFloat(ButtonB, keyboardId, KeyF2));
REQUIRE(map.MapFloat(ButtonB, mouseId, MouseAxisX));
REQUIRE(map.IsMapped(ButtonB));
map.Clear();
for (int b = ButtonStart; b < ButtonCount; ++b)
{
REQUIRE(!map.IsMapped(b));
}
REQUIRE(map.MapFloat(ButtonA, mouseId, MouseAxisX));
REQUIRE(map.IsMapped(ButtonA));
map.Unmap(ButtonA);
REQUIRE(!map.IsMapped(ButtonA));
DeviceButtonSpec mappings[32];
REQUIRE(map.GetMappings(ButtonA, mappings, 32) == 0);
REQUIRE(map.MapFloat(ButtonA, mouseId, MouseAxisX));
REQUIRE(map.MapFloat(ButtonA, keyboardId, KeyF5));
REQUIRE(map.MapFloat(ButtonD, padId, PadButtonLeftStickY));
REQUIRE(map.GetMappings(ButtonA, mappings, 32) == 2);
REQUIRE(mappings[0].deviceId == mouseId);
REQUIRE(mappings[0].buttonId == MouseAxisX);
REQUIRE(mappings[1].deviceId == keyboardId);
REQUIRE(mappings[1].buttonId == KeyF5);
char buf[32];
REQUIRE(map.GetUserButtonName(ButtonA, buf, 32));
REQUIRE(map.GetUserButtonId(mouseId, MouseAxisX) == ButtonA);
REQUIRE(map.GetUserButtonId(keyboardId, KeyF5) == ButtonA);
REQUIRE(map.GetUserButtonId(padId, PadButtonLeftStickY) == ButtonD);
}
TEST_CASE("InputMap/SetDeadZone_SetUserButtonPolicy", "")
{
InputManager manager;
const DeviceId keyboardId = manager.CreateDevice<InputDeviceKeyboard>();
const DeviceId mouseId = manager.CreateDevice<InputDeviceMouse>();
const DeviceId padId = manager.CreateDevice<InputDevicePad>();
InputMap map(manager, "testmap");
for (int b = ButtonStart; b < ButtonCount; ++b)
{
REQUIRE(!map.SetDeadZone(b, 0.1f));
REQUIRE(!map.SetUserButtonPolicy(b, InputMap::UBP_AVERAGE));
}
REQUIRE(map.MapFloat(ButtonA, mouseId, MouseAxisX));
REQUIRE(map.SetDeadZone(ButtonA, 0.01f));
REQUIRE(map.SetDeadZone(ButtonA, 0.0f));
REQUIRE(map.SetDeadZone(ButtonA, 1.01f));
REQUIRE(!map.SetDeadZone(ButtonF, 1.01f));
REQUIRE(map.SetUserButtonPolicy(ButtonA, InputMap::UBP_AVERAGE));
REQUIRE(map.SetUserButtonPolicy(ButtonA, InputMap::UBP_MAX));
REQUIRE(map.SetUserButtonPolicy(ButtonA, InputMap::UBP_MIN));
REQUIRE(map.SetUserButtonPolicy(ButtonA, InputMap::UBP_FIRST_DOWN));
map.Clear();
for (int b = ButtonStart; b < ButtonCount; ++b)
{
REQUIRE(!map.SetDeadZone(b, 0.1f));
REQUIRE(!map.SetUserButtonPolicy(b, InputMap::UBP_AVERAGE));
}
}
| 28.848315 | 73 | 0.742162 | carlcc |
2edb74012b69c690542f07b751cb6ef226b2532d | 22,472 | cpp | C++ | molecular/gfx/opengl/GlCommandSink.cpp | petrarce/molecular-gfx | fdf95c28a5693a2e1f9abaedda9521f8521b1f84 | [
"MIT"
] | null | null | null | molecular/gfx/opengl/GlCommandSink.cpp | petrarce/molecular-gfx | fdf95c28a5693a2e1f9abaedda9521f8521b1f84 | [
"MIT"
] | 1 | 2019-10-23T14:33:25.000Z | 2019-10-23T14:33:25.000Z | molecular/gfx/opengl/GlCommandSink.cpp | petrarce/molecular-gfx | fdf95c28a5693a2e1f9abaedda9521f8521b1f84 | [
"MIT"
] | 2 | 2020-09-24T13:33:39.000Z | 2022-03-29T13:17:47.000Z | /* GlCommandSink.cpp
MIT License
Copyright (c) 2019-2020 Fabian Herb
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "GlCommandSink.h"
#include "GlCommandSinkProgram.h"
#include "PixelFormatConversion.h"
#include <molecular/util/Logging.h>
#include <cassert>
#include <string>
namespace molecular
{
namespace gfx
{
using namespace std::string_literals;
GlFunctions GlCommandSink::gl;
GlCommandSink::GlslVersion GlCommandSink::glslVersion = GlCommandSink::GlslVersion::UNKNOWN;
void GlCommandSink::Init()
{
gl.Init();
LOG(INFO) << "GL_VERSION: " << gl.GetString(gl.VERSION);
LOG(INFO) << "GL_SHADING_LANGUAGE_VERSION: " << gl.GetString(gl.SHADING_LANGUAGE_VERSION);
LOG(INFO) << "GL_EXTENSIONS: ";
GLint numExtensions = 0;
gl.GetIntegerv(gl.NUM_EXTENSIONS, &numExtensions);
for(GLint i = 0; i < numExtensions; ++i)
LOG(INFO) << " " << gl.GetStringi(gl.EXTENSIONS, i);
GLint numCompressedTextureFormats = 0;
gl.GetIntegerv(gl.NUM_COMPRESSED_TEXTURE_FORMATS, &numCompressedTextureFormats);
if(GLenum error = glGetError())
LOG(ERROR) << "glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS): " << GlConstantString(error);
else
{
LOG(INFO) << "GL_COMPRESSED_TEXTURE_FORMATS[" << numCompressedTextureFormats << "]: ";
std::vector<GLint> compressedTextureFormats(numCompressedTextureFormats);
gl.GetIntegerv(gl.COMPRESSED_TEXTURE_FORMATS, compressedTextureFormats.data());
for(GLint i = 0; i < numCompressedTextureFormats; ++i)
LOG(INFO) << " " << GlConstantString(compressedTextureFormats[i]);
}
gl.Enable(gl.DEPTH_TEST);
gl.Enable(gl.CULL_FACE);
SetTarget(nullptr);
/* if(gl.HasPrimitiveRestartIndex())
{
gl.PrimitiveRestartIndex(0xffff);
gl.Enable(gl.PRIMITIVE_RESTART);
}
*/
#ifndef OPENGL_ES3
gl.Enable(gl.PROGRAM_POINT_SIZE); // Always enabled on GLES3
// OpenGL ES always renders in sRGB when the underlying framebuffer has sRGB color format:
gl.Enable(gl.FRAMEBUFFER_SRGB);
CheckError("glEnable", __LINE__, __FILE__);
GLint colorEncoding = 0;
gl.GetFramebufferAttachmentParameteriv(gl.FRAMEBUFFER, gl.FRONT_LEFT, gl.FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING, &colorEncoding);
CheckError("glGetFramebufferAttachmentParameteriv", __LINE__, __FILE__);
LOG(INFO) << "GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: " << GlConstantString(colorEncoding);
#endif
// Determine supported GLSL version by compiling two-liners:
if(Program::Shader(Program::ShaderType::kVertexShader).SourceCompile("#version 330 core\nvoid main(){}\n"s, false))
glslVersion = GlslVersion::V_330;
else if(Program::Shader(Program::ShaderType::kVertexShader).SourceCompile("#version 300 es\nvoid main(){}\n"s, false))
glslVersion = GlslVersion::V_300_ES;
else if(Program::Shader(Program::ShaderType::kVertexShader).SourceCompile("#version 150\nvoid main(){}\n"s, false))
glslVersion = GlslVersion::V_150;
else
throw std::runtime_error("No supported GLSL version found");
}
void GlCommandSink::VertexBuffer::Store(const void* data, size_t size, bool stream)
{
gl.BindBuffer(gl.ARRAY_BUFFER, mBuffer);
CheckError("glBindBuffer", __LINE__, __FILE__);
if(stream)
{
// https://www.opengl.org/wiki/Buffer_Object_Streaming#Buffer_re-specification
gl.BufferData(gl.ARRAY_BUFFER, size, nullptr, gl.STREAM_DRAW);
}
gl.BufferData(gl.ARRAY_BUFFER, size, data, stream ? gl.STREAM_DRAW : gl.STATIC_DRAW);
CheckError("glBufferData", __LINE__, __FILE__);
}
void GlCommandSink::IndexBuffer::Store(const void* data, size_t size)
{
gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, mBuffer);
CheckError("glBindBuffer", __LINE__, __FILE__);
gl.BufferData(gl.ELEMENT_ARRAY_BUFFER, size, data, gl.STATIC_DRAW);
CheckError("glBufferData", __LINE__, __FILE__);
}
GlCommandSink::Texture* GlCommandSink::CreateTexture() {return new Texture;}
void GlCommandSink::DestroyTexture(Texture* texture) {delete texture;}
GlCommandSink::Program* GlCommandSink::CreateProgram()
{
return new Program;
}
void GlCommandSink::DestroyProgram(Program* program)
{
delete program;
}
void GlCommandSink::UseProgram(Program* program)
{
if(program)
{
#ifndef NDEBUG
gl.ValidateProgram(program->mProgram);
CheckError("glValidateProgram", __LINE__, __FILE__);
GLint status;
gl.GetProgramiv(program->mProgram, gl.VALIDATE_STATUS, &status);
CheckError("glGetProgramiv", __LINE__, __FILE__);
if(status != GL_TRUE)
LOG(ERROR) << "GL_VALIDATE_STATUS == GL_FALSE";
#endif
gl.UseProgram(program->mProgram);
CheckError("glUseProgram", __LINE__, __FILE__);
gl.BindVertexArray(program->mVertexArrayObject);
CheckError("glBindVertexArray", __LINE__, __FILE__);
}
else
{
gl.UseProgram(0);
CheckError("glUseProgram", __LINE__, __FILE__);
gl.BindVertexArray(0);
CheckError("glBindVertexArray", __LINE__, __FILE__);
}
}
GlCommandSink::RenderTarget* GlCommandSink::CreateRenderTarget()
{
return new RenderTarget;
}
void GlCommandSink::DestroyRenderTarget(RenderTarget* target)
{
delete target;
}
void GlCommandSink::SetTarget(RenderTarget* target)
{
// if(target == mCurrentTarget)
// return;
if(target)
{
gl.BindFramebuffer(gl.FRAMEBUFFER, target->mFramebuffer);
CheckError("glBindFramebuffer", __LINE__, __FILE__);
if(target->ColorBufferAttached())
{
GLenum drawBuffer = gl.COLOR_ATTACHMENT0;
gl.DrawBuffers(1, &drawBuffer);
CheckError("glDrawBuffers", __LINE__, __FILE__);
gl.ReadBuffer(gl.COLOR_ATTACHMENT0);
CheckError("glReadBuffer", __LINE__, __FILE__);
}
else
{
GLenum drawBuffer = GL_NONE;
gl.DrawBuffers(1, &drawBuffer);
CheckError("glDrawBuffers", __LINE__, __FILE__);
gl.ReadBuffer(GL_NONE);
CheckError("glReadBuffer", __LINE__, __FILE__);
}
#ifndef NDEBUG
GLenum status = gl.CheckFramebufferStatus(gl.FRAMEBUFFER);
CheckError("glCheckFramebufferStatus", __LINE__, __FILE__);
if(status != gl.FRAMEBUFFER_COMPLETE)
{
LOG(ERROR) << std::hex << "glCheckFramebufferStatus Return: " << status;
return;
}
#endif
gl.Viewport(0, 0, target->GetWidth(), target->GetHeight());
CheckError("glViewport", __LINE__, __FILE__);
}
else
{
gl.BindFramebuffer(gl.FRAMEBUFFER, mBaseTargetFramebuffer);
CheckError("glBindFramebuffer", __LINE__, __FILE__);
#ifdef OPENGL_ES3
// GLenum drawBuffer = GL_BACK;
#else
// GLenum drawBuffer = GL_BACK_LEFT;
#endif
// gl.DrawBuffers(1, &drawBuffer);
// CheckError("glDrawBuffers", __LINE__, __FILE__);
// gl.ReadBuffer(drawBuffer);
// CheckError("glReadBuffer", __LINE__, __FILE__);
gl.Viewport(mBaseTargetViewport[0], mBaseTargetViewport[1], mBaseTargetViewport[2], mBaseTargetViewport[3]);
CheckError("glViewport", __LINE__, __FILE__);
}
mCurrentTarget = target;
}
void GlCommandSink::SetBaseTarget(const IntVector4& viewport, int renderTarget)
{
mBaseTargetViewport = viewport;
mBaseTargetFramebuffer = renderTarget;
}
GlCommandSink::TransformFeedback* GlCommandSink::CreateTransformFeedback()
{
GLuint feedback;
gl.GenTransformFeedbacks(1, &feedback);
return new TransformFeedback(feedback);
}
void GlCommandSink::DestroyTransformFeedback(TransformFeedback* feedback)
{
delete feedback;
}
void GlCommandSink::Clear(bool color, bool depth)
{
GLbitfield bits = 0;
if(color)
bits |= GL_COLOR_BUFFER_BIT;
if(depth)
bits |= GL_DEPTH_BUFFER_BIT;
gl.Clear(bits);
}
void GlCommandSink::ReadPixels(int x, int y, int width, int height, PixelFormat format, void* data)
{
gl.ReadPixels(x, y, width, height, PixelFormatConversion::ToGlFormat(format), PixelFormatConversion::ToGlType(format), data);
CheckError("glReadPixels", __LINE__, __FILE__);
}
void GlCommandSink::SetBlending(bool enable, BlendFactor sourceFactor, BlendFactor destFactor)
{
if(enable)
{
glEnable(GL_BLEND);
glBlendFunc(sourceFactor, destFactor);
}
else
glDisable(GL_BLEND);
}
void GlCommandSink::SetDepthState(bool depthTest, bool depthWrite, CompareOp compareOp)
{
if(depthTest)
glEnable(gl.DEPTH_TEST);
else
glDisable(gl.DEPTH_TEST);
glDepthMask(depthWrite ? GL_TRUE : GL_FALSE);
glDepthFunc(compareOp);
}
void GlCommandSink::SetScissor(bool enable, int x, int y, int width, int height)
{
if(enable)
{
glEnable(GL_SCISSOR_TEST);
glScissor(x, y, width, height);
}
else
glDisable(GL_SCISSOR_TEST);
}
void GlCommandSink::SetRasterizationState(bool rasterizerDiscard, CullMode cullMode)
{
if(rasterizerDiscard)
glEnable(gl.RASTERIZER_DISCARD);
else
glDisable(gl.RASTERIZER_DISCARD);
glCullFace(cullMode);
}
void GlCommandSink::Draw(IndexBuffer* buffer, const IndexBufferInfo& info)
{
assert(buffer);
gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, buffer->mBuffer);
CheckError("glBindBuffer", __LINE__, __FILE__);
gl.DrawElements(ToGlEnum(info.mode), info.count, ToGlEnum(info.type), reinterpret_cast<const GLvoid*>(info.offset));
CheckError("glDrawElements", __LINE__, __FILE__);
/* Found on the web:
GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound
to an enabled array or to the GL_DRAW_INDIRECT_BUFFER binding and the
buffer object's data store is currently mapped.
GL_INVALID_OPERATION is generated if glDrawArrays is executed between the
execution of glBegin and the corresponding glEnd.
GL_INVALID_OPERATION will be generated by glDrawArrays or glDrawElements if
any two active samplers in the current program object are of different
types, but refer to the same texture image unit.
GL_INVALID_OPERATION is generated if a geometry shader is active and mode
is incompatible with the input primitive type of the geometry shader in
the currently installed program object.
GL_INVALID_OPERATION is generated if mode is GL_PATCHES and no tessellation
control shader is active.
GL_INVALID_OPERATION is generated if recording the vertices of a primitive
to the buffer objects being used for transform feedback purposes would
result in either exceeding the limits of any buffer object’s size, or
in exceeding the end position offset + size - 1, as set by
glBindBufferRange.
GL_INVALID_OPERATION is generated by glDrawArrays() if no geometry shader
is present, transform feedback is active and mode is not one of the
allowed modes.
GL_INVALID_OPERATION is generated by glDrawArrays() if a geometry shader is
present, transform feedback is active and the output primitive type of
the geometry shader does not match the transform feedback primitiveMode.
GL_INVALID_OPERATION is generated if the bound shader program is invalid.
GL_INVALID_OPERATION is generated if transform feedback is in use, and the
buffer bound to the transform feedback binding point is also bound to
the array buffer binding point.
Own experience:
GL_INVALID_OPERATION may be generated (or the driver crashes) if an enabled
vertex attribute has no buffer attached and no pointer set.
*/
}
void GlCommandSink::Draw(TransformFeedback* transformFeedback, IndexBufferInfo::Mode mode)
{
if(gl.HasDrawTransformFeedback())
{
gl.DrawTransformFeedback(ToGlEnum(mode), transformFeedback->mFeedback);
CheckError("glDrawTransformFeedback", __LINE__, __FILE__);
}
else
{
// Query
GLuint primitives = 0;
gl.GetQueryObjectuiv(transformFeedback->mQuery, gl.QUERY_RESULT, &primitives);
CheckError("glGetQueryObjectiv", __LINE__, __FILE__);
gl.DrawArrays(ToGlEnum(mode), 0, primitives);
CheckError("glDrawArrays", __LINE__, __FILE__);
}
}
void GlCommandSink::Draw(IndexBufferInfo::Mode mode, unsigned int count)
{
gl.DrawArrays(ToGlEnum(mode), 0, count);
CheckError("glDrawArrays", __LINE__, __FILE__);
}
GLenum GlCommandSink::ToGlEnum(VertexAttributeInfo::Type type)
{
switch(type)
{
case VertexAttributeInfo::kFloat: return gl.FLOAT;
case VertexAttributeInfo::kInt8: return gl.BYTE;
case VertexAttributeInfo::kUInt8: return gl.UNSIGNED_BYTE;
case VertexAttributeInfo::kInt16: return gl.SHORT;
case VertexAttributeInfo::kUInt16: return gl.UNSIGNED_SHORT;
case VertexAttributeInfo::kInt32: return gl.INT;
case VertexAttributeInfo::kUInt32: return gl.UNSIGNED_INT;
case VertexAttributeInfo::kHalf: return gl.HALF_FLOAT;
}
return 0;
}
GLenum GlCommandSink::ToGlEnum(IndexBufferInfo::Type type)
{
switch(type)
{
case IndexBufferInfo::Type::kUInt8: return gl.UNSIGNED_BYTE;
case IndexBufferInfo::Type::kUInt16: return gl.UNSIGNED_SHORT;
case IndexBufferInfo::Type::kUInt32: return gl.UNSIGNED_INT;
}
return 0;
}
GLenum GlCommandSink::ToGlEnum(IndexBufferInfo::Mode mode)
{
switch(mode)
{
case IndexBufferInfo::Mode::kPoints: return GL_POINTS;
case IndexBufferInfo::Mode::kTriangles: return GL_TRIANGLES;
case IndexBufferInfo::Mode::kLines: return GL_LINES;
case IndexBufferInfo::Mode::kTriangleFan: return GL_TRIANGLE_FAN;
case IndexBufferInfo::Mode::kTriangleStrip: return GL_TRIANGLE_STRIP;
case IndexBufferInfo::Mode::kLineStrip: return GL_LINE_STRIP;
case IndexBufferInfo::Mode::kTrianglesAdjacency: return gl.TRIANGLES_ADJACENCY;
case IndexBufferInfo::Mode::kTriangleStripAdjacency: return gl.TRIANGLE_STRIP_ADJACENCY;
case IndexBufferInfo::Mode::kLineStripAdjacency: return gl.LINE_STRIP_ADJACENCY;
}
return 0;
}
/*****************************************************************************/
void GlCommandSink::Texture::Store(unsigned int width, unsigned int height, const void* data, PixelFormat format, int mipmapLevel, size_t dataSize)
{
gl.BindTexture(GL_TEXTURE_2D, mTexture);
CheckError("glBindTexture", __LINE__, __FILE__);
GLenum intFormat = PixelFormatConversion::ToGlInternalFormat(format);
if(Pf::IsCompressed(format))
{
gl.CompressedTexImage2D(GL_TEXTURE_2D, mipmapLevel, intFormat, width, height, 0, dataSize, data);
CheckError("glCompressedTexImage2D", __LINE__, __FILE__);
}
else
{
// Uncompressed
GLenum glFormat = PixelFormatConversion::ToGlFormat(format);
GLenum type = PixelFormatConversion::ToGlType(format);
if(width == mWidth && height == mHeight && mDepth == 0 && data)
gl.TexSubImage2D(GL_TEXTURE_2D, mipmapLevel, 0, 0, width, height, glFormat, type, data);
else
gl.TexImage2D(GL_TEXTURE_2D, mipmapLevel, intFormat, width, height, 0, glFormat, type, data);
CheckError("glTexImage2D", __LINE__, __FILE__);
}
mWidth = width;
mHeight = height;
mDepth = 0;
}
void GlCommandSink::Texture::Store(unsigned int width, unsigned int height, unsigned int depth, const void* data, PixelFormat format)
{
gl.BindTexture(gl.TEXTURE_3D, mTexture);
CheckError("glBindTexture", __LINE__, __FILE__);
GLenum glFormat = PixelFormatConversion::ToGlFormat(format);
GLenum intFormat = PixelFormatConversion::ToGlInternalFormat(format);
GLenum type = PixelFormatConversion::ToGlType(format);
gl.TexImage3D(gl.TEXTURE_3D, 0, intFormat, width, height, depth, 0, glFormat, type, data);
CheckError("glTexImage3D", __LINE__, __FILE__);
mWidth = width;
mHeight = height;
mDepth = depth;
}
void GlCommandSink::Texture::Store(unsigned int offsetX, unsigned int offsetY, unsigned int width, unsigned int height, const void* data, PixelFormat format, int mipmapLevel, size_t dataSize)
{
gl.BindTexture(GL_TEXTURE_2D, mTexture);
CheckError("glBindTexture", __LINE__, __FILE__);
if(Pf::IsCompressed(format))
{
GLenum internalFormat = PixelFormatConversion::ToGlInternalFormat(format);
gl.CompressedTexSubImage2D(GL_TEXTURE_2D, mipmapLevel, offsetX, offsetY, width, height, internalFormat, dataSize, data);
CheckError("glCompressedTexSubImage2D", __LINE__, __FILE__);
}
else
{
GLenum glFormat = PixelFormatConversion::ToGlFormat(format);
GLenum type = PixelFormatConversion::ToGlType(format);
gl.TexSubImage2D(GL_TEXTURE_2D, mipmapLevel, offsetX, offsetY, width, height, glFormat, type, data);
CheckError("glTexSubImage2D", __LINE__, __FILE__);
}
}
void GlCommandSink::Texture::SetParameter(Parameter param, ParamValue value)
{
if(mDepth > 0)
gl.BindTexture(gl.TEXTURE_3D, mTexture);
else
gl.BindTexture(GL_TEXTURE_2D, mTexture);
CheckError("glBindTexture", __LINE__, __FILE__);
gl.TexParameteri(GL_TEXTURE_2D, param, value);
CheckError("glTexParameteri", __LINE__, __FILE__);
}
void GlCommandSink::Texture::SetParameter(Parameter param, int value)
{
if(mDepth > 0)
gl.BindTexture(gl.TEXTURE_3D, mTexture);
else
gl.BindTexture(GL_TEXTURE_2D, mTexture);
CheckError("glBindTexture", __LINE__, __FILE__);
gl.TexParameteri(GL_TEXTURE_2D, param, value);
CheckError("glTexParameteri", __LINE__, __FILE__);
}
/*****************************************************************************/
void GlCommandSink::RenderTarget::AttachColorBuffer(Texture* texture, unsigned int attachment, unsigned int layer)
{
if(mColorRenderbuffers.size() > attachment && mColorRenderbuffers[attachment] != 0)
{
gl.DeleteRenderbuffers(1, &mColorRenderbuffers[attachment]);
CheckError("glDeleteRenderbuffers", __LINE__, __FILE__);
mColorRenderbuffers[attachment] = 0;
}
gl.BindFramebuffer(gl.FRAMEBUFFER, mFramebuffer);
CheckError("glBindFramebuffer", __LINE__, __FILE__);
if(texture)
{
if(texture->GetDepth() > 0)
{
assert(texture->GetDepth() > layer);
gl.FramebufferTexture3D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + attachment, gl.TEXTURE_3D, texture->mTexture, 0, layer);
}
else
gl.FramebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + attachment, GL_TEXTURE_2D, texture->mTexture, 0);
CheckError("glFramebufferTexture2D", __LINE__, __FILE__);
mWidth = texture->GetWidth();
mHeight = texture->GetHeight();
}
else // Detach texture
{
gl.FramebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + attachment, GL_TEXTURE_2D, 0, 0);
CheckError("glFramebufferTexture2D", __LINE__, __FILE__);
}
if(attachment == 0)
mColorBufferAttached = (texture != nullptr);
}
void GlCommandSink::RenderTarget::AttachColorBuffer(unsigned int width, unsigned int height, PixelFormat format, unsigned int attachment)
{
if(mColorRenderbuffers.size() <= attachment)
mColorRenderbuffers.resize(attachment + 1);
if(mColorRenderbuffers[attachment] == 0)
{
gl.GenRenderbuffers(1, &mColorRenderbuffers[attachment]);
CheckError("glGenRenderbuffers", __LINE__, __FILE__);
}
gl.BindRenderbuffer(gl.RENDERBUFFER, mColorRenderbuffers[attachment]);
CheckError("glBindRenderbuffer", __LINE__, __FILE__);
gl.RenderbufferStorage(gl.RENDERBUFFER, PixelFormatConversion::ToGlInternalFormat(format), width, height);
CheckError("glRenderbufferStorage", __LINE__, __FILE__);
gl.BindFramebuffer(gl.FRAMEBUFFER, mFramebuffer);
CheckError("glBindFramebuffer", __LINE__, __FILE__);
gl.FramebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + attachment, gl.RENDERBUFFER, mColorRenderbuffers[attachment]);
CheckError("glFramebufferRenderbuffer", __LINE__, __FILE__);
mColorBufferAttached = (attachment == 0);
mWidth = width;
mHeight = height;
}
void GlCommandSink::RenderTarget::AttachDepthBuffer(Texture* texture)
{
if(mDepthRenderbuffer)
{
gl.DeleteRenderbuffers(1, &mDepthRenderbuffer);
mDepthRenderbuffer = 0;
}
gl.BindFramebuffer(gl.FRAMEBUFFER, mFramebuffer);
CheckError("glBindFramebuffer", __LINE__, __FILE__);
if(texture)
{
gl.FramebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, GL_TEXTURE_2D, texture->mTexture, 0);
mWidth = texture->GetWidth();
mHeight = texture->GetHeight();
}
else
gl.FramebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
CheckError("glFramebufferTexture2D", __LINE__, __FILE__);
}
void GlCommandSink::RenderTarget::AttachDepthBuffer(unsigned int width, unsigned int height, PixelFormat format)
{
if(!mDepthRenderbuffer)
gl.GenRenderbuffers(1, &mDepthRenderbuffer);
gl.BindRenderbuffer(gl.RENDERBUFFER, mDepthRenderbuffer);
gl.RenderbufferStorage(gl.RENDERBUFFER, PixelFormatConversion::ToGlInternalFormat(format), width, height);
gl.BindFramebuffer(gl.FRAMEBUFFER, mFramebuffer);
gl.FramebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, mDepthRenderbuffer);
mWidth = width;
mHeight = height;
}
void GlCommandSink::RenderTarget::AttachStencilBuffer(Texture* texture)
{
if(mStencilRenderbuffer)
{
gl.DeleteRenderbuffers(1, &mStencilRenderbuffer);
mStencilRenderbuffer = 0;
}
gl.BindFramebuffer(gl.FRAMEBUFFER, mFramebuffer);
if(texture)
{
gl.FramebufferTexture2D(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, GL_TEXTURE_2D, texture->mTexture, 0);
mWidth = texture->GetWidth();
mHeight = texture->GetHeight();
}
else
gl.FramebufferTexture2D(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
}
void GlCommandSink::RenderTarget::AttachStencilBuffer(unsigned int width, unsigned int height, PixelFormat format)
{
if(!mStencilRenderbuffer)
gl.GenRenderbuffers(1, &mStencilRenderbuffer);
gl.BindRenderbuffer(gl.RENDERBUFFER, mStencilRenderbuffer);
gl.RenderbufferStorage(gl.RENDERBUFFER, PixelFormatConversion::ToGlInternalFormat(format), width, height);
gl.BindFramebuffer(gl.FRAMEBUFFER, mFramebuffer);
gl.FramebufferRenderbuffer(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.RENDERBUFFER, mStencilRenderbuffer);
mWidth = width;
mHeight = height;
}
GlCommandSink::RenderTarget::RenderTarget() :
mStencilRenderbuffer(0),
mDepthRenderbuffer(0),
mColorBufferAttached(false),
mWidth(0),
mHeight(0)
{
gl.GenFramebuffers(1, &mFramebuffer);
CheckError("glGenFramebuffers", __LINE__, __FILE__);
}
GlCommandSink::RenderTarget::~RenderTarget()
{
for(auto it: mColorRenderbuffers)
{
if(it != 0)
gl.DeleteRenderbuffers(1, &it);
}
if(mDepthRenderbuffer)
gl.DeleteRenderbuffers(1, &mDepthRenderbuffer);
if(mStencilRenderbuffer)
gl.DeleteRenderbuffers(1, &mStencilRenderbuffer);
gl.DeleteFramebuffers(1, &mFramebuffer);
}
}
}
| 33.894419 | 191 | 0.767132 | petrarce |
2edc8fb22f93cfe732adc670cdfb5d5c495179c8 | 9,521 | cpp | C++ | aligned-types-sycl/main.cpp | BeauJoh/HeCBench | 594b845171d686dc951971ce36ed59cf114dd2b4 | [
"BSD-3-Clause"
] | 58 | 2020-08-06T18:53:44.000Z | 2021-10-01T07:59:46.000Z | aligned-types-sycl/main.cpp | BeauJoh/HeCBench | 594b845171d686dc951971ce36ed59cf114dd2b4 | [
"BSD-3-Clause"
] | 2 | 2020-12-04T12:35:02.000Z | 2021-03-04T22:49:25.000Z | aligned-types-sycl/main.cpp | BeauJoh/HeCBench | 594b845171d686dc951971ce36ed59cf114dd2b4 | [
"BSD-3-Clause"
] | 13 | 2020-08-19T13:44:18.000Z | 2021-09-08T04:25:34.000Z | /*
* Copyright 1993-2015 NVIDIA Corporation. All rights reserved.
*
* Please refer to the NVIDIA end user license agreement (EULA) associated
* with this source code for terms and conditions that govern your use of
* this software. Any use, reproduction, disclosure, or distribution of
* this software and related documentation outside the terms of the EULA
* is strictly prohibited.
*
*/
/*
* This is a simple test showing performance differences
* between aligned and misaligned structures
* (those having/missing __attribute__((__aligned__ keyword).
* It measures per-element copy throughput for
* aligned and misaligned structures on
* big chunks of data.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <chrono>
#include "common.h"
// Forward declaration
template <typename TData>
class copy_kernel;
////////////////////////////////////////////////////////////////////////////////
// Misaligned types
////////////////////////////////////////////////////////////////////////////////
typedef unsigned char uchar_misaligned;
typedef unsigned short int ushort_misaligned;
struct uchar4_misaligned
{
unsigned char r, g, b, a;
};
struct uint2_misaligned
{
unsigned int l, a;
};
struct uint3_misaligned
{
unsigned int r, g, b;
};
struct uint4_misaligned
{
unsigned int r, g, b, a;
};
////////////////////////////////////////////////////////////////////////////////
// Aligned types
////////////////////////////////////////////////////////////////////////////////
struct alignas(4) uchar4_aligned
{
unsigned char r, g, b, a;
};
typedef unsigned int uint_aligned;
struct alignas(8) uint2_aligned
{
unsigned int l, a;
};
struct alignas(16) uint3_aligned
{
unsigned int r, g, b;
};
struct alignas(16) uint4_aligned
{
unsigned int r, g, b, a;
};
////////////////////////////////////////////////////////////////////////////////
// Because G80 class hardware natively supports global memory operations
// only with data elements of 4, 8 and 16 bytes, if structure size
// exceeds 16 bytes, it can't be efficiently read or written,
// since more than one global memory non-coalescable load/store instructions
// will be generated, even if __attribute__((__aligned__ option is supplied.
// "Structure of arrays" storage strategy offers best performance
// in general case. See section 5.1.2 of the Programming Guide.
////////////////////////////////////////////////////////////////////////////////
struct alignas(16) uint4_aligned_2
{
uint4_aligned c1, c2;
};
////////////////////////////////////////////////////////////////////////////////
// Common host and device functions
////////////////////////////////////////////////////////////////////////////////
//Round a / b to nearest higher integer value
int iDivUp(int a, int b)
{
return (a % b != 0) ? (a / b + 1) : (a / b);
}
//Round a / b to nearest lower integer value
int iDivDown(int a, int b)
{
return a / b;
}
//Align a to nearest higher multiple of b
int iAlignUp(int a, int b)
{
return (a % b != 0) ? (a - a % b + b) : a;
}
//Align a to nearest lower multiple of b
int iAlignDown(int a, int b)
{
return a - a % b;
}
////////////////////////////////////////////////////////////////////////////////
// Copy is carried out on per-element basis,
// so it's not per-byte in case of padded structures.
////////////////////////////////////////////////////////////////////////////////
template <typename TData>
void testKernel(TData *__restrict d_odata,
const TData *__restrict d_idata,
int numElements,
nd_item<1> &item)
{
const int pos = item.get_global_id(0);
if (pos < numElements)
{
d_odata[pos] = d_idata[pos];
}
}
////////////////////////////////////////////////////////////////////////////////
// Validation routine for simple copy kernel.
// We must know "packed" size of TData (number_of_fields * sizeof(simple_type))
// and compare only these "packed" parts of the structure,
// containing actual user data. The compiler behavior with padding bytes
// is undefined, since padding is merely a placeholder
// and doesn't contain any user data.
////////////////////////////////////////////////////////////////////////////////
template <typename TData>
int testCPU(
TData *h_odata,
TData *h_idata,
int numElements,
int packedElementSize)
{
for (int pos = 0; pos < numElements; pos++)
{
TData src = h_idata[pos];
TData dst = h_odata[pos];
for (int i = 0; i < packedElementSize; i++)
if (((char *)&src)[i] != ((char *)&dst)[i])
{
return 0;
}
}
return 1;
}
////////////////////////////////////////////////////////////////////////////////
// Data configuration
////////////////////////////////////////////////////////////////////////////////
//Memory chunk size in bytes. Reused for test
const int MEM_SIZE = 50000000;
const int NUM_ITERATIONS = 100;
//GPU input and output data
unsigned char *d_idata, *d_odata;
//CPU input data and instance of GPU output data
unsigned char *h_idataCPU, *h_odataGPU;
template <typename TData>
int runTest(
queue &q,
buffer<unsigned char, 1> &d_idata,
buffer<unsigned char, 1> &d_odata,
int packedElementSize,
int memory_size)
{
const int totalMemSizeAligned = iAlignDown(memory_size, sizeof(TData));
const int numElements = iDivDown(memory_size, sizeof(TData));
//Clean output buffer before current test
q.submit([&] (handler &cgh) {
auto odata = d_odata.get_access<sycl_discard_write>(cgh);
cgh.fill(odata, (unsigned char)0);
});
//Run test
q.wait();
auto start = std::chrono::high_resolution_clock::now();
range<1> gws ((numElements + 255)/256*256);
range<1> lws (256);
auto d_odata_re = d_odata.reinterpret<TData>(range<1>(memory_size/sizeof(TData)));
auto d_idata_re = d_idata.reinterpret<TData>(range<1>(memory_size/sizeof(TData)));
for (int i = 0; i < NUM_ITERATIONS; i++)
{
q.submit([&] (handler &cgh) {
auto odata = d_odata_re.template get_access<sycl_discard_write>(cgh);
auto idata = d_idata_re.template get_access<sycl_read>(cgh);
cgh.parallel_for<class copy_kernel<TData>>(nd_range<1>(gws, lws), [=] (nd_item<1> item) {
testKernel<TData>(odata.get_pointer(), idata.get_pointer(), numElements, item);
});
});
}
q.wait();
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed_seconds = end - start;
double gpuTime = (double)elapsed_seconds.count() / NUM_ITERATIONS;
printf("Avg. time: %f ms / Copy throughput: %f GB/s.\n", gpuTime * 1000,
(double)totalMemSizeAligned / (gpuTime * 1073741824.0));
//Read back GPU results and run validation
q.submit([&] (handler &cgh) {
auto odata = d_odata.get_access<sycl_read>(cgh);
cgh.copy(odata, h_odataGPU);
}).wait();
int flag = testCPU(
(TData *)h_odataGPU,
(TData *)h_idataCPU,
numElements,
packedElementSize
);
printf(flag ? "\tTEST OK\n" : "\tTEST FAILURE\n");
return !flag;
}
int main(int argc, char **argv)
{
int i, nTotalFailures = 0;
printf("[%s] - Starting...\n", argv[0]);
printf("Allocating memory...\n");
int MemorySize = (int)(MEM_SIZE) & 0xffffff00; // force multiple of 256 bytes
h_idataCPU = (unsigned char *)malloc(MemorySize);
h_odataGPU = (unsigned char *)malloc(MemorySize);
printf("Generating host input data array...\n");
for (i = 0; i < MemorySize; i++)
{
h_idataCPU[i] = (i & 0xFF) + 1;
}
#ifdef USE_GPU
gpu_selector dev_sel;
#else
cpu_selector dev_sel;
#endif
queue q(dev_sel);
printf("Uploading input data to GPU memory...\n");
buffer<unsigned char, 1> d_idata (h_idataCPU, MemorySize);
buffer<unsigned char, 1> d_odata (MemorySize);
printf("Testing misaligned types...\n");
printf("uchar_misaligned...\n");
nTotalFailures += runTest<uchar_misaligned>(q, d_idata, d_odata, 1, MemorySize);
printf("uchar4_misaligned...\n");
nTotalFailures += runTest<uchar4_misaligned>(q, d_idata, d_odata, 4, MemorySize);
printf("uchar4_aligned...\n");
nTotalFailures += runTest<uchar4_aligned>(q, d_idata, d_odata, 4, MemorySize);
printf("ushort_misaligned...\n");
nTotalFailures += runTest<ushort_misaligned>(q, d_idata, d_odata, 2, MemorySize);
printf("uint_aligned...\n");
nTotalFailures += runTest<uint_aligned>(q, d_idata, d_odata, 4, MemorySize);
printf("uint2_misaligned...\n");
nTotalFailures += runTest<uint2_misaligned>(q, d_idata, d_odata, 8, MemorySize);
printf("uint2_aligned...\n");
nTotalFailures += runTest<uint2_aligned>(q, d_idata, d_odata, 8, MemorySize);
printf("uint3_misaligned...\n");
nTotalFailures += runTest<uint3_misaligned>(q, d_idata, d_odata, 12, MemorySize);
printf("uint3_aligned...\n");
nTotalFailures += runTest<uint3_aligned>(q, d_idata, d_odata, 12, MemorySize);
printf("uint4_misaligned...\n");
nTotalFailures += runTest<uint4_misaligned>(q, d_idata, d_odata, 16, MemorySize);
printf("uint4_aligned...\n");
nTotalFailures += runTest<uint4_aligned>(q, d_idata, d_odata, 16, MemorySize);
printf("uint4_aligned_2...\n");
nTotalFailures += runTest<uint4_aligned_2>(q, d_idata, d_odata, 32, MemorySize);
printf("\n[alignedTypes] -> Test Results: %d Failures\n", nTotalFailures);
printf("Shutting down...\n");
free(h_odataGPU);
free(h_idataCPU);
if (nTotalFailures != 0)
{
printf("Test failed!\n");
exit(EXIT_FAILURE);
}
printf("Test passed\n");
exit(EXIT_SUCCESS);
}
| 28.002941 | 95 | 0.604243 | BeauJoh |
2edebe498538eb35f41ceb8f08790d873710904f | 1,188 | hpp | C++ | simulation/libsimulator/include/simulator/nat.hpp | SylemST-UtilCollection/libtorrent-build | 76c22d0f0aa0e6541983fa793789f3a5774cf0ca | [
"BSL-1.0",
"BSD-3-Clause"
] | null | null | null | simulation/libsimulator/include/simulator/nat.hpp | SylemST-UtilCollection/libtorrent-build | 76c22d0f0aa0e6541983fa793789f3a5774cf0ca | [
"BSL-1.0",
"BSD-3-Clause"
] | null | null | null | simulation/libsimulator/include/simulator/nat.hpp | SylemST-UtilCollection/libtorrent-build | 76c22d0f0aa0e6541983fa793789f3a5774cf0ca | [
"BSL-1.0",
"BSD-3-Clause"
] | null | null | null | /*
Copyright (c) 2018, Arvid Norberg
All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef NAT_HPP_INCLUDED
#define NAT_HPP_INCLUDED
#include "simulator/sink.hpp"
#include "simulator/simulator.hpp"
#include <string>
namespace sim {
namespace aux {
struct packet;
}
struct SIMULATOR_DECL nat : sink
{
nat(asio::ip::address external_addr);
~nat() = default;
void incoming_packet(aux::packet p) override;
// used for visualization
std::string label() const override;
private:
asio::ip::address m_external_addr;
};
} // sim
#endif
| 22.846154 | 73 | 0.728956 | SylemST-UtilCollection |
2ee072991c17b1497ae153980f6bc9260119375e | 481 | cpp | C++ | 122A-luckyDivision.cpp | utkuozbudak/Codeforces | bf0b58604f9150f83356a8633407f873b1a49164 | [
"MIT"
] | 1 | 2020-02-29T20:01:03.000Z | 2020-02-29T20:01:03.000Z | 122A-luckyDivision.cpp | utkuozbudak/Codeforces | bf0b58604f9150f83356a8633407f873b1a49164 | [
"MIT"
] | null | null | null | 122A-luckyDivision.cpp | utkuozbudak/Codeforces | bf0b58604f9150f83356a8633407f873b1a49164 | [
"MIT"
] | null | null | null | #include <iostream>
#include "string"
using namespace std;
int main(int argc, const char * argv[])
{
int n;
cin>>n;
string s = to_string(n);
bool flag = true;
for(int i=0;i<s.length();i++)
{
if(s.at(i)== '4' || s.at(i) == '7') continue;
else flag = false;
}
if(!flag)
{
if(n%4 == 0 || n%7 == 0 || n%47 == 0 || n%74 == 0) flag = true;
}
if(flag) cout<<"YES";
else cout<< "NO";
return 0;
}
| 17.178571 | 71 | 0.455301 | utkuozbudak |
2ee7ccf009097205e3573651df2770506f364526 | 1,095 | cpp | C++ | Leetcode/L46.cpp | yanjinbin/Foxconn | d8340d228deb35bd8ec244f6156374da8a1f0aa0 | [
"CC0-1.0"
] | 8 | 2021-02-14T01:48:09.000Z | 2022-01-29T09:12:55.000Z | Leetcode/L46.cpp | yanjinbin/Foxconn | d8340d228deb35bd8ec244f6156374da8a1f0aa0 | [
"CC0-1.0"
] | null | null | null | Leetcode/L46.cpp | yanjinbin/Foxconn | d8340d228deb35bd8ec244f6156374da8a1f0aa0 | [
"CC0-1.0"
] | null | null | null | #include <vector>
#include <iostream>
#include <functional>
#define FOR(i, a, b) for (int i = a; i < b; i++)
using namespace std;
class Solution {
public:
vector<vector<int>> permute(vector<int> nums) {
const int N = nums.size();
vector<vector<int>> ans;
vector<bool> used(N, false);
vector<int> path;
function<void(int)> dfs = [&](int cur) {
if (cur == N) {
ans.push_back(path);
return;
}
for (int i = 0; i < N; i++) {
if (used[i])continue;
used[i] = true;
path.push_back(nums[i]);
dfs(cur + 1);
path.pop_back();
used[i] = false;
}
};
dfs(0);
return ans;
}
};
int main() {
Solution INSTANCE;
vector<int> nums = {1, 2, 3, 4};
vector<vector<int>> ans = INSTANCE.permute(nums);
FOR(i, 0, ans.size()) {
FOR(j, 0, ans[i].size()) {
cout << ans[i][j] << " ";
}
cout << endl;
}
return 0;
}
| 23.297872 | 53 | 0.438356 | yanjinbin |
2ee8af1983d8a6962a8e3cc5652578af7d603173 | 1,793 | cpp | C++ | Source/Urho3D/Graphics/Direct3D11/D3D11ConstantBuffer.cpp | 1vanK/Dviglo | 468a61e6d9a87cf7d998312c1261aaa83b37ff3c | [
"MIT"
] | null | null | null | Source/Urho3D/Graphics/Direct3D11/D3D11ConstantBuffer.cpp | 1vanK/Dviglo | 468a61e6d9a87cf7d998312c1261aaa83b37ff3c | [
"MIT"
] | 1 | 2021-04-17T22:38:25.000Z | 2021-04-18T00:43:15.000Z | Source/Urho3D/Graphics/Direct3D11/D3D11ConstantBuffer.cpp | 1vanK/Dviglo | 468a61e6d9a87cf7d998312c1261aaa83b37ff3c | [
"MIT"
] | null | null | null | // Copyright (c) 2008-2021 the Urho3D project
// Copyright (c) 2021 проект Dviglo
// Лицензия: MIT
#include "../../Precompiled.h"
#include "../../Graphics/Graphics.h"
#include "../../Graphics/GraphicsImpl.h"
#include "../../Graphics/ConstantBuffer.h"
#include "../../IO/Log.h"
#include "../../DebugNew.h"
using namespace std;
namespace Dviglo
{
void ConstantBuffer::OnDeviceReset()
{
// No-op on Direct3D11
}
void ConstantBuffer::Release()
{
URHO3D_SAFE_RELEASE(object_.ptr_);
shadowData_.reset();
size_ = 0;
}
bool ConstantBuffer::SetSize(unsigned size)
{
Release();
if (!size)
{
URHO3D_LOGERROR("Can not create zero-sized constant buffer");
return false;
}
// Round up to next 16 bytes
size += 15;
size &= 0xfffffff0;
size_ = size;
dirty_ = false;
shadowData_ = make_shared<unsigned char[]>(size_);
memset(shadowData_.get(), 0, size_);
if (graphics_)
{
D3D11_BUFFER_DESC bufferDesc;
memset(&bufferDesc, 0, sizeof bufferDesc);
bufferDesc.ByteWidth = size_;
bufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
bufferDesc.CPUAccessFlags = 0;
bufferDesc.Usage = D3D11_USAGE_DEFAULT;
HRESULT hr = graphics_->GetImpl()->GetDevice()->CreateBuffer(&bufferDesc, 0, (ID3D11Buffer**)&object_.ptr_);
if (FAILED(hr))
{
URHO3D_SAFE_RELEASE(object_.ptr_);
URHO3D_LOGD3DERROR("Failed to create constant buffer", hr);
return false;
}
}
return true;
}
void ConstantBuffer::Apply()
{
if (dirty_ && object_.ptr_)
{
graphics_->GetImpl()->GetDeviceContext()->UpdateSubresource((ID3D11Buffer*)object_.ptr_, 0, 0, shadowData_.get(), 0, 0);
dirty_ = false;
}
}
}
| 21.60241 | 128 | 0.626882 | 1vanK |
2ef024d12862684091c5cba12dd8f350567e315d | 3,451 | cpp | C++ | src/Value/Value.cpp | DmitrySoshnikov/mmgc | 57dd46374131758f2db5cf744c9fc2e4870f55e0 | [
"MIT"
] | 3 | 2019-10-27T02:35:48.000Z | 2021-07-23T14:06:03.000Z | src/Value/Value.cpp | DmitrySoshnikov/mmgc | 57dd46374131758f2db5cf744c9fc2e4870f55e0 | [
"MIT"
] | null | null | null | src/Value/Value.cpp | DmitrySoshnikov/mmgc | 57dd46374131758f2db5cf744c9fc2e4870f55e0 | [
"MIT"
] | 2 | 2019-10-29T09:54:25.000Z | 2019-11-28T02:19:18.000Z | /**
* The MIT License (MIT)
* Copyright (c) 2018-present Dmitry Soshnikov <[email protected]>
*/
#include "Value.h"
#include <stdexcept>
#include <string>
/**
* Returns the type of the value.
*/
Type Value::getType() {
if (_value & 1) {
return Type::Number;
} else if (_value == Value::TRUE || _value == Value::FALSE) {
return Type::Boolean;
}
return Type::Pointer;
}
/**
* Encodes a binary as a value.
*/
Value Value::encode(uint32_t value, Type valueType) {
switch (valueType) {
case Type::Number:
return Value((value << 1) | 1);
case Type::Boolean:
return Value(value == 1 ? TRUE : FALSE);
case Type::Pointer:
return Value(value);
default:
throw std::invalid_argument("Value::encode: unknown type.");
}
}
/**
* Encodes a number.
*/
Value Value::Number(uint32_t value) { return encode(value, Type::Number); }
/**
* Checks whether a value is a Number.
*/
bool Value::isNumber() { return getType() == Type::Number; }
/**
* Encodes a pointer.
*/
Value Value::Pointer(uint32_t value) { return encode(value, Type::Pointer); }
/**
* Encodes a nullptr.
*/
Value Value::Pointer(std::nullptr_t _p) { return encode(0, Type::Pointer); }
/**
* Checks whether a value is a Pointer.
*/
bool Value::isPointer() { return getType() == Type::Pointer; }
/**
* Checks whether a value is a Null Pointer.
*/
bool Value::isNullPointer() { return isPointer() && _value == 0; }
/**
* Encodes a boolean.
*/
Value Value::Boolean(uint32_t value) { return encode(value, Type::Boolean); }
/**
* Checks whether a value is a Boolean.
*/
bool Value::isBoolean() { return getType() == Type::Boolean; }
/**
* Returns the decoded value from this binary.
*/
uint32_t Value::decode() {
switch (getType()) {
case Type::Number:
return _value >> 1;
case Type::Boolean:
return (_value >> 4) & 1;
case Type::Pointer:
return _value;
default:
throw std::invalid_argument("Value::decode: unknown type.");
}
}
/**
* Enforces the pointer.
*/
inline void Value::_enforcePointer() {
if (!isPointer()) {
throw std::invalid_argument("Value is not a Pointer.");
}
}
/**
* Pointer arithmetics: p + i
*/
Value Value::operator +(int i) {
_enforcePointer();
return _value + (i * sizeof(uint32_t));
}
/**
* Pointer arithmetics: p += i
*/
Value Value::operator +=(int i) {
_enforcePointer();
_value += (i * sizeof(uint32_t));
return *this;
}
/**
* Pointer arithmetics: ++p
*/
Value& Value::operator ++() {
_enforcePointer();
_value += sizeof(uint32_t);
return *this;
}
/**
* Pointer arithmetics: p++
*/
Value Value::operator ++(int) {
_enforcePointer();
auto prev = _value;
_value += sizeof(uint32_t);
return prev;
}
/**
* Pointer arithmetics: p - i
*/
Value Value::operator -(int i) {
_enforcePointer();
return _value - (i * sizeof(uint32_t));
}
/**
* Pointer arithmetics: p -= i
*/
Value Value::operator -=(int i) {
_enforcePointer();
_value -= (i * sizeof(uint32_t));
return *this;
}
/**
* Pointer arithmetics: --p
*/
Value& Value::operator --() {
_enforcePointer();
_value -= sizeof(uint32_t);
return *this;
}
/**
* Pointer arithmetics: p--
*/
Value Value::operator --(int) {
_enforcePointer();
auto prev = _value;
_value -= sizeof(uint32_t);
return prev;
}
/**
* Encoded boolean values.
*/
const uint32_t Value::TRUE = 0b10110;
const uint32_t Value::FALSE = 0b00110;
| 19.172222 | 77 | 0.623587 | DmitrySoshnikov |
2ef1e2efa50baec9038aa2b06097c1ccf9ff634b | 13,570 | cpp | C++ | src/core/hw/gfxip/gfx9/gfx9PipelineChunkPs.cpp | ardacoskunses/pal | b2000b19a20b8ea1df06f50733d51e37c803b9c0 | [
"MIT"
] | null | null | null | src/core/hw/gfxip/gfx9/gfx9PipelineChunkPs.cpp | ardacoskunses/pal | b2000b19a20b8ea1df06f50733d51e37c803b9c0 | [
"MIT"
] | null | null | null | src/core/hw/gfxip/gfx9/gfx9PipelineChunkPs.cpp | ardacoskunses/pal | b2000b19a20b8ea1df06f50733d51e37c803b9c0 | [
"MIT"
] | null | null | null | /*
***********************************************************************************************************************
*
* Copyright (c) 2015-2018 Advanced Micro Devices, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
**********************************************************************************************************************/
#include "core/hw/gfxip/gfx9/gfx9CmdStream.h"
#include "core/hw/gfxip/gfx9/gfx9CmdUtil.h"
#include "core/hw/gfxip/gfx9/gfx9Device.h"
#include "core/hw/gfxip/gfx9/gfx9PipelineChunkPs.h"
#include "core/platform.h"
#include "palPipeline.h"
#include "palPipelineAbiProcessorImpl.h"
using namespace Util;
namespace Pal
{
namespace Gfx9
{
// =====================================================================================================================
PipelineChunkPs::PipelineChunkPs(
const Device& device)
:
m_device(device),
m_pPsPerfDataInfo(nullptr)
{
memset(&m_pm4ImageSh, 0, sizeof(m_pm4ImageSh));
memset(&m_pm4ImageShDynamic, 0, sizeof(m_pm4ImageShDynamic));
memset(&m_pm4ImageContext, 0, sizeof(m_pm4ImageContext));
memset(&m_stageInfo, 0, sizeof(m_stageInfo));
m_stageInfo.stageId = Abi::HardwareStage::Ps;
m_paScShaderControl.u32All = 0;
}
// =====================================================================================================================
// Initializes this pipeline chunk.
void PipelineChunkPs::Init(
const AbiProcessor& abiProcessor,
const CodeObjectMetadata& metadata,
const RegisterVector& registers,
const PsParams& params)
{
const Gfx9PalSettings& settings = m_device.Settings();
m_pPsPerfDataInfo = params.pPsPerfDataInfo;
uint16 lastPsInterpolator = mmSPI_PS_INPUT_CNTL_0;
for (uint32 i = 0; i < MaxPsInputSemantics; ++i)
{
const uint16 offset = static_cast<uint16>(mmSPI_PS_INPUT_CNTL_0 + i);
if (registers.HasEntry(offset, &m_pm4ImageContext.spiPsInputCntl[i].u32All))
{
lastPsInterpolator = offset;
}
else
{
break;
}
}
BuildPm4Headers(lastPsInterpolator);
m_pm4ImageSh.spiShaderPgmRsrc1Ps.u32All = registers.At(mmSPI_SHADER_PGM_RSRC1_PS);
m_pm4ImageSh.spiShaderPgmRsrc2Ps.u32All = registers.At(mmSPI_SHADER_PGM_RSRC2_PS);
registers.HasEntry(mmSPI_SHADER_PGM_RSRC3_PS, &m_pm4ImageShDynamic.spiShaderPgmRsrc3Ps.u32All);
// NOTE: The Pipeline ABI doesn't specify CU_GROUP_DISABLE for various shader stages, so it should be safe to
// always use the setting PAL prefers.
m_pm4ImageSh.spiShaderPgmRsrc1Ps.bits.CU_GROUP_DISABLE = (settings.psCuGroupEnabled ? 0 : 1);
m_pm4ImageShDynamic.spiShaderPgmRsrc3Ps.bits.CU_EN = m_device.GetCuEnableMask(0, settings.psCuEnLimitMask);
m_pm4ImageContext.dbShaderControl.u32All = registers.At(mmDB_SHADER_CONTROL);
m_pm4ImageContext.paScAaConfig.reg_data = registers.At(mmPA_SC_AA_CONFIG);
m_paScShaderControl.u32All = registers.At(mmPA_SC_SHADER_CONTROL);
m_pm4ImageContext.spiBarycCntl.u32All = registers.At(mmSPI_BARYC_CNTL);
m_pm4ImageContext.spiPsInputAddr.u32All = registers.At(mmSPI_PS_INPUT_ADDR);
m_pm4ImageContext.spiPsInputEna.u32All = registers.At(mmSPI_PS_INPUT_ENA);
m_pm4ImageContext.spiShaderColFormat.u32All = registers.At(mmSPI_SHADER_COL_FORMAT);
m_pm4ImageContext.spiShaderZFormat.u32All = registers.At(mmSPI_SHADER_Z_FORMAT);
m_pm4ImageContext.paScConservativeRastCntl.reg_data =
registers.At(mmPA_SC_CONSERVATIVE_RASTERIZATION_CNTL);
// Override the Pipeline ABI's reported COVERAGE_AA_MASK_ENABLE bit if the settings request it.
if (settings.disableCoverageAaMask)
{
m_pm4ImageContext.paScConservativeRastCntl.reg_data &=
~PA_SC_CONSERVATIVE_RASTERIZATION_CNTL__COVERAGE_AA_MASK_ENABLE_MASK;
}
// Binner_cntl1:
// 16 bits: Maximum amount of parameter storage allowed per batch.
// - Legacy: param cache lines/2 (groups of 16 vert-attributes) (0 means 1 encoding)
// - NGG: number of vert-attributes (0 means 1 encoding)
// - NGG + PC: param cache lines/2 (groups of 16 vert-attributes) (0 means 1 encoding)
// 16 bits: Max number of primitives in batch
m_pm4ImageContext.paScBinnerCntl1.u32All = 0;
m_pm4ImageContext.paScBinnerCntl1.bits.MAX_PRIM_PER_BATCH = settings.binningMaxPrimPerBatch - 1;
if (params.isNgg)
{
// If we add support for off-chip parameter cache this code will need to be updated as well.
PAL_ALERT(m_device.Parent()->ChipProperties().gfx9.primShaderInfo.parameterCacheSize != 0);
m_pm4ImageContext.paScBinnerCntl1.bits.MAX_ALLOC_COUNT = settings.binningMaxAllocCountNggOnChip - 1;
}
else
{
m_pm4ImageContext.paScBinnerCntl1.bits.MAX_ALLOC_COUNT = settings.binningMaxAllocCountLegacy - 1;
}
// Compute the checksum here because we don't want it to include the GPU virtual addresses!
params.pHasher->Update(m_pm4ImageContext);
Abi::PipelineSymbolEntry symbol = { };
if (abiProcessor.HasPipelineSymbolEntry(Abi::PipelineSymbolType::PsMainEntry, &symbol))
{
const gpusize programGpuVa = (symbol.value + params.codeGpuVirtAddr);
PAL_ASSERT(programGpuVa == Pow2Align(programGpuVa, 256));
m_pm4ImageSh.spiShaderPgmLoPs.bits.MEM_BASE = Get256BAddrLo(programGpuVa);
m_pm4ImageSh.spiShaderPgmHiPs.bits.MEM_BASE = Get256BAddrHi(programGpuVa);
m_stageInfo.codeLength = static_cast<size_t>(symbol.size);
}
if (abiProcessor.HasPipelineSymbolEntry(Abi::PipelineSymbolType::PsShdrIntrlTblPtr, &symbol))
{
const gpusize srdTableGpuVa = (symbol.value + params.dataGpuVirtAddr);
m_pm4ImageSh.spiShaderUserDataLoPs.bits.DATA = LowPart(srdTableGpuVa);
}
if (abiProcessor.HasPipelineSymbolEntry(Abi::PipelineSymbolType::PsDisassembly, &symbol))
{
m_stageInfo.disassemblyLength = static_cast<size_t>(symbol.size);
}
}
// =====================================================================================================================
// Copies this pipeline chunk's sh commands into the specified command space. Returns the next unused DWORD in
// pCmdSpace.
uint32* PipelineChunkPs::WriteShCommands(
CmdStream* pCmdStream,
uint32* pCmdSpace,
const DynamicStageInfo& vsStageInfo
) const
{
Pm4ImageShDynamic pm4ImageShDynamic = m_pm4ImageShDynamic;
if (vsStageInfo.wavesPerSh > 0)
{
pm4ImageShDynamic.spiShaderPgmRsrc3Ps.bits.WAVE_LIMIT = vsStageInfo.wavesPerSh;
}
if (vsStageInfo.cuEnableMask != 0)
{
pm4ImageShDynamic.spiShaderPgmRsrc3Ps.bits.CU_EN &= vsStageInfo.cuEnableMask;
}
pCmdSpace = pCmdStream->WritePm4Image(m_pm4ImageSh.spaceNeeded, &m_pm4ImageSh, pCmdSpace);
pCmdSpace = pCmdStream->WritePm4Image(pm4ImageShDynamic.spaceNeeded, &pm4ImageShDynamic, pCmdSpace);
if (m_pPsPerfDataInfo->regOffset != UserDataNotMapped)
{
pCmdSpace = pCmdStream->WriteSetOneShReg<ShaderGraphics>(m_pPsPerfDataInfo->regOffset,
m_pPsPerfDataInfo->gpuVirtAddr,
pCmdSpace);
}
return pCmdSpace;
}
// =====================================================================================================================
// Copies this pipeline chunk's context commands into the specified command space. Returns the next unused DWORD in
// pCmdSpace.
uint32* PipelineChunkPs::WriteContextCommands(
CmdStream* pCmdStream,
uint32* pCmdSpace
) const
{
pCmdSpace = pCmdStream->WritePm4Image(m_pm4ImageContext.spaceNeeded, &m_pm4ImageContext, pCmdSpace);
return pCmdSpace;
}
// =====================================================================================================================
// Assembles the PM4 headers for the commands in this pipeline chunk.
void PipelineChunkPs::BuildPm4Headers(
uint32 lastPsInterpolator)
{
const CmdUtil& cmdUtil = m_device.CmdUtil();
// Sets the following SH registers: SPI_SHADER_PGM_LO_PS, SPI_SHADER_PGM_HI_PS,
// SPI_SHADER_PGM_RSRC1_PS, SPI_SHADER_PGM_RSRC2_PS.
m_pm4ImageSh.spaceNeeded = cmdUtil.BuildSetSeqShRegs(mmSPI_SHADER_PGM_LO_PS,
mmSPI_SHADER_PGM_RSRC2_PS,
ShaderGraphics,
&m_pm4ImageSh.hdrSpiShaderPgm);
// Sets the following SH register: SPI_SHADER_USER_DATA_PS_1.
m_pm4ImageSh.spaceNeeded += cmdUtil.BuildSetOneShReg(mmSPI_SHADER_USER_DATA_PS_0 + ConstBufTblStartReg,
ShaderGraphics,
&m_pm4ImageSh.hdrSpiShaderUserData);
// Sets the following SH register: SPI_SHADER_PGM_RSRC3_PS.
// We must use the SET_SH_REG_INDEX packet to support the real-time compute feature.
m_pm4ImageShDynamic.spaceNeeded = cmdUtil.BuildSetOneShRegIndex(mmSPI_SHADER_PGM_RSRC3_PS,
ShaderGraphics,
index__pfp_set_sh_reg_index__apply_kmd_cu_and_mask,
&m_pm4ImageShDynamic.hdrPgmRsrc3Ps);
// Sets the following context register:
// SPI_SHADER_Z_FORMAT, SPI_SHADER_COL_FORMAT.
m_pm4ImageContext.spaceNeeded = cmdUtil.BuildSetSeqContextRegs(mmSPI_SHADER_Z_FORMAT,
mmSPI_SHADER_COL_FORMAT,
&m_pm4ImageContext.hdrSpiShaderFormat);
// Sets the following context register: SPI_BARYC_CNTL.
m_pm4ImageContext.spaceNeeded += cmdUtil.BuildSetOneContextReg(mmSPI_BARYC_CNTL,
&m_pm4ImageContext.hdrSpiBarycCntl);
// Sets the following context registers: SPI_PS_INPUT_ENA, SPI_PS_INPUT_ADDR.
m_pm4ImageContext.spaceNeeded += cmdUtil.BuildSetSeqContextRegs(mmSPI_PS_INPUT_ENA,
mmSPI_PS_INPUT_ADDR,
&m_pm4ImageContext.hdrSpiPsInput);
// Sets the following context register: DB_SHADER_CONTROL.
m_pm4ImageContext.spaceNeeded += cmdUtil.BuildSetOneContextReg(mmDB_SHADER_CONTROL,
&m_pm4ImageContext.hdrDbShaderControl);
// Sets the following context register: PA_SC_BINNER_CNTL_1.
m_pm4ImageContext.spaceNeeded += cmdUtil.BuildSetOneContextReg(mmPA_SC_BINNER_CNTL_1,
&m_pm4ImageContext.hdrPaScBinnerCntl1);
m_pm4ImageContext.spaceNeeded += cmdUtil.BuildContextRegRmw(
mmPA_SC_AA_CONFIG,
static_cast<uint32>(PA_SC_AA_CONFIG__COVERAGE_TO_SHADER_SELECT_MASK),
0,
&m_pm4ImageContext.paScAaConfig);
m_pm4ImageContext.spaceNeeded += cmdUtil.BuildContextRegRmw(
mmPA_SC_CONSERVATIVE_RASTERIZATION_CNTL,
static_cast<uint32>(PA_SC_CONSERVATIVE_RASTERIZATION_CNTL__COVERAGE_AA_MASK_ENABLE_MASK |
PA_SC_CONSERVATIVE_RASTERIZATION_CNTL__UNDER_RAST_ENABLE_MASK),
0, // filled in by the "Init" function
&m_pm4ImageContext.paScConservativeRastCntl);
// Sets the following context registers: SPI_PS_INPUT_CNTL_0 - SPI_PS_INPUT_CNTL_X.
m_pm4ImageContext.spaceNeeded += m_device.CmdUtil().BuildSetSeqContextRegs(mmSPI_PS_INPUT_CNTL_0,
lastPsInterpolator,
&m_pm4ImageContext.hdrSpiPsInputCntl);
}
// =====================================================================================================================
regPA_SC_SHADER_CONTROL PipelineChunkPs::PaScShaderControl(
uint32 numIndices
) const
{
regPA_SC_SHADER_CONTROL paScShaderControl = m_paScShaderControl;
return paScShaderControl;
}
} // Gfx9
} // Pal
| 47.118056 | 120 | 0.628592 | ardacoskunses |
2ef78ae07de7820a064167e31e229956b76ee6ff | 1,046 | cpp | C++ | src/xray/editor/world/sources/property_integer_limited.cpp | ixray-team/ixray-2.0 | 85c3a544175842323fc82f42efd96c66f0fc5abb | [
"Linux-OpenIB"
] | 3 | 2021-10-30T09:36:14.000Z | 2022-03-26T17:00:06.000Z | src/xray/editor/world/sources/property_integer_limited.cpp | acidicMercury8/ixray-2.0 | 85c3a544175842323fc82f42efd96c66f0fc5abb | [
"Linux-OpenIB"
] | null | null | null | src/xray/editor/world/sources/property_integer_limited.cpp | acidicMercury8/ixray-2.0 | 85c3a544175842323fc82f42efd96c66f0fc5abb | [
"Linux-OpenIB"
] | 1 | 2022-03-26T17:00:08.000Z | 2022-03-26T17:00:08.000Z | ////////////////////////////////////////////////////////////////////////////
// Created : 07.12.2007
// Author : Dmitriy Iassenev
// Copyright (C) GSC Game World - 2009
////////////////////////////////////////////////////////////////////////////
#include "pch.h"
#include "property_integer_limited.h"
property_integer_limited::property_integer_limited (
integer_getter_type^ getter,
integer_setter_type^ setter,
int const %min,
int const %max
) :
inherited (getter, setter),
m_min (min),
m_max (max)
{
}
System::Object ^property_integer_limited::get_value ()
{
int value = safe_cast<int>(inherited::get_value());
if (value < m_min)
value = m_min;
if (value > m_max)
value = m_max;
return (value);
}
void property_integer_limited::set_value (System::Object ^object)
{
int new_value = safe_cast<int>(object);
if (new_value < m_min)
new_value = m_min;
if (new_value > m_max)
new_value = m_max;
inherited::set_value (new_value);
} | 23.244444 | 77 | 0.546845 | ixray-team |
2efc95b839c26f5d7faa4b2cbdab481ba04b3704 | 478 | cpp | C++ | Engine/src/Engine.cpp | listopat/Ray-Tracer | e29c37475b7b575c399cce03b0f4d7fafc942643 | [
"MIT"
] | 2 | 2020-12-27T21:49:38.000Z | 2020-12-28T22:49:11.000Z | Engine/src/Engine.cpp | listopat/Ray-Tracer | e29c37475b7b575c399cce03b0f4d7fafc942643 | [
"MIT"
] | null | null | null | Engine/src/Engine.cpp | listopat/Ray-Tracer | e29c37475b7b575c399cce03b0f4d7fafc942643 | [
"MIT"
] | null | null | null | #include <Engine.h>
#include <SceneParser.h>
#include <ImageIOInterface.h>
#include <fstream>
void Engine::renderToFile(std::string scenePath, std::string outputPath)
{
std::ifstream ifs(scenePath);
nlohmann::json sceneJson = nlohmann::json::parse(ifs);
Camera camera = SceneParser::getCameraFromSceneJSON(sceneJson);
World world = SceneParser::getWorldFromSceneJSON(sceneJson);
Canvas image = camera.render(world);
ImageIOInterface::saveToImage(image, outputPath);
}
| 26.555556 | 72 | 0.771967 | listopat |
2c01a95c0be9a3dcccd40093413dff54587a4329 | 2,614 | cpp | C++ | src/simulator/simulator.cpp | happydpc/RobotSimulator | 0c09d09e802c3118a2beabc7999637ce1fa4e7a7 | [
"MIT"
] | 1 | 2021-12-22T18:24:08.000Z | 2021-12-22T18:24:08.000Z | src/simulator/simulator.cpp | happydpc/RobotSimulator | 0c09d09e802c3118a2beabc7999637ce1fa4e7a7 | [
"MIT"
] | null | null | null | src/simulator/simulator.cpp | happydpc/RobotSimulator | 0c09d09e802c3118a2beabc7999637ce1fa4e7a7 | [
"MIT"
] | null | null | null | //--------------------------------------------------
// Robot Simulator
// simulator.cpp
// Date: 2020-06-21
// By Breno Cunha Queiroz
//--------------------------------------------------
#include "simulator.h"
#include "objects/basic/importedObject.h"
#include "objects/basic/plane.h"
#include "objects/basic/box.h"
#include "objects/basic/sphere.h"
#include "objects/basic/cylinder.h"
#include "physics/constraints/fixedConstraint.h"
#include "physics/constraints/hingeConstraint.h"
Simulator::Simulator()
{
_scene = new Scene();
// Load objects
_scene->loadObject("wheel");
// Create object instances
Box* ground = new Box("Ground", {0,-1,0}, {0,0,0}, {200, 2, 200}, 0.0f, {0,0,0});
ImportedObject* wheel = new ImportedObject("Wheel test", "wheel", {-0.4,0.06,0}, {0,0,90}, {1,1,1}, 0.1f);
// Create demo robot (ttzinho)
_ttzinho = new Ttzinho();
_scene->addObject((Object*)ground);// Add a simple object
_scene->addComplexObject(_ttzinho->getObject());// Add the object and its children
_scene->addObject((Object*)wheel);// Add a simple object
_scene->linkObjects();
_debugDrawer = new DebugDrawer(_scene);
_vulkanApp = new Application(_scene);
_vulkanApp->onDrawFrame = [this](float dt){ onDrawFrame(dt); };
_vulkanApp->onRaycastClick = [this](glm::vec3 pos, glm::vec3 ray){ onRaycastClick(pos, ray); };
}
Simulator::~Simulator()
{
if(_vulkanApp != nullptr)
{
delete _vulkanApp;
_vulkanApp = nullptr;
}
if(_scene != nullptr)
{
delete _scene;
_scene = nullptr;
}
if(_debugDrawer != nullptr)
{
delete _debugDrawer;
_debugDrawer = nullptr;
}
if(_ttzinho != nullptr)
{
delete _ttzinho;
_ttzinho = nullptr;
}
}
void Simulator::run()
{
_vulkanApp->run();
}
void Simulator::onDrawFrame(float dt)
{
//btVector3 old = _scene->getObjects()[9]->getObjectPhysics()->getRigidBody()->getLinearVelocity();
//_scene->getObjects()[9]->getObjectPhysics()->getRigidBody()->setLinearVelocity(btVector3(-1.0f, old.y(), old.z()));
//_scene->getObjects()[9]->getObjectPhysics()->getRigidBody()->setAngularVelocity(btVector3(0.0f, 1.0f, 0.0f));
}
void Simulator::onRaycastClick(glm::vec3 pos, glm::vec3 ray)
{
//_scene->addLine(pos, pos+ray, {rand()%255/255.f,rand()%255/255.f,rand()%255/255.f});
//PhysicsEngine::RayResult result;
//if(!_scene->getPhysicsEngine()->raycast(pos, ray, result))
// return;
//Object* object = _scene->getObjectFromPhysicsBody(result.body);
//
//if(object != nullptr)
//{
// printf("Hit something! %s (%f, %f, %f)\n", object->getName().c_str(), result.hitPoint.x, result.hitPoint.y, result.hitPoint.z);
// fflush(stdout);
//}
}
| 26.673469 | 131 | 0.657995 | happydpc |
2c05b81bb231c3c4338610f4df8a995eeda15619 | 5,576 | cpp | C++ | Development/Source/Engine/Framework/Graphics/DX12/SwapchainDX12.cpp | onovytskyi/Headless-Droid-Engine | 358cd3164bfe5b1d0aaf38c4a1a96dce54ac00c9 | [
"MIT"
] | null | null | null | Development/Source/Engine/Framework/Graphics/DX12/SwapchainDX12.cpp | onovytskyi/Headless-Droid-Engine | 358cd3164bfe5b1d0aaf38c4a1a96dce54ac00c9 | [
"MIT"
] | null | null | null | Development/Source/Engine/Framework/Graphics/DX12/SwapchainDX12.cpp | onovytskyi/Headless-Droid-Engine | 358cd3164bfe5b1d0aaf38c4a1a96dce54ac00c9 | [
"MIT"
] | null | null | null | #include "Engine/Config/Bootstrap.h"
#include "Engine/Framework/Graphics/Swapchain.h"
#if defined(HD_GRAPHICS_API_DX12)
#include "Engine/Debug/Assert.h"
#include "Engine/Debug/Log.h"
#include "Engine/Foundation/Memory/Utils.h"
#include "Engine/Framework/Graphics/Backend.h"
#include "Engine/Framework/Graphics/DX12/TextureDX12.h"
#include "Engine/Framework/Graphics/DX12/UtilsDX12.h"
#include "Engine/Framework/Graphics/Device.h"
#include "Engine/Framework/Graphics/Fence.h"
#include "Engine/Framework/Graphics/Queue.h"
#include "Engine/Framework/System/SystemWindow.h"
namespace hd
{
namespace gfx
{
SwapchainPlatform::SwapchainPlatform(Allocator& persistentAllocator, Backend& backend, Device& device, Queue& queue, sys::SystemWindow& window, GraphicFormat format)
: m_PersistentAllocator{ persistentAllocator }
, m_OwnerDevice{ &device }
, m_FlipQueue{ &queue }
, m_Format{ format }
, m_FramebufferIndex{}
, m_FrameFence{}
, m_CPUFrame{}
, m_GPUFrame{}
{
DXGI_SWAP_CHAIN_DESC1 swapChainDesc{};
swapChainDesc.Width = window.GetWidth();
swapChainDesc.Height = window.GetHeight();
swapChainDesc.Format = ConvertToResourceFormat(m_Format);
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.BufferCount = cfg::MaxFrameLatency();
swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
ComPtr<IDXGISwapChain1> swapChain1;
hdEnsure(backend.GetNativeFactory()->CreateSwapChainForHwnd(
queue.GetNativeQueue(),
window.GetNativeHandle(),
&swapChainDesc,
nullptr,
nullptr,
&swapChain1));
hdEnsure(swapChain1.As<IDXGISwapChain3>(&m_SwapChain));
hdLogInfo(u8"Swap chain created %x% [%].", swapChainDesc.Width, swapChainDesc.Height, size_t(window.GetNativeHandle()));
// Disable fullscreen transitions
hdEnsure(backend.GetNativeFactory()->MakeWindowAssociation(window.GetNativeHandle(), DXGI_MWA_NO_ALT_ENTER));
m_FramebufferIndex = m_SwapChain->GetCurrentBackBufferIndex();
CreateFramebufferTextures();
m_FrameFence = hdNew(m_PersistentAllocator, Fence)(*m_OwnerDevice, 0U);
}
SwapchainPlatform::~SwapchainPlatform()
{
m_FlipQueue->Flush();
ReleaseFrameBufferTextures();
hdSafeDelete(m_PersistentAllocator, m_FrameFence);
}
void SwapchainPlatform::UpdateGPUFrame()
{
m_GPUFrame = m_FrameFence->GetValue();
// Wait for GPU to not exceed maximum queued frames
if (m_CPUFrame - m_GPUFrame >= cfg::MaxFrameLatency())
{
uint64_t gpuFrameToWait = m_CPUFrame - cfg::MaxFrameLatency() + 1;
m_FrameFence->Wait(gpuFrameToWait);
m_GPUFrame = m_FrameFence->GetValue();
}
}
void SwapchainPlatform::CreateFramebufferTextures()
{
for (uint32_t framebufferIdx = 0U; framebufferIdx < cfg::MaxFrameLatency(); ++framebufferIdx)
{
ID3D12Resource* resource{};
hdEnsure(m_SwapChain->GetBuffer(framebufferIdx, IID_PPV_ARGS(&resource)));
m_FramebufferTextures[framebufferIdx] = m_OwnerDevice->RegisterTexture(resource, D3D12_RESOURCE_STATE_PRESENT, m_Format, TextureFlagsBits::RenderTarget,
TextureDimenstion::Texture2D);
}
}
void SwapchainPlatform::ReleaseFrameBufferTextures()
{
for (uint32_t framebufferIdx = 0; framebufferIdx < cfg::MaxFrameLatency(); ++framebufferIdx)
{
m_OwnerDevice->DestroyTextureImmediate(m_FramebufferTextures[framebufferIdx]);
}
}
void Swapchain::Flip()
{
TextureHandle framebuffer;
framebuffer = GetActiveFramebuffer();
m_FlipQueue->PresentFrom(framebuffer);
m_CPUFrame += 1;
m_FlipQueue->Signal(*m_FrameFence, m_CPUFrame);
m_SwapChain->Present(0, 0);
m_FramebufferIndex = m_SwapChain->GetCurrentBackBufferIndex();
UpdateGPUFrame();
}
void Swapchain::Resize(uint32_t width, uint32_t height)
{
m_FlipQueue->Flush();
UpdateGPUFrame();
ReleaseFrameBufferTextures();
DXGI_SWAP_CHAIN_DESC1 swapchainDesc{};
hdEnsure(m_SwapChain->GetDesc1(&swapchainDesc));
hdEnsure(m_SwapChain->ResizeBuffers(swapchainDesc.BufferCount, width, height, swapchainDesc.Format, swapchainDesc.Flags));
CreateFramebufferTextures();
m_FramebufferIndex = m_SwapChain->GetCurrentBackBufferIndex();
}
TextureHandle Swapchain::GetActiveFramebuffer() const
{
return m_FramebufferTextures[m_FramebufferIndex];
}
uint64_t Swapchain::GetCPUFrame() const
{
return m_CPUFrame;
}
uint64_t Swapchain::GetGPUFrame() const
{
return m_GPUFrame;
}
}
}
#endif | 35.74359 | 173 | 0.630739 | onovytskyi |
2c07ab83a256fc9d21b95c3671fbcfc83004ac5e | 8,728 | cc | C++ | SimG4Core/MagneticField/src/CMSFieldManager.cc | akhter-towsifa/cmssw | c9dad837e419070a532a4951c397bcc68f5bd095 | [
"Apache-2.0"
] | 1 | 2021-01-25T16:39:35.000Z | 2021-01-25T16:39:35.000Z | SimG4Core/MagneticField/src/CMSFieldManager.cc | akhter-towsifa/cmssw | c9dad837e419070a532a4951c397bcc68f5bd095 | [
"Apache-2.0"
] | 2 | 2021-02-17T10:06:46.000Z | 2021-02-22T08:00:41.000Z | SimG4Core/MagneticField/src/CMSFieldManager.cc | akhter-towsifa/cmssw | c9dad837e419070a532a4951c397bcc68f5bd095 | [
"Apache-2.0"
] | null | null | null | #include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "SimG4Core/MagneticField/interface/CMSFieldManager.h"
#include "SimG4Core/MagneticField/interface/Field.h"
#include "CLHEP/Units/GlobalSystemOfUnits.h"
#include "G4ChordFinder.hh"
#include "G4MagIntegratorStepper.hh"
#include "G4PropagatorInField.hh"
#include "G4Region.hh"
#include "G4RegionStore.hh"
#include "G4Track.hh"
CMSFieldManager::CMSFieldManager()
: G4FieldManager(),
m_currChordFinder(nullptr),
m_chordFinder(nullptr),
m_chordFinderMonopole(nullptr),
m_propagator(nullptr),
m_dChord(0.001),
m_dChordTracker(0.001),
m_dOneStep(0.001),
m_dOneStepTracker(0.0001),
m_dIntersection(0.0001),
m_dInterTracker(1e-6),
m_Rmax2(1.e+6),
m_Zmax(3.e+3),
m_stepMax(1000000.),
m_energyThTracker(1.e+7),
m_energyThreshold(0.0),
m_dChordSimple(0.1),
m_dOneStepSimple(0.1),
m_dIntersectionSimple(0.01),
m_stepMaxSimple(1000.),
m_cfTracker(false),
m_cfVacuum(false) {}
CMSFieldManager::~CMSFieldManager() {
if (m_chordFinder != m_currChordFinder) {
delete m_chordFinder;
}
if (m_chordFinderMonopole != m_currChordFinder) {
delete m_chordFinderMonopole;
}
}
void CMSFieldManager::InitialiseForVolume(const edm::ParameterSet &p,
sim::Field *field,
G4ChordFinder *cf,
G4ChordFinder *cfmon,
const std::string &vol,
const std::string &type,
const std::string &stepper,
double delta,
G4PropagatorInField *pf) {
double minstep = p.getParameter<double>("MinStep") * CLHEP::mm;
double minEpsStep = p.getUntrackedParameter<double>("MinimumEpsilonStep", 0.00001) * CLHEP::mm;
double maxEpsStep = p.getUntrackedParameter<double>("MaximumEpsilonStep", 0.01) * CLHEP::mm;
int maxLC = (int)p.getUntrackedParameter<double>("MaximumLoopCounts", 1000.);
// double
m_dChord = p.getParameter<double>("DeltaChord") * CLHEP::mm;
m_dChordTracker = p.getParameter<double>("DeltaChord") * CLHEP::mm;
m_dOneStep = p.getParameter<double>("DeltaOneStep") * CLHEP::mm;
m_dOneStepTracker = p.getParameter<double>("DeltaOneStepTracker") * CLHEP::mm;
m_dIntersection = p.getParameter<double>("DeltaIntersection") * CLHEP::mm;
m_dInterTracker = p.getParameter<double>("DeltaIntersectionTracker") * CLHEP::mm;
m_stepMax = p.getParameter<double>("MaxStep") * CLHEP::cm;
m_energyThreshold = p.getParameter<double>("EnergyThSimple") * CLHEP::GeV;
m_energyThTracker = p.getParameter<double>("EnergyThTracker") * CLHEP::GeV;
double rmax = p.getParameter<double>("RmaxTracker") * CLHEP::mm;
m_Rmax2 = rmax * rmax;
m_Zmax = p.getParameter<double>("ZmaxTracker") * CLHEP::mm;
m_dChordSimple = p.getParameter<double>("DeltaChordSimple") * CLHEP::mm;
m_dOneStepSimple = p.getParameter<double>("DeltaOneStepSimple") * CLHEP::mm;
m_dIntersectionSimple = p.getParameter<double>("DeltaIntersectionSimple") * CLHEP::mm;
m_stepMaxSimple = p.getParameter<double>("MaxStepSimple") * CLHEP::cm;
edm::LogVerbatim("SimG4CoreApplication")
<< " New CMSFieldManager: LogicalVolume: <" << vol << ">\n"
<< " Stepper: <" << stepper << ">\n"
<< " Field type <" << type << ">\n"
<< " Field const delta " << delta << " mm\n"
<< " MaximumLoopCounts " << maxLC << "\n"
<< " MinimumEpsilonStep " << minEpsStep << "\n"
<< " MaximumEpsilonStep " << maxEpsStep << "\n"
<< " MinStep " << minstep << " mm\n"
<< " MaxStep " << m_stepMax / CLHEP::cm << " cm\n"
<< " DeltaChord " << m_dChord << " mm\n"
<< " DeltaOneStep " << m_dOneStep << " mm\n"
<< " DeltaIntersection " << m_dIntersection << " mm\n"
<< " DeltaInterTracker " << m_dInterTracker << " mm\n"
<< " EnergyThresholdSimple " << m_energyThreshold / CLHEP::MeV << " MeV\n"
<< " EnergyThresholdTracker " << m_energyThTracker / CLHEP::MeV << " MeV\n"
<< " DeltaChordSimple " << m_dChordSimple << " mm\n"
<< " DeltaOneStepSimple " << m_dOneStepSimple << " mm\n"
<< " DeltaIntersectionSimple " << m_dIntersectionSimple << " mm\n"
<< " MaxStepInVacuum " << m_stepMaxSimple / CLHEP::cm << " cm";
// initialisation of chord finders
m_chordFinder = cf;
m_chordFinderMonopole = cfmon;
m_chordFinderMonopole->SetDeltaChord(m_dChord);
// initialisation of field manager
theField.reset(field);
SetDetectorField(field);
SetMinimumEpsilonStep(minEpsStep);
SetMaximumEpsilonStep(maxEpsStep);
// propagater in field
m_propagator = pf;
pf->SetMaxLoopCount(maxLC);
pf->SetMinimumEpsilonStep(minEpsStep);
pf->SetMaximumEpsilonStep(maxEpsStep);
// initial initialisation the default chord finder
setMonopoleTracking(false);
// define regions
std::vector<std::string> rnames = p.getParameter<std::vector<std::string>>("VacRegions");
if (!rnames.empty()) {
std::stringstream ss;
std::vector<G4Region *> *rs = G4RegionStore::GetInstance();
for (auto ®nam : rnames) {
for (auto ® : *rs) {
if (regnam == reg->GetName()) {
m_regions.push_back(reg);
ss << " " << regnam;
}
}
}
edm::LogVerbatim("SimG4CoreApplication") << "Simple field integration in G4Regions:\n" << ss.str() << "\n";
}
}
void CMSFieldManager::ConfigureForTrack(const G4Track *track) {
// run time parameters per track
if (track->GetKineticEnergy() > m_energyThTracker && isInsideTracker(track)) {
if (!m_cfTracker) {
setChordFinderForTracker();
}
} else if ((track->GetKineticEnergy() <= m_energyThreshold && track->GetParentID() > 0) || isInsideVacuum(track)) {
if (!m_cfVacuum) {
setChordFinderForVacuum();
}
} else if (m_cfTracker || m_cfVacuum) {
// restore defaults
setDefaultChordFinder();
}
}
void CMSFieldManager::setMonopoleTracking(G4bool flag) {
if (flag) {
if (m_currChordFinder != m_chordFinderMonopole) {
if (m_cfTracker || m_cfVacuum) {
setDefaultChordFinder();
}
m_currChordFinder = m_chordFinderMonopole;
SetChordFinder(m_currChordFinder);
}
} else {
setDefaultChordFinder();
}
SetFieldChangesEnergy(flag);
m_currChordFinder->ResetStepEstimate();
}
bool CMSFieldManager::isInsideVacuum(const G4Track *track) {
if (!m_regions.empty()) {
const G4Region *reg = track->GetVolume()->GetLogicalVolume()->GetRegion();
for (auto &areg : m_regions) {
if (reg == areg) {
return true;
}
}
}
return false;
}
bool CMSFieldManager::isInsideTracker(const G4Track *track) {
const G4ThreeVector &pos = track->GetPosition();
const double x = pos.x();
const double y = pos.y();
return (x * x + y * y < m_Rmax2 && std::abs(pos.z()) < m_Zmax);
}
void CMSFieldManager::setDefaultChordFinder() {
if (m_currChordFinder != m_chordFinder) {
m_currChordFinder = m_chordFinder;
SetChordFinder(m_currChordFinder);
}
m_currChordFinder->SetDeltaChord(m_dChord);
SetDeltaOneStep(m_dOneStep);
SetDeltaIntersection(m_dIntersection);
m_propagator->SetLargestAcceptableStep(m_stepMax);
m_cfVacuum = m_cfTracker = false;
}
void CMSFieldManager::setChordFinderForTracker() {
if (m_currChordFinder != m_chordFinder) {
m_currChordFinder = m_chordFinder;
SetChordFinder(m_currChordFinder);
}
m_currChordFinder->SetDeltaChord(m_dChordTracker);
SetDeltaOneStep(m_dOneStepTracker);
SetDeltaIntersection(m_dInterTracker);
m_propagator->SetLargestAcceptableStep(m_stepMax);
m_cfVacuum = false;
m_cfTracker = true;
}
void CMSFieldManager::setChordFinderForVacuum() {
if (m_currChordFinder != m_chordFinder) {
m_currChordFinder = m_chordFinder;
SetChordFinder(m_currChordFinder);
}
m_currChordFinder->SetDeltaChord(m_dChordSimple);
SetDeltaOneStep(m_dOneStepSimple);
SetDeltaIntersection(m_dIntersectionSimple);
m_propagator->SetLargestAcceptableStep(m_stepMaxSimple);
m_cfVacuum = true;
m_cfTracker = false;
}
| 37.947826 | 117 | 0.623854 | akhter-towsifa |
2c09499c65944a7e2454ae72a6072ca1dc77b716 | 2,566 | cpp | C++ | Source/ReadingTracker/Private/SubmixRecorder.cpp | scivi-tools/scivi.ue.board | c41ea99f4016f22f122bc38b45410ee773c2ec1b | [
"MIT"
] | 1 | 2022-02-17T19:48:49.000Z | 2022-02-17T19:48:49.000Z | Source/ReadingTracker/Private/SubmixRecorder.cpp | scivi-tools/scivi.ue.board | c41ea99f4016f22f122bc38b45410ee773c2ec1b | [
"MIT"
] | null | null | null | Source/ReadingTracker/Private/SubmixRecorder.cpp | scivi-tools/scivi.ue.board | c41ea99f4016f22f122bc38b45410ee773c2ec1b | [
"MIT"
] | null | null | null | // Fill out your copyright notice in the Description page of Project Settings.
#include "SubmixRecorder.h"
#include "AudioDevice.h"
#include "AudioDeviceManager.h"
#include "Sound/SoundSubmix.h"
// Sets default values for this component's properties
USubmixRecorder::USubmixRecorder()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = false;
new_batch.NumChannels = RecordNumChannels;
new_batch.NumSamples = 0;
new_batch.NumFrames = 0;
new_batch.SampleDuration = 0.0f;
}
// Called when the game starts
void USubmixRecorder::BeginPlay()
{
Super::BeginPlay();
if (!GEngine) return;
if (FAudioDevice* AudioDevice = GetWorld()->GetAudioDeviceRaw())
{
AudioDevice->RegisterSubmixBufferListener(this, SubmixToRecord);
}
}
void USubmixRecorder::DestroyComponent(bool bPromoteChildren)
{
Super::DestroyComponent(bPromoteChildren);
if (!GEngine) return;
if (FAudioDevice* AudioDevice = GetWorld()->GetAudioDeviceRaw())
{
AudioDevice->UnregisterSubmixBufferListener(this, SubmixToRecord);
}
}
void USubmixRecorder::SetNumChannels(int newNumChannels)
{
if (newNumChannels > 2)
UE_LOG(LogAudio, Warning, TEXT("SubmixRecorder::Only 1 or 2 channels supported"));
RecordNumChannels = std::min(2, newNumChannels);
}
void USubmixRecorder::PopFirstRecordedBuffer(AudioSampleBuffer& destination)
{
FScopeLock lock(&use_queue);
destination = RecordingRawData.Peek();//copying
RecordingRawData.Pop();
}
std::size_t USubmixRecorder::GetRecordedBuffersCount()
{
FScopeLock lock(&use_queue);
return RecordingRawData.Count();
}
void USubmixRecorder::StartRecording()
{
bIsRecording = true;
}
void USubmixRecorder::StopRecording()
{
bIsRecording = false;
RecordingRawData.Enqueue(new_batch);
}
void USubmixRecorder::Reset()
{
FScopeLock lock(&use_queue);
RecordingRawData.Reset();
}
void USubmixRecorder::OnNewSubmixBuffer(const USoundSubmix* OwningSubmix, float* AudioData, int32 NumSamples, int32 NumChannels, const int32 sample_rate, double AudioClock)
{
if (bIsRecording)
{
new_batch.Append(AudioData, NumSamples, NumChannels);
new_batch.sample_rate = sample_rate;
if (new_batch.NumSamples >= AudioSampleBuffer_MaxSamplesCount)
{
use_queue.Lock();
RecordingRawData.Enqueue(new_batch);
use_queue.Unlock();
new_batch.NumSamples = 0;
new_batch.NumFrames = 0;
new_batch.SampleDuration = 0.0f;
new_batch.NumChannels = RecordNumChannels;
}
}
}
| 25.156863 | 172 | 0.767732 | scivi-tools |
2c0ca1775a2045a5a922d50f94a7b78f217b262e | 5,132 | cpp | C++ | src/bind/window/snap_win.cpp | e-ntro-py/win-vind | 1ec805420732c82a46e2c79720db728ded792814 | [
"MIT"
] | null | null | null | src/bind/window/snap_win.cpp | e-ntro-py/win-vind | 1ec805420732c82a46e2c79720db728ded792814 | [
"MIT"
] | null | null | null | src/bind/window/snap_win.cpp | e-ntro-py/win-vind | 1ec805420732c82a46e2c79720db728ded792814 | [
"MIT"
] | null | null | null | #include "snap_win.hpp"
#include <functional>
#include "winutil.hpp"
#include "core/ntypelogger.hpp"
#include "util/box2d.hpp"
#include "util/def.hpp"
#include "util/screen_metrics.hpp"
#include "util/winwrap.hpp"
namespace
{
using namespace vind ;
inline void snap_foreground_window(
const std::function<util::Box2D(const util::Box2D&)>& calc_half_size,
const std::function<POINT(const util::Box2D&)>& next_monitor_pos) {
auto hwnd = util::get_foreground_window() ;
util::MonitorInfo minfo ;
util::get_monitor_metrics(hwnd, minfo) ;
auto half_rect = calc_half_size(minfo.work_rect) ;
auto cur_rect = util::get_window_rect(hwnd) ;
if(cur_rect == half_rect) {
util::get_monitor_metrics(next_monitor_pos(minfo.rect), minfo) ;
half_rect = calc_half_size(minfo.work_rect) ;
}
bind::resize_window(hwnd, half_rect) ;
}
}
namespace vind
{
namespace bind
{
//SnapCurrentWindow2Left
SnapCurrentWindow2Left::SnapCurrentWindow2Left()
: BindedFuncVoid("snap_current_window_to_left")
{}
void SnapCurrentWindow2Left::sprocess() {
auto calc_half_size = [] (const util::Box2D& mrect) {
return util::Box2D{
mrect.left(),
mrect.top(),
mrect.center_x(),
mrect.bottom()
} ;
} ;
auto next_monitor_pos = [] (const util::Box2D& rect) {
return POINT{rect.left() - 100, rect.center_y()} ;
} ;
snap_foreground_window(calc_half_size, next_monitor_pos) ;
}
void SnapCurrentWindow2Left::sprocess(core::NTypeLogger& parent_lgr) {
if(!parent_lgr.is_long_pressing()) {
sprocess() ;
}
}
void SnapCurrentWindow2Left::sprocess(const core::CharLogger& UNUSED(parent_lgr)) {
sprocess() ;
}
//SnapCurrentWindow2Right
SnapCurrentWindow2Right::SnapCurrentWindow2Right()
: BindedFuncVoid("snap_current_window_to_right")
{}
void SnapCurrentWindow2Right::sprocess() {
auto calc_half_size = [] (const util::Box2D& mrect) {
return util::Box2D {
mrect.center_x(),
mrect.top(),
mrect.right(),
mrect.bottom()
} ;
} ;
auto next_monitor_pos = [] (const util::Box2D& rect) {
return POINT{rect.right() + 100, rect.center_y()} ;
} ;
snap_foreground_window(calc_half_size, next_monitor_pos) ;
}
void SnapCurrentWindow2Right::sprocess(core::NTypeLogger& parent_lgr) {
if(!parent_lgr.is_long_pressing()) {
sprocess() ;
}
}
void SnapCurrentWindow2Right::sprocess(const core::CharLogger& UNUSED(parent_lgr)) {
sprocess() ;
}
//SnapCurrentWindow2Top
SnapCurrentWindow2Top::SnapCurrentWindow2Top()
: BindedFuncVoid("snap_current_window_to_top")
{}
void SnapCurrentWindow2Top::sprocess() {
auto calc_half_size = [] (const util::Box2D& mrect) {
return util::Box2D {
mrect.left(),
mrect.top(),
mrect.right(),
mrect.center_y()
} ;
} ;
auto next_monitor_pos = [] (const util::Box2D& rect) {
return POINT{rect.center_x(), rect.top() - 100} ;
} ;
snap_foreground_window(calc_half_size, next_monitor_pos) ;
}
void SnapCurrentWindow2Top::sprocess(core::NTypeLogger& parent_lgr) {
if(!parent_lgr.is_long_pressing()) {
sprocess() ;
}
}
void SnapCurrentWindow2Top::sprocess(const core::CharLogger& UNUSED(parent_lgr)) {
sprocess() ;
}
//SnapCurrentWindow2Bottom
SnapCurrentWindow2Bottom::SnapCurrentWindow2Bottom()
: BindedFuncVoid("snap_current_window_to_bottom")
{}
void SnapCurrentWindow2Bottom::sprocess() {
auto calc_half_size = [] (const util::Box2D& mrect) {
return util::Box2D {
mrect.left(),
mrect.center_y(),
mrect.right(),
mrect.bottom()
} ;
} ;
auto next_monitor_pos = [] (const util::Box2D& rect) {
return POINT{rect.center_x(), rect.bottom() + 100} ;
} ;
snap_foreground_window(calc_half_size, next_monitor_pos) ;
}
void SnapCurrentWindow2Bottom::sprocess(core::NTypeLogger& parent_lgr) {
if(!parent_lgr.is_long_pressing()) {
sprocess() ;
}
}
void SnapCurrentWindow2Bottom::sprocess(const core::CharLogger& UNUSED(parent_lgr)) {
sprocess() ;
}
}
}
| 31.484663 | 93 | 0.543453 | e-ntro-py |
2c0ec26d20ec240c296e5ceff6e6fc481db1046d | 772 | cpp | C++ | cppcode/cpp execise/day07/final.cpp | jiedou/study | 606676ebc3d1fb1a87de26b6609307d71dafec22 | [
"Apache-2.0"
] | null | null | null | cppcode/cpp execise/day07/final.cpp | jiedou/study | 606676ebc3d1fb1a87de26b6609307d71dafec22 | [
"Apache-2.0"
] | null | null | null | cppcode/cpp execise/day07/final.cpp | jiedou/study | 606676ebc3d1fb1a87de26b6609307d71dafec22 | [
"Apache-2.0"
] | null | null | null | #include <iostream>
using namespace std;
class Point2D {
public:
Point2D (int x = 0, int y = 0) :
m_x (x), m_y (y) {}
void draw (void) const {
cout << "2D(" << m_x << ',' << m_y
<< ')' << endl;
}
protected:
int m_x;
int m_y;
};
class Point3D : public Point2D {
public:
void draw (void) const {
cout << "3D(" << m_x << ',' << m_y
<< ',' << m_z << ')' << endl;
}
static Point3D* create (int x = 0,
int y = 0, int z = 0) {
return new Point3D (x, y, z);
}
private:
Point3D (int x = 0, int y = 0, int z = 0):
Point2D (x, y), m_z (z) {}
int m_z;
};
/*
class Point4D : public Point3D {};
*/
int main (void) {
Point2D p2 (100, 200);
p2.draw ();
Point3D* p3 = Point3D::create (300,
400, 500);
p3->draw ();
delete p3;
// Point4D p4;
return 0;
}
| 17.953488 | 43 | 0.537565 | jiedou |
2c15bcdda00f40b655aa33941d2d37b886fb76b3 | 314 | cpp | C++ | Xtreme Rappers/Xtreme Rappers.cpp | Sleepy105/IEEE-Xtreme-13.0 | c24fe4fff553e338bffc8f042fcbcc2ace4ccf5d | [
"MIT"
] | null | null | null | Xtreme Rappers/Xtreme Rappers.cpp | Sleepy105/IEEE-Xtreme-13.0 | c24fe4fff553e338bffc8f042fcbcc2ace4ccf5d | [
"MIT"
] | null | null | null | Xtreme Rappers/Xtreme Rappers.cpp | Sleepy105/IEEE-Xtreme-13.0 | c24fe4fff553e338bffc8f042fcbcc2ace4ccf5d | [
"MIT"
] | null | null | null | #include <iostream>
using namespace std;
int main() {
uint64_t a, b, n = 0;
cin >> a >> b;
if (!(a && b))
cout << 0;
else if (a >= b*2) {
cout << b;
}
else if (b >= a*2) {
cout << a;
}
else
cout << a/3+b/3;
return 0;
}
| 14.952381 | 26 | 0.356688 | Sleepy105 |
2c18eec2985f433249a34a289c55aa0fb5f6ad4c | 262 | hpp | C++ | src/vm_error.hpp | cuttle-system/cuttle-vm | ec34cb75e335130c6deb8b46ed47a3545415c8af | [
"MIT"
] | null | null | null | src/vm_error.hpp | cuttle-system/cuttle-vm | ec34cb75e335130c6deb8b46ed47a3545415c8af | [
"MIT"
] | null | null | null | src/vm_error.hpp | cuttle-system/cuttle-vm | ec34cb75e335130c6deb8b46ed47a3545415c8af | [
"MIT"
] | null | null | null | #pragma once
#include <stdexcept>
namespace cuttle {
namespace vm {
class vm_error : public std::runtime_error
{
public:
vm_error() : runtime_error("Unknown vm error") {}
explicit vm_error(std::string msg) : runtime_error(msg.c_str()) {}
};
}
} | 18.714286 | 69 | 0.675573 | cuttle-system |
2c1a8d20538c054fb169ba7447bcd9afd1845b21 | 571 | cpp | C++ | Chapter 10. Generic Algorithms/Codes/10.31 Solution.cpp | Yunxiang-Li/Cpp_Primer | b5c857e3f6be993b2ff8fc03f634141ae24925fc | [
"MIT"
] | null | null | null | Chapter 10. Generic Algorithms/Codes/10.31 Solution.cpp | Yunxiang-Li/Cpp_Primer | b5c857e3f6be993b2ff8fc03f634141ae24925fc | [
"MIT"
] | null | null | null | Chapter 10. Generic Algorithms/Codes/10.31 Solution.cpp | Yunxiang-Li/Cpp_Primer | b5c857e3f6be993b2ff8fc03f634141ae24925fc | [
"MIT"
] | 1 | 2021-09-30T14:08:03.000Z | 2021-09-30T14:08:03.000Z | #include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
int main()
{
// Get int sequences from the standard input.
std::istream_iterator<int> istream_iterator(std::cin), istream_endIter;
// Copy int sequences from standard input to the vector and sort all integers.
std::vector<int> vec(istream_iterator, istream_endIter);
std::sort(vec.begin(), vec.end());
// Output the vector's elements.
std::ostream_iterator<int> ostream_iterator(std::cout, " ");
std::unique_copy(vec.cbegin(), vec.cend(), ostream_iterator);
return 0;
}
| 27.190476 | 80 | 0.71979 | Yunxiang-Li |
2c1ad73b964a9b6ddeafecb8ba82be45d1345cb2 | 987 | cpp | C++ | samples/cpp/mao/53_pyrDown.cpp | chenghyang2001/opencv-2.4.11 | 020af901059236c702da580048d25e9fe082e8f8 | [
"BSD-3-Clause"
] | null | null | null | samples/cpp/mao/53_pyrDown.cpp | chenghyang2001/opencv-2.4.11 | 020af901059236c702da580048d25e9fe082e8f8 | [
"BSD-3-Clause"
] | null | null | null | samples/cpp/mao/53_pyrDown.cpp | chenghyang2001/opencv-2.4.11 | 020af901059236c702da580048d25e9fe082e8f8 | [
"BSD-3-Clause"
] | 1 | 2020-07-22T07:08:24.000Z | 2020-07-22T07:08:24.000Z | #include <stdio.h>
#include <stdio.h>
//:read /home/peter/mao/53_pyrDown.cpp
//---------------------------------【頭文件、命名空間包含部分】----------------------------
// 描述:包含程序所使用的頭文件和命名空間
//------------------------------------------------------------------------------------------------
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
//-----------------------------------【main( )函數】-----------------------------------------
// 描述:控制臺應用程序的入口函數,我們的程序從這里開始
//-----------------------------------------------------------------------------------------------
int main( )
{
//載入原始圖
Mat srcImage = imread("/home/peter/opencv-2.4.11/samples/cpp/mao/1.jpg"); //專案目錄下應該有一張名為1.jpg的素材圖
Mat tmpImage,dstImage;//臨時變數和目標圖的定義
tmpImage=srcImage;//將原始圖賦給臨時變數
//顯示原始圖
imshow("【原始圖】", srcImage);
//進行向下取樣操作
pyrDown( tmpImage, dstImage, Size( tmpImage.cols/2, tmpImage.rows/2 ) );
//顯示效果圖
imshow("【效果圖】", dstImage);
waitKey(0);
return 0;
}
| 27.416667 | 99 | 0.450861 | chenghyang2001 |
2c1ddc3dfb21d125f5eadb54a1ce0e51645905ff | 1,092 | hpp | C++ | Includes/Core/Grid.hpp | Jeckhys/golPlayground | 7ad5282340ec5badda9322e2aab54c4ea996d983 | [
"MIT"
] | null | null | null | Includes/Core/Grid.hpp | Jeckhys/golPlayground | 7ad5282340ec5badda9322e2aab54c4ea996d983 | [
"MIT"
] | null | null | null | Includes/Core/Grid.hpp | Jeckhys/golPlayground | 7ad5282340ec5badda9322e2aab54c4ea996d983 | [
"MIT"
] | null | null | null | #ifndef HEADER_GRID_HPP
#define HEADER_GRID_HPP
#include <vector>
class Grid
{
public:
Grid(int width, int height);
~Grid() = default;
/**
* Compute the next generation internally.
*/
void nextGeneration();
void setState(int line, int column, bool value);
bool getState(int line, int column) const;
/**
* Gets the current generation number.
* @return The current generation
*/
long getGeneration() const;
private:
bool isValid(int line, int column) const;
bool getNextState(int line, int column) const;
int getNeighborsAlive(int line, int column) const;
std::vector<bool> getNeighbors(int line, int column) const;
private:
std::vector<bool> m_cells; ///< States of the current generation
std::vector<bool> m_buffer; ///< States of the next generation
int m_width; ///< Cells per line
int m_height; ///< Cells per column
long m_generation; ///< Generation count
};
#endif // HEADER_GRID_HPP | 26 | 72 | 0.608059 | Jeckhys |
2c20a7ba3d7e15c4e8f2ba7ceedf6550849f5c7d | 6,331 | cpp | C++ | TomGine/GLDCWindowGetEvent.cpp | OpenNurbsFit/OpenNurbsFit | d1ca01437a6da6bbf921466013ff969def5dfe65 | [
"BSD-3-Clause"
] | 14 | 2015-07-06T13:04:49.000Z | 2022-02-06T10:09:05.000Z | TomGine/GLDCWindowGetEvent.cpp | OpenNurbsFit/OpenNurbsFit | d1ca01437a6da6bbf921466013ff969def5dfe65 | [
"BSD-3-Clause"
] | 1 | 2020-12-07T03:26:39.000Z | 2020-12-07T03:26:39.000Z | TomGine/GLDCWindowGetEvent.cpp | OpenNurbsFit/OpenNurbsFit | d1ca01437a6da6bbf921466013ff969def5dfe65 | [
"BSD-3-Clause"
] | 11 | 2015-07-06T13:04:43.000Z | 2022-03-29T10:57:04.000Z | /*
* Software License Agreement (GNU General Public License)
*
* Copyright (c) 2011, Thomas Mörwald
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author thomas.moerwald
*
*/
#ifdef WIN32
#include "GLWindow.h"
#include <stdio.h>
namespace V4R{
void MapKey(WPARAM wp, Input &input);
bool GLWindow::GetEvent(Event &event)
{
short wheel = 0;
MSG msg;
if( PeekMessage( &msg, hWnd, 0, 0, PM_REMOVE ) ){
// handle or dispatch messages
//printf("msg.wParam: %d\n", msg.wParam);
switch ( msg.message ){
case WM_QUIT:
event.type = TMGL_Quit;
break;
case WM_KEYDOWN:
event.type = TMGL_Press;
MapKey(msg.wParam, event.input);
break;
case WM_KEYUP:
event.type = TMGL_Release;
MapKey(msg.wParam, event.input);
break;
// Mouse input
case WM_MOUSEMOVE:
event.type = TMGL_Motion;
event.motion.x = LOWORD(msg.lParam);
event.motion.y = HIWORD(msg.lParam);
break;
case WM_LBUTTONDOWN:
event.type = TMGL_Press;
event.input = TMGL_Button1;
break;
case WM_LBUTTONUP:
event.type = TMGL_Release;
event.input = TMGL_Button1;
break;
case WM_MBUTTONDOWN:
event.type = TMGL_Press;
event.input = TMGL_Button2;
break;
case WM_MBUTTONUP:
event.type = TMGL_Release;
event.input = TMGL_Button2;
break;
case WM_RBUTTONDOWN:
event.type = TMGL_Press;
event.input = TMGL_Button3;
break;
case WM_RBUTTONUP:
event.type = TMGL_Release;
event.input = TMGL_Button3;
break;
case WM_MOUSEWHEEL:
event.type = TMGL_Press;
wheel = (short)HIWORD(msg.wParam)/WHEEL_DELTA;
if(wheel == -1)
event.input = TMGL_Button4;
else
event.input = TMGL_Button5;
break;
default:
TranslateMessage( &msg );
DispatchMessage( &msg );
return false;
break;
}
return true;
}
return false;
}
void MapKey(WPARAM wp, Input &input)
{
switch(wp)
{
case 0x30:
input = TMGL_0;
break;
case 0x31:
input = TMGL_1;
break;
case 0x32:
input = TMGL_2;
break;
case 0x33:
input = TMGL_3;
break;
case 0x34:
input = TMGL_4;
break;
case 0x35:
input = TMGL_5;
break;
case 0x36:
input = TMGL_6;
break;
case 0x37:
input = TMGL_7;
break;
case 0x38:
input = TMGL_8;
break;
case 0x39:
input = TMGL_9;
break;
case 0x41:
input = TMGL_a;
break;
case 0x42:
input = TMGL_b;
break;
case 0x43:
input = TMGL_c;
break;
case 0x44:
input = TMGL_d;
break;
case 0x45:
input = TMGL_e;
break;
case 0x46:
input = TMGL_f;
break;
case 0x47:
input = TMGL_g;
break;
case 0x48:
input = TMGL_h;
break;
case 0x49:
input = TMGL_i;
break;
case 0x4A:
input = TMGL_j;
break;
case 0x4B:
input = TMGL_k;
break;
case 0x4C:
input = TMGL_l;
break;
case 0x4D:
input = TMGL_m;
break;
case 0x4E:
input = TMGL_n;
break;
case 0x4F:
input = TMGL_o;
break;
case 0x50:
input = TMGL_p;
break;
case 0x51:
input = TMGL_q;
break;
case 0x52:
input = TMGL_r;
break;
case 0x53:
input = TMGL_s;
break;
case 0x54:
input = TMGL_t;
break;
case 0x55:
input = TMGL_u;
break;
case 0x56:
input = TMGL_v;
break;
case 0x57:
input = TMGL_w;
break;
case 0x58:
input = TMGL_x;
break;
case 0x59:
input = TMGL_y;
break;
case 0x5A:
input = TMGL_z;
break;
case VK_BACK:
input = TMGL_BackSpace;
break;
case VK_TAB:
input = TMGL_Tab;
break;
case VK_RETURN:
input = TMGL_Return;
break;
case VK_SPACE:
input = TMGL_Space;
break;
case VK_PAUSE:
input = TMGL_Pause;
break;
case VK_ESCAPE:
input = TMGL_Escape;
break;
case VK_DELETE:
input = TMGL_Delete;
break;
case VK_LEFT:
input = TMGL_Left;
break;
case VK_UP:
input = TMGL_Up;
break;
case VK_RIGHT:
input = TMGL_Right;
break;
case VK_DOWN:
input = TMGL_Down;
break;
case VK_PRIOR:
input = TMGL_Page_Up;
break;
case VK_NEXT:
input = TMGL_Page_Down;
break;
case VK_END:
input = TMGL_End;
break;
case VK_HOME:
input = TMGL_Home;
break;
case VK_MULTIPLY:
input = TMGL_KP_Multiply;
break;
case VK_ADD:
input = TMGL_KP_Add;
break;
case VK_SUBTRACT:
input = TMGL_KP_Subtract;
break;
case VK_DIVIDE:
input = TMGL_KP_Divide;
break;
case VK_NUMPAD0:
input = TMGL_KP_0;
break;
case VK_NUMPAD1:
input = TMGL_KP_1;
break;
case VK_NUMPAD2:
input = TMGL_KP_2;
break;
case VK_NUMPAD3:
input = TMGL_KP_3;
break;
case VK_NUMPAD4:
input = TMGL_KP_4;
break;
case VK_NUMPAD5:
input = TMGL_KP_5;
break;
case VK_NUMPAD6:
input = TMGL_KP_6;
break;
case VK_NUMPAD7:
input = TMGL_KP_7;
break;
case VK_NUMPAD8:
input = TMGL_KP_8;
break;
case VK_NUMPAD9:
input = TMGL_KP_9;
break;
case VK_F1:
input = TMGL_F1;
break;
case VK_F2:
input = TMGL_F2;
break;
case VK_F3:
input = TMGL_F3;
break;
case VK_F4:
input = TMGL_F4;
break;
case VK_F5:
input = TMGL_F5;
break;
case VK_F6:
input = TMGL_F6;
break;
case VK_F7:
input = TMGL_F7;
break;
case VK_F8:
input = TMGL_F8;
break;
case VK_F9:
input = TMGL_F9;
break;
case VK_F10:
input = TMGL_F10;
break;
case VK_F11:
input = TMGL_F11;
break;
case VK_F12:
input = TMGL_F12;
break;
case VK_LSHIFT:
input = TMGL_Shift_L;
break;
case VK_RSHIFT:
input = TMGL_Shift_R;
break;
case VK_LCONTROL:
input = TMGL_Control_L;
break;
case VK_RCONTROL:
input = TMGL_Control_R;
break;
}
}
} /* namespace */
#endif /* WIN32 */
| 17.635097 | 73 | 0.632601 | OpenNurbsFit |
2c295066ece7629cb207ed41049e01a2444a60f1 | 4,515 | cpp | C++ | src/Entity.cpp | darkbitsorg/db-08_green_grappler | f009228edb2eb1a943ab6d5801a78a5d00ac9e43 | [
"BSD-2-Clause-NetBSD",
"BSD-2-Clause",
"BSD-3-Clause"
] | 1 | 2018-06-12T13:35:31.000Z | 2018-06-12T13:35:31.000Z | src/Entity.cpp | darkbitsorg/db-08_green_grappler | f009228edb2eb1a943ab6d5801a78a5d00ac9e43 | [
"BSD-2-Clause-NetBSD",
"BSD-2-Clause",
"BSD-3-Clause"
] | null | null | null | src/Entity.cpp | darkbitsorg/db-08_green_grappler | f009228edb2eb1a943ab6d5801a78a5d00ac9e43 | [
"BSD-2-Clause-NetBSD",
"BSD-2-Clause",
"BSD-3-Clause"
] | null | null | null | #include "Precompiled.hpp"
#include "Entity.hpp"
#include "Time.hpp"
#include "Room.hpp"
Entity::Entity()
: mRemoved(false)
, mFrameCounter(0)
, mRoom(0)
{
}
Entity::~Entity()
{
}
void Entity::setPosition(float2 position) { mPosition = position; }
float2 Entity::getPosition() { return mPosition; }
void Entity::setVelocity(float2 velocity) { mVelocity = velocity; }
float2 Entity::getVelocity() { return mVelocity; }
void Entity::setSize(float2 size) { mSize = size; }
float2 Entity::getSize() { return mSize; }
float2 Entity::getHalfSize() { return mSize * 0.5f; };
void Entity::setRoom(Room *room) { mRoom = room; }
Room *Entity::getRoom() { return mRoom; }
unsigned int Entity::moveWithCollision(float2 delta)
{
int substeps = (int)ceil((abs(delta.x) + abs(delta.y)) * 0.2);
delta /= substeps;
unsigned int result = Direction_None;
float2 halfSize = getHalfSize();
for (int i = 0; i < substeps; i++) {
mPosition.x += delta.x;
int x1 = (int)((mPosition.x - halfSize.x) / mRoom->getTileWidth());
int x2 = (int)((mPosition.x + halfSize.x) / mRoom->getTileWidth());
int y1n = (int)((mPosition.y - halfSize.y + 0.01f) / mRoom->getTileHeight());
int y2n = (int)((mPosition.y + halfSize.y - 0.01f) / mRoom->getTileHeight());
if (delta.x > 0) {
for (int y = y1n; y <= y2n; y++) {
if (mRoom->isCollidable(x2, y)) {
delta.x = 0;
result |= Direction_Right;
mPosition.x = x2 * mRoom->getTileWidth() - halfSize.x;
break;
}
}
} else if (delta.x < 0) {
for (int y = y1n; y <= y2n; y++) {
if (mRoom->isCollidable(x1, y)) {
delta.x = 0;
result |= Direction_Left;
mPosition.x = (x1 + 1) * mRoom->getTileWidth() + halfSize.x;
break;
}
}
}
mPosition.y += delta.y;
int y1 = (int)((mPosition.y - halfSize.y) / mRoom->getTileHeight());
int y2 = (int)((mPosition.y + halfSize.y) / mRoom->getTileHeight());
int x1n = (int)((mPosition.x - halfSize.x + 0.01f) / mRoom->getTileWidth());
int x2n = (int)((mPosition.x + halfSize.x - 0.01f) / mRoom->getTileWidth());
if (delta.y > 0) {
for (int x = x1n; x <= x2n; x++) {
if (mRoom->isCollidable(x, y2)) {
delta.y = 0;
result |= Direction_Down;
mPosition.y = y2 * mRoom->getTileHeight() - halfSize.y;
break;
}
}
} else if (delta.y < 0) {
for (int x = x1n; x <= x2n; x++) {
if (mRoom->isCollidable(x, y1)) {
delta.y = 0;
result |= Direction_Up;
mPosition.y = (y1 + 1) * mRoom->getTileHeight() + halfSize.y;
}
}
}
}
return result;
}
unsigned int Entity::moveWithCollision()
{
return moveWithCollision(mVelocity / Time::TicksPerSecond);
}
void Entity::update()
{
mFrameCounter++;
}
void Entity::draw(BITMAP *buffer, int offsetX, int offsetY, int layer)
{
int x = getDrawPositionX() + offsetX;
int y = getDrawPositionY() + offsetY;
int x1 = (int)(x - getHalfSize().x);
int y1 = (int)(y - getHalfSize().y);
int x2 = (int)(x + getHalfSize().x);
int y2 = (int)(y + getHalfSize().y);
rect(buffer, x1, y1, x2, y2, makecol(255, 255, 0));
line(buffer, x - 3, y, x + 3, y, makecol(255, 255, 0));
line(buffer, x, y - 3, x, y + 3, makecol(255, 255, 0));
//textout_centre_ex(buffer, font, typeid(this).name(), x, y - 9, makecol(200, 200, 200), 0);
}
void Entity::remove()
{
mRemoved = true;
}
bool Entity::isRemoved()
{
return mRemoved;
}
int
Entity::getDrawPositionX()
{
return getPosition().x+0.5;
}
int
Entity::getDrawPositionY()
{
return getPosition().y+0.5;
}
Entity::CollisionRect
Entity::getCollisionRect()
{
CollisionRect collisionRect;
collisionRect.myTopLeft = getPosition()-getHalfSize();
collisionRect.myBottomRight = getPosition()+getHalfSize();
return collisionRect;
}
bool
Entity::Collides( const CollisionRect& aRect1, CollisionRect& aRect2 )
{
if (aRect1.myBottomRight.x <= aRect2.myTopLeft.x)
return false;
if (aRect1.myTopLeft.x >= aRect2.myBottomRight.x)
return false;
if (aRect1.myBottomRight.y <= aRect2.myTopLeft.y)
return false;
if (aRect1.myTopLeft.y >= aRect2.myBottomRight.y)
return false;
return true;
}
bool Entity::isDamagable()
{
return false;
}
bool Entity::isHookable()
{
return false;
}
void Entity::onDamage()
{
}
void Entity::onButtonUp( int aId )
{
}
void Entity::onButtonDown( int aId )
{
}
void Entity::onRespawn()
{
}
void Entity::onStartWallOfDeath()
{
}
void Entity::onLevelComplete()
{
}
void Entity::onBossFloorActivate()
{
}
void Entity::onBossWallActivate()
{
}
void Entity::onBossWallDeactivate()
{
}
| 20.522727 | 93 | 0.636766 | darkbitsorg |
2c2f08ebc758310c6978fb56a3c15f1b4412181d | 802 | hpp | C++ | source/ui/scene/settingsScene.hpp | Stephouuu/Epitech-Bomberman | 8650071a6a21ba2e0606e4d8e38794de37bdf39f | [
"Unlicense"
] | null | null | null | source/ui/scene/settingsScene.hpp | Stephouuu/Epitech-Bomberman | 8650071a6a21ba2e0606e4d8e38794de37bdf39f | [
"Unlicense"
] | null | null | null | source/ui/scene/settingsScene.hpp | Stephouuu/Epitech-Bomberman | 8650071a6a21ba2e0606e4d8e38794de37bdf39f | [
"Unlicense"
] | null | null | null | /*
** settingsScene.hpp for UI in /home/escoba_j/Downloads/irrlicht-1.8.3/ui/scene
**
** Made by Joffrey Escobar
** Login <[email protected]>
**
** Started on Sun May 29 03:00:07 2016 Joffrey Escobar
*/
#ifndef SETTINGSSCENE_HPP
#define SETTINGSSCENE_HPP
#include <vector>
#include <string>
#include <utility>
#include "ASubLayout.hpp"
class settingsScene : public ASubLayout
{
public:
settingsScene(ui &ui);
~settingsScene(void);
void loadScene(void);
void updateRuntime(void);
void manageEvent(bbman::InputListener &listener);
void loadRessources(void);
void loadIA(void);
void loadSound(void);
std::vector<std::pair<std::string, int> > const getVolume(void) const;
int getIADifficulty(void) const;
private:
int _music;
int _effect;
int _iaLevel;
};
#endif
| 18.651163 | 79 | 0.720698 | Stephouuu |
2c2f4016621901e8c25420b89f2e1198b1afa2c2 | 5,750 | cpp | C++ | igvc_navigation/src/path_follower/path_follower.cpp | jiajunmao/igvc-software | ea1b11d9bb20e85e5f47aa03f930e9b65877d80c | [
"MIT"
] | 2 | 2020-06-04T01:33:01.000Z | 2021-12-22T03:59:53.000Z | igvc_navigation/src/path_follower/path_follower.cpp | jiajunmao/igvc-software | ea1b11d9bb20e85e5f47aa03f930e9b65877d80c | [
"MIT"
] | null | null | null | igvc_navigation/src/path_follower/path_follower.cpp | jiajunmao/igvc-software | ea1b11d9bb20e85e5f47aa03f930e9b65877d80c | [
"MIT"
] | 2 | 2020-06-04T01:26:43.000Z | 2021-12-22T03:59:54.000Z | #define _USE_MATH_DEFINES
#include <Eigen/Dense>
#include <cmath>
#include <iostream>
#include <geometry_msgs/PointStamped.h>
#include <geometry_msgs/PoseStamped.h>
#include <igvc_msgs/velocity_pair.h>
#include <nav_msgs/Odometry.h>
#include <visualization_msgs/MarkerArray.h>
#include <tf/transform_datatypes.h>
#include <igvc_utils/robot_state.h>
#include <parameter_assertions/assertions.h>
#include "path_follower.h"
PathFollower::PathFollower()
{
ros::NodeHandle nh;
ros::NodeHandle pNh("~");
// load controller parameters
using seconds = double;
double target_velocity;
double axle_length;
double k1;
double k2;
double simulation_frequency;
double lookahead_dist;
seconds simulation_horizon;
assertions::param(pNh, "target_v", target_velocity, 1.0);
assertions::param(pNh, "axle_length", axle_length, 0.52);
assertions::param(pNh, "k1", k1, 1.0);
assertions::param(pNh, "k2", k2, 3.0);
assertions::param(pNh, "simulation_frequency", simulation_frequency, 100.0);
assertions::param(pNh, "lookahead_dist", lookahead_dist, 2.0);
assertions::param(pNh, "simulation_horizon", simulation_horizon, 5.0);
controller_ = std::unique_ptr<SmoothControl>(new SmoothControl{
k1, k2, axle_length, simulation_frequency, target_velocity, lookahead_dist, simulation_horizon });
// load global parameters
assertions::getParam(pNh, "maximum_vel", maximum_vel_, { assertions::NumberAssertionType::POSITIVE });
assertions::param(pNh, "stop_dist", stop_dist_, 0.9);
ros::Subscriber path_sub = nh.subscribe("/path", 1, &PathFollower::pathCallback, this);
ros::Subscriber pose_sub = nh.subscribe("/odometry/filtered", 1, &PathFollower::positionCallback, this);
ros::Subscriber waypoint_sub = nh.subscribe("/waypoint", 1, &PathFollower::waypointCallback, this);
cmd_pub_ = nh.advertise<igvc_msgs::velocity_pair>("/motors", 1);
target_pub_ = nh.advertise<geometry_msgs::PointStamped>("/target_point", 1);
trajectory_pub_ = nh.advertise<nav_msgs::Path>("/trajectory", 1);
ros::spin();
}
void PathFollower::pathCallback(const nav_msgs::PathConstPtr& msg)
{
ROS_DEBUG_STREAM("Follower got path. Size: " << msg->poses.size());
// path_ = msg;
// TODO: Remove patch when motion planning correctly incorporates heading
path_ = getPatchedPath(msg);
}
void PathFollower::waypointCallback(const geometry_msgs::PointStampedConstPtr& msg)
{
waypoint_ = msg;
}
/**
Constructs a new trajectory to follow using the current path msg and publishes
the first velocity command from this trajectory.
*/
void PathFollower::positionCallback(const nav_msgs::OdometryConstPtr& msg)
{
if (path_.get() == nullptr || path_->poses.empty() || path_->poses.size() < 2)
{
ROS_INFO_THROTTLE(1, "Path empty.");
igvc_msgs::velocity_pair vel;
vel.left_velocity = 0.;
vel.right_velocity = 0.;
cmd_pub_.publish(vel);
path_.reset();
return;
}
// Current pose
RobotState cur_pos(msg);
double goal_dist = cur_pos.distTo(waypoint_->point.x, waypoint_->point.y);
ROS_DEBUG_STREAM("Distance to waypoint: " << goal_dist << "(m.)");
ros::Time time = msg->header.stamp;
igvc_msgs::velocity_pair vel; // immediate velocity command
vel.header.stamp = time;
if (goal_dist <= stop_dist_)
{
/**
Stop when the robot is a set distance away from the waypoint
*/
ROS_INFO_STREAM(">>>WAYPOINT REACHED...STOPPING<<<");
vel.right_velocity = 0;
vel.left_velocity = 0;
// make path null to stop planning until path generated
// for new waypoint
path_ = nullptr;
}
else
{
/**
Obtain smooth control law from the controller. This includes a smooth
trajectory for visualization purposes and an immediate velocity command.
*/
nav_msgs::Path trajectory_msg;
trajectory_msg.header.stamp = time;
trajectory_msg.header.frame_id = "/odom";
RobotState target;
controller_->getTrajectory(vel, path_, trajectory_msg, cur_pos, target);
// publish trajectory
trajectory_pub_.publish(trajectory_msg);
// publish target position
geometry_msgs::PointStamped target_point;
target_point.header.frame_id = "/odom";
target_point.header.stamp = time;
tf::pointTFToMsg(target.transform.getOrigin(), target_point.point);
target_pub_.publish(target_point);
ROS_DEBUG_STREAM("Distance to target: " << cur_pos.distTo(target) << "(m.)");
}
// make sure maximum velocity not exceeded
if (std::max(std::abs(vel.right_velocity), std::abs(vel.left_velocity)) > maximum_vel_)
{
ROS_ERROR_STREAM_THROTTLE(5, "Maximum velocity exceeded. Right: "
<< vel.right_velocity << "(m/s), Left: " << vel.left_velocity
<< "(m/s), Max: " << maximum_vel_ << "(m/s) ... Stopping robot...");
vel.right_velocity = 0;
vel.left_velocity = 0;
}
cmd_pub_.publish(vel); // pub velocity command
}
nav_msgs::PathConstPtr PathFollower::getPatchedPath(const nav_msgs::PathConstPtr& msg) const
{
nav_msgs::PathPtr new_path = boost::make_shared<nav_msgs::Path>(*msg);
size_t num_poses = new_path->poses.size();
for (size_t i = 0; i < num_poses; i++)
{
double delta_x = new_path->poses[i + 1].pose.position.x - new_path->poses[i].pose.position.x;
double delta_y = new_path->poses[i + 1].pose.position.y - new_path->poses[i].pose.position.y;
double heading = atan2(delta_y, delta_x);
new_path->poses[i].pose.orientation = tf::createQuaternionMsgFromYaw(heading);
}
new_path->poses.back().pose.orientation = new_path->poses[num_poses - 2].pose.orientation;
return new_path;
}
int main(int argc, char** argv)
{
ros::init(argc, argv, "path_follower");
PathFollower path_follower;
return 0;
}
| 33.045977 | 106 | 0.704696 | jiajunmao |
2c40fb408529f022c3148e790e76fef540fb1e09 | 2,923 | cc | C++ | wobble/term.cc | spanezz/wobble | 482266913b1bf1907555b620d88a29c66f3d1638 | [
"BSD-3-Clause"
] | 1 | 2017-01-10T12:46:54.000Z | 2017-01-10T12:46:54.000Z | wobble/term.cc | spanezz/wobble | 482266913b1bf1907555b620d88a29c66f3d1638 | [
"BSD-3-Clause"
] | 1 | 2015-10-01T15:03:33.000Z | 2015-11-23T15:50:33.000Z | wobble/term.cc | spanezz/wobble | 482266913b1bf1907555b620d88a29c66f3d1638 | [
"BSD-3-Clause"
] | 3 | 2015-09-15T06:35:50.000Z | 2018-04-03T10:59:15.000Z | #include "term.h"
#include <unistd.h>
#include <cerrno>
#include <system_error>
namespace wobble {
namespace term {
#define ANSI_COLOR_RED "\x1b[31m"
#define ANSI_COLOR_GREEN "\x1b[32m"
#define ANSI_COLOR_YELLOW "\x1b[33m"
#define ANSI_COLOR_BLUE "\x1b[34m"
#define ANSI_COLOR_MAGENTA "\x1b[35m"
#define ANSI_COLOR_CYAN "\x1b[36m"
#define ANSI_COLOR_RESET "\x1b[0m"
const unsigned Terminal::black = 1;
const unsigned Terminal::red = 2;
const unsigned Terminal::green = 3;
const unsigned Terminal::yellow = 4;
const unsigned Terminal::blue = 5;
const unsigned Terminal::magenta = 6;
const unsigned Terminal::cyan = 7;
const unsigned Terminal::white = 8;
const unsigned Terminal::bright = 0x10;
static const unsigned color_mask = 0xf;
Terminal::Restore::Restore(Terminal& term)
: term(term)
{
}
Terminal::Restore::~Restore()
{
if (!term.isatty) return;
fputs("\x1b[0m", term.out);
}
Terminal::Terminal(FILE* out)
: out(out)
{
int fd = fileno(out);
if (fd == -1)
isatty = false;
else
{
int res = ::isatty(fd);
if (res == 1)
isatty = true;
else if (errno == EINVAL || errno == ENOTTY)
isatty = false;
else
throw std::system_error(errno, std::system_category(), "isatty failed");
}
}
namespace {
struct SGR
{
std::string seq;
bool first = true;
SGR() : seq("\x1b[") {}
void append(int code)
{
if (first)
first = false;
else
seq += ";";
seq += std::to_string(code);
}
void end()
{
seq += "m";
}
void set_fg(int col)
{
if (col & Terminal::bright)
append(1);
if (col & color_mask)
append(29 + (col & color_mask));
}
void set_bg(int col)
{
if ((col & Terminal::bright) && (col & color_mask))
{
append(99 + (col & color_mask));
} else if (col & color_mask) {
append(89 + (col & color_mask));
}
}
};
}
Terminal::Restore Terminal::set_color(int fg, int bg)
{
if (!isatty) return Restore(*this);
SGR set;
if (fg) set.set_fg(fg);
if (bg) set.set_bg(bg);
set.end();
fputs(set.seq.c_str(), out);
return Restore(*this);
}
Terminal::Restore Terminal::set_color_fg(int col)
{
return set_color(col, 0);
}
Terminal::Restore Terminal::set_color_bg(int col)
{
return set_color(0, col);
}
std::string Terminal::color(int fg, int bg, const std::string& s)
{
if (!isatty) return s;
SGR set;
if (fg) set.set_fg(fg);
if (bg) set.set_bg(bg);
set.end();
set.seq += s;
set.seq += "\x1b[0m";
return set.seq;
}
std::string Terminal::color_fg(int col, const std::string& s)
{
return color(col, 0, s);
}
std::string Terminal::color_bg(int col, const std::string& s)
{
return color(0, col, s);
}
}
}
| 19.357616 | 84 | 0.575094 | spanezz |
2c4435cd742ce64637c3d027dcc8bb8197814463 | 2,186 | cpp | C++ | modules/task_1/romanuyk_algoritm_kennona/algoritm_kennona.cpp | stasyurin/pp_2021_spring_informatics | dd9136c28cca4c538c5ecc82512fd78ad1fa7bd3 | [
"BSD-3-Clause"
] | null | null | null | modules/task_1/romanuyk_algoritm_kennona/algoritm_kennona.cpp | stasyurin/pp_2021_spring_informatics | dd9136c28cca4c538c5ecc82512fd78ad1fa7bd3 | [
"BSD-3-Clause"
] | null | null | null | modules/task_1/romanuyk_algoritm_kennona/algoritm_kennona.cpp | stasyurin/pp_2021_spring_informatics | dd9136c28cca4c538c5ecc82512fd78ad1fa7bd3 | [
"BSD-3-Clause"
] | 1 | 2021-12-02T22:38:53.000Z | 2021-12-02T22:38:53.000Z | // Copyright 2020 Romanuyk Sergey
#include <vector>
#include <random>
#include "../../../modules/task_1/romanuyk_algoritm_kennona/algoritm_kennona.h"
std::vector<double> genMatrix(int n) {
int SIZE = n * n;
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_real_distribution<> urd(-50, 50);
std::vector<double> arr(SIZE);
for (int i = 0; i < SIZE; i++) {
arr[i] = urd(gen);
}
return arr;
}
std::vector<double> SequentinalMultiMatrix(const std::vector<double>& A,
const std::vector<double>& B, int n) {
if (A.size() !=B.size()) {
throw "Matrices sizes differ";
}
std::vector<double> res(n * n, 0);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
res[i * n + j] += A[i * n + k] * B[k * n + j];
}
}
}
return res;
}
std::vector<double> KennonMultiplication(std::vector<double> A,
std::vector<double> B, int BlockSize) {
if (A.size() != B.size()) {
throw "Size of matrix different";
}
if (BlockSize <= 0) {
throw "Size of Block must be > 0";
}
if (A.size() < (unsigned int)(BlockSize * BlockSize)) {
throw "Block size cannot be larger than size of original matrices";
}
int size = static_cast<int>(sqrt(A.size()));
std::vector<double> C(size * size);
int BlockCount = size / BlockSize;
for (int i = 0; i < size * size; i++) {
C[i] = 0;
}
for (int i = 0; i < size; i += BlockCount) {
for (int j = 0; j < size; j += BlockCount) {
for (int k = 0; k < size; k += BlockCount) {
for (int ii = i; ii < std::min(size, i + BlockCount); ii++) {
for (int jj = j;
jj < std::min(size, j + BlockCount); jj++) {
for (int kk = k;
kk < std::min(size, k + BlockCount); kk++) {
C[ii * size + jj] += A[ii * size + kk]
* B[kk * size + jj];
}
}
}
}
}
}
return C;
}
| 28.025641 | 79 | 0.467521 | stasyurin |
2c445efc4e762428c06e95d1ca3ca31ee298c411 | 57,216 | cpp | C++ | AuthServer.cpp | apostoldevel/module-AuthServer | 284b0271eac5bc52a1710d47eb4acbad0f778a82 | [
"MIT"
] | null | null | null | AuthServer.cpp | apostoldevel/module-AuthServer | 284b0271eac5bc52a1710d47eb4acbad0f778a82 | [
"MIT"
] | null | null | null | AuthServer.cpp | apostoldevel/module-AuthServer | 284b0271eac5bc52a1710d47eb4acbad0f778a82 | [
"MIT"
] | null | null | null | /*++
Program name:
Apostol Web Service
Module Name:
AuthServer.cpp
Notices:
Module: OAuth 2 Authorization Server
Author:
Copyright (c) Prepodobny Alen
mailto: [email protected]
mailto: [email protected]
--*/
//----------------------------------------------------------------------------------------------------------------------
#include "Core.hpp"
#include "AuthServer.hpp"
//----------------------------------------------------------------------------------------------------------------------
#include "jwt.h"
//----------------------------------------------------------------------------------------------------------------------
#define WEB_APPLICATION_NAME "web"
#define SERVICE_APPLICATION_NAME "service"
extern "C++" {
namespace Apostol {
namespace Module {
//--------------------------------------------------------------------------------------------------------------
//-- CAuthServer -----------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------
CAuthServer::CAuthServer(CModuleProcess *AProcess) : CApostolModule(AProcess, "authorization server", "module/AuthServer") {
m_Headers.Add("Authorization");
m_FixedDate = Now();
CAuthServer::InitMethods();
}
//--------------------------------------------------------------------------------------------------------------
void CAuthServer::InitMethods() {
#if defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE >= 9)
m_pMethods->AddObject(_T("GET") , (CObject *) new CMethodHandler(true , [this](auto && Connection) { DoGet(Connection); }));
m_pMethods->AddObject(_T("POST") , (CObject *) new CMethodHandler(true , [this](auto && Connection) { DoPost(Connection); }));
m_pMethods->AddObject(_T("OPTIONS"), (CObject *) new CMethodHandler(true , [this](auto && Connection) { DoOptions(Connection); }));
m_pMethods->AddObject(_T("HEAD") , (CObject *) new CMethodHandler(false, [this](auto && Connection) { MethodNotAllowed(Connection); }));
m_pMethods->AddObject(_T("PUT") , (CObject *) new CMethodHandler(false, [this](auto && Connection) { MethodNotAllowed(Connection); }));
m_pMethods->AddObject(_T("DELETE") , (CObject *) new CMethodHandler(false, [this](auto && Connection) { MethodNotAllowed(Connection); }));
m_pMethods->AddObject(_T("TRACE") , (CObject *) new CMethodHandler(false, [this](auto && Connection) { MethodNotAllowed(Connection); }));
m_pMethods->AddObject(_T("PATCH") , (CObject *) new CMethodHandler(false, [this](auto && Connection) { MethodNotAllowed(Connection); }));
m_pMethods->AddObject(_T("CONNECT"), (CObject *) new CMethodHandler(false, [this](auto && Connection) { MethodNotAllowed(Connection); }));
#else
m_pMethods->AddObject(_T("GET") , (CObject *) new CMethodHandler(true , std::bind(&CAuthServer::DoGet, this, _1)));
m_pMethods->AddObject(_T("POST") , (CObject *) new CMethodHandler(true , std::bind(&CAuthServer::DoPost, this, _1)));
m_pMethods->AddObject(_T("OPTIONS"), (CObject *) new CMethodHandler(true , std::bind(&CAuthServer::DoOptions, this, _1)));
m_pMethods->AddObject(_T("HEAD") , (CObject *) new CMethodHandler(false, std::bind(&CAuthServer::MethodNotAllowed, this, _1)));
m_pMethods->AddObject(_T("PUT") , (CObject *) new CMethodHandler(false, std::bind(&CAuthServer::MethodNotAllowed, this, _1)));
m_pMethods->AddObject(_T("DELETE") , (CObject *) new CMethodHandler(false, std::bind(&CAuthServer::MethodNotAllowed, this, _1)));
m_pMethods->AddObject(_T("TRACE") , (CObject *) new CMethodHandler(false, std::bind(&CAuthServer::MethodNotAllowed, this, _1)));
m_pMethods->AddObject(_T("PATCH") , (CObject *) new CMethodHandler(false, std::bind(&CAuthServer::MethodNotAllowed, this, _1)));
m_pMethods->AddObject(_T("CONNECT"), (CObject *) new CMethodHandler(false, std::bind(&CAuthServer::MethodNotAllowed, this, _1)));
#endif
}
//--------------------------------------------------------------------------------------------------------------
CHTTPReply::CStatusType CAuthServer::ErrorCodeToStatus(int ErrorCode) {
CHTTPReply::CStatusType Status = CHTTPReply::ok;
if (ErrorCode != 0) {
switch (ErrorCode) {
case 401:
Status = CHTTPReply::unauthorized;
break;
case 403:
Status = CHTTPReply::forbidden;
break;
case 404:
Status = CHTTPReply::not_found;
break;
case 500:
Status = CHTTPReply::internal_server_error;
break;
default:
Status = CHTTPReply::bad_request;
break;
}
}
return Status;
}
//--------------------------------------------------------------------------------------------------------------
int CAuthServer::CheckError(const CJSON &Json, CString &ErrorMessage, bool RaiseIfError) {
int ErrorCode = 0;
if (Json.HasOwnProperty(_T("error"))) {
const auto& error = Json[_T("error")];
if (error.HasOwnProperty(_T("code"))) {
ErrorCode = error[_T("code")].AsInteger();
} else {
ErrorCode = 40000;
}
if (error.HasOwnProperty(_T("message"))) {
ErrorMessage = error[_T("message")].AsString();
} else {
ErrorMessage = _T("Invalid request.");
}
if (RaiseIfError)
throw EDBError(ErrorMessage.c_str());
if (ErrorCode >= 10000)
ErrorCode = ErrorCode / 100;
if (ErrorCode < 0)
ErrorCode = 400;
}
return ErrorCode;
}
//--------------------------------------------------------------------------------------------------------------
int CAuthServer::CheckOAuth2Error(const CJSON &Json, CString &Error, CString &ErrorDescription) {
int ErrorCode = 0;
if (Json.HasOwnProperty(_T("error"))) {
const auto& error = Json[_T("error")];
if (error.HasOwnProperty(_T("code"))) {
ErrorCode = error[_T("code")].AsInteger();
} else {
ErrorCode = 400;
}
if (error.HasOwnProperty(_T("error"))) {
Error = error[_T("error")].AsString();
} else {
Error = _T("invalid_request");
}
if (error.HasOwnProperty(_T("message"))) {
ErrorDescription = error[_T("message")].AsString();
} else {
ErrorDescription = _T("Invalid request.");
}
}
return ErrorCode;
}
//--------------------------------------------------------------------------------------------------------------
void CAuthServer::AfterQuery(CHTTPServerConnection *AConnection, const CString &Path, const CJSON &Payload) {
if (Path == _T("/sign/in/token")) {
SetAuthorizationData(AConnection, Payload);
}
}
//--------------------------------------------------------------------------------------------------------------
void CAuthServer::DoPostgresQueryExecuted(CPQPollQuery *APollQuery) {
auto pResult = APollQuery->Results(0);
if (pResult->ExecStatus() != PGRES_TUPLES_OK) {
QueryException(APollQuery, Delphi::Exception::EDBError(pResult->GetErrorMessage()));
return;
}
CString ErrorMessage;
auto pConnection = dynamic_cast<CHTTPServerConnection *> (APollQuery->Binding());
if (pConnection != nullptr && !pConnection->ClosedGracefully()) {
const auto& Path = pConnection->Data()["path"].Lower();
auto pRequest = pConnection->Request();
auto pReply = pConnection->Reply();
const auto& result_object = pRequest->Params[_T("result_object")];
const auto& data_array = pRequest->Params[_T("data_array")];
CHTTPReply::CStatusType status = CHTTPReply::ok;
try {
if (pResult->nTuples() == 1) {
const CJSON Payload(pResult->GetValue(0, 0));
status = ErrorCodeToStatus(CheckError(Payload, ErrorMessage));
if (status == CHTTPReply::ok) {
AfterQuery(pConnection, Path, Payload);
}
}
PQResultToJson(pResult, pReply->Content);
} catch (Delphi::Exception::Exception &E) {
ErrorMessage = E.what();
status = CHTTPReply::bad_request;
Log()->Error(APP_LOG_ERR, 0, "%s", E.what());
}
const auto& caRedirect = status == CHTTPReply::ok ? pConnection->Data()["redirect"] : pConnection->Data()["redirect_error"];
if (caRedirect.IsEmpty()) {
if (status == CHTTPReply::ok) {
pConnection->SendReply(status, nullptr, true);
} else {
ReplyError(pConnection, status, "server_error", ErrorMessage);
}
} else {
if (status == CHTTPReply::ok) {
Redirect(pConnection, caRedirect, true);
} else {
switch (status) {
case CHTTPReply::unauthorized:
RedirectError(pConnection, caRedirect, status, "unauthorized_client", ErrorMessage);
break;
case CHTTPReply::forbidden:
RedirectError(pConnection, caRedirect, status, "access_denied", ErrorMessage);
break;
case CHTTPReply::internal_server_error:
RedirectError(pConnection, caRedirect, status, "server_error", ErrorMessage);
break;
default:
RedirectError(pConnection, caRedirect, status, "invalid_request", ErrorMessage);
break;
}
}
}
}
}
//--------------------------------------------------------------------------------------------------------------
void CAuthServer::QueryException(CPQPollQuery *APollQuery, const Delphi::Exception::Exception &E) {
auto pConnection = dynamic_cast<CHTTPServerConnection *> (APollQuery->Binding());
if (pConnection != nullptr && !pConnection->ClosedGracefully()) {
auto pReply = pConnection->Reply();
const auto& caRedirect = pConnection->Data()["redirect_error"];
if (!caRedirect.IsEmpty()) {
RedirectError(pConnection, caRedirect, CHTTPReply::internal_server_error, "server_error", E.what());
} else {
ExceptionToJson(CHTTPReply::internal_server_error, E, pReply->Content);
pConnection->SendReply(CHTTPReply::ok, nullptr, true);
}
}
Log()->Error(APP_LOG_ERR, 0, "%s", E.what());
}
//--------------------------------------------------------------------------------------------------------------
void CAuthServer::DoPostgresQueryException(CPQPollQuery *APollQuery, const Delphi::Exception::Exception &E) {
QueryException(APollQuery, E);
}
//--------------------------------------------------------------------------------------------------------------
CString CAuthServer::CreateToken(const CCleanToken& CleanToken) {
const auto& Providers = Server().Providers();
const auto& Default = Providers.Default().Value();
const CString Application(WEB_APPLICATION_NAME);
auto token = jwt::create()
.set_issuer(Default.Issuer(Application))
.set_audience(Default.ClientId(Application))
.set_issued_at(std::chrono::system_clock::now())
.set_expires_at(std::chrono::system_clock::now() + std::chrono::seconds{3600})
.sign(jwt::algorithm::hs256{std::string(Default.Secret(Application))});
return token;
}
//--------------------------------------------------------------------------------------------------------------
CString CAuthServer::VerifyToken(const CString &Token) {
const auto& GetSecret = [](const CProvider &Provider, const CString &Application) {
const auto &Secret = Provider.Secret(Application);
if (Secret.IsEmpty())
throw ExceptionFrm("Not found Secret for \"%s:%s\"", Provider.Name().c_str(), Application.c_str());
return Secret;
};
auto decoded = jwt::decode(Token);
const auto& aud = CString(decoded.get_audience());
CString Application;
const auto& Providers = Server().Providers();
const auto Index = OAuth2::Helper::ProviderByClientId(Providers, aud, Application);
if (Index == -1)
throw COAuth2Error(_T("Not found provider by Client ID."));
const auto& provider = Providers[Index].Value();
const auto& iss = CString(decoded.get_issuer());
CStringList Issuers;
provider.GetIssuers(Application, Issuers);
if (Issuers[iss].IsEmpty())
throw jwt::token_verification_exception("Token doesn't contain the required issuer.");
const auto& alg = decoded.get_algorithm();
const auto& ch = alg.substr(0, 2);
const auto& Secret = GetSecret(provider, Application);
if (ch == "HS") {
if (alg == "HS256") {
auto verifier = jwt::verify()
.allow_algorithm(jwt::algorithm::hs256{Secret});
verifier.verify(decoded);
return Token; // if algorithm HS256
} else if (alg == "HS384") {
auto verifier = jwt::verify()
.allow_algorithm(jwt::algorithm::hs384{Secret});
verifier.verify(decoded);
} else if (alg == "HS512") {
auto verifier = jwt::verify()
.allow_algorithm(jwt::algorithm::hs512{Secret});
verifier.verify(decoded);
}
} else if (ch == "RS") {
const auto& kid = decoded.get_key_id();
const auto& key = OAuth2::Helper::GetPublicKey(Providers, kid);
if (alg == "RS256") {
auto verifier = jwt::verify()
.allow_algorithm(jwt::algorithm::rs256{key});
verifier.verify(decoded);
} else if (alg == "RS384") {
auto verifier = jwt::verify()
.allow_algorithm(jwt::algorithm::rs384{key});
verifier.verify(decoded);
} else if (alg == "RS512") {
auto verifier = jwt::verify()
.allow_algorithm(jwt::algorithm::rs512{key});
verifier.verify(decoded);
}
} else if (ch == "ES") {
const auto& kid = decoded.get_key_id();
const auto& key = OAuth2::Helper::GetPublicKey(Providers, kid);
if (alg == "ES256") {
auto verifier = jwt::verify()
.allow_algorithm(jwt::algorithm::es256{key});
verifier.verify(decoded);
} else if (alg == "ES384") {
auto verifier = jwt::verify()
.allow_algorithm(jwt::algorithm::es384{key});
verifier.verify(decoded);
} else if (alg == "ES512") {
auto verifier = jwt::verify()
.allow_algorithm(jwt::algorithm::es512{key});
verifier.verify(decoded);
}
} else if (ch == "PS") {
const auto& kid = decoded.get_key_id();
const auto& key = OAuth2::Helper::GetPublicKey(Providers, kid);
if (alg == "PS256") {
auto verifier = jwt::verify()
.allow_algorithm(jwt::algorithm::ps256{key});
verifier.verify(decoded);
} else if (alg == "PS384") {
auto verifier = jwt::verify()
.allow_algorithm(jwt::algorithm::ps384{key});
verifier.verify(decoded);
} else if (alg == "PS512") {
auto verifier = jwt::verify()
.allow_algorithm(jwt::algorithm::ps512{key});
verifier.verify(decoded);
}
}
const auto& Result = CCleanToken(R"({"alg":"HS256","typ":"JWT"})", decoded.get_payload(), true);
return Result.Sign(jwt::algorithm::hs256{Secret});
}
//--------------------------------------------------------------------------------------------------------------
bool CAuthServer::CheckAuthorization(CHTTPServerConnection *AConnection, CAuthorization &Authorization) {
auto pRequest = AConnection->Request();
try {
if (CheckAuthorizationData(pRequest, Authorization)) {
if (Authorization.Schema == CAuthorization::asBearer) {
VerifyToken(Authorization.Token);
return true;
}
}
if (Authorization.Schema == CAuthorization::asBasic)
AConnection->Data().Values("Authorization", "Basic");
ReplyError(AConnection, CHTTPReply::unauthorized, "unauthorized", "Unauthorized.");
} catch (jwt::token_expired_exception &e) {
ReplyError(AConnection, CHTTPReply::forbidden, "forbidden", e.what());
} catch (jwt::token_verification_exception &e) {
ReplyError(AConnection, CHTTPReply::bad_request, "invalid_request", e.what());
} catch (CAuthorizationError &e) {
ReplyError(AConnection, CHTTPReply::bad_request, "invalid_request", e.what());
} catch (std::exception &e) {
ReplyError(AConnection, CHTTPReply::bad_request, "invalid_request", e.what());
}
return false;
}
//--------------------------------------------------------------------------------------------------------------
void CAuthServer::DoIdentifier(CHTTPServerConnection *AConnection) {
auto OnExecuted = [AConnection](CPQPollQuery *APollQuery) {
auto pReply = AConnection->Reply();
auto pResult = APollQuery->Results(0);
CString errorMessage;
CHTTPReply::CStatusType status = CHTTPReply::internal_server_error;
try {
if (pResult->ExecStatus() != PGRES_TUPLES_OK)
throw Delphi::Exception::EDBError(pResult->GetErrorMessage());
pReply->ContentType = CHTTPReply::json;
pReply->Content = pResult->GetValue(0, 0);
const CJSON Payload(pReply->Content);
status = ErrorCodeToStatus(CheckError(Payload, errorMessage));
} catch (Delphi::Exception::Exception &E) {
pReply->Content.Clear();
ExceptionToJson(status, E, pReply->Content);
Log()->Error(APP_LOG_ERR, 0, "%s", E.what());
}
AConnection->SendReply(status, nullptr, true);
};
auto OnException = [AConnection](CPQPollQuery *APollQuery, const Delphi::Exception::Exception &E) {
ReplyError(AConnection, CHTTPReply::internal_server_error, "server_error", E.what());
};
auto pRequest = AConnection->Request();
CJSON Json;
ContentToJson(pRequest, Json);
const auto &Identifier = Json["value"].AsString();
if (Identifier.IsEmpty()) {
ReplyError(AConnection, CHTTPReply::bad_request, "invalid_request", "Invalid request.");
return;
}
CAuthorization Authorization;
if (CheckAuthorization(AConnection, Authorization)) {
if (Authorization.Schema == CAuthorization::asBearer) {
CStringList SQL;
SQL.Add(CString().Format("SELECT * FROM daemon.identifier(%s, %s);",
PQQuoteLiteral(Authorization.Token).c_str(),
PQQuoteLiteral(Identifier).c_str()
));
try {
ExecSQL(SQL, nullptr, OnExecuted, OnException);
} catch (Delphi::Exception::Exception &E) {
ReplyError(AConnection, CHTTPReply::service_unavailable, "temporarily_unavailable", "Temporarily unavailable.");
}
return;
}
ReplyError(AConnection, CHTTPReply::unauthorized, "unauthorized", "Unauthorized.");
}
}
//--------------------------------------------------------------------------------------------------------------
void CAuthServer::RedirectError(CHTTPServerConnection *AConnection, const CString &Location, int ErrorCode, const CString &Error, const CString &Message) {
CString errorLocation(Location);
errorLocation << "?code=" << ErrorCode;
errorLocation << "&error=" << Error;
errorLocation << "&error_description=" << CHTTPServer::URLEncode(Message);
Redirect(AConnection, errorLocation, true);
Log()->Error(APP_LOG_ERR, 0, _T("RedirectError: %s"), Message.c_str());
}
//--------------------------------------------------------------------------------------------------------------
void CAuthServer::ReplyError(CHTTPServerConnection *AConnection, int ErrorCode, const CString &Error, const CString &Message) {
auto pReply = AConnection->Reply();
pReply->ContentType = CHTTPReply::json;
CHTTPReply::CStatusType Status = ErrorCodeToStatus(ErrorCode);
if (ErrorCode == CHTTPReply::unauthorized) {
CHTTPReply::AddUnauthorized(pReply, true, "access_denied", Message.c_str());
}
pReply->Content.Clear();
pReply->Content.Format(R"({"error": "%s", "error_description": "%s"})",
Error.c_str(), Delphi::Json::EncodeJsonString(Message).c_str());
AConnection->SendReply(Status, nullptr, true);
Log()->Notice(_T("ReplyError: %s"), Message.c_str());
};
//--------------------------------------------------------------------------------------------------------------
void CAuthServer::DoToken(CHTTPServerConnection *AConnection) {
auto OnExecuted = [AConnection](CPQPollQuery *APollQuery) {
auto pReply = AConnection->Reply();
auto pResult = APollQuery->Results(0);
CString error;
CString errorDescription;
CHTTPReply::CStatusType status;
try {
if (pResult->ExecStatus() != PGRES_TUPLES_OK)
throw Delphi::Exception::EDBError(pResult->GetErrorMessage());
PQResultToJson(pResult, pReply->Content);
const CJSON Json(pReply->Content);
status = ErrorCodeToStatus(CheckOAuth2Error(Json, error, errorDescription));
if (status == CHTTPReply::ok) {
AConnection->SendReply(status, nullptr, true);
} else {
ReplyError(AConnection, status, error, errorDescription);
}
} catch (Delphi::Exception::Exception &E) {
ReplyError(AConnection, CHTTPReply::internal_server_error, "server_error", E.what());
}
};
auto OnException = [AConnection](CPQPollQuery *APollQuery, const Delphi::Exception::Exception &E) {
ReplyError(AConnection, CHTTPReply::internal_server_error, "server_error", E.what());
};
LPCTSTR js_origin_error = _T("The JavaScript origin in the request, %s, does not match the ones authorized for the OAuth client.");
LPCTSTR redirect_error = _T("Invalid parameter value for redirect_uri: Non-public domains not allowed: %s");
LPCTSTR value_error = _T("Parameter value %s cannot be empty.");
auto pRequest = AConnection->Request();
CJSON Json;
ContentToJson(pRequest, Json);
CAuthorization Authorization;
const auto &grant_type = Json["grant_type"].AsString();
if (grant_type != "urn:ietf:params:oauth:grant-type:jwt-bearer") {
const auto &client_id = Json["client_id"].AsString();
const auto &client_secret = Json["client_secret"].AsString();
const auto &redirect_uri = Json["redirect_uri"].AsString();
const auto &authorization = pRequest->Headers["Authorization"];
const auto &origin = GetOrigin(AConnection);
const auto &providers = Server().Providers();
if (authorization.IsEmpty()) {
Authorization.Schema = CAuthorization::asBasic;
Authorization.Username = client_id;
Authorization.Password = client_secret;
} else {
Authorization << authorization;
if (Authorization.Schema != CAuthorization::asBasic) {
ReplyError(AConnection, CHTTPReply::bad_request, "invalid_request",
"Invalid authorization schema.");
return;
}
}
if (Authorization.Username.IsEmpty()) {
if (grant_type != "password") {
ReplyError(AConnection, CHTTPReply::bad_request, "invalid_request",
CString().Format(value_error, "client_id"));
return;
}
const auto &provider = providers.DefaultValue();
Authorization.Username = provider.ClientId(WEB_APPLICATION_NAME);
}
if (Authorization.Password.IsEmpty()) {
CString Application;
const auto index = OAuth2::Helper::ProviderByClientId(providers, Authorization.Username, Application);
if (index != -1) {
const auto &provider = providers[index].Value();
if (Application == WEB_APPLICATION_NAME ||
Application == SERVICE_APPLICATION_NAME) { // TODO: Need delete application "service"
if (!redirect_uri.empty()) {
CStringList RedirectURI;
provider.RedirectURI(Application, RedirectURI);
if (RedirectURI.IndexOfName(redirect_uri) == -1) {
ReplyError(AConnection, CHTTPReply::bad_request, "invalid_request",
CString().Format(redirect_error, redirect_uri.c_str()));
return;
}
}
CStringList JavaScriptOrigins;
provider.JavaScriptOrigins(Application, JavaScriptOrigins);
if (JavaScriptOrigins.IndexOfName(origin) == -1) {
ReplyError(AConnection, CHTTPReply::bad_request, "invalid_request",
CString().Format(js_origin_error, origin.c_str()));
return;
}
Authorization.Password = provider.Secret(Application);
}
}
}
if (Authorization.Password.IsEmpty()) {
ReplyError(AConnection, CHTTPReply::bad_request, "invalid_request",
CString().Format(value_error, "client_secret"));
return;
}
}
const auto &agent = GetUserAgent(AConnection);
const auto &host = GetRealIP(AConnection);
CStringList SQL;
SQL.Add(CString().Format("SELECT * FROM daemon.token(%s, %s, '%s'::jsonb, %s, %s);",
PQQuoteLiteral(Authorization.Username).c_str(),
PQQuoteLiteral(Authorization.Password).c_str(),
Json.ToString().c_str(),
PQQuoteLiteral(agent).c_str(),
PQQuoteLiteral(host).c_str()
));
try {
ExecSQL(SQL, AConnection, OnExecuted, OnException);
} catch (Delphi::Exception::Exception &E) {
ReplyError(AConnection, CHTTPReply::bad_request, "temporarily_unavailable", "Temporarily unavailable.");
}
}
//--------------------------------------------------------------------------------------------------------------
void CAuthServer::Login(CHTTPServerConnection *AConnection, const CJSON &Token) {
const auto &errorLocation = AConnection->Data()["redirect_error"];
try {
const auto &token_type = Token["token_type"].AsString();
const auto &id_token = Token["id_token"].AsString();
CAuthorization Authorization;
try {
Authorization << (token_type + " " + id_token);
if (Authorization.Schema == CAuthorization::asBearer) {
Authorization.Token = VerifyToken(Authorization.Token);
}
const auto &agent = GetUserAgent(AConnection);
const auto &protocol = GetProtocol(AConnection);
const auto &host = GetRealIP(AConnection);
const auto &host_name = GetHost(AConnection);
CStringList SQL;
SQL.Add(CString().Format("SELECT * FROM daemon.login(%s, %s, %s, %s);",
PQQuoteLiteral(Authorization.Token).c_str(),
PQQuoteLiteral(agent).c_str(),
PQQuoteLiteral(host).c_str(),
PQQuoteLiteral(CString().Format("%s://%s", protocol.c_str(), host_name.c_str())).c_str()
));
AConnection->Data().Values("authorized", "false");
AConnection->Data().Values("signature", "false");
AConnection->Data().Values("path", "/sign/in/token");
try {
ExecSQL(SQL, AConnection);
} catch (Delphi::Exception::Exception &E) {
RedirectError(AConnection, errorLocation, CHTTPReply::service_unavailable, "temporarily_unavailable", "Temporarily unavailable.");
}
} catch (jwt::token_expired_exception &e) {
RedirectError(AConnection, errorLocation, CHTTPReply::forbidden, "invalid_token", e.what());
} catch (jwt::token_verification_exception &e) {
RedirectError(AConnection, errorLocation, CHTTPReply::unauthorized, "invalid_token", e.what());
} catch (CAuthorizationError &e) {
RedirectError(AConnection, errorLocation, CHTTPReply::unauthorized, "unauthorized_client", e.what());
} catch (std::exception &e) {
RedirectError(AConnection, errorLocation, CHTTPReply::bad_request, "invalid_token", e.what());
}
} catch (Delphi::Exception::Exception &E) {
RedirectError(AConnection, errorLocation, CHTTPReply::internal_server_error, "server_error", E.what());
Log()->Error(APP_LOG_INFO, 0, "[Token] Message: %s", E.what());
}
}
//--------------------------------------------------------------------------------------------------------------
void CAuthServer::SetAuthorizationData(CHTTPServerConnection *AConnection, const CJSON &Payload) {
auto pReply = AConnection->Reply();
const auto &session = Payload[_T("session")].AsString();
if (!session.IsEmpty())
pReply->SetCookie(_T("SID"), session.c_str(), _T("/"), 60 * SecsPerDay);
CString Redirect = AConnection->Data()["redirect"];
if (!Redirect.IsEmpty()) {
const auto &access_token = Payload[_T("access_token")].AsString();
const auto &refresh_token = Payload[_T("refresh_token")].AsString();
const auto &token_type = Payload[_T("token_type")].AsString();
const auto &expires_in = Payload[_T("expires_in")].AsString();
const auto &state = Payload[_T("state")].AsString();
Redirect << "#access_token=" << access_token;
if (!refresh_token.IsEmpty())
Redirect << "&refresh_token=" << CHTTPServer::URLEncode(refresh_token);
Redirect << "&token_type=" << token_type;
Redirect << "&expires_in=" << expires_in;
Redirect << "&session=" << session;
if (!state.IsEmpty())
Redirect << "&state=" << CHTTPServer::URLEncode(state);
AConnection->Data().Values("redirect", Redirect);
}
}
//--------------------------------------------------------------------------------------------------------------
bool CAuthServer::CheckAuthorizationData(CHTTPRequest *ARequest, CAuthorization &Authorization) {
const auto &headers = ARequest->Headers;
const auto &authorization = headers["Authorization"];
if (authorization.IsEmpty()) {
Authorization.Username = headers["Session"];
Authorization.Password = headers["Secret"];
if (Authorization.Username.IsEmpty() || Authorization.Password.IsEmpty())
return false;
Authorization.Schema = CAuthorization::asBasic;
Authorization.Type = CAuthorization::atSession;
} else {
Authorization << authorization;
}
return true;
}
//--------------------------------------------------------------------------------------------------------------
void CAuthServer::ParseString(const CString &String, const CStringList &Strings, CStringList &Valid, CStringList &Invalid) {
Valid.Clear();
Invalid.Clear();
if (!String.IsEmpty()) {
Valid.LineBreak(", ");
Invalid.LineBreak(", ");
CStringList Scopes;
SplitColumns(String, Scopes, ' ');
for (int i = 0; i < Scopes.Count(); i++) {
if (Strings.IndexOfName(Scopes[i]) == -1) {
Invalid.Add(Scopes[i]);
} else {
Valid.Add(Scopes[i]);
}
}
}
}
//--------------------------------------------------------------------------------------------------------------
void CAuthServer::FetchAccessToken(CHTTPServerConnection *AConnection, const CProvider &Provider, const CString &Code) {
auto OnRequestToken = [](CHTTPClient *Sender, CHTTPRequest *ARequest) {
const auto &token_uri = Sender->Data()["token_uri"];
const auto &code = Sender->Data()["code"];
const auto &client_id = Sender->Data()["client_id"];
const auto &client_secret = Sender->Data()["client_secret"];
const auto &redirect_uri = Sender->Data()["redirect_uri"];
const auto &grant_type = Sender->Data()["grant_type"];
ARequest->Content = _T("client_id=");
ARequest->Content << CHTTPServer::URLEncode(client_id);
ARequest->Content << _T("&client_secret=");
ARequest->Content << CHTTPServer::URLEncode(client_secret);
ARequest->Content << _T("&grant_type=");
ARequest->Content << grant_type;
ARequest->Content << _T("&code=");
ARequest->Content << CHTTPServer::URLEncode(code);
ARequest->Content << _T("&redirect_uri=");
ARequest->Content << CHTTPServer::URLEncode(redirect_uri);
CHTTPRequest::Prepare(ARequest, _T("POST"), token_uri.c_str(), _T("application/x-www-form-urlencoded"));
DebugRequest(ARequest);
};
auto OnReplyToken = [this, AConnection](CTCPConnection *Sender) {
auto pConnection = dynamic_cast<CHTTPClientConnection *> (Sender);
auto pReply = pConnection->Reply();
DebugReply(pReply);
pConnection->CloseConnection(true);
if (!Assigned(AConnection))
return false;
if (AConnection->ClosedGracefully())
return false;
const CJSON Json(pReply->Content);
if (pReply->Status == CHTTPReply::ok) {
if (AConnection->Data()["provider"] == "google") {
Login(AConnection, Json);
} else {
SetAuthorizationData(AConnection, Json);
Redirect(AConnection, AConnection->Data()["redirect"], true);
}
} else {
const auto &redirect_error = AConnection->Data()["redirect_error"];
const auto &error = Json[_T("error")].AsString();
const auto &error_description = Json[_T("error_description")].AsString();
RedirectError(AConnection, redirect_error, pReply->Status, error, error_description);
}
return true;
};
auto OnException = [AConnection](CTCPConnection *Sender, const Delphi::Exception::Exception &E) {
auto pConnection = dynamic_cast<CHTTPClientConnection *> (Sender);
auto pClient = dynamic_cast<CHTTPClient *> (pConnection->Client());
DebugReply(pConnection->Reply());
const auto &redirect_error = AConnection->Data()["redirect_error"];
if (!AConnection->ClosedGracefully())
RedirectError(AConnection, redirect_error, CHTTPReply::internal_server_error, "server_error", E.what());
Log()->Error(APP_LOG_ERR, 0, "[%s:%d] %s", pClient->Host().c_str(), pClient->Port(), E.what());
};
auto pRequest = AConnection->Request();
const auto &redirect_error = AConnection->Data()["redirect_error"];
const auto &caApplication = WEB_APPLICATION_NAME;
CString TokenURI(Provider.TokenURI(caApplication));
if (!TokenURI.IsEmpty()) {
if (TokenURI.front() == '/') {
TokenURI = pRequest->Location.Origin() + TokenURI;
}
CLocation URI(TokenURI);
auto pClient = GetClient(URI.hostname, URI.port);
pClient->Data().Values("client_id", Provider.ClientId(caApplication));
pClient->Data().Values("client_secret", Provider.Secret(caApplication));
pClient->Data().Values("grant_type", "authorization_code");
pClient->Data().Values("code", Code);
pClient->Data().Values("redirect_uri", pRequest->Location.Origin() + pRequest->Location.pathname);
pClient->Data().Values("token_uri", URI.pathname);
pClient->OnRequest(OnRequestToken);
pClient->OnExecute(OnReplyToken);
pClient->OnException(OnException);
pClient->Active(true);
} else {
RedirectError(AConnection, redirect_error, CHTTPReply::bad_request, "invalid_request", "Parameter \"token_uri\" not found in provider configuration.");
}
}
//--------------------------------------------------------------------------------------------------------------
void CAuthServer::DoGet(CHTTPServerConnection *AConnection) {
auto SetSearch = [](const CStringList &Search, CString &Location) {
for (int i = 0; i < Search.Count(); ++i) {
if (i == 0) {
Location << "?";
} else {
Location << "&";
}
Location << Search.Strings(i);
}
};
auto pRequest = AConnection->Request();
auto pReply = AConnection->Reply();
pReply->ContentType = CHTTPReply::html;
CStringList Routs;
SplitColumns(pRequest->Location.pathname, Routs, '/');
if (Routs.Count() < 2) {
AConnection->SendStockReply(CHTTPReply::not_found);
return;
}
const auto &siteConfig = GetSiteConfig(pRequest->Location.Host());
const auto &redirect_identifier = siteConfig["oauth2.identifier"];
const auto &redirect_secret = siteConfig["oauth2.secret"];
const auto &redirect_callback = siteConfig["oauth2.callback"];
const auto &redirect_error = siteConfig["oauth2.error"];
const auto &redirect_debug = siteConfig["oauth2.debug"];
CString oauthLocation;
CStringList Search;
CStringList Valid;
CStringList Invalid;
CStringList ResponseType;
ResponseType.Add("code");
ResponseType.Add("token");
CStringList AccessType;
AccessType.Add("online");
AccessType.Add("offline");
CStringList Prompt;
Prompt.Add("none");
Prompt.Add("signin");
Prompt.Add("secret");
Prompt.Add("consent");
Prompt.Add("select_account");
const auto &providers = Server().Providers();
const auto &action = Routs[1].Lower();
if (action == "authorize" || action == "auth") {
const auto &response_type = pRequest->Params["response_type"];
const auto &client_id = pRequest->Params["client_id"];
const auto &access_type = pRequest->Params["access_type"];
const auto &redirect_uri = pRequest->Params["redirect_uri"];
const auto &scope = pRequest->Params["scope"];
const auto &state = pRequest->Params["state"];
const auto &prompt = pRequest->Params["prompt"];
if (redirect_uri.IsEmpty()) {
RedirectError(AConnection, redirect_error, CHTTPReply::bad_request, "invalid_request",
CString().Format("Parameter value redirect_uri cannot be empty."));
return;
}
CString Application;
const auto index = OAuth2::Helper::ProviderByClientId(providers, client_id, Application);
if (index == -1) {
RedirectError(AConnection, redirect_error, CHTTPReply::unauthorized, "invalid_client", CString().Format("The OAuth client was not found."));
return;
}
const auto& provider = providers[index].Value();
CStringList RedirectURI;
provider.RedirectURI(Application, RedirectURI);
if (RedirectURI.IndexOfName(redirect_uri) == -1) {
RedirectError(AConnection, redirect_error, CHTTPReply::bad_request, "invalid_request",
CString().Format("Invalid parameter value for redirect_uri: Non-public domains not allowed: %s", redirect_uri.c_str()));
return;
}
ParseString(response_type, ResponseType, Valid, Invalid);
if (Invalid.Count() > 0) {
RedirectError(AConnection, redirect_error, CHTTPReply::bad_request, "unsupported_response_type",
CString().Format("Some requested response type were invalid: {valid=[%s], invalid=[%s]}",
Valid.Text().c_str(), Invalid.Text().c_str()));
return;
}
if (response_type == "token")
AccessType.Clear();
if (!access_type.IsEmpty() && AccessType.IndexOfName(access_type) == -1) {
RedirectError(AConnection, redirect_error, CHTTPReply::bad_request, "invalid_request",
CString().Format("Invalid access_type: %s", access_type.c_str()));
return;
}
CStringList Scopes;
provider.GetScopes(Application, Scopes);
ParseString(scope, Scopes, Valid, Invalid);
if (Invalid.Count() > 0) {
RedirectError(AConnection, redirect_error, CHTTPReply::bad_request, "invalid_scope",
CString().Format("Some requested scopes were invalid: {valid=[%s], invalid=[%s]}",
Valid.Text().c_str(), Invalid.Text().c_str()));
return;
}
ParseString(prompt, Prompt, Valid, Invalid);
if (Invalid.Count() > 0) {
RedirectError(AConnection, redirect_error, CHTTPReply::bad_request, "unsupported_prompt_type",
CString().Format("Some requested prompt type were invalid: {valid=[%s], invalid=[%s]}",
Valid.Text().c_str(), Invalid.Text().c_str()));
return;
}
oauthLocation = prompt == "secret" ? redirect_secret : redirect_identifier;
Search.Clear();
Search.AddPair("client_id", client_id);
Search.AddPair("response_type", response_type);
if (!redirect_uri.IsEmpty())
Search.AddPair("redirect_uri", CHTTPServer::URLEncode(redirect_uri));
if (!access_type.IsEmpty())
Search.AddPair("access_type", access_type);
if (!scope.IsEmpty())
Search.AddPair("scope", CHTTPServer::URLEncode(scope));
if (!prompt.IsEmpty())
Search.AddPair("prompt", CHTTPServer::URLEncode(prompt));
if (!state.IsEmpty())
Search.AddPair("state", CHTTPServer::URLEncode(state));
SetSearch(Search, oauthLocation);
} else if (action == "code") {
const auto &error = pRequest->Params["error"];
if (!error.IsEmpty()) {
const auto ErrorCode = StrToIntDef(pRequest->Params["code"].c_str(), CHTTPReply::bad_request);
RedirectError(AConnection, redirect_error, (int) ErrorCode, error, pRequest->Params["error_description"]);
return;
}
const auto &code = pRequest->Params["code"];
const auto &state = pRequest->Params["state"];
if (!code.IsEmpty()) {
const auto &providerName = Routs.Count() == 3 ? Routs[2].Lower() : "default";
const auto &provider = providers[providerName];
AConnection->Data().Values("provider", providerName);
AConnection->Data().Values("redirect", state == "debug" ? redirect_debug : redirect_callback);
AConnection->Data().Values("redirect_error", redirect_error);
FetchAccessToken(AConnection, provider, code);
} else {
RedirectError(AConnection, redirect_error, CHTTPReply::bad_request, "invalid_request", "Parameter \"code\" not found.");
}
return;
} else if (action == "callback") {
oauthLocation = redirect_callback;
} else if (action == "identifier") {
DoIdentifier(AConnection);
return;
}
if (oauthLocation.IsEmpty())
AConnection->SendStockReply(CHTTPReply::not_found);
else
Redirect(AConnection, oauthLocation);
}
//--------------------------------------------------------------------------------------------------------------
void CAuthServer::DoPost(CHTTPServerConnection *AConnection) {
auto pRequest = AConnection->Request();
auto pReply = AConnection->Reply();
pReply->ContentType = CHTTPReply::json;
CStringList Routs;
SplitColumns(pRequest->Location.pathname, Routs, '/');
if (Routs.Count() < 2) {
ReplyError(AConnection, CHTTPReply::not_found, "invalid_request", "Not found.");
return;
}
AConnection->Data().Values("oauth2", "true");
AConnection->Data().Values("path", pRequest->Location.pathname);
try {
const auto &action = Routs[1].Lower();
if (action == "token") {
DoToken(AConnection);
} else if (action == "identifier") {
DoIdentifier(AConnection);
} else {
ReplyError(AConnection, CHTTPReply::not_found, "invalid_request", "Not found.");
}
} catch (Delphi::Exception::Exception &E) {
ReplyError(AConnection, CHTTPReply::bad_request, "invalid_request", E.what());
}
}
//--------------------------------------------------------------------------------------------------------------
void CAuthServer::FetchCerts(CProvider &Provider) {
const auto& URI = Provider.CertURI(WEB_APPLICATION_NAME);
if (URI.IsEmpty()) {
Log()->Error(APP_LOG_INFO, 0, _T("Certificate URI in provider \"%s\" is empty."), Provider.Name().c_str());
return;
}
Log()->Error(APP_LOG_INFO, 0, _T("Trying to fetch public keys from: %s"), URI.c_str());
auto OnRequest = [&Provider](CHTTPClient *Sender, CHTTPRequest *Request) {
Provider.KeyStatusTime(Now());
Provider.KeyStatus(ksFetching);
CLocation Location(Provider.CertURI(WEB_APPLICATION_NAME));
CHTTPRequest::Prepare(Request, "GET", Location.pathname.c_str());
};
auto OnExecute = [&Provider](CTCPConnection *AConnection) {
auto pConnection = dynamic_cast<CHTTPClientConnection *> (AConnection);
auto pReply = pConnection->Reply();
try {
DebugRequest(pConnection->Request());
DebugReply(pReply);
Provider.KeyStatusTime(Now());
Provider.Keys().Clear();
Provider.Keys() << pReply->Content;
Provider.KeyStatus(ksSuccess);
} catch (Delphi::Exception::Exception &E) {
Provider.KeyStatus(ksFailed);
Log()->Error(APP_LOG_ERR, 0, "[Certificate] Message: %s", E.what());
}
pConnection->CloseConnection(true);
return true;
};
auto OnException = [this, &Provider](CTCPConnection *AConnection, const Delphi::Exception::Exception &E) {
auto pConnection = dynamic_cast<CHTTPClientConnection *> (AConnection);
auto pClient = dynamic_cast<CHTTPClient *> (pConnection->Client());
Provider.KeyStatusTime(Now());
Provider.KeyStatus(ksFailed);
m_FixedDate = Now() + (CDateTime) 5 / SecsPerDay; // 5 sec
Log()->Error(APP_LOG_ERR, 0, "[%s:%d] %s", pClient->Host().c_str(), pClient->Port(), E.what());
};
CLocation Location(URI);
auto pClient = GetClient(Location.hostname, Location.port);
pClient->OnRequest(OnRequest);
pClient->OnExecute(OnExecute);
pClient->OnException(OnException);
pClient->Active(true);
}
//--------------------------------------------------------------------------------------------------------------
void CAuthServer::FetchProviders() {
auto& Providers = Server().Providers();
for (int i = 0; i < Providers.Count(); i++) {
auto& Provider = Providers[i].Value();
if (Provider.ApplicationExists(WEB_APPLICATION_NAME)) {
if (Provider.KeyStatus() == ksUnknown) {
FetchCerts(Provider);
}
}
}
}
//--------------------------------------------------------------------------------------------------------------
void CAuthServer::CheckProviders() {
auto& Providers = Server().Providers();
for (int i = 0; i < Providers.Count(); i++) {
auto& Provider = Providers[i].Value();
if (Provider.ApplicationExists(WEB_APPLICATION_NAME)) {
if (Provider.KeyStatus() != ksUnknown) {
Provider.KeyStatusTime(Now());
Provider.KeyStatus(ksUnknown);
}
}
}
}
//--------------------------------------------------------------------------------------------------------------
void CAuthServer::Heartbeat(CDateTime DateTime) {
if ((DateTime >= m_FixedDate)) {
m_FixedDate = DateTime + (CDateTime) 30 / MinsPerDay; // 30 min
CheckProviders();
FetchProviders();
}
}
//--------------------------------------------------------------------------------------------------------------
bool CAuthServer::Enabled() {
if (m_ModuleStatus == msUnknown)
m_ModuleStatus = Config()->IniFile().ReadBool(SectionName(), "enable", true) ? msEnabled : msDisabled;
return m_ModuleStatus == msEnabled;
}
//--------------------------------------------------------------------------------------------------------------
bool CAuthServer::CheckLocation(const CLocation &Location) {
return Location.pathname.SubString(0, 8) == _T("/oauth2/");
}
//--------------------------------------------------------------------------------------------------------------
}
}
} | 44.805012 | 167 | 0.483519 | apostoldevel |
2c44abb54c5fd459022aedda333fb842d8826d66 | 1,751 | hpp | C++ | src/signedzoneimp.hpp | sischkg/nxnsattack | c20896e40187bbcacb5c0255ff8f3cc7d0592126 | [
"MIT"
] | 5 | 2020-05-22T10:01:51.000Z | 2022-01-01T04:45:14.000Z | src/signedzoneimp.hpp | sischkg/dns-fuzz-server | 6f45079014e745537c2f564fdad069974e727da1 | [
"MIT"
] | 1 | 2020-06-07T14:09:44.000Z | 2020-06-07T14:09:44.000Z | src/signedzoneimp.hpp | sischkg/dns-fuzz-server | 6f45079014e745537c2f564fdad069974e727da1 | [
"MIT"
] | 2 | 2020-03-10T03:06:20.000Z | 2021-07-25T15:07:45.000Z | #ifndef SIGNED_ZONE_IMP_HPP
#define SIGNED_ZONE_IMP_HPP
#include "abstractzoneimp.hpp"
#include "nsecdb.hpp"
#include "nsec3db.hpp"
namespace dns
{
class SignedZoneImp : public AbstractZoneImp
{
private:
ZoneSigner mSigner;
NSECDBPtr mNSECDB;
NSECDBPtr mNSEC3DB;
bool mEnableNSEC;
bool mEnableNSEC3;
public:
SignedZoneImp( const Domainname &zone_name, const std::string &ksk_config, const std::string &zsk_config,
const std::vector<uint8_t> &salt, uint16_t iterate, HashAlgorithm alog,
bool enable_nsec, bool enable_nsec3 );
virtual void setup();
virtual std::vector<std::shared_ptr<RecordDS>> getDSRecords() const;
virtual std::shared_ptr<RRSet> signRRSet( const RRSet & ) const;
virtual void responseNoData( const Domainname &qname, MessageInfo &response, bool need_wildcard_nsec ) const;
virtual void responseNXDomain( const Domainname &qname, MessageInfo &response ) const;
virtual void responseRRSIG( const Domainname &qname, MessageInfo &response ) const;
virtual void responseNSEC( const Domainname &qname, MessageInfo &response ) const;
virtual void responseDNSKEY( const Domainname &qname, MessageInfo &response ) const;
virtual void addRRSIG( MessageInfo &, std::vector<ResourceRecord> &, const RRSet &original_rrset ) const;
virtual void addRRSIG( MessageInfo &, std::vector<ResourceRecord> &, const RRSet &original_rrset, const Domainname &owner ) const;
virtual RRSetPtr getDNSKEYRRSet() const;
virtual RRSetPtr generateNSECRRSet( const Domainname &domainname ) const;
virtual RRSetPtr generateNSEC3RRSet( const Domainname &domainname ) const;
static void initialize();
};
}
#endif
| 39.795455 | 138 | 0.73044 | sischkg |
2c45ddb59e4267c50323ce35521d2e5e4f0c714e | 760 | cpp | C++ | docs/mfc/reference/codesnippet/CPP/cwnd-class_65.cpp | bobbrow/cpp-docs | 769b186399141c4ea93400863a7d8463987bf667 | [
"CC-BY-4.0",
"MIT"
] | 965 | 2017-06-25T23:57:11.000Z | 2022-03-31T14:17:32.000Z | docs/mfc/reference/codesnippet/CPP/cwnd-class_65.cpp | bobbrow/cpp-docs | 769b186399141c4ea93400863a7d8463987bf667 | [
"CC-BY-4.0",
"MIT"
] | 3,272 | 2017-06-24T00:26:34.000Z | 2022-03-31T22:14:07.000Z | docs/mfc/reference/codesnippet/CPP/cwnd-class_65.cpp | bobbrow/cpp-docs | 769b186399141c4ea93400863a7d8463987bf667 | [
"CC-BY-4.0",
"MIT"
] | 951 | 2017-06-25T12:36:14.000Z | 2022-03-26T22:49:06.000Z | // In this example a rectangle is drawn in a view.
// The OnChangeRect() function changes the dimensions
// of the rectangle and then calls CWnd::Invalidate() so the
// client area of the view will be redrawn next time the
// window is updated. It then calls CWnd::UpdateWindow
// to force the new rectangle to be painted.
void CMdiView::OnChangeRect()
{
// Change Rectangle size.
m_rcBox = CRect(20, 20, 210, 210);
// Invalidate window so entire client area
// is redrawn when UpdateWindow is called.
Invalidate();
// Update Window to cause View to redraw.
UpdateWindow();
}
// On Draw function draws the rectangle.
void CMdiView::OnDraw(CDC *pDC)
{
// Other draw code here.
pDC->Draw3dRect(m_rcBox, 0x00FF0000, 0x0000FF00);
} | 28.148148 | 60 | 0.710526 | bobbrow |
2c46ee4492448793b16bf05202c35e10261f85fd | 15,687 | cpp | C++ | src/framebufferobject.cpp | AlessandroParrotta/parrlib | d1679ee8a7cff7d14b2d93e898ed58fecff13159 | [
"MIT"
] | 2 | 2020-05-08T20:27:14.000Z | 2021-01-21T10:28:19.000Z | src/framebufferobject.cpp | AlessandroParrotta/parrlib | d1679ee8a7cff7d14b2d93e898ed58fecff13159 | [
"MIT"
] | null | null | null | src/framebufferobject.cpp | AlessandroParrotta/parrlib | d1679ee8a7cff7d14b2d93e898ed58fecff13159 | [
"MIT"
] | 1 | 2020-05-08T20:27:16.000Z | 2020-05-08T20:27:16.000Z | #include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <parrlib/framebufferobject.h>
#include <parrlib/timer.h>
#include <parrlib/context.h>
#include <iostream>
void FrameBufferObject::addAttachment(GLenum att, FrameBufferObject::ColorAttachment format) {
if (attachments.find(att) != attachments.end()) { std::cout << "FBO: " << fboID << ": error: attachment " << att << " already created\n"; return; }
bind();
if (isNotRenderBuffer(att)) {
//attachments.push_back(0);
GLuint at = 0;
glGenTextures(1, &at);
glBindTexture(GL_TEXTURE_2D, at);
glTexImage2D(GL_TEXTURE_2D, 0, format.internalFormat, sizeX, sizeY, 0, format.format, format.type, NULL);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, format.minFilter);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, format.magFilter);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, format.wrap_s);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, format.wrap_t);
//if (att == GL_DEPTH_ATTACHMENT) glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, att, GL_TEXTURE_2D, at, 0);
glBindTexture(GL_TEXTURE_2D, 0);
attachments[att] = at;
//formats[att] = { internalFormat, format, type, minFilter, magFilter, wrap_s, wrap_t };
formats[att] = format;
}
else if (att == GL_DEPTH_ATTACHMENT) {
GLuint at = 0;
glGenRenderbuffers(1, &at);
glBindRenderbuffer(GL_RENDERBUFFER, at);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, sizeX, sizeY);
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, at);
attachments[att] = at;
}
else if (att == GL_STENCIL_ATTACHMENT) {
GLuint at = 0;
glGenRenderbuffers(1, &at);
glBindRenderbuffer(GL_RENDERBUFFER, at);
glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_COMPONENTS/*probably wrong*/, sizeX, sizeY);
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, at);
attachments[att] = at;
}
else if (att == GL_DEPTH_STENCIL_ATTACHMENT) {
GLuint at = 0;
glGenRenderbuffers(1, &at);
glBindRenderbuffer(GL_RENDERBUFFER, at);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, sizeX, sizeY);
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, at);
attachments[att] = at;
}
compCheck();
unbind();
}
void FrameBufferObject::addAttachment(GLenum att) {
if (formats.empty() || formats.find(GL_COLOR_ATTACHMENT0) == formats.end())
addAttachment(att, { GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR,GL_LINEAR, GL_REPEAT, GL_REPEAT });
else addAttachment(att, formats[GL_COLOR_ATTACHMENT0]);
}
//default initialization
void FrameBufferObject::init() {
glGenFramebuffers(1, &fboID);
//glGenRenderbuffers(1, &depID);
//render buffer is like a texture but you can access directly without weird color conversions
//so its faster and that's why it's better to use it for the depth attachment (it's not really a texture)
//in a nutshell: use render buffers if you're never going to use them as a texture
//you cannot access a renderbuffer from a shared in any way
//glBindFramebuffer(GL_FRAMEBUFFER, fboID);
//GLint drawFboId = 0, readFboId = 0;
//glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &drawFboId);
//glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &readFboId);
//std::cout << "FBO IDs: " << drawFboId << " " << readFboId << " " << fboID << "\n";
addAttachment(GL_COLOR_ATTACHMENT0);
addAttachment(GL_DEPTH_STENCIL_ATTACHMENT);
//glBindRenderbuffer(GL_RENDERBUFFER, depID);
//glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, sizeX, sizeY);
//glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depID);
compCheck();
//glBindFramebuffer(GL_FRAMEBUFFER, 0);
//std::cout << "Framebuffer initialized.";
}
void FrameBufferObject::bind() {
oldres = cst::res();
cst::res(vec2(sizeX, sizeY));
util::bindFramebuffer(fboID);
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0, 0, sizeX, sizeY);
}
void FrameBufferObject::unbind() {
glPopAttrib();
util::unbindFramebuffer();
//std::cout << "unbind oldbuf " << oldBufferID << "\n";
cst::res(oldres);
}
void FrameBufferObject::resize(int sizeX, int sizeY) {
if (sizeX <= 0 || sizeY <= 0) return;
if (!(this->sizeX == sizeX && this->sizeY == sizeY)) {
this->sizeX = sizeX;
this->sizeY = sizeY;
for (auto& it : attachments) {
if (isNotRenderBuffer(it.first)) {
if (formats.find(it.first) == formats.end()) { std::cout << "fbo " << fboID << " error: could not find format for attachment " << it.first << "\n"; return; }
ColorAttachment fm = formats[it.first];
glBindTexture(GL_TEXTURE_2D, it.second);
glTexImage2D(GL_TEXTURE_2D, 0, fm.internalFormat, sizeX, sizeY, 0, fm.format, fm.type, NULL);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, fm.minFilter);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, fm.magFilter);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, fm.wrap_s);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, fm.wrap_t);
glBindTexture(GL_TEXTURE_2D, 0);
}
}
//std::cout << "check\n";
if (getAttachment(GL_DEPTH_ATTACHMENT) != 0) {
glBindRenderbuffer(GL_RENDERBUFFER, attachments[GL_DEPTH_ATTACHMENT]);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, sizeX, sizeY);
}
if (getAttachment(GL_STENCIL_ATTACHMENT) != 0) {
glBindRenderbuffer(GL_RENDERBUFFER, attachments[GL_STENCIL_ATTACHMENT]);
glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_COMPONENTS/*probably wrong*/, sizeX, sizeY);
}
if (getAttachment(GL_DEPTH_STENCIL_ATTACHMENT) != 0) {
glBindRenderbuffer(GL_RENDERBUFFER, attachments[GL_DEPTH_STENCIL_ATTACHMENT]);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, sizeX, sizeY);
}
compCheck();
}
}
void FrameBufferObject::resize(vec2 size) { resize(size.x, size.y); }
GLuint FrameBufferObject::getID() const {
return fboID;
}
//GLuint FrameBufferObject::getDepID() { return depID; }
GLuint FrameBufferObject::getAttachment(GLenum att) const {
auto it = attachments.find(att);
if (it == attachments.end()) { /*std::cout << "FBO " << fboID << ": warning: could not find attachment " << util::fboAttachmentToString(att) << "\n";*/ return 0; }
//return attachments[att];
return it->second;
}
GLuint FrameBufferObject::getPrimaryColorAttachment() const { return getAttachment(GL_COLOR_ATTACHMENT0); }
int FrameBufferObject::sizex() const { return sizeX; }
int FrameBufferObject::sizey() const { return sizeY; }
vec2 FrameBufferObject::size() const { return { (float)sizeX, (float)sizeY }; }
void FrameBufferObject::clear(vec4 color){
if (sizeX <= 0 || sizeY <= 0) return;
GLint oldb = prc::fboid;
//glGetIntegerv(GL_FRAMEBUFFER_BINDING, &oldb);
if(oldb != fboID) bind();
glClearColor(color.x, color.y, color.z, color.w);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
if (oldb != fboID) unbind();
}
void FrameBufferObject::clear() { clear(vc4::black); }
void FrameBufferObject::setFiltering(int minFilter, int magFilter) {
//this->minFilter = minFilter;
//this->magFilter = magFilter;
for (auto& it : attachments) {
if (isNotRenderBuffer(it.first)) {
if (formats.find(it.first) == formats.end()) { std::cout << "fbo " << fboID << " error: could not find format for attachment " << it.first << "\n"; return; }
ColorAttachment fm = formats[it.first];
glBindTexture(GL_TEXTURE_2D, it.second);
glTexImage2D(GL_TEXTURE_2D, 0, fm.internalFormat, sizeX, sizeY, 0, fm.format, fm.type, NULL);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
glBindTexture(GL_TEXTURE_2D, 0);
formats[it.first].minFilter = minFilter;
formats[it.first].magFilter = magFilter;
}
}
}
void FrameBufferObject::setFiltering(int filtering) {
setFiltering(filtering, filtering);
}
GLenum FrameBufferObject::getMinFiltering(GLenum att) {
if (attachments.find(att) == attachments.end()) { std::cout << "FBO: " << fboID << ": error: attachment " << att << " doesn't exist\n"; return 0; }
return formats[att].minFilter;
}
GLenum FrameBufferObject::getMinFiltering() {return getMinFiltering(GL_COLOR_ATTACHMENT0);}
GLenum FrameBufferObject::getMagFiltering(GLenum att) {
if (attachments.find(att) == attachments.end()) { std::cout << "FBO: " << fboID << ": error: attachment " << att << " doesn't exist\n"; return 0; }
return formats[att].magFilter;
}
GLenum FrameBufferObject::getMagFiltering() {return getMagFiltering(GL_COLOR_ATTACHMENT0);}
void FrameBufferObject::setWrapMode(int wrap_s, int wrap_t) {
//this->wrap_s = wrap_s;
//this->wrap_t = wrap_t;
for (auto& it : attachments) {
if (isNotRenderBuffer(it.first)) {
if (formats.find(it.first) == formats.end()) { std::cout << "fbo " << fboID << " error: could not find format for attachment " << it.first << "\n"; return; }
ColorAttachment fm = formats[it.first];
glBindTexture(GL_TEXTURE_2D, it.second);
glTexImage2D(GL_TEXTURE_2D, 0, fm.internalFormat, sizeX, sizeY, 0, fm.format,fm. type, NULL);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t);
glBindTexture(GL_TEXTURE_2D, 0);
formats[it.first].wrap_s = wrap_s;
formats[it.first].wrap_t = wrap_t;
}
}
}
void FrameBufferObject::setWrapMode(int wrapMode) {
setWrapMode(wrapMode, wrapMode);
}
bool FrameBufferObject::isNotRenderBuffer(GLenum att) {
return att != GL_DEPTH_ATTACHMENT &&
att != GL_STENCIL_ATTACHMENT &&
att != GL_DEPTH_STENCIL_ATTACHMENT;
}
GLenum FrameBufferObject::getWrap_s(GLenum att) {
if (attachments.find(att) == attachments.end()) { std::cout << "FBO: " << fboID << ": error: attachment " << att << " doesn't exist\n"; return 0; }
return formats[att].wrap_s;
}
GLenum FrameBufferObject::getWrap_s() {return getWrap_s(GL_COLOR_ATTACHMENT0);}
GLenum FrameBufferObject::getWrap_t(GLenum att) {
if (attachments.find(att) == attachments.end()) { std::cout << "FBO: " << fboID << ": error: attachment " << att << " doesn't exist\n"; return 0; }
return formats[att].wrap_t;
}
GLenum FrameBufferObject::getWrap_t() {return getWrap_t(GL_COLOR_ATTACHMENT0);}
void FrameBufferObject::setFormat(GLenum att, GLenum type, GLint internalFormat, GLenum format) {
if (attachments.find(att) == attachments.end()) { std::cout << "FBO: " << fboID << ": error: attachment " << att << " doesn't exist\n"; return; }
formats[att].type = type;
formats[att].internalFormat = internalFormat;
formats[att].format = format;
glBindTexture(GL_TEXTURE_2D, attachments[att]);
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, sizeX, sizeY, 0, format, type, NULL);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, formats[att].minFilter);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, formats[att].magFilter);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, formats[att].wrap_s);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, formats[att].wrap_t);
glBindTexture(GL_TEXTURE_2D, 0);
}
void FrameBufferObject::setFormat(GLenum type, GLint internalFormat, GLenum format) {
for (auto& a : attachments)
if (isNotRenderBuffer(a.second)) {
setFormat(a.second, type, internalFormat, format);
}
}
GLenum FrameBufferObject::getInternalFormat(GLenum att) {
if (attachments.find(att) == attachments.end()) { std::cout << "FBO: " << fboID << ": error: attachment " << att << " doesn't exist\n"; return 0; }
return formats[att].internalFormat;
}
GLenum FrameBufferObject::getInternalFormat() {return getInternalFormat(GL_COLOR_ATTACHMENT0);}
void FrameBufferObject::removeAttachment(GLenum att) {
if (att == GL_DEPTH_ATTACHMENT) glDeleteRenderbuffers(1, &attachments[GL_DEPTH_ATTACHMENT]);
else if (att == GL_STENCIL_ATTACHMENT) glDeleteRenderbuffers(1, &attachments[GL_STENCIL_ATTACHMENT]);
else if (att == GL_DEPTH_STENCIL_ATTACHMENT) glDeleteRenderbuffers(1, &attachments[GL_DEPTH_STENCIL_ATTACHMENT]);
else { glDeleteTextures(1, &attachments[att]); formats.erase(att); }
attachments.erase(att);
}
void FrameBufferObject::dispose() {
for (auto& it : attachments) {
if (isNotRenderBuffer(it.first)) glDeleteTextures(1, &it.second);
}
if(getAttachment(attachments[GL_DEPTH_ATTACHMENT]) != 0) glDeleteRenderbuffers(1, &attachments[GL_DEPTH_ATTACHMENT]);
if(getAttachment(attachments[GL_STENCIL_ATTACHMENT]) != 0) glDeleteRenderbuffers(1, &attachments[GL_STENCIL_ATTACHMENT]);
if(getAttachment(attachments[GL_DEPTH_STENCIL_ATTACHMENT]) != 0) glDeleteRenderbuffers(1, &attachments[GL_DEPTH_STENCIL_ATTACHMENT]);
glDeleteFramebuffers(1, &fboID);
}
void FrameBufferObject::compCheck() {
GLenum check = glCheckFramebufferStatus(GL_FRAMEBUFFER);
switch (check) {
case GL_FRAMEBUFFER_COMPLETE:
break;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
std::cout << "FrameBuffer: " << fboID << ", has caused a GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT exception\n";
glfwTerminate();
break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
std::cout << "FrameBuffer: " << fboID << ", has caused a GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT exception\n";
glfwTerminate();
break;
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
std::cout << "FrameBuffer: " << fboID << ", has caused a GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER exception\n";
break;
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
std::cout << "FrameBuffer: " << fboID << ", has caused a GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER exception\n";
glfwTerminate();
break;
default:
std::cout << "Unexpected reply from glCheckFramebufferStatus: " << check << ".\n";
glfwTerminate();
break;
}
}
FrameBufferObject::FrameBufferObject(){
}
FrameBufferObject::FrameBufferObject(int sizeX, int sizeY) {
this->sizeX = sizeX;
this->sizeY = sizeY;
init();
}
FrameBufferObject::FrameBufferObject(int sizeX, int sizeY, int minFilter, int magFilter) {
this->sizeX = sizeX;
this->sizeY = sizeY;
//this->minFilter = minFilter;
//this->magFilter = magFilter;
init();
}
FrameBufferObject::FrameBufferObject(int sizeX, int sizeY, int minFilter, int magFilter, int internalFormat, int format, int type) {
this->sizeX = sizeX;
this->sizeY = sizeY;
//this->minFilter = minFilter;
//this->magFilter = magFilter;
//this->internalFormat = internalFormat;
//this->format = format;
//this->type = type;
init();
}
//attachments must not contain duplicates
FrameBufferObject::FrameBufferObject(vec2 size, std::vector<GLenum> attachments, FrameBufferObject::ColorAttachment format) {
this->sizeX = (int)size.x;
this->sizeY = (int)size.y;
glGenFramebuffers(1, &fboID);
for (GLuint a : attachments) {
//if (a == GL_DEPTH_ATTACHMENT) {
// std::cout << "adding depth\n";
// glBindFramebuffer(GL_FRAMEBUFFER, fboID);
//
// glGenRenderbuffers(1, &depID);
// glBindRenderbuffer(GL_RENDERBUFFER, depID);
// glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, sizeX, sizeY);
// glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depID);
// compCheck();
// glBindFramebuffer(GL_FRAMEBUFFER, 0);
// //addAttachment(a);
//}
//else addAttachment(a);
addAttachment(a, format);
}
}
FrameBufferObject::FrameBufferObject(vec2 size, std::vector<GLenum> attachments) :
FrameBufferObject(size, attachments, FrameBufferObject::ColorAttachment{ GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR,GL_LINEAR, GL_REPEAT, GL_REPEAT }) {}
FrameBufferObject::~FrameBufferObject(){
//dispose();
}
| 35.979358 | 165 | 0.730159 | AlessandroParrotta |
2c493b1afc411ba07e17453bb470fa3dde154b8e | 4,441 | cpp | C++ | projects/PathosEngine/src/pathos/render/postprocessing/anti_aliasing_fxaa.cpp | codeonwort/pathosengine | ea568afeac9af3ebe3f2e53cc5abeecb40714466 | [
"MIT"
] | 11 | 2016-08-30T12:01:35.000Z | 2021-12-29T15:34:03.000Z | projects/PathosEngine/src/pathos/render/postprocessing/anti_aliasing_fxaa.cpp | codeonwort/pathosengine | ea568afeac9af3ebe3f2e53cc5abeecb40714466 | [
"MIT"
] | 9 | 2016-05-19T03:14:22.000Z | 2021-01-17T05:45:52.000Z | projects/PathosEngine/src/pathos/render/postprocessing/anti_aliasing_fxaa.cpp | codeonwort/pathosengine | ea568afeac9af3ebe3f2e53cc5abeecb40714466 | [
"MIT"
] | null | null | null | #include "anti_aliasing_fxaa.h"
#include "pathos/shader/shader.h"
#include "pathos/render/render_device.h"
#include "pathos/render/scene_render_targets.h"
namespace pathos {
void FXAA::initializeResources(RenderCommandList& cmdList)
{
std::string vshader = R"(
#version 430 core
layout (location = 0) in vec3 position;
out vec2 uv;
void main() {
const vec2[4] uvs = vec2[4](vec2(0,0), vec2(1,0), vec2(0,1), vec2(1,1));
uv = uvs[gl_VertexID];
gl_Position = vec4(position, 1.0);
}
)";
Shader vs(GL_VERTEX_SHADER, "VS_FXAA");
Shader fs(GL_FRAGMENT_SHADER, "FS_FXAA");
vs.setSource(vshader);
fs.addDefine("FXAA_PC 1");
fs.addDefine("FXAA_GLSL_130 1");
fs.addDefine("FXAA_GREEN_AS_LUMA 1");
fs.addDefine("FXAA_QUALITY__PRESET 23");
fs.loadSource("fxaa_fs.glsl");
program = pathos::createProgram(vs, fs, "FXAA");
#define GET_UNIFORM(uniform) { uniform = gRenderDevice->getUniformLocation(program, #uniform); }
GET_UNIFORM(fxaaQualityRcpFrame );
GET_UNIFORM(fxaaConsoleRcpFrameOpt );
GET_UNIFORM(fxaaConsoleRcpFrameOpt2 );
GET_UNIFORM(fxaaConsole360RcpFrameOpt2 );
GET_UNIFORM(fxaaQualitySubpix );
GET_UNIFORM(fxaaQualityEdgeThreshold );
GET_UNIFORM(fxaaQualityEdgeThresholdMin);
GET_UNIFORM(fxaaConsoleEdgeSharpness );
GET_UNIFORM(fxaaConsoleEdgeThreshold );
GET_UNIFORM(fxaaConsoleEdgeThresholdMin);
GET_UNIFORM(fxaaConsole360ConstDir );
#undef GET_UNIFORM
//////////////////////////////////////////////////////////////////////////
gRenderDevice->createFramebuffers(1, &fbo);
cmdList.namedFramebufferDrawBuffer(fbo, GL_COLOR_ATTACHMENT0);
cmdList.objectLabel(GL_FRAMEBUFFER, fbo, -1, "FBO_FXAA");
//checkFramebufferStatus(cmdList, fbo); // #todo-framebuffer: Can't check completeness now
}
void FXAA::releaseResources(RenderCommandList& cmdList)
{
gRenderDevice->deleteProgram(program);
gRenderDevice->deleteFramebuffers(1, &fbo);
markDestroyed();
}
void FXAA::renderPostProcess(RenderCommandList& cmdList, PlaneGeometry* fullscreenQuad)
{
SCOPED_DRAW_EVENT(FXAA);
const GLuint input0 = getInput(EPostProcessInput::PPI_0); // toneMappingResult
const GLuint output0 = getOutput(EPostProcessOutput::PPO_0); // sceneFinal or backbuffer
SceneRenderTargets& sceneContext = *cmdList.sceneRenderTargets;
// #note-fxaa: See the FXAA pixel shader for details
float sharpness = 0.5f;
float subpix = 0.75f;
float edge_threshold = 0.166f;
float edge_threshold_min = 0.0f; // 0.0833f;
float console_edge_sharpness = 8.0f;
float console_edge_threshold = 0.125f;
float console_edge_threshold_min = 0.05f;
glm::vec2 inv_size(1.0f / (float)sceneContext.sceneWidth, 1.0f / (float)sceneContext.sceneHeight);
glm::vec4 inv_size_4(-inv_size.x, -inv_size.y, inv_size.x, inv_size.y);
glm::vec4 sharp_param = sharpness * inv_size_4;
glm::vec4 sharp2_param = 2.0f * inv_size_4;
glm::vec4 sharp3_param = glm::vec4(8.0f, 8.0f, -4.0f, -4.0f) * inv_size_4;
cmdList.useProgram(program);
cmdList.uniform2f(fxaaQualityRcpFrame , inv_size.x, inv_size.y);
cmdList.uniform4f(fxaaConsoleRcpFrameOpt , sharp_param.x, sharp_param.y, sharp_param.z, sharp_param.w);
cmdList.uniform4f(fxaaConsoleRcpFrameOpt2 , sharp2_param.x, sharp2_param.y, sharp2_param.z, sharp2_param.w);
cmdList.uniform4f(fxaaConsole360RcpFrameOpt2 , sharp3_param.x, sharp3_param.y, sharp3_param.z, sharp3_param.w);
cmdList.uniform1f(fxaaQualitySubpix , subpix);
cmdList.uniform1f(fxaaQualityEdgeThreshold , edge_threshold);
cmdList.uniform1f(fxaaQualityEdgeThresholdMin, edge_threshold_min);
cmdList.uniform1f(fxaaConsoleEdgeSharpness , console_edge_sharpness);
cmdList.uniform1f(fxaaConsoleEdgeThreshold , console_edge_threshold);
cmdList.uniform1f(fxaaConsoleEdgeThresholdMin, console_edge_threshold_min);
cmdList.uniform4f(fxaaConsole360ConstDir , 1.0f, -1.0f, 0.25f, -0.25f);
if (output0 == 0) {
cmdList.bindFramebuffer(GL_FRAMEBUFFER, 0);
} else {
cmdList.bindFramebuffer(GL_FRAMEBUFFER, fbo);
cmdList.namedFramebufferTexture(fbo, GL_COLOR_ATTACHMENT0, output0, 0);
}
cmdList.textureParameteri(input0, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
cmdList.textureParameteri(input0, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
cmdList.bindTextureUnit(0, input0);
fullscreenQuad->activate_position_uv(cmdList);
fullscreenQuad->activateIndexBuffer(cmdList);
fullscreenQuad->drawPrimitive(cmdList);
}
}
| 36.105691 | 113 | 0.747579 | codeonwort |
2c4df4e10509d9bc13f215281642d935ff5f472f | 145 | cpp | C++ | Windows-Socket-C++/Projects/TCP-Socket/Thread.cpp | khanh245/Windows-Socket | 443f145aa94125d0ac5d5f8efce56c2a61508906 | [
"MIT"
] | 1 | 2017-04-27T13:45:16.000Z | 2017-04-27T13:45:16.000Z | Windows-Socket-C++/Projects/TCP-Socket/Thread.cpp | khanh245/Windows-Socket | 443f145aa94125d0ac5d5f8efce56c2a61508906 | [
"MIT"
] | 1 | 2017-08-08T14:26:32.000Z | 2017-08-10T09:19:32.000Z | Windows-Socket-C++/Projects/TCP-Socket/Thread.cpp | khanh245/Windows-Socket | 443f145aa94125d0ac5d5f8efce56c2a61508906 | [
"MIT"
] | null | null | null | #include "Thread.h"
Kronos::Thread::Thread()
{
}
Kronos::Thread::Thread(Kronos::IRunnable* runnableObj)
{
}
Kronos::Thread::~Thread()
{
}
| 8.055556 | 54 | 0.648276 | khanh245 |
2c51287740901c6901e09416029cc3b55ea170f9 | 1,413 | cpp | C++ | cpp/atcoder/DPL_1_B.cpp | KeiichiHirobe/algorithms | 8de082dab33054f3e433330a2cf5d06bd770bd04 | [
"Apache-2.0"
] | null | null | null | cpp/atcoder/DPL_1_B.cpp | KeiichiHirobe/algorithms | 8de082dab33054f3e433330a2cf5d06bd770bd04 | [
"Apache-2.0"
] | null | null | null | cpp/atcoder/DPL_1_B.cpp | KeiichiHirobe/algorithms | 8de082dab33054f3e433330a2cf5d06bd770bd04 | [
"Apache-2.0"
] | null | null | null | #include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <queue>
#include <iomanip>
// clang-format off
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define SZ(x) ((int)(x).size())
using ll = long long;
// 2^60
const ll INF = 1LL << 60;
// lower_bound(ALL(a), 4)
#define ALL(a) (a).begin(),(a).end()
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
// clang-format on
int main()
{
cout << fixed << setprecision(16);
int N;
int W;
cin >> N;
cin >> W;
vector<int> v(N);
vector<int> w(N);
rep(i, N)
{
cin >> v[i] >> w[i];
}
vector<vector<long long>> vmax(W + 1, vector<long long>(N + 1, 0));
for (int i = 1; i < W + 1; ++i)
{
for (int j = 1; j < N + 1; ++j)
{
chmax(vmax[i][j], vmax[i][j - 1]);
if (i - w[j - 1] >= 0)
{
chmax(vmax[i][j], vmax[i - w[j - 1]][j - 1] + v[j - 1]);
}
}
}
/*
rep(i, W + 1)
{
rep(j, N + 1)
{
cout << vmax[i][j] << ",";
}
cout << endl;
}
*/
cout << vmax[W][N] << endl;
} | 21.738462 | 87 | 0.457183 | KeiichiHirobe |
2c5cbc4506d717f3d1f7307983521593c7f1e88c | 308 | cpp | C++ | Poker/Classes/GameState.cpp | zivlhoo/Poker | f0525b7c5119256c70b2e76b7c09d8729dcd5f76 | [
"Apache-2.0"
] | null | null | null | Poker/Classes/GameState.cpp | zivlhoo/Poker | f0525b7c5119256c70b2e76b7c09d8729dcd5f76 | [
"Apache-2.0"
] | null | null | null | Poker/Classes/GameState.cpp | zivlhoo/Poker | f0525b7c5119256c70b2e76b7c09d8729dcd5f76 | [
"Apache-2.0"
] | null | null | null | //
// GameState.cpp
// Poker
//
// Created by ZivHoo on 15/6/27.
//
//
#include "GameState.h"
static GameState* instance = nullptr;
GameState::GameState()
{
}
GameState::~GameState()
{
}
GameState* GameState::getInstance()
{
if( !instance ) instance = new GameState();
return instance;
} | 11.846154 | 47 | 0.633117 | zivlhoo |
2c5df87d48a229dbef6e8a08344c80b0b87671c4 | 2,707 | hpp | C++ | examples/vector-io.hpp | yangxianpku/cuarma | 404f20b5b3fa74e5e27338e89343450f8853024c | [
"X11",
"MIT"
] | null | null | null | examples/vector-io.hpp | yangxianpku/cuarma | 404f20b5b3fa74e5e27338e89343450f8853024c | [
"X11",
"MIT"
] | null | null | null | examples/vector-io.hpp | yangxianpku/cuarma | 404f20b5b3fa74e5e27338e89343450f8853024c | [
"X11",
"MIT"
] | null | null | null | #pragma once
/* =========================================================================
Copyright (c) 2015-2017, COE of Peking University, Shaoqiang Tang.
-----------------
cuarma - COE of Peking University, Shaoqiang Tang.
-----------------
Author Email [email protected]
Code Repo https://github.com/yangxianpku/cuarma
License: MIT (X11) License
============================================================================= */
/** @file vector-io.hpp
* @coding UTF-8
* @brief Vector,Matrix IO
* @brief 测试:向量、矩阵 IO测试
*/
#include <string>
#include <iostream>
#include <fstream>
#include "cuarma/tools/tools.hpp"
#include "cuarma/meta/result_of.hpp"
#include "cuarma/traits/size.hpp"
template<typename MatrixType, typename ScalarType>
void insert(MatrixType & matrix, long row, long col, ScalarType value)
{
matrix(row, col) = value;
}
template<typename MatrixType>
class my_inserter
{
public:
my_inserter(MatrixType & mat) : mat_(mat) {}
void apply(long row, long col, double value)
{
insert(mat_, row, col, value);
}
private:
MatrixType & mat_;
};
template<typename VectorType>
void resize_vector(VectorType & vec, unsigned int size)
{
vec.resize(size);
}
template<typename VectorType>
bool readVectorFromFile(const std::string & filename, VectorType & vec)
{
typedef typename cuarma::result_of::value_type<VectorType>::type ScalarType;
std::ifstream file(filename.c_str());
if (!file) return false;
unsigned int size;
file >> size;
resize_vector(vec, size);
for (unsigned int i = 0; i < size; ++i)
{
ScalarType element;
file >> element;
vec[i] = element;
}
return true;
}
template<class MatrixType>
bool readMatrixFromFile(const std::string & filename, MatrixType & matrix)
{
typedef typename cuarma::result_of::value_type<MatrixType>::type ScalarType;
std::cout << "Reading matrix..." << std::endl;
std::ifstream file(filename.c_str());
if (!file) return false;
std::string id;
file >> id;
if (id != "Matrix") return false;
unsigned int num_rows, num_columns;
file >> num_rows >> num_columns;
if (num_rows != num_columns) return false;
cuarma::traits::resize(matrix, num_rows, num_rows);
my_inserter<MatrixType> ins(matrix);
for (unsigned int row = 0; row < num_rows; ++row)
{
int num_entries;
file >> num_entries;
for (int j = 0; j < num_entries; ++j)
{
unsigned int column;
ScalarType element;
file >> column >> element;
ins.apply(row, column, element);
}
}
return true;
} | 22.188525 | 81 | 0.595863 | yangxianpku |
2c6034f85cfba4de83792b04d8f79b0d932271b0 | 658 | hpp | C++ | tlab/include/tlab/threading_model.hpp | gwonhyeong/tlab | f84963f2636fdb830ab300b92ec1d8395ce2da58 | [
"MIT"
] | null | null | null | tlab/include/tlab/threading_model.hpp | gwonhyeong/tlab | f84963f2636fdb830ab300b92ec1d8395ce2da58 | [
"MIT"
] | null | null | null | tlab/include/tlab/threading_model.hpp | gwonhyeong/tlab | f84963f2636fdb830ab300b92ec1d8395ce2da58 | [
"MIT"
] | null | null | null | /**
* @file threading_mode.hpp
* @author ghtak ([email protected])
* @brief
* @version 0.1
* @date 2019-07-29
*
* @copyright Copyright (c) 2019
*
*/
#ifndef __tlab_threading_model_h__
#define __tlab_threading_model_h__
#include <mutex>
namespace tlab{
namespace internal {
class no_lock{
public:
void lock(void){}
void unlock(void){}
bool try_lock(void){return true;}
};
} // namespace internal
struct single_threading_model{
using lock_type = internal::no_lock;
};
struct multi_threading_model{
using lock_type = std::mutex;
};
} // namespace tlab
#endif | 17.315789 | 44 | 0.636778 | gwonhyeong |
2c64ec6635d67cb39e81767676dc80ed898a03d8 | 929 | cc | C++ | lib/asan/lit_tests/stack-overflow.cc | SaleJumper/android-source-browsing.platform--external--compiler-rt | 1f922a5259510f70a12576e7a61eaa0033a02b16 | [
"MIT"
] | 1 | 2015-02-04T20:57:19.000Z | 2015-02-04T20:57:19.000Z | src/llvm/projects/compiler-rt/lib/asan/lit_tests/stack-overflow.cc | jeltz/rust-debian-package | 07eaa3658867408248c555b1b3a593c012b4f931 | [
"ECL-2.0",
"Apache-2.0",
"MIT-0",
"MIT"
] | null | null | null | src/llvm/projects/compiler-rt/lib/asan/lit_tests/stack-overflow.cc | jeltz/rust-debian-package | 07eaa3658867408248c555b1b3a593c012b4f931 | [
"ECL-2.0",
"Apache-2.0",
"MIT-0",
"MIT"
] | 1 | 2021-05-26T06:41:58.000Z | 2021-05-26T06:41:58.000Z | // RUN: %clangxx_asan -m64 -O0 %s -o %t && %t 2>&1 | %symbolize | FileCheck %s
// RUN: %clangxx_asan -m64 -O1 %s -o %t && %t 2>&1 | %symbolize | FileCheck %s
// RUN: %clangxx_asan -m64 -O2 %s -o %t && %t 2>&1 | %symbolize | FileCheck %s
// RUN: %clangxx_asan -m64 -O3 %s -o %t && %t 2>&1 | %symbolize | FileCheck %s
// RUN: %clangxx_asan -m32 -O0 %s -o %t && %t 2>&1 | %symbolize | FileCheck %s
// RUN: %clangxx_asan -m32 -O1 %s -o %t && %t 2>&1 | %symbolize | FileCheck %s
// RUN: %clangxx_asan -m32 -O2 %s -o %t && %t 2>&1 | %symbolize | FileCheck %s
// RUN: %clangxx_asan -m32 -O3 %s -o %t && %t 2>&1 | %symbolize | FileCheck %s
#include <string.h>
int main(int argc, char **argv) {
char x[10];
memset(x, 0, 10);
int res = x[argc * 10]; // BOOOM
// CHECK: {{READ of size 1 at 0x.* thread T0}}
// CHECK: {{ #0 0x.* in main .*stack-overflow.cc:14}}
// CHECK: {{Address 0x.* is .* frame <main>}}
return res;
}
| 46.45 | 78 | 0.564047 | SaleJumper |
2c655d8b404ce1a8a699ae4e320b9ae1a58f2661 | 4,757 | hh | C++ | nox/src/include/port-stats-in.hh | ayjazz/OESS | deadc504d287febc7cbd7251ddb102bb5c8b1f04 | [
"Apache-2.0"
] | 28 | 2015-02-04T13:59:25.000Z | 2021-12-29T03:44:47.000Z | nox/src/include/port-stats-in.hh | ayjazz/OESS | deadc504d287febc7cbd7251ddb102bb5c8b1f04 | [
"Apache-2.0"
] | 552 | 2015-01-05T18:25:54.000Z | 2022-03-16T18:51:13.000Z | nox/src/include/port-stats-in.hh | ayjazz/OESS | deadc504d287febc7cbd7251ddb102bb5c8b1f04 | [
"Apache-2.0"
] | 25 | 2015-02-04T18:48:20.000Z | 2020-06-18T15:51:05.000Z | /* Copyright 2008 (C) Nicira, Inc.
*
* This file is part of NOX.
*
* NOX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NOX 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 NOX. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PORT_STATS_IN_HH__
#define PORT_STATS_IN_HH__
#include <string>
#include "event.hh"
#include "netinet++/datapathid.hh"
#include "ofp-msg-event.hh"
#include "openflow/openflow.h"
namespace vigil {
struct Port_stats
{
Port_stats(uint16_t pn) :
port_no(pn),
rx_packets(0), tx_packets(0), rx_bytes(0), tx_bytes(0),
rx_dropped(0), tx_dropped(0), rx_errors(0), tx_errors(0),
rx_frame_err(0), rx_over_err(0), rx_crc_err(0), collisions(0) { ; }
Port_stats(const Port_stats& ps) :
port_no(ps.port_no),
rx_packets(ps.rx_packets),
tx_packets(ps.tx_packets),
rx_bytes(ps.rx_bytes),
tx_bytes(ps.tx_bytes),
rx_dropped(ps.rx_dropped),
tx_dropped(ps.tx_dropped),
rx_errors(ps.rx_errors),
tx_errors(ps.tx_errors),
rx_frame_err(ps.rx_frame_err),
rx_over_err(ps.rx_over_err),
rx_crc_err(ps.rx_crc_err),
collisions(ps.collisions) { ; }
Port_stats(struct ofp_port_stats *ops) :
port_no(ntohs(ops->port_no)),
rx_packets(ntohll(ops->rx_packets)),
tx_packets(ntohll(ops->tx_packets)),
rx_bytes(ntohll(ops->rx_bytes)),
tx_bytes(ntohll(ops->tx_bytes)),
rx_dropped(ntohll(ops->rx_dropped)),
tx_dropped(ntohll(ops->tx_dropped)),
rx_errors(ntohll(ops->rx_errors)),
tx_errors(ntohll(ops->tx_errors)),
rx_frame_err(ntohll(ops->rx_frame_err)),
rx_over_err(ntohll(ops->rx_over_err)),
rx_crc_err(ntohll(ops->rx_crc_err)),
collisions(ntohll(ops->collisions)) { ; }
uint16_t port_no;
uint64_t rx_packets;
uint64_t tx_packets;
uint64_t rx_bytes;
uint64_t tx_bytes;
uint64_t rx_dropped;
uint64_t tx_dropped;
uint64_t rx_errors;
uint64_t tx_errors;
uint64_t rx_frame_err;
uint64_t rx_over_err;
uint64_t rx_crc_err;
uint64_t collisions;
Port_stats& operator=(const Port_stats& ps)
{
port_no = ps.port_no;
rx_packets = ps.rx_packets;
tx_packets = ps.tx_packets;
rx_bytes = ps.rx_bytes;
tx_bytes = ps.tx_bytes;
rx_dropped = ps.rx_dropped;
tx_dropped = ps.tx_dropped;
rx_errors = ps.rx_errors;
tx_errors = ps.tx_errors;
rx_frame_err = ps.rx_frame_err;
rx_over_err = ps.rx_over_err;
rx_crc_err = ps.rx_crc_err;
collisions = ps.collisions;
return *this;
}
};
/** \ingroup noxevents
*
* Port_stats events are thrown for each port stats message received
* from the switches. Port stats messages are sent in response to
* OpenFlow port stats requests.
*
* Each messages contains the statistics for all ports on a switch.
* The available values are contained in the Port_stats struct.
*
*/
struct Port_stats_in_event
: public Event,
public Ofp_msg_event
{
Port_stats_in_event(const datapathid& dpid, const ofp_stats_reply *osr,
std::auto_ptr<Buffer> buf);
// -- only for use within python
Port_stats_in_event() : Event(static_get_name()) { }
static const Event_name static_get_name() {
return "Port_stats_in_event";
}
//! ID of switch sending the port stats message
datapathid datapath_id;
//! List of port statistics
std::vector<Port_stats> ports;
Port_stats_in_event(const Port_stats_in_event&);
Port_stats_in_event& operator=(const Port_stats_in_event&);
void add_port(uint16_t pn);
void add_port(struct ofp_port_stats *ops);
}; // Port_stats_in_event
inline
Port_stats_in_event::Port_stats_in_event(const datapathid& dpid,
const ofp_stats_reply *osr,
std::auto_ptr<Buffer> buf)
: Event(static_get_name()), Ofp_msg_event(&osr->header, buf)
{
datapath_id = dpid;
}
inline
void
Port_stats_in_event::add_port(uint16_t pn)
{
ports.push_back(Port_stats(pn));
}
inline
void
Port_stats_in_event::add_port(struct ofp_port_stats *ops)
{
ports.push_back(Port_stats(ops));
}
} // namespace vigil
#endif // PORT_STATS_IN_HH__
| 27.982353 | 75 | 0.678159 | ayjazz |
2c67cba99306424bfbc2015ff0c3d863ff86f4da | 1,631 | hh | C++ | cc/virus/name.hh | skepner/ae | d53336a561df1a46a39debb143c9f9496b222a46 | [
"MIT"
] | null | null | null | cc/virus/name.hh | skepner/ae | d53336a561df1a46a39debb143c9f9496b222a46 | [
"MIT"
] | null | null | null | cc/virus/name.hh | skepner/ae | d53336a561df1a46a39debb143c9f9496b222a46 | [
"MIT"
] | null | null | null | #pragma once
#include "ext/fmt.hh"
#include "ext/compare.hh"
#include "utils/string.hh"
// ----------------------------------------------------------------------
namespace ae::virus::inline v2
{
class Name
{
public:
Name() = default;
Name(const Name&) = default;
Name(Name&&) = default;
explicit Name(std::string_view src) : value_{string::uppercase(src)} {}
Name& operator=(const Name&) = default;
Name& operator=(Name&&) = default;
operator std::string_view() const { return value_; }
std::string_view operator*() const { return value_; }
// bool operator==(const Name& rhs) const = default;
auto operator<=>(const Name& rhs) const = default;
bool empty() const { return value_.empty(); }
size_t size() const { return value_.size(); }
auto operator[](size_t pos) const { return value_[pos]; }
template <typename S> auto find(S look_for) const { return value_.find(look_for); }
auto substr(size_t pos, size_t len) const { return value_.substr(pos, len); }
private:
std::string value_{};
};
} // namespace acmacs::virus::inline v2
// ----------------------------------------------------------------------
template <> struct fmt::formatter<ae::virus::Name> : public fmt::formatter<std::string_view>
{
template <typename FormatContext> auto format(const ae::virus::Name& ts, FormatContext& ctx) { return fmt::formatter<std::string_view>::format(static_cast<std::string_view>(ts), ctx); }
};
// ----------------------------------------------------------------------
| 33.979167 | 189 | 0.543225 | skepner |
2c69920a4a1a923c7063902112d73590db5567b5 | 5,819 | hpp | C++ | sdk/storage/inc/datalake/directory_client.hpp | CaseyCarter/azure-sdk-for-cpp | b9212922e7184e4b03756f0f6f586aec00997744 | [
"MIT"
] | null | null | null | sdk/storage/inc/datalake/directory_client.hpp | CaseyCarter/azure-sdk-for-cpp | b9212922e7184e4b03756f0f6f586aec00997744 | [
"MIT"
] | 1 | 2021-02-23T00:43:57.000Z | 2021-02-23T00:49:17.000Z | sdk/storage/inc/datalake/directory_client.hpp | CaseyCarter/azure-sdk-for-cpp | b9212922e7184e4b03756f0f6f586aec00997744 | [
"MIT"
] | null | null | null | // Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#pragma once
#include "common/storage_credential.hpp"
#include "common/storage_uri_builder.hpp"
#include "credentials/credentials.hpp"
#include "datalake/path_client.hpp"
#include "datalake_options.hpp"
#include "datalake_responses.hpp"
#include "http/pipeline.hpp"
#include "protocol/datalake_rest_client.hpp"
#include "response.hpp"
#include <memory>
#include <string>
namespace Azure { namespace Storage { namespace Files { namespace DataLake {
class DirectoryClient : public PathClient {
public:
/**
* @brief Create from connection string
* @param connectionString Azure Storage connection string.
* @param fileSystemName The name of a file system.
* @param directoryPath The path of a directory within the file system.
* @param options Optional parameters used to initialize the client.
* @return DirectoryClient
*/
static DirectoryClient CreateFromConnectionString(
const std::string& connectionString,
const std::string& fileSystemName,
const std::string& directoryPath,
const DirectoryClientOptions& options = DirectoryClientOptions());
/**
* @brief Shared key authentication client.
* @param directoryUri The URI of the file system this client's request targets.
* @param credential The shared key credential used to initialize the client.
* @param options Optional parameters used to initialize the client.
*/
explicit DirectoryClient(
const std::string& directoryUri,
std::shared_ptr<SharedKeyCredential> credential,
const DirectoryClientOptions& options = DirectoryClientOptions());
/**
* @brief Bearer token authentication client.
* @param directoryUri The URI of the file system this client's request targets.
* @param credential The token credential used to initialize the client.
* @param options Optional parameters used to initialize the client.
*/
explicit DirectoryClient(
const std::string& directoryUri,
std::shared_ptr<Core::Credentials::TokenCredential> credential,
const DirectoryClientOptions& options = DirectoryClientOptions());
/**
* @brief Anonymous/SAS/customized pipeline auth.
* @param directoryUri The URI of the file system this client's request targets.
* @param options Optional parameters used to initialize the client.
*/
explicit DirectoryClient(
const std::string& directoryUri,
const DirectoryClientOptions& options = DirectoryClientOptions());
/**
* @brief Create a FileClient from current DirectoryClient
* @param path Path of the file under the directory.
* @return FileClient
*/
FileClient GetFileClient(const std::string& path) const;
/**
* @brief Gets the directory's primary uri endpoint. This is the endpoint used for blob
* storage available features in DataLake.
*
* @return The directory's primary uri endpoint.
*/
std::string GetUri() const { return m_blobClient.GetUri(); }
/**
* @brief Gets the directory's primary uri endpoint. This is the endpoint used for dfs
* endpoint only operations
*
* @return The directory's primary uri endpoint.
*/
std::string GetDfsUri() const { return m_dfsUri.ToString(); }
/**
* @brief Create a directory. By default, the destination is overwritten and
* if the destination already exists and has a lease the lease is broken.
* @param options Optional parameters to create the directory the path points to.
* @return Azure::Core::Response<DirectoryInfo>
* @remark This request is sent to dfs endpoint.
*/
Azure::Core::Response<DirectoryInfo> Create(
const DirectoryCreateOptions& options = DirectoryCreateOptions()) const
{
return PathClient::Create(PathResourceType::Directory, options);
}
/**
* @brief Renames a directory. By default, the destination is overwritten and
* if the destination already exists and has a lease the lease is broken.
* @param destinationDirectoryPath The destinationPath this current directory is renaming to.
* @param options Optional parameters to rename a resource to the resource the destination
* directory points to.
* @return Azure::Core::Response<DirectoryRenameInfo>
* @remark This operation will not change the URL this directory client points too, to use the
* new name, customer needs to initialize a new directory client with the new name/path.
* @remark This request is sent to dfs endpoint.
*/
Azure::Core::Response<DirectoryRenameInfo> Rename(
const std::string& destinationDirectoryPath,
const DirectoryRenameOptions& options = DirectoryRenameOptions()) const;
/**
* @brief Deletes the directory.
* @param Recursive If "true", all paths beneath the directory will be deleted. If "false" and
* the directory is non-empty, an error occurs.
* @param options Optional parameters to delete the directory the path points to.
* @return Azure::Core::Response<DirectoryDeleteResponse>
* @remark This request is sent to dfs endpoint.
*/
Azure::Core::Response<DirectoryDeleteInfo> Delete(
bool Recursive,
const DirectoryDeleteOptions& options = DirectoryDeleteOptions()) const;
private:
explicit DirectoryClient(
UriBuilder dfsUri,
Blobs::BlobClient blobClient,
std::shared_ptr<Azure::Core::Http::HttpPipeline> pipeline)
: PathClient(std::move(dfsUri), std::move(blobClient), pipeline)
{
}
friend class FileSystemClient;
};
}}}} // namespace Azure::Storage::Files::DataLake
| 40.978873 | 100 | 0.701151 | CaseyCarter |
ef1b35f95afb4e08cd5cd564be8b762e6aadb2f9 | 599 | cpp | C++ | MinecraftSpeedrunHelper/Memory/HookManager.cpp | FFace32/MinecraftSpeedrunHelper | 1ebf57fbb2c1f0e48d9f67fc10bbbae1db9a7b69 | [
"MIT"
] | 1 | 2020-08-10T13:21:54.000Z | 2020-08-10T13:21:54.000Z | MinecraftSpeedrunHelper/Memory/HookManager.cpp | FFace32/MinecraftSpeedrunHelper | 1ebf57fbb2c1f0e48d9f67fc10bbbae1db9a7b69 | [
"MIT"
] | null | null | null | MinecraftSpeedrunHelper/Memory/HookManager.cpp | FFace32/MinecraftSpeedrunHelper | 1ebf57fbb2c1f0e48d9f67fc10bbbae1db9a7b69 | [
"MIT"
] | null | null | null | #include "HookManager.h"
#include "DetourHook.h"
#include <thread>
using namespace Memory;
HookManager::HookManager()
{
InitMinHook();
}
Hook* HookManager::RegisterHook( Hook* Hook )
{
return m_Hooks.emplace_back( Hook );
}
void HookManager::Unhook()
{
if ( m_Hooks.empty() )
return UninitMinHook();
for ( const auto& Hook : m_Hooks )
Hook->Unhook();
std::this_thread::sleep_for( std::chrono::milliseconds( 500 ) ); // Hopefully 500ms are enough for all the hooked functions to leave the stack
for ( const auto& Hook : m_Hooks )
delete Hook;
m_Hooks.clear();
UninitMinHook();
} | 18.71875 | 143 | 0.702838 | FFace32 |
ef1daf2e4801b4f51b7344e007e9c39ab8101209 | 2,719 | hpp | C++ | include/algorithms/algorithm.hpp | Felix-Droop/static_task_scheduling | 084b7d53caeff9ac3593aa7e3d2c5206afd234d0 | [
"MIT"
] | null | null | null | include/algorithms/algorithm.hpp | Felix-Droop/static_task_scheduling | 084b7d53caeff9ac3593aa7e3d2c5206afd234d0 | [
"MIT"
] | null | null | null | include/algorithms/algorithm.hpp | Felix-Droop/static_task_scheduling | 084b7d53caeff9ac3593aa7e3d2c5206afd234d0 | [
"MIT"
] | null | null | null | #pragma once
#include <array>
#include <cctype>
#include <functional>
#include <optional>
#include <ranges>
#include <string>
#include <algorithms/cpop.hpp>
#include <algorithms/dbca.hpp>
#include <algorithms/heft.hpp>
#include <algorithms/rbca.hpp>
#include <algorithms/tdca.hpp>
#include <cluster/cluster.hpp>
#include <io/command_line_arguments.hpp>
#include <schedule/schedule.hpp>
#include <workflow/workflow.hpp>
namespace algorithms {
enum class algorithm {
HEFT, CPOP, RBCA, DBCA, TDCA
};
std::array<algorithm, 5> constexpr ALL = {
algorithm::HEFT,
algorithm::CPOP,
algorithm::RBCA,
algorithm::DBCA,
algorithm::TDCA
};
std::string to_string(algorithm const algo) {
std::string s;
switch (algo) {
case algorithm::HEFT: s = "HEFT";
break;
case algorithm::CPOP: s = "CPOP";
break;
case algorithm::RBCA: s = "RBCA";
break;
case algorithm::DBCA: s = "DBCA";
break;
case algorithm::TDCA: s = "TDCA";
break;
default: throw std::runtime_error("Internal bug: unknown algorithm.");
}
return s;
}
std::optional<algorithm> from_string(std::string const & s) {
auto lower = s | std::views::transform([] (unsigned char const c) {
return std::tolower(c);
});
std::string lower_s(lower.begin(), lower.end());
if (lower_s == "heft") {
return algorithm::HEFT;
} else if (lower_s == "cpop") {
return algorithm::CPOP;
} else if (lower_s == "rbca") {
return algorithm::RBCA;
} else if (lower_s == "dbca") {
return algorithm::DBCA;
} else if (lower_s == "tdca") {
return algorithm::TDCA;
} else if (lower_s == "none") {
return std::nullopt;
}
throw std::runtime_error("The selected algorithm is unknown or contains a typo.");
}
std::function<schedule::schedule()> to_function(
algorithm const algo,
cluster::cluster const & c,
workflow::workflow const & w,
io::command_line_arguments const & args
) {
switch (algo) {
case algorithm::HEFT: return [&] () {
return algorithms::heft(c, w, args);
};
case algorithm::CPOP: return [&] () {
return algorithms::cpop(c, w, args);
};
case algorithm::RBCA: return [&] () {
return algorithms::rbca(c, w, args);
};
case algorithm::DBCA: return [&] () {
return algorithms::dbca(c, w, args);
};
case algorithm::TDCA: return [&] () {
return algorithms::tdca(c, w, args);
};
default:
throw std::runtime_error("Internal bug: unknown algorithm.");
}
}
} // namespace algorithms
| 25.895238 | 86 | 0.589923 | Felix-Droop |
ef1ebb6e3d5ac696e3cf2bb4bb532f6bbb1555be | 45 | cpp | C++ | Ejercicios/Ejercicio39- Modulacion/calculadora.cpp | FabiolaCastillo8/cpp | b81808e0e90090b4e385540c29089dc53859d086 | [
"MIT"
] | null | null | null | Ejercicios/Ejercicio39- Modulacion/calculadora.cpp | FabiolaCastillo8/cpp | b81808e0e90090b4e385540c29089dc53859d086 | [
"MIT"
] | null | null | null | Ejercicios/Ejercicio39- Modulacion/calculadora.cpp | FabiolaCastillo8/cpp | b81808e0e90090b4e385540c29089dc53859d086 | [
"MIT"
] | null | null | null | int sumar(int a, int b)
{
return a +b;
} | 9 | 23 | 0.533333 | FabiolaCastillo8 |
ef237a79fd6740d5bec2ca20494573b6b8eac87a | 3,427 | cpp | C++ | src/input/FileInput.cpp | fgguo/A-heterogeneous-dataflow-system | 421715922ca87b8fd1e680a1a2e5e0c071f1d3ea | [
"BSD-3-Clause"
] | 2 | 2020-05-09T04:17:02.000Z | 2020-05-27T09:05:49.000Z | src/input/FileInput.cpp | fgguo/A-heterogeneous-dataflow-system | 421715922ca87b8fd1e680a1a2e5e0c071f1d3ea | [
"BSD-3-Clause"
] | null | null | null | src/input/FileInput.cpp | fgguo/A-heterogeneous-dataflow-system | 421715922ca87b8fd1e680a1a2e5e0c071f1d3ea | [
"BSD-3-Clause"
] | null | null | null |
#include "../communication/Window.hpp"
#include <unistd.h>
#include <stdlib.h>
#include <ctime>
#include <cstring>
#include "FileInput.hpp"
using namespace std;
FileInput::FileInput(string file, Window* window) :
Input() {
this->fileName = new char[file.length()];
this->window = window;
strcpy(this->fileName, file.c_str());
this->is_open = false;
this->file_size = 0;
this->file_pos = 0;
}
FileInput::~FileInput() {
delete[] fileName;
}
bool FileInput::isOpen() {
return is_open;
}
void FileInput::open() {
//writeBinaryFileIntType(WINDOW_SIZE / sizeof(int));
dataSource.open(fileName, ios::binary | ios::in);
if (dataSource) {
dataSource.seekg(0, ios::end);
file_size = dataSource.tellg();
dataSource.seekg(0, ios::beg);
is_open = true;
cout<<file_size<<endl;
cout<<window->capacity<<endl;
} else {
char cwd[1024];
getcwd(cwd, sizeof(cwd));
cout << "PROBLEM OPENING [" << cwd << "/" << fileName << "]" << endl;
is_open = false;
file_size = 0;
}
file_pos = 0;
}
Window* FileInput::nextWindow() {
if (is_open) {
if (file_pos + window->capacity < file_size) {
dataSource.read(&window->buffer[0], window->capacity);
window->size = window->capacity;
file_pos += window->capacity;
} else {
// dataSource.read(&window->buffer[0], file_size - file_pos);
// dataSource.close();
// window->size = file_size - file_pos;
// file_pos = file_size;
// is_open = false;
dataSource.read(&window->buffer[0], file_size - file_pos);
//dataSource.close();
window->size = file_size - file_pos;
file_pos = file_size;
while((window->size + file_size) < (window->capacity)){
dataSource.seekg(0, ios::beg);
dataSource.read(&window->buffer[file_pos], file_size);
window->size = file_size + window->size;
file_pos=file_pos+file_size;
}
dataSource.close();
is_open = false;
}
}
cout << window->size << " BYTES READ FROM [" << fileName << "]" << endl;
return window;
}
void FileInput::close() {
if (is_open) {
dataSource.close();
is_open = false;
}
}
// Write a binary file with 'numberOfInts' many int values
void FileInput::writeBinaryFileIntType(int numberOfInts) {
ofstream dataSource;
dataSource.open(fileName, ios::binary | ios::out);
if (dataSource) {
srand(time(NULL));
int len = sizeof(int);
for (int i = 0; i < numberOfInts; i++) {
int val = i; //rand();
dataSource.write((char*) &val, len);
//cout << "WRITE VALUE: " << val << endl;
}
cout << numberOfInts * sizeof(int) << " BYTES WRITTEN TO [" << fileName
<< "]" << endl;
} else {
char cwd[1024];
getcwd(cwd, sizeof(cwd));
cout << "PROBLEM WRITING TO [" << cwd << "/" << fileName << "]" << endl;
}
}
// Read a whole binary file into a window (size is adjusted if necessary)
void FileInput::readBinaryFile(Window* window) {
ifstream dataSource;
dataSource.open(fileName, ios::binary | ios::in);
if (dataSource) {
dataSource.seekg(0, ios::end);
int size = dataSource.tellg();
if (size > window->capacity)
window->resize(size);
window->size = size;
dataSource.seekg(0, ios::beg);
dataSource.read(&window->buffer[0], size);
//cout << size << " BYTES READ FROM [" << fileName << "]" << endl;
} else {
char cwd[1024];
getcwd(cwd, sizeof(cwd));
cout << "PROBLEM READING FROM [" << cwd << "/" << fileName << "]"
<< endl;
}
dataSource.close();
}
| 21.41875 | 74 | 0.62562 | fgguo |
ef2e4ffb6e958871ef82b5013eb80768a42d3d07 | 1,472 | cp | C++ | Sources_Common/Tasks/CNewMailTask.cp | mulberry-mail/mulberry4-client | cdaae15c51dd759110b4fbdb2063d0e3d5202103 | [
"ECL-2.0",
"Apache-2.0"
] | 12 | 2015-04-21T16:10:43.000Z | 2021-11-05T13:41:46.000Z | Sources_Common/Tasks/CNewMailTask.cp | mulberry-mail/mulberry4-client | cdaae15c51dd759110b4fbdb2063d0e3d5202103 | [
"ECL-2.0",
"Apache-2.0"
] | 2 | 2015-11-02T13:32:11.000Z | 2019-07-10T21:11:21.000Z | Sources_Common/Tasks/CNewMailTask.cp | mulberry-mail/mulberry4-client | cdaae15c51dd759110b4fbdb2063d0e3d5202103 | [
"ECL-2.0",
"Apache-2.0"
] | 6 | 2015-01-12T08:49:12.000Z | 2021-03-27T09:11:10.000Z | /*
Copyright (c) 2007 Cyrus Daboo. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Source for CNewMailAlertTask class
#include "CNewMailTask.h"
#include "CErrorHandler.h"
#pragma mark ____________________________CNewMailAlertTask
cdmutex CNewMailAlertTask::sOnlyOne;
unsigned long CNewMailAlertTask::sInUse = 0;
void CNewMailAlertTask::Make_NewMailAlertTask(const char* rsrcid, const CMailNotification& notifier)
{
// Protect against multiple access
cdmutex::lock_cdmutex _lock(sOnlyOne);
// Bump in use counter
sInUse++;
// Create new mail task with indication of whether others are pending
CNewMailAlertTask* task = new CNewMailAlertTask(rsrcid, notifier, sInUse > 1);
task->Go();
}
void CNewMailAlertTask::Work()
{
CErrorHandler::PutNoteAlertRsrc(mRsrcId, mNotify, mNoDisplay);
// Protect against multiple access and decrement in use count
cdmutex::lock_cdmutex _lock(sOnlyOne);
sInUse--;
}
| 29.44 | 100 | 0.754755 | mulberry-mail |
ef33fe889e821a38493209168937e223d3ab1434 | 1,656 | cpp | C++ | drv/hd44780/hd44780.example.cpp | yhsb2k/omef | 7425b62dd4b5d0af4e320816293f69d16d39f57a | [
"MIT"
] | null | null | null | drv/hd44780/hd44780.example.cpp | yhsb2k/omef | 7425b62dd4b5d0af4e320816293f69d16d39f57a | [
"MIT"
] | null | null | null | drv/hd44780/hd44780.example.cpp | yhsb2k/omef | 7425b62dd4b5d0af4e320816293f69d16d39f57a | [
"MIT"
] | null | null | null | // Example for STM32F4DISCOVERY development board
#include "gpio/gpio.hpp"
#include "tim/tim.hpp"
#include "systick/systick.hpp"
#include "drv/hd44780/hd44780.hpp"
#include "drv/di/di.hpp"
#include "FreeRTOS.h"
#include "task.h"
using namespace hal;
using namespace drv;
struct di_poll_task_ctx_t
{
di &button_1;
hd44780 &lcd;
};
static void di_poll_task(void *pvParameters)
{
di_poll_task_ctx_t *ctx = (di_poll_task_ctx_t *)pvParameters;
ctx->lcd.init();
ctx->lcd.print(0, "Test");
uint8_t cgram[8][8] =
{
{
0b00011000,
0b00001110,
0b00000110,
0b00000111,
0b00000111,
0b00000110,
0b00001100,
0b00011000
}
};
ctx->lcd.write_cgram(cgram);
ctx->lcd.print(64, char(0)); // goto the line 2 and print custom symbol
ctx->lcd.print(20, "Line 3");
ctx->lcd.print(84, "Line 4");
while(1)
{
bool new_state;
if(ctx->button_1.poll_event(new_state))
{
if(new_state)
{
ctx->lcd.print(0, "Test");
}
}
vTaskDelay(1);
}
}
int main(void)
{
systick::init();
static gpio b1(0, 0, gpio::mode::DI);
static gpio rs(0, 5, gpio::mode::DO);
static gpio rw(0, 4, gpio::mode::DO);
static gpio e(0, 3, gpio::mode::DO);
static gpio db4(0, 6, gpio::mode::DO);
static gpio db5(0, 7, gpio::mode::DO);
static gpio db6(0, 8, gpio::mode::DO);
static gpio db7(0, 10, gpio::mode::DO);
static tim tim6(tim::TIM_6);
static hd44780 lcd(rs, rw, e, db4, db5, db6, db7, tim6);
static di b1_di(b1, 50, 1);
di_poll_task_ctx_t di_poll_task_ctx = {.button_1 = b1_di, .lcd = lcd};
xTaskCreate(di_poll_task, "di_poll", configMINIMAL_STACK_SIZE,
&di_poll_task_ctx, 1, NULL);
vTaskStartScheduler();
} | 19.714286 | 72 | 0.66244 | yhsb2k |
ef346a60f06e4ccbe3095fc09dd3557bea0b78be | 6,762 | hpp | C++ | src/Expression.hpp | tefu/cpsl | 49b9a2fade84c2ce8e4d5ed3001a4bce65b70026 | [
"MIT"
] | null | null | null | src/Expression.hpp | tefu/cpsl | 49b9a2fade84c2ce8e4d5ed3001a4bce65b70026 | [
"MIT"
] | null | null | null | src/Expression.hpp | tefu/cpsl | 49b9a2fade84c2ce8e4d5ed3001a4bce65b70026 | [
"MIT"
] | null | null | null | #ifndef CPSL_EXPRESSION_H
#define CPSL_EXPRESSION_H
#include <string>
#include <vector>
#include <memory>
#include "ProgramNode.hpp"
#include "Type.hpp"
#include "FormalParameter.hpp"
struct Expression : ProgramNode
{
virtual std::string gen_asm()=0;
virtual bool is_constant() const=0;
virtual Type* data_type() const=0;
virtual int result() const;
virtual int flatten_int() const;
virtual void allocate();
virtual void release();
virtual bool can_be_referenced();
virtual std::string get_address();
static const int NULL_REGISTER = -1;
protected:
int result_reg=NULL_REGISTER;
};
struct LogicalOr : Expression
{
LogicalOr(Expression* l, Expression* r) : left(l), right(r) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
Expression* left;
Expression* right;
};
struct LogicalAnd : Expression
{
LogicalAnd(Expression* l, Expression* r) : left(l), right(r) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
Expression* left;
Expression* right;
};
struct Equality : Expression
{
Equality(Expression* l, Expression* r) : left(l), right(r) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
Expression* left;
Expression* right;
};
struct Inequality : Expression
{
Inequality(Expression* l, Expression* r) : left(l), right(r) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
Expression* left;
Expression* right;
};
struct LessThanOrEqual : Expression
{
LessThanOrEqual(Expression* l, Expression* r) : left(l), right(r) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
Expression* left;
Expression* right;
};
struct LessThan : Expression
{
LessThan(Expression* l, Expression* r) : left(l), right(r) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
Expression* left;
Expression* right;
};
struct GreaterThanOrEqual : Expression
{
GreaterThanOrEqual(Expression* l, Expression* r) : left(l), right(r) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
Expression* left;
Expression* right;
};
struct GreaterThan : Expression
{
GreaterThan(Expression* l, Expression* r) : left(l), right(r) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
Expression* left;
Expression* right;
};
struct OperatorPlus : Expression
{
OperatorPlus(Expression* l, Expression* r) : left(l), right(r) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
int flatten_int() const;
Expression* left;
Expression* right;
};
struct OperatorMinus : Expression
{
OperatorMinus(Expression* l, Expression* r) : left(l), right(r) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
int flatten_int() const;
Expression* left;
Expression* right;
};
struct OperatorMult : Expression
{
OperatorMult(Expression* l, Expression* r) : left(l), right(r) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
int flatten_int() const;
Expression* left;
Expression* right;
};
struct OperatorDivide : Expression
{
OperatorDivide(Expression* l, Expression* r) : left(l), right(r) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
int flatten_int() const;
Expression* left;
Expression* right;
};
struct OperatorModulus : Expression
{
OperatorModulus(Expression* l, Expression* r) : left(l), right(r) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
int flatten_int() const;
Expression* left;
Expression* right;
};
struct Negation : Expression
{
Negation(Expression* e) : expr(e) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
int flatten_int() const;
Expression* expr;
};
struct UnaryMinus : Expression
{
UnaryMinus(Expression* e) : expr(e) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
int flatten_int() const;
Expression* expr;
};
struct FunctionCall : Expression
{
FunctionCall(std::vector<FormalParameter*> fparams,
std::vector<Expression*> el,
Type* rt,
std::string jt,
int sov)
: parameters(fparams), exprList(el), return_type(rt), jump_to(jt), size_of_vars(sov) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
std::vector<FormalParameter*> parameters;
std::vector<Expression*> exprList;
Type* return_type;
std::string jump_to;
const int size_of_vars;
};
struct ToChar : Expression
{
ToChar(Expression* e) : expr(e) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
virtual int result() const;
virtual void release();
Expression* expr;
};
struct ToInt : Expression
{
ToInt(Expression* e) : expr(e) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
virtual int result() const;
virtual void release();
Expression* expr;
};
struct Predecessor : Expression
{
Predecessor(Expression* e) : expr(e) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
Expression* expr;
};
struct Successor : Expression
{
Successor(Expression* e) : expr(e) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
Expression* expr;
};
struct StringLiteral : Expression
{
StringLiteral(std::string* l) : literal(l) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
std::string* literal;
};
struct CharLiteral : Expression
{
CharLiteral(std::string* c) : literal(c) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
std::string* literal;
};
struct IntLiteral : Expression
{
IntLiteral(int l) : literal(l) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
int flatten_int() const;
int literal;
};
struct BoolLiteral : Expression
{
BoolLiteral(bool l) : literal(l) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
bool literal;
};
struct LoadExpression : Expression
{
LoadExpression(Type* t, Expression* a) : datatype(t), address(a) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
bool can_be_referenced();
std::string get_address();
Expression* address;
private:
Type* datatype;
};
struct Address : Expression
{
Address(Expression* o, int sr) : offset(o), starting_register(sr) {}
std::string gen_asm();
bool is_constant() const;
Type* data_type() const;
Expression* offset;
int starting_register;
};
#endif //CPSL_EXPRESSION_H
| 22.316832 | 91 | 0.684265 | tefu |
ef3b76535518b23423a5999d0ef174c92dd5d56e | 15,984 | cpp | C++ | AkameCore/Source Files/Rendering/Model.cpp | SudharsanZen/Akame | 376efe3929e4426e6dc01440ab9f6aa3e8dcb2bf | [
"Apache-2.0"
] | 2 | 2022-03-30T20:58:58.000Z | 2022-03-31T02:06:17.000Z | AkameCore/Source Files/Rendering/Model.cpp | SudharsanZen/Akame | 376efe3929e4426e6dc01440ab9f6aa3e8dcb2bf | [
"Apache-2.0"
] | null | null | null | AkameCore/Source Files/Rendering/Model.cpp | SudharsanZen/Akame | 376efe3929e4426e6dc01440ab9f6aa3e8dcb2bf | [
"Apache-2.0"
] | null | null | null | #include "Rendering/Model.h"
#include<iostream>
#include"misc/temp.h"
#include"Core/Log/Log.h"
#include"Components/Animation/SkeletalMesh.h"
#include"Animation/AnimationControllerSystem.h"
#include"Core/Scene.h"
#pragma warning(push, 0)
#pragma warning( disable : 26812)
#pragma warning( disable : 26495)
#include<assimp/version.h>
#include<assimp/Importer.hpp>
#include<assimp/scene.h>
#include<assimp/postprocess.h>
#include<glad/glad.h>
#include<GLFW/glfw3.h>
#pragma warning(pop)
void set_material(Material &mat,aiMesh *mesh,const aiScene *mAiScene,std::string mDir)
{
if (mesh->mMaterialIndex >= 0)
{
aiString diff, rough, norm, metallic, ao;
int difC = 0, roughC = 0, normC = 0, metalC = 0, aoC = 0;
aiMaterial* material = mAiScene->mMaterials[mesh->mMaterialIndex];
for (int i = 0; i < (difC = material->GetTextureCount(aiTextureType_DIFFUSE)); i++)
{
material->GetTexture(aiTextureType_DIFFUSE, i, &diff);
}
for (int i = 0; i < (roughC = material->GetTextureCount(aiTextureType_DIFFUSE_ROUGHNESS)); i++)
{
material->GetTexture(aiTextureType_DIFFUSE_ROUGHNESS, i, &rough);
}
for (int i = 0; i < (normC = material->GetTextureCount(aiTextureType_NORMALS)); i++)
{
material->GetTexture(aiTextureType_NORMALS, i, &norm);
}
for (int i = 0; i < (metalC = material->GetTextureCount(aiTextureType_METALNESS)); i++)
{
material->GetTexture(aiTextureType_METALNESS, i, &metallic);
}
for (int i = 0; i < (aoC = material->GetTextureCount(aiTextureType_AMBIENT_OCCLUSION)); i++)
{
material->GetTexture(aiTextureType_AMBIENT_OCCLUSION, i, &ao);
}
std::string rDir = AssetManager::assetRootPath;
if (difC)
mat.setTexture2D("material.diffuse", (mDir + diff.C_Str()).c_str());
else
mat.setTexture2D("material.diffuse", rDir + "EngineAssets/defaultDiff.jpg");
if (roughC)
mat.setTexture2D("material.roughness", (mDir + rough.C_Str()).c_str());
else
{
mat.setValue("noRoughness", 1.0f);
mat.setValue("roughness", 0.4f);
}
if (normC)
{
mat.setTexture2D("material.normalMap", (mDir + norm.C_Str()).c_str());
mat.setValue("normalStrength", 5);
}
else
{
mat.setValue("noNormal", 1);
}
if (metalC)
mat.setTexture2D("material.metallic", (mDir + metallic.C_Str()).c_str());
else
{
mat.setValue("noMetallic", 1.0f);
mat.setValue("metallic", 0.0f);
}
if (aoC)
mat.setTexture2D("material.metallic", (mDir + ao.C_Str()).c_str());
else
{
mat.setValue("noAO", 1.0f);
mat.setValue("ambientocclusion", 1.0f);
}
std::cout << "Diffuse: " << diff.C_Str() << std::endl;
std::cout << "rougness: " << rough.C_Str() << std::endl;
std::cout << "normal: " << norm.C_Str() << std::endl;
std::cout << "metallic: " << metallic.C_Str() << std::endl;
std::cout << "ao: " << ao.C_Str() << std::endl;
mat.setValue("roughness", 1);
}
}
template <typename real>
void mat4x4_AiToAkame_converter(aiMatrix4x4t<real> const &aiMat,glm::mat4 &akMat)
{
akMat[0][0] = aiMat.a1,akMat[0][1]=aiMat.b1, akMat[0][2] = aiMat.c1, akMat[0][3] = aiMat.d1;
akMat[1][0] = aiMat.a2,akMat[1][1]=aiMat.b2, akMat[1][2] = aiMat.c2, akMat[1][3] = aiMat.d2;
akMat[2][0] = aiMat.a3,akMat[2][1]=aiMat.b3, akMat[2][2] = aiMat.c3, akMat[2][3] = aiMat.d3;
akMat[3][0] = aiMat.a4,akMat[3][1]=aiMat.b4, akMat[3][2] = aiMat.c4, akMat[3][3] = aiMat.d4;
}
Entity Model::processSkeletalMesh(Entity parent,aiMesh* mesh)
{
std::set<std::string> bonesNames;
std::vector<sk_vert> vertices;
std::vector<unsigned int> indices;
std::string meshName = mesh->mName.C_Str();
for (unsigned int i = 0; i < mesh->mNumVertices; i++)
{
sk_vert vertex;
vertex.pos.x = mesh->mVertices[i].x;
vertex.pos.y = mesh->mVertices[i].y;
vertex.pos.z = mesh->mVertices[i].z;
vertex.biTangent.x = mesh->mBitangents[i].x;
vertex.biTangent.y = mesh->mBitangents[i].y;
vertex.biTangent.z = mesh->mBitangents[i].z;
vertex.tangent.x = mesh->mTangents[i].x;
vertex.tangent.y = mesh->mTangents[i].y;
vertex.tangent.z = mesh->mTangents[i].z;
vertex.normal.x = mesh->mNormals[i].x;
vertex.normal.y = mesh->mNormals[i].y;
vertex.normal.z = mesh->mNormals[i].z;
vertex.boneWeight.x = 0;
vertex.boneWeight.y = 0;
vertex.boneWeight.z = 0;
vertex.boneWeight.w = 0;
vertex.boneIndex.x = -1;
vertex.boneIndex.y = -1;
vertex.boneIndex.z = -1;
vertex.boneIndex.w = -1;
if (mesh->mTextureCoords[0])
{
vertex.uv.x = mesh->mTextureCoords[0][i].x;
vertex.uv.y = mesh->mTextureCoords[0][i].y;
}
else
{
vertex.uv.x = 0;
vertex.uv.y = 0;
}
vertices.push_back(vertex);
}
for (GLuint i = 0; i < mesh->mNumFaces; i++)
{
aiFace face = mesh->mFaces[i];
for (unsigned int j = 0; j < face.mNumIndices; j++)
{
indices.push_back(face.mIndices[j]);
}
}
Entity meshid = mCurrScene.CreateEntity();
mSkMeshList.push_back(meshid);
Transform& t = mCurrScene.AddComponent<Transform>(meshid);
t.setParent(parent);
t.SetLocalScale(glm::vec3(1,1,1));
t.SetLocalPosition(glm::vec3(0,0,0));
t.SetLocalRotation(glm::quat(1,0,0,0));
mCurrScene.SetEntityName(meshid, meshName);
for (unsigned int i_bone = 0; i_bone < mesh->mNumBones; i_bone++)
{
int boneId = -1;
auto &currBone=mesh->mBones[i_bone];
if (bonesNames.find(currBone->mName.C_Str())==bonesNames.end())
{
bonesNames.insert(currBone->mName.C_Str());
}
if (mBoneMap.find(currBone->mName.C_Str()) == mBoneMap.end())
{
BoneInfo b;
b.id = static_cast<int>(mBoneMap.size());
b.name = currBone->mName.C_Str();
aiVector3D pose;
aiVector3D scale;
aiQuaternion rot;
aiVector3D angles;
boneId = b.id;
currBone->mArmature->mTransformation.Decompose(scale,rot,pose);
b.scale = glm::vec3(scale.x,scale.y,scale.z);
b.pose = glm::vec3(pose.x,pose.y,pose.z);
b.rot = (glm::quat(rot.w,rot.x,rot.y,rot.z));
//b.rotAxis = glm::vec3(axis.x, axis.y, axis.z);
//b.rotAngle = angle;
mat4x4_AiToAkame_converter(currBone->mOffsetMatrix,b.offsetMat);
b.parentName = "";
if (currBone->mNode->mParent != nullptr)
{
b.parentName=currBone->mNode->mParent->mName.C_Str();
}
mBoneNodeMap[b.name] = currBone->mNode;
mBoneMap[b.name] = b;
}
else
{
boneId = mBoneMap[currBone->mName.C_Str()].id;
}
assert(boneId!=-1);
auto weights = currBone->mWeights;
for (unsigned int i_weight = 0; i_weight < currBone->mNumWeights; i_weight++)
{
int vertexId = weights[i_weight].mVertexId;
float weight = weights[i_weight].mWeight;
assert(vertexId<=vertices.size());
for (int i = 0; i < 4; i++)
{
if (vertices[vertexId].boneIndex[i] == -1)
{
vertices[vertexId].boneIndex[i] = boneId;
vertices[vertexId].boneWeight[i]= weight;
break;
}
}
}
}
SkeletalMesh &skMesh=mCurrScene.AddComponent<SkeletalMesh>(meshid);
Material mat("SkinnedMeshRenderer");
set_material(mat,mesh,mAiScene,mDir);
mCurrScene.AddComponent<Material>(meshid)=mat;
/*m.boneMap = std::vector<BoneInfo>(bonesNames.size());
for (auto bStr : bonesNames)
{
assert(mBoneMap.find(bStr) != mBoneMap.end());
{
auto& bone = mBoneMap[bStr];
m.boneMap[bone.id]=bone;
}
}*/
std::vector<sk_vert> finalVert;
//
for (size_t i = 0; i < vertices.size(); i++)
{
//rescale vertex weights so that it adds up to one
float total = vertices[i].boneWeight[0] + vertices[i].boneWeight[1] + vertices[i].boneWeight[2] + vertices[i].boneWeight[3];
float factor = 1/total;
vertices[i].boneWeight *= factor;
}
for (size_t i = 0; i < indices.size(); i += 3)
{
sk_vert v1, v2, v3;
v1 = vertices[indices[i]];
v2 = vertices[indices[i + 1]];
v3 = vertices[indices[i + 2]];
//calTangentBiTangent(v1, v2, v3);
finalVert.push_back(v1);
finalVert.push_back(v2);
finalVert.push_back(v3);
}
skMesh.CreateMesh(finalVert);
return meshid;
}
Entity Model::processMesh(Entity parent,aiMesh* mesh)
{
if (mesh->HasBones())
return processSkeletalMesh(parent,mesh);
std::vector<vert> vertices;
std::vector<unsigned int> indices;
std::string meshName=mesh->mName.C_Str();
for (unsigned int i = 0; i < mesh->mNumVertices; i++)
{
vert vertex;
vertex.pos.x = mesh->mVertices[i].x;
vertex.pos.y = mesh->mVertices[i].y;
vertex.pos.z = mesh->mVertices[i].z;
vertex.normal.x = mesh->mNormals[i].x;
vertex.normal.y = mesh->mNormals[i].y;
vertex.normal.z = mesh->mNormals[i].z;
if (mesh->mTextureCoords[0])
{
vertex.uv.x = mesh->mTextureCoords[0][i].x;
vertex.uv.y = mesh->mTextureCoords[0][i].y;
}
else
{
vertex.uv.x = 0;
vertex.uv.y = 0;
}
vertices.push_back(vertex);
}
for (GLuint i = 0; i < mesh->mNumFaces; i++)
{
aiFace face = mesh->mFaces[i];
for (unsigned int j = 0; j < face.mNumIndices; j++)
{
indices.push_back(face.mIndices[j]);
}
}
std::vector<vert> finalVert;
for (size_t i = 0; i < indices.size(); i += 3)
{
vert v1, v2, v3;
v1 = vertices[indices[i]];
v2 = vertices[indices[i + 1]];
v3 = vertices[indices[i + 2]];
calTangentBiTangent(v1, v2, v3);
finalVert.push_back(v1);
finalVert.push_back(v2);
finalVert.push_back(v3);
}
Entity meshid = mCurrScene.CreateEntity();
Transform &t=mCurrScene.AddComponent<Transform>(meshid);
t.setParent(parent);
t.SetLocalScale(glm::vec3(1, 1, 1));
t.SetLocalPosition(glm::vec3(0, 0, 0));
t.SetLocalRotation(glm::quat(1, 0, 0, 0));
mCurrScene.SetEntityName(meshid,meshName);
Material mat("DEFERRED");
set_material(mat,mesh,mAiScene,mDir);
mCurrScene.AddComponent<Material>(meshid) = mat;
mCurrScene.AddComponent<Mesh>(meshid).CreateMesh(vertices,indices);
return meshid;
}
void Model::processNode(Entity parent,aiNode* node)
{
Entity currNode;
/*
if (node->mNumMeshes <= 1 && node->mNumChildren==0)
{
currNode = parent;
}
else*/
{
currNode=mCurrScene.CreateEntity();
mAllNodeMap[node] = currNode;
Transform& t = mCurrScene.AddComponent<Transform>(currNode);
t.setParent(parent);
aiVector3D pose;
aiVector3D scale;
aiQuaternion quat;
node->mTransformation.Decompose(scale, quat, pose);
glm::vec3 p = glm::vec3(pose.x, pose.y, pose.z);
glm::quat a = glm::quat(quat.w,quat.x,quat.y,quat.z);
t.SetLocalPosition(p);
t.SetLocalRotation(Quaternion(a));
t.SetLocalScale(glm::vec3(scale.x,scale.y,scale.z));
mCurrScene.SetEntityName(currNode, node->mName.C_Str());
}
for (GLuint i = 0; i < node->mNumMeshes; i++)
{
aiMesh* mesh = mAiScene->mMeshes[node->mMeshes[i]];
processMesh(currNode,mesh);
}
for (GLuint i = 0; i < node->mNumChildren; i++)
{
processNode(currNode,node->mChildren[i]);
}
}
Entity Model::LoadModelToScene(std::string modelPath)
{
unsigned int importOptions = aiProcess_Triangulate
| aiProcess_JoinIdenticalVertices
| aiProcess_Triangulate
|aiProcess_PopulateArmatureData
| aiProcess_CalcTangentSpace
;
Assimp::Importer importer;
mAiScene = importer.ReadFile(modelPath, importOptions);
if (!mAiScene || mAiScene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !mAiScene->mRootNode)
{
std::string errstr = "ERROR::ASSIMP::" + std::string(importer.GetErrorString());
ENGINE_CORE_ERROR(errstr);
return Entity(-1,-1);
}
std::filesystem::path model_path(modelPath);
mDir = model_path.parent_path().string()+"/";
Entity parent=mCurrScene.CreateEntity();
mCurrScene.AddComponent<Transform>(parent);
processNode(parent,mAiScene->mRootNode);
//finds root bone node, also assigns the bone entity ids "eid" in the BoneInfo of "mBoneMap"
aiNode* rootBone;
for (auto &bonePair : mBoneMap)
{
auto& bone = bonePair.second;
if (mBoneNodeMap.find(bone.name) != mBoneNodeMap.end())
{
aiNode *currBoneNode = mBoneNodeMap[bone.name];
if (mBoneNodeMap.find(currBoneNode->mParent->mName.C_Str()) == mBoneNodeMap.end())
{
rootBone = currBoneNode->mParent;;
}
if (mAllNodeMap.find(mBoneNodeMap[bone.name]) != mAllNodeMap.end())
{
Entity currBone = mAllNodeMap[mBoneNodeMap[bone.name]];
bone.eid = currBone;
}
else
{
std::cout << "Can't find node "<<bone.name<<" in the scene\n";
}
}
else
{
std::cout <<"can't find bone in bone list: "<<bone.name<<std::endl;
}
Transform& bT = mCurrScene.GetComponent<Transform>(bone.eid);
}
if (mBoneMap.size() > 0)
{
AnimationController& anim = mCurrScene.AddComponent<AnimationController>(parent);
anim.boneList = std::make_shared<std::vector<BoneInfo>>(mBoneMap.size());
anim.boneMap = std::make_shared<std::map<std::string, BoneInfo>>();
(*anim.boneMap) = mBoneMap;
for (auto& ent : mSkMeshList)
{
SkeletalMesh& skm = mCurrScene.GetComponent<SkeletalMesh>(ent);
skm.animController = parent;
/*for (int i = 0; i < skm.boneMap.size(); i++)
{
assert(mBoneMap.find(skm.boneMap[i].name)!=mBoneMap.end());
skm.boneMap[i].eid = mBoneMap[skm.boneMap[i].name].eid;
}*/
}
for (auto& bone : mBoneMap)
{
(*anim.boneList)[bone.second.id] = bone.second;
}
if (mAiScene->HasAnimations())
{
unsigned int animCount=mAiScene->mNumAnimations;
auto animList = mAiScene->mAnimations;
std::cout << "animation list:\n";
for (unsigned int i = 0; i < animCount; i++)
{
std::cout << animList[i]->mName.C_Str()<<"\n";
//testCode:this code only for testA.fbx
std::shared_ptr<AnimationClip> aClip=std::make_shared<AnimationClip>();
aClip->clipName = animList[i]->mName.C_Str();
aClip->duration=animList[i]->mDuration;
aClip->ticksPerSec = animList[i]->mTicksPerSecond;
aClip->numChannels=animList[i]->mNumChannels;
auto mChannel = animList[i]->mChannels;
for (unsigned int i_channel = 0; i_channel < aClip->numChannels; i_channel++)
{
AnimationClip::AnimKeys animkeys;
//get animation key count
animkeys.pose_count=animList[i]->mChannels[i_channel]->mNumPositionKeys;
animkeys.scale_count=animList[i]->mChannels[i_channel]->mNumScalingKeys;
animkeys.rot_count=animList[i]->mChannels[i_channel]->mNumRotationKeys;
//get animation keys for this the current node
//get pose keys
for (unsigned int i_key = 0; i_key < animkeys.pose_count; i_key++)
{
auto currKey = mChannel[i_channel]->mPositionKeys[i_key];
glm::vec3 pose = glm::vec3(currKey.mValue.x,currKey.mValue.y,currKey.mValue.z);
AnimationClip::Key key(currKey.mTime,pose);
animkeys.position.push_back(key);
}
//get rotation keys
for (unsigned int i_key = 0; i_key < animkeys.rot_count; i_key++)
{
auto currKey = mChannel[i_channel]->mRotationKeys[i_key];
glm::quat rot = glm::quat(currKey.mValue.w,currKey.mValue.x, currKey.mValue.y, currKey.mValue.z);
AnimationClip::Key key(currKey.mTime, rot);
animkeys.rotation.push_back(key);
}
//get scale keys
for (unsigned int i_key = 0; i_key < animkeys.scale_count; i_key++)
{
auto currKey = mChannel[i_channel]->mScalingKeys[i_key];
glm::vec3 scale = glm::vec3(currKey.mValue.x, currKey.mValue.y, currKey.mValue.z);
AnimationClip::Key key(currKey.mTime, scale);
animkeys.scale.push_back(key);
}
//add the created animation keys to the boneName to Keys map in the animation clip
aClip->boneNameKeysMap[animList[i]->mChannels[i_channel]->mNodeName.C_Str()]= animkeys;
}
if(i==0)
anim.setCurrentClip(*aClip);
m_animation_clips.push_back(aClip);
}
}
}
//UpdateHierarchy(rootBone);
return parent;
}
void Model::UpdateHierarchy(aiNode* rootNode)
{
if (!rootNode)
return;
std::string boneName = rootNode->mName.C_Str();
if (mBoneMap.find(boneName) != mBoneMap.end())
{
Transform& t = mCurrScene.GetComponent<Transform>(mBoneMap[boneName].eid);
auto bone = mBoneMap[boneName];
t.SetLocalPosition(bone.pose);
t.SetLocalRotation(bone.rot);
t.SetLocalScale(bone.scale);
}
for (unsigned int i = 0; i < rootNode->mNumChildren; i++)
{
UpdateHierarchy(rootNode->mChildren[i]);
}
}
Model::Model(Scene& s) :mCurrScene(s)
{
}
| 27.653979 | 126 | 0.666229 | SudharsanZen |
ef3bc7942e919768065e1fab05d103374b7de34e | 946 | cpp | C++ | Example/interprocess_14/main.cpp | KwangjoJeong/Boost | 29c4e2422feded66a689e3aef73086c5cf95b6fe | [
"MIT"
] | null | null | null | Example/interprocess_14/main.cpp | KwangjoJeong/Boost | 29c4e2422feded66a689e3aef73086c5cf95b6fe | [
"MIT"
] | null | null | null | Example/interprocess_14/main.cpp | KwangjoJeong/Boost | 29c4e2422feded66a689e3aef73086c5cf95b6fe | [
"MIT"
] | null | null | null | #include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/sync/named_mutex.hpp>
#include <boost/interprocess/sync/named_condition.hpp>
#include <boost/interprocess/sync/scoped_lock.hpp>
#include <iostream>
using namespace boost::interprocess;
int main()
{
managed_shared_memory managed_shm{open_or_create, "shm", 1024};
int *i = managed_shm.find_or_construct<int>("Integer")(0);
named_mutex named_mtx{open_or_create, "mtx"};
named_condition named_cnd{open_or_create, "cnd"};
scoped_lock<named_mutex> lock{named_mtx};
while (*i < 10)
{
if (*i % 2 == 0)
{
++(*i);
named_cnd.notify_all();
named_cnd.wait(lock);
}
else
{
std::cout << *i << std::endl;
++(*i);
named_cnd.notify_all();
named_cnd.wait(lock);
}
}
named_cnd.notify_all();
shared_memory_object::remove("shm");
named_mutex::remove("mtx");
named_condition::remove("cnd");
} | 26.277778 | 65 | 0.674419 | KwangjoJeong |
ef3e895793e05651b6aace107751c179c5d77cb1 | 37,177 | cpp | C++ | titan-infinite/src/texture.cpp | KyleKaiWang/titan-infinite | d2905e050501fc076589bb8e1578d3285ec5aab0 | [
"Apache-2.0"
] | null | null | null | titan-infinite/src/texture.cpp | KyleKaiWang/titan-infinite | d2905e050501fc076589bb8e1578d3285ec5aab0 | [
"Apache-2.0"
] | null | null | null | titan-infinite/src/texture.cpp | KyleKaiWang/titan-infinite | d2905e050501fc076589bb8e1578d3285ec5aab0 | [
"Apache-2.0"
] | null | null | null | /*
* Vulkan Renderer Program
*
* Copyright (C) 2020 Kyle Wang
*/
#include "pch.h"
#include "texture.h"
#include <filesystem>
#include <gli.hpp>
namespace texture {
TextureObject loadTexture(
const std::string& filename,
VkFormat format,
Device* device,
int num_requested_components,
VkFilter filter,
VkImageUsageFlags imageUsageFlags,
VkImageLayout imageLayout) {
// Load data, width, height and num_components
TextureObject texObj = loadTexture(filename);
texObj.device = device;
texObj.mipLevels = static_cast<uint32_t>(std::floor(std::log2(std::max(texObj.width, texObj.height)))) + 1;
auto image_data_size = texObj.data.size();
VkFormatProperties formatProps;
vkGetPhysicalDeviceFormatProperties(device->getPhysicalDevice(), format, &formatProps);
VkBuffer stage_buffer;
VkDeviceMemory stage_buffer_memory;
stage_buffer = buffer::createBuffer(
device->getDevice(),
image_data_size,
VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
);
VkMemoryRequirements memReqs;
vkGetBufferMemoryRequirements(device->getDevice(), stage_buffer, &memReqs);
VkMemoryAllocateInfo allocInfo{};
allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
allocInfo.allocationSize = memReqs.size;
allocInfo.memoryTypeIndex = device->findMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
if (vkAllocateMemory(device->getDevice(), &allocInfo, nullptr, &stage_buffer_memory) != VK_SUCCESS) {
throw std::runtime_error("No mappable, coherent memory!");
}
if (vkBindBufferMemory(device->getDevice(), stage_buffer, stage_buffer_memory, 0) != VK_SUCCESS) {
throw std::runtime_error("Failed to bind buffer memory");
}
// copy texture data to staging buffer
void* data;
memory::map(device->getDevice(), stage_buffer_memory, 0, memReqs.size, &data);
memcpy(data, texObj.data.data(), image_data_size);
memory::unmap(device->getDevice(), stage_buffer_memory);
// Image
texObj.image = device->createImage(
device->getDevice(),
0,
VK_IMAGE_TYPE_2D,
format,
{ (uint32_t)texObj.width, (uint32_t)texObj.height, 1 },
texObj.mipLevels,
1,
VK_SAMPLE_COUNT_1_BIT,
VK_IMAGE_TILING_OPTIMAL,
(imageUsageFlags & VK_IMAGE_USAGE_TRANSFER_DST_BIT) ? imageUsageFlags : (imageUsageFlags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT),
VK_SHARING_MODE_EXCLUSIVE,
VK_IMAGE_LAYOUT_UNDEFINED
);
vkGetImageMemoryRequirements(device->getDevice(), texObj.image, &memReqs);
texObj.buffer_size = memReqs.size;
// VkMemoryAllocateInfo
allocInfo.allocationSize = memReqs.size;
allocInfo.memoryTypeIndex = device->findMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
if (vkAllocateMemory(device->getDevice(), &allocInfo, nullptr, &texObj.image_memory) != VK_SUCCESS) {
throw std::runtime_error("Failed to allocate buffer memory!");
}
if (vkBindImageMemory(device->getDevice(), texObj.image, texObj.image_memory, 0) != VK_SUCCESS) {
throw std::runtime_error("Failed to bind image memory");
}
// Use a separate command buffer for texture loading
VkCommandBuffer copyCmd = device->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, device->getCommandPool(), true);
VkImageSubresourceRange subresourceRange{};
subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
subresourceRange.baseMipLevel = 0;
subresourceRange.levelCount = texObj.mipLevels;
subresourceRange.layerCount = 1;
/* Since we're going to blit to the texture image, set its layout to DESTINATION_OPTIMAL */
texture::setImageLayout(
copyCmd,
texObj.image,
VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
subresourceRange,
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT,
0,
VK_ACCESS_TRANSFER_WRITE_BIT);
//Generate first one and setup each mipmap later
std::vector<VkBufferImageCopy> bufferImgCopyList;
for (uint32_t i = 0; i < 1; ++i)
{
VkBufferImageCopy copy_region{};
copy_region.bufferOffset = 0;
copy_region.bufferRowLength = 0;
copy_region.bufferImageHeight = 0;
copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
copy_region.imageSubresource.mipLevel = i;
copy_region.imageSubresource.baseArrayLayer = 0;
copy_region.imageSubresource.layerCount = 1;
copy_region.imageOffset = { 0, 0, 0 };
copy_region.imageExtent = {
static_cast<uint32_t>(texObj.width),
static_cast<uint32_t>(texObj.height),
1
};
bufferImgCopyList.push_back(copy_region);
}
/* Put the copy command into the command buffer */
vkCmdCopyBufferToImage(
copyCmd,
stage_buffer,
texObj.image,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
uint32_t(bufferImgCopyList.size()),
bufferImgCopyList.data()
);
/* Set the layout for the texture image from DESTINATION_OPTIMAL to SHADER_READ_ONLY */
texObj.image_layout = imageLayout;
device->flushCommandBuffer(copyCmd, device->getGraphicsQueue(), true);
vkFreeMemory(device->getDevice(), stage_buffer_memory, NULL);
vkDestroyBuffer(device->getDevice(), stage_buffer, NULL);
generateMipmaps(device, texObj, format);
texObj.view = device->createImageView(device->getDevice(),
texObj.image,
VK_IMAGE_VIEW_TYPE_2D,
format,
{ VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 });
texObj.sampler = texture::createSampler(device->getDevice(),
filter,
filter,
VK_SAMPLER_MIPMAP_MODE_LINEAR,
VK_SAMPLER_ADDRESS_MODE_REPEAT,
VK_SAMPLER_ADDRESS_MODE_REPEAT,
VK_SAMPLER_ADDRESS_MODE_REPEAT,
0.0,
VK_TRUE,
1.0f,
VK_FALSE,
VK_COMPARE_OP_NEVER,
0.0,
(float)texObj.mipLevels,
VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE,
VK_FALSE);
return texObj;
}
TextureObject loadTextureCube_gli(
const std::string& filename,
VkFormat format,
Device* device,
VkImageUsageFlags imageUsageFlags,
VkImageLayout imageLayout)
{
gli::texture_cube texCube(gli::load(filename));
assert(!texCube.empty());
TextureObject texObj;
uint32_t width, height, mip_levels;
size_t cube_size;
width = static_cast<uint32_t>(texCube.extent().x);
height = static_cast<uint32_t>(texCube.extent().y);
cube_size = texCube.size();
mip_levels = static_cast<uint32_t>(texCube.levels());
auto cube_data = texCube.data();
texObj.width = width;
texObj.height = height;
texObj.mipLevels = mip_levels;
texObj.device = device;
VkFormatProperties formatProps;
vkGetPhysicalDeviceFormatProperties(device->getPhysicalDevice(), format, &formatProps);
// Use a separate command buffer for texture loading
VkCommandBuffer copyCmd = device->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, device->getCommandPool(), true);
VkBuffer stage_buffer;
VkDeviceMemory stage_buffer_memory;
stage_buffer = buffer::createBuffer(
device->getDevice(),
cube_size,
VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
);
VkMemoryRequirements memReqs;
vkGetBufferMemoryRequirements(device->getDevice(), stage_buffer, &memReqs);
VkMemoryAllocateInfo allocInfo{};
allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
allocInfo.allocationSize = memReqs.size;
allocInfo.memoryTypeIndex = device->findMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
if (vkAllocateMemory(device->getDevice(), &allocInfo, nullptr, &stage_buffer_memory) != VK_SUCCESS) {
throw std::runtime_error("No mappable, coherent memory!");
}
if (vkBindBufferMemory(device->getDevice(), stage_buffer, stage_buffer_memory, 0) != VK_SUCCESS) {
throw std::runtime_error("Failed to bind buffer memory");
}
// copy texture data to staging buffer
void* data;
memory::map(device->getDevice(), stage_buffer_memory, 0, memReqs.size, &data);
memcpy(data, cube_data, cube_size);
memory::unmap(device->getDevice(), stage_buffer_memory);
// Image
texObj.image = device->createImage(
device->getDevice(),
VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT,
VK_IMAGE_TYPE_2D,
format,
{ width, height, 1 },
texObj.mipLevels,
6,
VK_SAMPLE_COUNT_1_BIT,
VK_IMAGE_TILING_OPTIMAL,
(imageUsageFlags & VK_IMAGE_USAGE_TRANSFER_DST_BIT) ? imageUsageFlags : (imageUsageFlags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT),
VK_SHARING_MODE_EXCLUSIVE,
VK_IMAGE_LAYOUT_UNDEFINED
);
vkGetImageMemoryRequirements(device->getDevice(), texObj.image, &memReqs);
texObj.buffer_size = memReqs.size;
// VkMemoryAllocateInfo
allocInfo.allocationSize = memReqs.size;
allocInfo.memoryTypeIndex = device->findMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
if (vkAllocateMemory(device->getDevice(), &allocInfo, nullptr, &texObj.image_memory) != VK_SUCCESS) {
throw std::runtime_error("Failed to allocate buffer memory!");
}
if (vkBindImageMemory(device->getDevice(), texObj.image, texObj.image_memory, 0) != VK_SUCCESS) {
throw std::runtime_error("Failed to bind image memory");
}
std::vector<VkBufferImageCopy> bufferCopyRegions;
size_t offset = 0;
for (uint32_t layer = 0; layer < texCube.faces(); ++layer) {
for (uint32_t level = 0; level < mip_levels; ++level) {
VkBufferImageCopy copy_region{};
copy_region.bufferRowLength = 0;
copy_region.bufferImageHeight = 0;
copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
copy_region.imageSubresource.mipLevel = level;
copy_region.imageSubresource.baseArrayLayer = layer;
copy_region.imageSubresource.layerCount = 1;
copy_region.imageOffset = { 0, 0, 0 };
copy_region.imageExtent = {
static_cast<uint32_t>(texCube[layer][level].extent().x),
static_cast<uint32_t>(texCube[layer][level].extent().y),
1 };
copy_region.bufferOffset = offset;
bufferCopyRegions.push_back(copy_region);
offset += texCube[layer][level].size();
}
}
VkImageSubresourceRange subresourceRange{};
subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
subresourceRange.baseMipLevel = 0;
subresourceRange.levelCount = texObj.mipLevels;
subresourceRange.layerCount = 6;
/* Since we're going to blit to the texture image, set its layout to DESTINATION_OPTIMAL */
texture::setImageLayout(
copyCmd,
texObj.image,
VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
subresourceRange,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
0,
VK_ACCESS_TRANSFER_WRITE_BIT);
/* Put the copy command into the command buffer */
vkCmdCopyBufferToImage(
copyCmd,
stage_buffer,
texObj.image,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
static_cast<uint32_t>(bufferCopyRegions.size()),
bufferCopyRegions.data()
);
/* Set the layout for the texture image from DESTINATION_OPTIMAL to SHADER_READ_ONLY */
texObj.image_layout = imageLayout;
setImageLayout(
copyCmd,
texObj.image,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
texObj.image_layout,
subresourceRange,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
VK_ACCESS_TRANSFER_WRITE_BIT,
VK_ACCESS_TRANSFER_READ_BIT
);
device->flushCommandBuffer(copyCmd, device->getGraphicsQueue());
texObj.view = device->createImageView(device->getDevice(),
texObj.image,
VK_IMAGE_VIEW_TYPE_CUBE,
format,
{ VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
{ VK_IMAGE_ASPECT_COLOR_BIT, 0, texObj.mipLevels, 0, 6 });
texObj.sampler = texture::createSampler(device->getDevice(),
VK_FILTER_LINEAR,
VK_FILTER_LINEAR,
VK_SAMPLER_MIPMAP_MODE_LINEAR,
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
0.0,
VK_TRUE,
16.0f,
VK_FALSE,
VK_COMPARE_OP_NEVER,
0.0,
(float)texObj.mipLevels,
VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE,
VK_FALSE);
vkFreeMemory(device->getDevice(), stage_buffer_memory, NULL);
vkDestroyBuffer(device->getDevice(), stage_buffer, NULL);
return texObj;
}
TextureObject loadTextureCube(
const std::string& filename,
VkFormat format,
Device* device,
VkImageUsageFlags imageUsageFlags,
VkImageLayout imageLayout) {
std::filesystem::path p(filename);
if (p.extension() == ".ktx")
return loadTextureCube_gli(filename, format, device, imageUsageFlags, imageLayout);
else
throw std::runtime_error("File type is not supported");
}
TextureObject loadTexture(
void* buffer,
VkDeviceSize bufferSize,
VkFormat format,
uint32_t texWidth,
uint32_t texHeight,
Device* device,
VkQueue copyQueue,
VkFilter filter,
VkImageUsageFlags imageUsageFlags,
VkImageLayout image_layout)
{
assert(buffer);
TextureObject texObj;
texObj.width = texWidth;
texObj.height = texHeight;
VkMemoryAllocateInfo memAllocInfo{};
memAllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
VkMemoryRequirements memReqs;
VkCommandBuffer copyCmd = device->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, device->getCommandPool(), 1);
VkBuffer stagingBuffer;
VkDeviceMemory stagingMemory;
stagingBuffer = buffer::createBuffer(
device->getDevice(),
bufferSize,
VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
);
vkGetBufferMemoryRequirements(device->getDevice(), stagingBuffer, &memReqs);
memAllocInfo.allocationSize = memReqs.size;
memAllocInfo.memoryTypeIndex = device->findMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
if (vkAllocateMemory(device->getDevice(), &memAllocInfo, nullptr, &stagingMemory) != VK_SUCCESS) {
throw std::runtime_error("Failed to allocate staging buffer memory!");
}
if (vkBindBufferMemory(device->getDevice(), stagingBuffer, stagingMemory, 0) != VK_SUCCESS) {
throw std::runtime_error("Failed to bind staging buffer memory");
}
void* data;
memory::map(device->getDevice(), stagingMemory, 0, memReqs.size, &data);
memcpy(data, buffer, bufferSize);
memory::unmap(device->getDevice(), stagingMemory);
VkBufferImageCopy bufferCopyRegion{};
bufferCopyRegion.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
bufferCopyRegion.imageSubresource.mipLevel = 0;
bufferCopyRegion.imageSubresource.baseArrayLayer = 0;
bufferCopyRegion.imageSubresource.layerCount = 1;
bufferCopyRegion.imageExtent.width = texObj.width;
bufferCopyRegion.imageExtent.height = texObj.height;
bufferCopyRegion.imageExtent.depth = 1;
bufferCopyRegion.bufferOffset = 0;
VkBufferImageCopy copy_region;
copy_region.bufferOffset = 0;
copy_region.bufferRowLength = texObj.width;
copy_region.bufferImageHeight = texObj.height;
copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
copy_region.imageSubresource.mipLevel = 0;
copy_region.imageSubresource.baseArrayLayer = 0;
copy_region.imageSubresource.layerCount = 1;
copy_region.imageOffset.x = 0;
copy_region.imageOffset.y = 0;
copy_region.imageOffset.z = 0;
copy_region.imageExtent.width = texObj.width;
copy_region.imageExtent.height = texObj.height;
copy_region.imageExtent.depth = 1;
texObj.image = device->createImage(
device->getDevice(),
0,
VK_IMAGE_TYPE_2D,
format,
{ (uint32_t)texObj.width, (uint32_t)texObj.height, 1 },
1,
1,
VK_SAMPLE_COUNT_1_BIT,
VK_IMAGE_TILING_OPTIMAL,
(imageUsageFlags & VK_IMAGE_USAGE_TRANSFER_DST_BIT) ? imageUsageFlags : (imageUsageFlags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT),
VK_SHARING_MODE_EXCLUSIVE,
VK_IMAGE_LAYOUT_UNDEFINED
);
vkGetImageMemoryRequirements(device->getDevice(), texObj.image, &memReqs);
memAllocInfo.allocationSize = memReqs.size;
memAllocInfo.memoryTypeIndex = device->findMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
if (vkAllocateMemory(device->getDevice(), &memAllocInfo, nullptr, &texObj.image_memory) != VK_SUCCESS) {
throw std::runtime_error("Failed to allocate buffer memory!");
}
if (vkBindImageMemory(device->getDevice(), texObj.image, texObj.image_memory, 0) != VK_SUCCESS) {
throw std::runtime_error("Failed to bind image memory");
}
// Image barrier for optimal image (target)
// Optimal image will be used as destination for the copy
// Create an image barrier object
texture::setImageLayout(copyCmd,
texObj.image,
VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT
);
// Copy mip levels from staging buffer
vkCmdCopyBufferToImage(
copyCmd,
stagingBuffer,
texObj.image,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1,
&bufferCopyRegion
);
// Change texture image layout to shader read after all mip levels have been copied
texObj.image_layout = image_layout;
texture::setImageLayout(copyCmd,
texObj.image,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
texObj.image_layout,
{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT
);
device->flushCommandBuffer(copyCmd, copyQueue);
vkFreeMemory(device->getDevice(), stagingMemory, nullptr);
vkDestroyBuffer(device->getDevice(), stagingBuffer, nullptr);
// view
texObj.view = device->createImageView(device->getDevice(),
texObj.image,
VK_IMAGE_VIEW_TYPE_2D,
format,
{ VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 });
// sampler
texObj.sampler = texture::createSampler(device->getDevice(),
filter,
filter,
VK_SAMPLER_MIPMAP_MODE_LINEAR,
VK_SAMPLER_ADDRESS_MODE_REPEAT,
VK_SAMPLER_ADDRESS_MODE_REPEAT,
VK_SAMPLER_ADDRESS_MODE_REPEAT,
0.0,
VK_TRUE,
1.0f,
VK_FALSE,
VK_COMPARE_OP_NEVER,
0.0,
0.0,
VK_BORDER_COLOR_INT_OPAQUE_BLACK,
VK_FALSE);
return texObj;
}
VkSampler createSampler(const VkDevice& device,
VkFilter magFilter,
VkFilter minFilter,
VkSamplerMipmapMode mipmapMode,
VkSamplerAddressMode addressModeU,
VkSamplerAddressMode addressModeV,
VkSamplerAddressMode addressModeW,
float mipLodBias,
VkBool32 anisotropyEnable,
float maxAnisotropy,
VkBool32 compareEnable,
VkCompareOp compareOp,
float minLod,
float maxLod,
VkBorderColor borderColor,
VkBool32 unnormalizedCoordinates) {
VkSamplerCreateInfo samplerInfo{};
samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
samplerInfo.magFilter = magFilter;
samplerInfo.minFilter = minFilter;
samplerInfo.mipmapMode = mipmapMode;
samplerInfo.addressModeU = addressModeU;
samplerInfo.addressModeV = addressModeV;
samplerInfo.addressModeW = addressModeW;
samplerInfo.mipLodBias = mipLodBias;
samplerInfo.anisotropyEnable = anisotropyEnable;
samplerInfo.maxAnisotropy = maxAnisotropy;
samplerInfo.borderColor = borderColor;
samplerInfo.unnormalizedCoordinates = unnormalizedCoordinates;
samplerInfo.compareEnable = compareEnable;
samplerInfo.compareOp = compareOp;
samplerInfo.minLod = minLod;
samplerInfo.maxLod = maxLod;
VkSampler sampler;
if (vkCreateSampler(device, &samplerInfo, nullptr, &sampler) != VK_SUCCESS) {
throw std::runtime_error("failed to create texture sampler!");
}
return sampler;
}
void setImageLayout(
VkCommandBuffer commandBuffer,
VkImage image,
VkImageLayout old_image_layout,
VkImageLayout new_image_layout,
VkImageSubresourceRange subresource_range,
VkPipelineStageFlags src_stages,
VkPipelineStageFlags dest_stages,
VkAccessFlags src_access_mask,
VkAccessFlags dst_access_mask) {
assert(commandBuffer != VK_NULL_HANDLE);
VkImageMemoryBarrier image_memory_barrier = {};
image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
image_memory_barrier.pNext = NULL;
image_memory_barrier.srcAccessMask = src_access_mask;
image_memory_barrier.dstAccessMask = dst_access_mask;
image_memory_barrier.oldLayout = old_image_layout;
image_memory_barrier.newLayout = new_image_layout;
image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.image = image;
image_memory_barrier.subresourceRange = subresource_range;
switch (old_image_layout)
{
case VK_IMAGE_LAYOUT_UNDEFINED:
// Image layout is undefined (or does not matter)
// Only valid as initial layout
// No flags required, listed only for completeness
image_memory_barrier.srcAccessMask = 0;
break;
case VK_IMAGE_LAYOUT_PREINITIALIZED:
// Image is preinitialized
// Only valid as initial layout for linear images, preserves memory contents
// Make sure host writes have been finished
image_memory_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
break;
case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
// Image is a color attachment
// Make sure any writes to the color buffer have been finished
image_memory_barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
break;
case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
// Image is a depth/stencil attachment
// Make sure any writes to the depth/stencil buffer have been finished
image_memory_barrier.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
break;
case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL:
// Image is a transfer source
// Make sure any reads from the image have been finished
image_memory_barrier.srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
break;
case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL:
// Image is a transfer destination
// Make sure any writes to the image have been finished
image_memory_barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
break;
case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
// Image is read by a shader
// Make sure any shader reads from the image have been finished
image_memory_barrier.srcAccessMask = VK_ACCESS_SHADER_READ_BIT;
break;
default:
// Other source layouts aren't handled (yet)
break;
}
// Target layouts (new)
// Destination access mask controls the dependency for the new image layout
switch (new_image_layout)
{
case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL:
// Image will be used as a transfer destination
// Make sure any writes to the image have been finished
image_memory_barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
break;
case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL:
// Image will be used as a transfer source
// Make sure any reads from the image have been finished
image_memory_barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
break;
case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
// Image will be used as a color attachment
// Make sure any writes to the color buffer have been finished
image_memory_barrier.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
break;
case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
// Image layout will be used as a depth/stencil attachment
// Make sure any writes to depth/stencil buffer have been finished
image_memory_barrier.dstAccessMask = image_memory_barrier.dstAccessMask | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
break;
case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
// Image will be read in a shader (sampler, input attachment)
// Make sure any writes to the image have been finished
if (image_memory_barrier.srcAccessMask == 0)
{
image_memory_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT;
}
image_memory_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
break;
default:
// Other source layouts aren't handled (yet)
break;
}
vkCmdPipelineBarrier(commandBuffer, src_stages, dest_stages, 0, 0, NULL, 0, NULL, 1, &image_memory_barrier);
}
void generateMipmaps(
Device* device,
TextureObject& texture,
VkFormat format)
{
assert(texture.mipLevels > 1);
// Check if image format supports linear blitting
VkFormatProperties formatProperties;
vkGetPhysicalDeviceFormatProperties(device->getPhysicalDevice(), format, &formatProperties);
if (!(formatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT)) {
throw std::runtime_error("texture image format does not support linear blitting!");
}
VkCommandBuffer commandBuffer = device->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, device->getCommandPool(), true);
VkImageMemoryBarrier barrier = {};
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
barrier.image = texture.image;
barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
barrier.subresourceRange.baseArrayLayer = 0;
barrier.subresourceRange.layerCount = 1;
barrier.subresourceRange.levelCount = 1;
// Iterate through mip chain and consecutively blit from previous level to next level with linear filtering.
for (uint32_t level = 1; level < texture.mipLevels; ++level) {
barrier.subresourceRange.baseMipLevel = level - 1;
barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
vkCmdPipelineBarrier(commandBuffer,
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0,
0, nullptr,
0, nullptr,
1, &barrier);
VkImageBlit region{};
region.srcSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, level - 1, 0, 1 };
region.dstSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, level, 0, 1 };
region.srcOffsets[1] = { texture.width > 1 ? int32_t(texture.width >> (level - 1)) : 1, texture.height > 1 ? int32_t(texture.height >> (level - 1)) : 1, 1 };
region.dstOffsets[1] = { texture.width > 1 ? int32_t(texture.width >> (level)) : 1, texture.height > 1 ? int32_t(texture.height >> (level)) : 1, 1 };
vkCmdBlitImage(commandBuffer,
texture.image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
texture.image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1, ®ion, VK_FILTER_LINEAR);
barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
barrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
barrier.srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
vkCmdPipelineBarrier(commandBuffer,
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0,
0, nullptr,
0, nullptr,
1, &barrier);
}
// Transition whole mip chain to shader read only layout.
{
barrier.subresourceRange.baseMipLevel = texture.mipLevels - 1;
barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
barrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
vkCmdPipelineBarrier(commandBuffer,
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0,
0, nullptr,
0, nullptr,
1, &barrier);
}
device->flushCommandBuffer(commandBuffer, device->getGraphicsQueue(), true);
}
bool loadTextureData(char const* filename,
int num_requested_components,
std::vector<unsigned char>& image_data,
int* image_width,
int* image_height,
int* image_num_components,
int* image_data_size,
bool* is_hdr) {
int width = 0;
int height = 0;
int num_components = 0;
if (stbi_is_hdr(filename)) {
std::unique_ptr<float, void(*)(void*)> stbi_data(stbi_loadf(filename, &width, &height, &num_components, num_requested_components), stbi_image_free);
if ((!stbi_data) ||
(0 >= width) ||
(0 >= height) ||
(0 >= num_components)) {
std::cout << "Could not read image!" << std::endl;
return false;
}
int data_size = width * height * sizeof(float) * (0 < num_requested_components ? num_requested_components : num_components);
if (image_data_size) {
*image_data_size = data_size;
}
if (image_width) {
*image_width = width;
}
if (image_height) {
*image_height = height;
}
if (image_num_components) {
*image_num_components = num_components;
}
*is_hdr = true;
image_data.resize(data_size);
std::memcpy(image_data.data(), stbi_data.get(), data_size);
return true;
}
else {
std::unique_ptr<unsigned char, void(*)(void*)> stbi_data(stbi_load(filename, &width, &height, &num_components, num_requested_components), stbi_image_free);
if ((!stbi_data) ||
(0 >= width) ||
(0 >= height) ||
(0 >= num_components)) {
std::cout << "Could not read image!" << std::endl;
return false;
}
int data_size = width * height * (0 < num_requested_components ? num_requested_components : num_components);
if (image_data_size) {
*image_data_size = data_size;
}
if (image_width) {
*image_width = width;
}
if (image_height) {
*image_height = height;
}
if (image_num_components) {
*image_num_components = num_components;
}
*is_hdr = false;
image_data.resize(data_size);
std::memcpy(image_data.data(), stbi_data.get(), data_size);
return true;
}
}
TextureObject loadTexture(const std::string& filename)
{
TextureObject texObj{};
auto data = vkHelper::readFile(filename);
auto extension = vkHelper::getFileExtension(filename);
if (extension == "png" || extension == "jpg")
{
int width;
int height;
int comp;
int req_comp = 4;
auto data_buffer = reinterpret_cast<const stbi_uc*>(data.data());
auto data_size = static_cast<int>(data.size());
auto raw_data = stbi_load_from_memory(data_buffer, data_size, &width, &height, &comp, req_comp);
if (!raw_data) {
throw std::runtime_error{ "Failed to load " + filename + ": " + stbi_failure_reason() };
}
assert(texObj.data.empty() && "Image data already set");
texObj.data = { raw_data, raw_data + width * height * req_comp };
stbi_image_free(raw_data);
texObj.width = width;
texObj.height = height;
texObj.num_components = comp;
texObj.format = VK_FORMAT_R8G8B8A8_UNORM;
}
else if (extension == "ktx")
{
gli::texture2d tex(gli::load(filename));
assert(!tex.empty());
texObj.data.resize(tex.size());
memcpy(&texObj.data[0], tex.data(), tex.size());
texObj.width = static_cast<uint32_t>(tex.extent().x);
texObj.height = static_cast<uint32_t>(tex.extent().y);
texObj.format = VK_FORMAT_R8G8B8A8_UNORM;
texObj.mipLevels = tex.levels();
}
return texObj;
}
}
void TextureObject::destroy(const VkDevice& device)
{
if (sampler != VK_NULL_HANDLE) {
vkDestroySampler(device, sampler, nullptr);
}
if (view != VK_NULL_HANDLE) {
vkDestroyImageView(device, view, nullptr);
}
if (image != VK_NULL_HANDLE) {
vkDestroyImage(device, image, nullptr);
}
if (image_memory != VK_NULL_HANDLE) {
vkFreeMemory(device, image_memory, nullptr);
}
} | 39.932331 | 171 | 0.63585 | KyleKaiWang |
ef4071cc75c614136a68f101bdf4354167a039ca | 2,003 | cpp | C++ | src/calc_velocity.cpp | suwamaro/rpa | fc9d37f03705334ee17b77de6ad2b8feab3cc7b0 | [
"Apache-2.0"
] | null | null | null | src/calc_velocity.cpp | suwamaro/rpa | fc9d37f03705334ee17b77de6ad2b8feab3cc7b0 | [
"Apache-2.0"
] | null | null | null | src/calc_velocity.cpp | suwamaro/rpa | fc9d37f03705334ee17b77de6ad2b8feab3cc7b0 | [
"Apache-2.0"
] | null | null | null | /*****************************************************************************
*
* Functions for calculating the velocity
*
* Copyright (C) 2018 by Hidemaro Suwa
* e-mail:[email protected]
*
*****************************************************************************/
#include "calc_velocity.h"
#include "self_consistent_eq.h"
#include "calc_gap.h"
void calc_velocity_square() {
/* Calculating the velocity */
double t = 1.;
double t_bar = 0;
double mu = 0;
int L = 256;
double k1 = 2. * M_PI / (double)L;
double qx = M_PI;
double qy = M_PI - k1;
int prec = 15;
std::unique_ptr<hoppings_square> ts;
ts = hoppings_square::mk_square(t, t_bar);
std::ofstream out;
out.open("velocity.text");
double U_delta = 0.05;
double U_min = 0.8;
double U_max = 15.0;
for(double U = U_min; U <= U_max; U += U_delta){
double delta = solve_self_consistent_eq_square( L, *ts, mu, U );
std::cout << "delta = " << delta << std::endl;
double E1 = calc_gap_square( L, t, mu, U, delta, qx, qy );
// double J = 4. * t * t / U;
double velocity = E1 / k1;
out << U << std::setw( prec ) << velocity << std::endl;
}
out.close();
}
void calc_velocity_cubic() {
/* Calculating the velocity */
double t = 1.;
double mu = 0;
int L = 32;
double k1 = 2. * M_PI / (double)L;
double qx = M_PI;
double qy = M_PI;
double qz = M_PI - k1;
int prec = 15;
std::unique_ptr<hoppings_cubic> ts;
ts = hoppings_cubic::mk_cubic(t);
std::ofstream out;
out.open("velocity.text");
double U_delta = 1.;
double U_min = 1.;
double U_max = 2000.0;
for(double U = U_min; U <= U_max; U += U_delta){
double delta = solve_self_consistent_eq_cubic( L, *ts, mu, U );
std::cout << "delta = " << delta << std::endl;
double E1 = calc_gap_cubic( L, t, mu, U, delta, qx, qy, qz );
// double J = 4. * t * t / U;
double velocity = E1 / k1;
out << U << std::setw( prec ) << velocity << std::endl;
}
out.close();
}
| 26.706667 | 78 | 0.550175 | suwamaro |
ef4a1a3291c0ae6b2b9c88915e8663566e7e59d2 | 3,137 | cpp | C++ | common/display.cpp | CybJaz/Simulations | bcb99907afaccc06c7b1f294a77122da2819ee5a | [
"MIT"
] | null | null | null | common/display.cpp | CybJaz/Simulations | bcb99907afaccc06c7b1f294a77122da2819ee5a | [
"MIT"
] | 2 | 2018-04-02T14:47:24.000Z | 2018-04-02T14:55:42.000Z | common/display.cpp | CybJaz/Simulations | bcb99907afaccc06c7b1f294a77122da2819ee5a | [
"MIT"
] | null | null | null | #include "display.h"
#include <iostream>
#include <GL/glew.h>
Display::Display(unsigned int width, unsigned int height, const std::string& title)
: _title(title), _fullscreen(false), _width(width), _height(height)
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2);
SDL_GL_SetSwapInterval(0);
//window_ = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
// width, height, SDL_WINDOW_OPENGL);
_window = SDL_CreateWindow(_title.c_str(),
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
_width, _height,
SDL_WINDOW_OPENGL);
SDL_SetWindowPosition(_window, 100, 100);
_glContext = SDL_GL_CreateContext(_window);
GLenum res = glewInit();
if (res != GLEW_OK)
{
std::cerr << "Glew failed to initialize!" << std::endl;
}
//glEnable(GL_DEPTH_TEST);
glEnable(GL_MULTISAMPLE);
//glDisable(GL_CULL_FACE);
//glEnable(GL_CULL_FACE);
//glCullFace(GL_BACK);
// Enable blending
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//float att[3] = { 1.0f, 1.0f, 1.0f };
//glEnable(GL_POINT_SPRITE);
//glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
//glPointParameterf(GL_POINT_SIZE_MIN, 1.0f);
//glPointParameterf(GL_POINT_SIZE_MAX, 16.0f);
//glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, att);
//glEnable(GL_POINT_SPRITE);
}
Display::~Display()
{
SDL_GL_DeleteContext(_glContext);
SDL_DestroyWindow(_window);
SDL_Quit();
}
void Display::clear(float r, float g, float b, float a)
{
glClearColor(r, g, b, a);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void Display::clear()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void Display::swapBuffers()
{
SDL_GL_SwapWindow(_window);
}
void Display::toggleFullScreen()
{
if (_fullscreen)
{
SDL_SetWindowBordered(_window, SDL_TRUE);
SDL_SetWindowSize(_window, _width, _height);
SDL_SetWindowPosition(_window, _old_pos_w, _old_pos_h);
glViewport(0, 0, (GLsizei)_width, (GLsizei)_height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
}
else
{
SDL_GetWindowPosition(_window, &_old_pos_w, &_old_pos_h);
SDL_SetWindowBordered(_window, SDL_FALSE);
int d = SDL_GetWindowDisplayIndex(_window);
SDL_DisplayMode current;
int should_be_zero = SDL_GetCurrentDisplayMode(d, ¤t);
SDL_SetWindowSize(_window, current.w, current.h);
SDL_SetWindowPosition(_window, 0, 0);
glViewport(0, 0, (GLsizei)current.w, (GLsizei)current.h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
}
_fullscreen = !_fullscreen;
}
float Display::getAspectRatio()
{
if (_fullscreen)
{
int d = SDL_GetWindowDisplayIndex(_window);
SDL_DisplayMode current;
int should_be_zero = SDL_GetCurrentDisplayMode(d, ¤t);
return (float)current.w / (float)current.h;
}
else
{
return (float)_width / (float)_height;
}
} | 24.130769 | 93 | 0.756774 | CybJaz |
ef4cf4a05b06bc98102021a2459362b8b9798c89 | 9,781 | cpp | C++ | src/Lib/scheduling/ScreamScheduler.cpp | miseri/rtp_plus_plus | 244ddd86f40f15247dd39ae7f9283114c2ef03a2 | [
"BSD-3-Clause"
] | 1 | 2021-07-14T08:15:05.000Z | 2021-07-14T08:15:05.000Z | src/Lib/scheduling/ScreamScheduler.cpp | 7956968/rtp_plus_plus | 244ddd86f40f15247dd39ae7f9283114c2ef03a2 | [
"BSD-3-Clause"
] | null | null | null | src/Lib/scheduling/ScreamScheduler.cpp | 7956968/rtp_plus_plus | 244ddd86f40f15247dd39ae7f9283114c2ef03a2 | [
"BSD-3-Clause"
] | 2 | 2021-07-14T08:15:02.000Z | 2021-07-14T08:56:10.000Z | #include "CorePch.h"
#include <rtp++/scheduling/ScreamScheduler.h>
#include <scream/code/RtpQueue.h>
#include <scream/code/ScreamTx.h>
#include <rtp++/experimental/ExperimentalRtcp.h>
#include <rtp++/experimental/Scream.h>
#define ENABLE_SCREAM_LOG true
namespace rtp_plus_plus
{
#ifdef ENABLE_SCREAM
ScreamScheduler::ScreamScheduler(RtpSession::ptr pRtpSession, TransmissionManager& transmissionManager,
ICooperativeCodec* pCooperative, boost::asio::io_service& ioService,
float fFps, float fMinBps, float fMaxBps)
:RtpScheduler(pRtpSession),
m_transmissionManager(transmissionManager),
m_ioService(ioService),
m_timer(m_ioService),
m_pRtpQueue(new RtpQueue()),
m_pScreamTx(new ScreamTx()),
m_pCooperative(pCooperative),
m_uiPreviousKbps(0),
m_uiLastExtendedSNReported(0),
m_uiLastLoss(0)
{
m_tStart = boost::posix_time::microsec_clock::universal_time();
float priority = 1.0f;
m_uiSsrc = pRtpSession->getRtpSessionState().getSSRC();
VLOG(2) << "Registering new scream stream: " << m_uiSsrc;
m_pScreamTx->registerNewStream(m_pRtpQueue, m_uiSsrc, priority, fMinBps, fMaxBps, fFps);
if (m_pCooperative)
{
VLOG(2) << "Cooperative interface has been set";
float fTargetBitrate = m_pScreamTx->getTargetBitrate(m_uiSsrc);
VLOG(2) << "### SCREAM ###: Scream target bitrate: " << fTargetBitrate << "bps";
uint32_t uiKbps = static_cast<uint32_t>(fTargetBitrate/1000.0);
m_pCooperative->setBitrate(uiKbps);
m_uiPreviousKbps = uiKbps;
}
}
ScreamScheduler::~ScreamScheduler()
{
// could add stop method?
m_timer.cancel();
delete m_pScreamTx;
}
void ScreamScheduler::scheduleRtpPackets(const std::vector<RtpPacket>& vRtpPackets)
{
VLOG(12) << "Scheduling RTP packets: SSRC " << hex(m_uiSsrc);
uint32_t ssrc = 0;
void *rtpPacketDummy = 0;
int size = 0;
uint16_t seqNr = 0;
float retVal = -1.0;
static float time = 0.0;
for (const RtpPacket& rtpPacket: vRtpPackets)
{
VLOG(12) << "Pushing RTP packet: SN: " << rtpPacket.getSequenceNumber() << " Size: " << rtpPacket.getSize();
// from VideoEnc.cpp
m_pRtpQueue->push(0, rtpPacket.getSize(), rtpPacket.getSequenceNumber(), time);
// store in our own map
m_mRtpPackets[rtpPacket.getSequenceNumber()] = rtpPacket;
}
// FIXME: HACK for now
time += 0.03;
boost::posix_time::ptime tNow = boost::posix_time::microsec_clock::universal_time();
uint64_t uiTimeUs = (tNow - m_tStart).total_microseconds();
uint32_t uiTotalBytes = std::accumulate(vRtpPackets.begin(), vRtpPackets.end(), 0, [](int sum, const RtpPacket& rtpPacket){ return sum + rtpPacket.getSize(); });
if (m_pCooperative)
{
float fTargetBitrate = m_pScreamTx->getTargetBitrate(m_uiSsrc);
VLOG(2) << "### SCREAM ###: Scream target bitrate: " << fTargetBitrate << "bps";
uint32_t uiKbps = static_cast<uint32_t>(fTargetBitrate/1000.0);
if (uiKbps != m_uiPreviousKbps)
m_pCooperative->setBitrate(uiKbps);
}
VLOG(2) << "### SCREAM ###: Calling new media frame: time_us: " << uiTimeUs << " SSRC: " << m_uiSsrc << " total bytes: " << uiTotalBytes;
m_pScreamTx->newMediaFrame(uiTimeUs, m_uiSsrc, uiTotalBytes);
retVal = m_pScreamTx->isOkToTransmit(uiTimeUs, ssrc);
if (ENABLE_SCREAM_LOG)
{
LOG(INFO) << m_pScreamTx->printLog(uiTimeUs);
}
VLOG_IF(12, retVal != -1) << "### SCREAM ###: isOkToTransmit: " << retVal << " ssrc: " << ssrc;
while (retVal == 0)
{
/*
* RTP packet can be transmitted
*/
if (m_pRtpQueue->sendPacket(rtpPacketDummy, size, seqNr))
{
VLOG(12) << "Retrieved packet from queue: SN: " << seqNr << " size: " << size;
// netQueueRate->insert(time,rtpPacket, ssrc, size, seqNr);
RtpPacket rtpPacket = m_mRtpPackets[seqNr];
m_mRtpPackets.erase(seqNr);
VLOG(2) << "Sending RTP packet in session: SN: " << rtpPacket.getSequenceNumber() << " Size: " << rtpPacket.getSize();
m_pRtpSession->sendRtpPacket(rtpPacket);
VLOG(2) << "### SCREAM ###: time_us: " << uiTimeUs << " ssrc: " << ssrc << " size: " << size << " seqNr: " << seqNr;
retVal = m_pScreamTx->addTransmitted(uiTimeUs, ssrc, size, seqNr);
VLOG_IF(12, retVal > 0.0) << "### SCREAM ###: addTransmitted: " << retVal;
}
else
{
VLOG(12) << "Failed to retrieve rtp packet from RTP queue";
retVal = -1.0;
}
}
if (retVal > 0)
{
int milliseconds = (int)(retVal * 1000);
VLOG(12) << "Starting timer in : " << milliseconds << " ms";
m_timer.expires_from_now(boost::posix_time::milliseconds(milliseconds));
m_timer.async_wait(boost::bind(&ScreamScheduler::onScheduleTimeout, this, boost::asio::placeholders::error));
}
}
void ScreamScheduler::onScheduleTimeout(const boost::system::error_code& ec )
{
if (!ec)
{
boost::posix_time::ptime tNow = boost::posix_time::microsec_clock::universal_time();
uint64_t uiTimeUs = (tNow - m_tStart).total_microseconds();
uint32_t ssrc = 0;
float retVal = m_pScreamTx->isOkToTransmit(uiTimeUs, ssrc);
VLOG(12) << "### SCREAM ###: isOkToTransmit: " << retVal << " ssrc: " << ssrc;
while (retVal == 0.0)
{
/*
* RTP packet can be transmitted
*/
void *rtpPacketDummy = 0;
int size = 0;
uint16_t seqNr = 0;
if (m_pRtpQueue->sendPacket(rtpPacketDummy, size, seqNr))
{
VLOG(12) << "### SCREAM ###: Retrieved packet from queue: SN: " << seqNr << " size: " << size;
// netQueueRate->insert(time,rtpPacket, ssrc, size, seqNr);
RtpPacket rtpPacket = m_mRtpPackets[seqNr];
m_mRtpPackets.erase(seqNr);
VLOG(2) << "ScreamScheduler::onScheduleTimeout Sending RTP packet in session: SN: " << rtpPacket.getSequenceNumber() << " Size: " << rtpPacket.getSize();
m_pRtpSession->sendRtpPacket(rtpPacket);
retVal = m_pScreamTx->addTransmitted(uiTimeUs, ssrc, size, seqNr);
VLOG(12) << "### SCREAM ###: ScreamScheduler::onScheduleTimeout addTransmitted: " << retVal;
if (ENABLE_SCREAM_LOG)
{
LOG(INFO) << m_pScreamTx->printLog(uiTimeUs);
}
}
else
{
VLOG(2) << "Failed to retrieve rtp packet from RTP queue";
retVal = -1.0;
}
}
if (retVal > 0.0)
{
int milliseconds = (int)(retVal * 1000);
VLOG(12) << "Starting timer in : " << milliseconds << " ms";
m_timer.expires_from_now(boost::posix_time::milliseconds(milliseconds));
m_timer.async_wait(boost::bind(&ScreamScheduler::onScheduleTimeout, this, boost::asio::placeholders::error));
}
}
}
void ScreamScheduler::scheduleRtxPacket(const RtpPacket& rtpPacket)
{
}
void ScreamScheduler::shutdown()
{
}
void ScreamScheduler::updateScreamParameters(uint32_t uiSSRC, uint32_t uiJiffy, uint32_t uiHighestSNReceived, uint32_t uiCumuLoss)
{
boost::posix_time::ptime tNow = boost::posix_time::microsec_clock::universal_time();
uint64_t uiTimeUs = (tNow - m_tStart).total_microseconds();
LOG(INFO) << "### SCREAM ###" << "time_us: " << uiTimeUs
<< " SSRC: " << uiSSRC
<< " Jiffy: " << uiJiffy
<< " highest SN: " << uiHighestSNReceived
<< " loss: " << uiCumuLoss;
m_pScreamTx->incomingFeedback(uiTimeUs, uiSSRC, uiJiffy, uiHighestSNReceived, uiCumuLoss, false);
float retVal = m_pScreamTx->isOkToTransmit(uiTimeUs, uiSSRC);
if (ENABLE_SCREAM_LOG)
{
LOG(INFO) << m_pScreamTx->printLog(uiTimeUs);
}
// TODO: do we need to cancel an existing timer here?
if (retVal > 0.0)
{
int milliseconds = (int)(retVal * 1000);
VLOG(12) << "### SCREAM ###: Starting timer in : " << milliseconds << " ms";
m_timer.expires_from_now(boost::posix_time::milliseconds(milliseconds));
m_timer.async_wait(boost::bind(&ScreamScheduler::onScheduleTimeout, this, boost::asio::placeholders::error));
}
}
void ScreamScheduler::processFeedback(const rfc4585::RtcpFb& fb, const EndPoint& ep)
{
if (fb.getTypeSpecific() == experimental::TL_FB_SCREAM_JIFFY)
{
const experimental::RtcpScreamFb& screamFb = static_cast<const experimental::RtcpScreamFb&>(fb);
VLOG(2) << "Received scream jiffy: SSRC: " << hex(screamFb.getSenderSSRC())
<< " jiffy: " << screamFb.getJiffy()
<< " highest SN: " << screamFb.getHighestSNReceived()
<< " lost: " << screamFb.getLost();
updateScreamParameters(screamFb.getSenderSSRC(), screamFb.getJiffy(), screamFb.getHighestSNReceived(), screamFb.getLost());
}
}
std::vector<rfc4585::RtcpFb::ptr> ScreamScheduler::retrieveFeedback()
{
std::vector<rfc4585::RtcpFb::ptr> feedback;
// add SCReaAM feedback
uint32_t uiHighestSN = m_transmissionManager.getLastReceivedExtendedSN();
VLOG(2) << "ScreamScheduler::retrieveFeedback: highest SN: " << uiHighestSN << " last reported: " << m_uiLastExtendedSNReported;
if (m_uiLastExtendedSNReported != uiHighestSN) // only report if there is new info
{
VLOG(2) << "RtpSessionManager::onFeedbackGeneration: Reporting new scream info";
m_uiLastExtendedSNReported = uiHighestSN;
boost::posix_time::ptime tLastTime = m_transmissionManager.getPacketArrivalTime(uiHighestSN);
boost::posix_time::ptime tInitial = m_transmissionManager.getInitialPacketArrivalTime();
uint32_t uiJiffy = (tLastTime - tInitial).total_milliseconds();
m_uiLastLoss = m_pRtpSession->getCumulativeLostAsReceiver();
RtpSessionState& state = m_pRtpSession->getRtpSessionState();
experimental::RtcpScreamFb::ptr pFb = experimental::RtcpScreamFb::create(uiJiffy, m_uiLastExtendedSNReported, m_uiLastLoss, state.getRemoteSSRC(), state.getSSRC());
feedback.push_back(pFb);
}
return feedback;
}
#endif
} // rtp_plus_plus
| 36.909434 | 168 | 0.668541 | miseri |
ef4d636592f368cd1c7e37220031970fa1899ad0 | 3,628 | cpp | C++ | src/main.cpp | alex-spataru/RFID-Manager | 6d7ad667f520466b8a5d3553b6b5b3dc6d2be18f | [
"MIT"
] | 2 | 2020-05-15T09:44:10.000Z | 2022-01-11T11:19:36.000Z | src/main.cpp | alex-spataru/RFID-Manager | 6d7ad667f520466b8a5d3553b6b5b3dc6d2be18f | [
"MIT"
] | null | null | null | src/main.cpp | alex-spataru/RFID-Manager | 6d7ad667f520466b8a5d3553b6b5b3dc6d2be18f | [
"MIT"
] | null | null | null | /*
* Copyright (c) 2019 Alex Spataru <https://github.com/alex-spataru>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <QApplication>
#include <QStyleFactory>
#include "AppInfo.h"
#include "MainWindow.h"
/**
* @brief Main entry point of the application
* @param argc argument count
* @param argv argument data
* @return @c qApp event loop exit code
*/
int main(int argc, char** argv)
{
// Set application attributes
QApplication::setApplicationName(APP_NAME);
QApplication::setApplicationVersion(APP_VERSION);
QApplication::setAttribute(Qt::AA_NativeWindows, true);
QApplication::setAttribute(Qt::AA_DisableHighDpiScaling, true);
// Create QApplication and change widget style to Fusion
QApplication app(argc, argv);
app.setStyle(QStyleFactory::create("Fusion"));
// Increase font size for better reading
QFont f = QApplication::font();
f.setPointSize(f.pointSize() + 2);
app.setFont(f);
// Generate dark color palette
QPalette p;
p.setColor(QPalette::Text, QColor(0xff, 0xff, 0xff));
p.setColor(QPalette::Base, QColor(0x2a, 0x2a, 0x2a));
p.setColor(QPalette::Dark, QColor(0x23, 0x23, 0x23));
p.setColor(QPalette::Link, QColor(0x2a, 0x82, 0xda));
p.setColor(QPalette::Window, QColor(0x35, 0x35, 0x35));
p.setColor(QPalette::Shadow, QColor(0x14, 0x14, 0x14));
p.setColor(QPalette::Button, QColor(0x35, 0x35, 0x35));
p.setColor(QPalette::Highlight, QColor(0x2a, 0x82, 0xda));
p.setColor(QPalette::BrightText, QColor(0xff, 0x00, 0x00));
p.setColor(QPalette::WindowText, QColor(0xff, 0xff, 0xff));
p.setColor(QPalette::ButtonText, QColor(0xff, 0xff, 0xff));
p.setColor(QPalette::ToolTipBase, QColor(0xff, 0xff, 0xff));
p.setColor(QPalette::ToolTipText, QColor(0xff, 0xff, 0xff));
p.setColor(QPalette::AlternateBase, QColor(0x42, 0x42, 0x42));
p.setColor(QPalette::HighlightedText, QColor(0xff, 0xff, 0xff));
p.setColor(QPalette::Disabled, QPalette::Text, QColor(0x7f, 0x7f, 0x7f));
p.setColor(QPalette::Disabled, QPalette::Highlight, QColor(0x50, 0x50, 0x50));
p.setColor(QPalette::Disabled, QPalette::WindowText, QColor(0x7f, 0x7f, 0x7f));
p.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(0x7f, 0x7f, 0x7f));
p.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(0x7f, 0x7f,0x7f));
// Change application palette
app.setPalette(p);
// Create MainWindow instance
MainWindow window;
window.showNormal();
// Begin qApp event loop
return app.exec();
}
| 42.682353 | 87 | 0.712514 | alex-spataru |
ef54b3dd95b4ca99180b18e52595461ec87ef8f8 | 1,212 | cpp | C++ | src/datatypes.cpp | arjun-menon/vcalc | 899c890b100ce33fb4bf2f94653c57d1a1997bc7 | [
"Apache-2.0"
] | 1 | 2019-07-16T08:25:52.000Z | 2019-07-16T08:25:52.000Z | src/datatypes.cpp | arjun-menon/vcalc | 899c890b100ce33fb4bf2f94653c57d1a1997bc7 | [
"Apache-2.0"
] | null | null | null | src/datatypes.cpp | arjun-menon/vcalc | 899c890b100ce33fb4bf2f94653c57d1a1997bc7 | [
"Apache-2.0"
] | null | null | null | #include "common.hpp"
map<string, weak_ptr<Symbol>> Symbol::existingSymbols;
shared_ptr<Symbol> Symbol::create(const string &name)
{
if(existingSymbols.find(name) != existingSymbols.end())
if(auto symbol = existingSymbols[name].lock())
return symbol;
auto symbol = shared_ptr<Symbol>(new Symbol(name));
existingSymbols[name] = symbol;
return symbol;
}
shared_ptr<Symbol> List::open = Symbol::create("(");
shared_ptr<Symbol> List::close = Symbol::create(")");
ostream& List::display(ostream &o) const {
o << '(';
for(auto i = lst.begin() ;; i++) {
if (i == lst.end()) {
o << ')';
break;
}
if (i != lst.begin()) {
o << ' ';
}
o << **i;
}
return o;
}
shared_ptr<Symbol> Function::args = Symbol::create("args");
shared_ptr<Symbol> Function::lhs = Symbol::create("lhs");
ostream& Function::display(ostream &o) const {
o << "function<";
if(!symbol.expired())
symbol.lock()->display(o);
else
o << "lambda";
return o << ">";
}
ostream& Real::display(ostream &o) const {
if (isValid())
o << val;
else
o << "NaN";
return o;
}
| 22.867925 | 59 | 0.55033 | arjun-menon |
ef57e19d35c66ec5bf8b193fd9e2be0d99dc4bbb | 5,165 | hxx | C++ | projects/Phantom/phantom/lang/MethodPointer.hxx | vlmillet/phantom | e5579ea52dafded64fd2fe88aabfdf8a73534918 | [
"MIT"
] | 12 | 2019-12-26T00:55:39.000Z | 2020-12-03T14:46:56.000Z | projects/Phantom/phantom/lang/MethodPointer.hxx | vlmillet/Phantom | e5579ea52dafded64fd2fe88aabfdf8a73534918 | [
"MIT"
] | null | null | null | projects/Phantom/phantom/lang/MethodPointer.hxx | vlmillet/Phantom | e5579ea52dafded64fd2fe88aabfdf8a73534918 | [
"MIT"
] | 1 | 2020-12-09T11:47:13.000Z | 2020-12-09T11:47:13.000Z | #pragma once
// haunt {
// clang-format off
#include "MethodPointer.h"
#if defined(_MSC_VER)
# pragma warning(push, 0)
#elif defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wall"
# pragma clang diagnostic ignored "-Wextra"
#endif
#include <phantom/namespace>
#include <phantom/package>
#include <phantom/source>
#include <phantom/class>
#include <phantom/method>
#include <phantom/static_method>
#include <phantom/constructor>
#include <phantom/field>
#include <phantom/using>
#include <phantom/friend>
#include <phantom/template-only-push>
#include <phantom/utils/SmallString.hxx>
#include <phantom/utils/StringView.hxx>
#include <phantom/template-only-pop>
namespace phantom {
namespace lang {
PHANTOM_PACKAGE("phantom.lang")
PHANTOM_SOURCE("MethodPointer")
#if PHANTOM_NOT_TEMPLATE
PHANTOM_CLASS(MethodPointer)
{
using Modifiers = typedef_< phantom::lang::Modifiers>;
using StringBuffer = typedef_< phantom::StringBuffer>;
using StringView = typedef_< phantom::StringView>;
using TypesView = typedef_< phantom::lang::TypesView>;
this_()(PHANTOM_R_FLAG_NO_COPY)
.inherits<::phantom::lang::MemberPointer>()
.public_()
.method<void(::phantom::lang::LanguageElementVisitor *, ::phantom::lang::VisitorData), virtual_|override_>("visit", &_::visit)({"a_pVisitor","a_Data"})
.public_()
.staticMethod<::phantom::lang::Class *()>("MetaClass", &_::MetaClass)
.public_()
.constructor<void(ClassType*, FunctionType*, Modifiers, uint)>()({"a_pObjectType","a_pFunctionType","a_Modifiers","a_uiFlags"})["0"]["0"]
.protected_()
.constructor<void(ClassType*, FunctionType*, size_t, size_t, Modifiers, uint)>()({"a_pObjectType","a_pFunctionType","a_Size","a_Alignment","a_Modifiers","a_uiFlags"})
.public_()
.method<void()>("initialize", &_::initialize)
.method<bool(TypesView, Modifiers, uint) const>("matches", &_::matches)({"parameters","a_Modifiers","a_uiFlags"})["0"]["0"]
/// missing symbol(s) reflection (phantom::Closure) -> use the 'haunt.bind' to bind symbols with your custom haunt files
// .method<::phantom::Closure(void*) const, virtual_>("getClosure", &_::getClosure)({"a_pPointer"})
.method<MethodPointer*() const, virtual_|override_>("asMethodPointer", &_::asMethodPointer)
.method<void(StringView, void*) const, virtual_|override_>("valueFromString", &_::valueFromString)({"a_str","dest"})
.method<void(StringBuffer&, const void*) const, virtual_|override_>("valueToString", &_::valueToString)({"a_Buf","src"})
.method<void(StringBuffer&, const void*) const, virtual_|override_>("valueToLiteral", &_::valueToLiteral)({"a_Buf","src"})
.method<bool() const, virtual_|override_>("isCopyable", &_::isCopyable)
.method<FunctionType*() const>("getFunctionType", &_::getFunctionType)
.method<Type*() const>("getReturnType", &_::getReturnType)
.method<Type*(size_t) const>("getParameterType", &_::getParameterType)({"i"})
.method<size_t() const>("getParameterTypeCount", &_::getParameterTypeCount)
.method<TypesView() const>("getParameterTypes", &_::getParameterTypes)
.method<Type*() const>("getImplicitObjectParameterType", &_::getImplicitObjectParameterType)
.method<bool(Type*) const>("acceptsCallerExpressionType", &_::acceptsCallerExpressionType)({"a_pType"})
.method<bool(Modifiers) const>("acceptsCallerExpressionQualifiers", &_::acceptsCallerExpressionQualifiers)({"a_CallerQualifiers"})
.method<void(void*, void**) const>("call", &_::call)({"a_pPointer","a_pArgs"})
.method<void(void*, void**, void*) const>("call", &_::call)({"a_pPointer","a_pArgs","a_pReturnAddress"})
.method<void(void*, void*, void**) const, virtual_>("call", &_::call)({"a_pPointer","a_pThis","a_pArgs"})
.method<void(void*, void*, void**, void*) const, virtual_>("call", &_::call)({"a_pPointer","a_pThis","a_pArgs","a_pReturnAddress"})
.method<void(StringBuffer&) const, virtual_|override_>("getQualifiedName", &_::getQualifiedName)({"a_Buf"})
.method<void(StringBuffer&) const, virtual_|override_>("getDecoratedName", &_::getDecoratedName)({"a_Buf"})
.method<void(StringBuffer&) const, virtual_|override_>("getQualifiedDecoratedName", &_::getQualifiedDecoratedName)({"a_Buf"})
.using_("LanguageElement::getQualifiedName")
.using_("LanguageElement::getDecoratedName")
.using_("LanguageElement::getQualifiedDecoratedName")
.protected_()
.field("m_pFunctionType", &_::m_pFunctionType)
;
}
#endif // PHANTOM_NOT_TEMPLATE
PHANTOM_END("MethodPointer")
PHANTOM_END("phantom.lang")
}
}
#if defined(_MSC_VER)
# pragma warning(pop)
#elif defined(__clang__)
# pragma clang diagnostic pop
#endif
// clang-format on
// haunt }
| 47.385321 | 178 | 0.654985 | vlmillet |
ef5827aab40050c59a3fa830f0a790c1ec13ebad | 2,133 | cpp | C++ | Plugins/ChromeDevTools/Source/ChromeDevToolsJSI.cpp | EricBeetsOfficial-Opuscope/BabylonNative | fc7b2add9da4ef8e79ad86e087457685bdb2417f | [
"MIT"
] | 474 | 2019-05-29T09:41:22.000Z | 2022-03-31T12:09:35.000Z | Plugins/ChromeDevTools/Source/ChromeDevToolsJSI.cpp | chrisfromwork/BabylonNative | 18455a1ac3363354040030adee39cd666c31df68 | [
"MIT"
] | 593 | 2019-05-31T23:56:36.000Z | 2022-03-31T19:25:09.000Z | Plugins/ChromeDevTools/Source/ChromeDevToolsJSI.cpp | chrisfromwork/BabylonNative | 18455a1ac3363354040030adee39cd666c31df68 | [
"MIT"
] | 114 | 2019-06-10T18:07:19.000Z | 2022-03-11T21:13:27.000Z | #include "ChromeDevTools.h"
#include <V8JsiRuntime.h>
#include <Babylon/JsRuntime.h>
namespace Babylon::Plugins
{
class ChromeDevTools::Impl final : public std::enable_shared_from_this<ChromeDevTools::Impl>
{
public:
explicit Impl(Napi::Env env)
: m_env(env)
{
JsRuntime::GetFromJavaScript(env).Dispatch([this](Napi::Env env) {
m_runtime = JsRuntime::NativeObject::GetFromJavaScript(env).Get("_JSIRuntime").As<Napi::External<facebook::jsi::Runtime>>().Data();
});
}
~Impl()
{
}
bool SupportsInspector()
{
return true;
}
void StartInspector(const unsigned short, const std::string&)
{
JsRuntime::GetFromJavaScript(m_env).Dispatch([this](Napi::Env) {
if (m_runtime != nullptr)
{
v8runtime::openInspector(*m_runtime);
}
});
}
void StopInspector()
{
}
private:
facebook::jsi::Runtime* m_runtime;
Napi::Env m_env;
};
ChromeDevTools ChromeDevTools::Initialize(Napi::Env env)
{
return {std::make_shared<ChromeDevTools::Impl>(env)};
}
ChromeDevTools::ChromeDevTools(std::shared_ptr<ChromeDevTools::Impl> impl)
: m_impl{std::move(impl)}
{
}
bool ChromeDevTools::SupportsInspector() const
{
return m_impl->SupportsInspector();
}
/*
Note: V8JSI doesn't currently support setting the port or appName at runtime.
For now the port is set to 5643 in AppRuntimeJSI.cpp.
*/
void ChromeDevTools::StartInspector(const unsigned short port, const std::string& appName) const
{
m_impl->StartInspector(port, appName);
}
/* Note: V8JSI doesn't currently have a method for stopping the inspector at runtime. */
void ChromeDevTools::StopInspector() const
{
m_impl->StopInspector();
}
}
| 27.701299 | 151 | 0.551805 | EricBeetsOfficial-Opuscope |
ef5f5cb056e96601973b80f8e642f8e1836a00d5 | 7,455 | cpp | C++ | TimothE/ResourceManager.cpp | Timothy-Needs-to-Die/TimothE | d4f458c166c15f8cb22095ade9c198bd30729f65 | [
"Apache-2.0"
] | null | null | null | TimothE/ResourceManager.cpp | Timothy-Needs-to-Die/TimothE | d4f458c166c15f8cb22095ade9c198bd30729f65 | [
"Apache-2.0"
] | 5 | 2022-01-17T13:05:42.000Z | 2022-01-28T12:40:00.000Z | TimothE/ResourceManager.cpp | Timothy-Needs-to-Die/TimothE | d4f458c166c15f8cb22095ade9c198bd30729f65 | [
"Apache-2.0"
] | null | null | null | #include "pch.h"
#include "ResourceManager.h"
#include "Core/Graphics/OpenGLError.h"
#include "FarmScene.h"
#include "MainMenuScene.h"
#include "Dirent.h"
#include "misc/cpp/imgui_stdlib.h"
#include "FarmScene.h"
#include "TownScene.h"
std::map<std::string, Texture2D*> ResourceManager::_textures;
std::map<std::string, Shader*> ResourceManager::_shaders;
std::map<std::string, Scene*> ResourceManager::_scenes;
std::map<std::string, SpriteSheet*> ResourceManager::_spritesheets;
std::map<std::string, Font*> ResourceManager::_fonts;
std::string ResourceManager::_UID;
void ResourceManager::Init()
{
_UID = UID::GenerateUID();
//LOAD TEXTURES
ResourceManager::InstantiateTexture("lenna", new Texture2D("lenna3.jpg"));
ResourceManager::InstantiateTexture("fish", new Texture2D("Fish.png"));
ResourceManager::InstantiateTexture("player", new Texture2D("Resources/Images/Spritesheets/PlayerSpritesheet.png", true));
ResourceManager::InstantiateTexture("enemy", new Texture2D("Resources/Images/Spritesheets/EnemySpritesheet.png", true));
ResourceManager::InstantiateTexture("bed", new Texture2D("Resources/Images/Bed.png", true));
ResourceManager::InstantiateTexture("cropspritesheet", new Texture2D("Resources/Images/Spritesheets/CropsSheet.png", true));
ResourceManager::InstantiateTexture("spritesheet", new Texture2D("Resources/Images/Spritesheets/RPGpack_sheet.png", true));
ResourceManager::InstantiateTexture("medispritesheet", new Texture2D("Resources/Images/Spritesheets/MediSprites.png", true));
ResourceManager::InstantiateTexture("roguespritesheet", new Texture2D("Resources/Images/Spritesheets/RogueSprites.png", true));
ResourceManager::InstantiateTexture("itemspritesheet", new Texture2D("Resources/Images/Spritesheets/ItemsSheet.png", true));
ResourceManager::InstantiateTexture("animalspritesheet", new Texture2D("Resources/Images/Spritesheets/AnimalSheet.png", true));
ResourceManager::InstantiateTexture("extraspritesheet", new Texture2D("Resources/Images/Spritesheets/ExtraSpriteSheet.png", true));
ResourceManager::InstantiateTexture("buildspritesheet", new Texture2D("Resources/Images/Spritesheets/BuildingSheet.png", true));
ResourceManager::InstantiateTexture("build2spritesheet", new Texture2D("Resources/Images/Spritesheets/BuildingSheet2.png", true));
ResourceManager::InstantiateTexture("Button", new Texture2D("Resources/Images/ButtonTest.png"));
ResourceManager::InstantiateTexture("swords", new Texture2D("Resources/Images/swords.png", true));
ResourceManager::InstantiateTexture("axes", new Texture2D("Resources/Images/axes.png"));
ResourceManager::InstantiateTexture("pickaxes", new Texture2D("Resources/Images/pickaxes.png"));
ResourceManager::InstantiateTexture("small_stone", new Texture2D("Resources/Images/Rock.png"));
ResourceManager::InstantiateTexture("small_wood", new Texture2D("Resources/Images/TreeStump.png"));
ResourceManager::InstantiateTexture("small_metal", new Texture2D("Resources/Images/Metal.png"));
ResourceManager::InstantiateTexture("small_coal", new Texture2D("Resources/Images/Coal.png"));
ResourceManager::InstantiateTexture("planks", new Texture2D("Resources/Images/Planks.png"));
ResourceManager::InstantiateTexture("wall", new Texture2D("Resources/Images/Wall.png", true));
ResourceManager::InstantiateTexture("tower", new Texture2D("Resources/Images/Tower.png", true));
ResourceManager::InstantiateTexture("fireball", new Texture2D("Resources/Images/Fireball.png", true));
ResourceManager::InstantiateTexture("whiteTexture", new Texture2D("Resources/Images/whiteTexture.png"));
ResourceManager::InstantiateTexture("campfire", new Texture2D("Resources/Images/Campfire.png", true));
ResourceManager::InstantiateTexture("gameover_bg", new Texture2D("Resources/Images/Game Over.png", true));
//LOAD SPRITESHEETS
ResourceManager::InstantiateSpritesheet("spritesheet", new SpriteSheet(ResourceManager::GetTexture("spritesheet"), 64, 64, "spritesheet"));
ResourceManager::InstantiateSpritesheet("medispritesheet", new SpriteSheet(ResourceManager::GetTexture("medispritesheet"), 64, 64, "medispritesheet"));
ResourceManager::InstantiateSpritesheet("itemspritesheet", new SpriteSheet(ResourceManager::GetTexture("itemspritesheet"), 128, 128, "itemspritesheet"));
ResourceManager::InstantiateSpritesheet("cropspritesheet", new SpriteSheet(ResourceManager::GetTexture("cropspritesheet"), 32, 32, "cropspritesheet"));
ResourceManager::InstantiateSpritesheet("roguespritesheet", new SpriteSheet(ResourceManager::GetTexture("roguespritesheet"), 17, 17, "roguespritesheet"));
ResourceManager::InstantiateSpritesheet("animalspritesheet", new SpriteSheet(ResourceManager::GetTexture("animalspritesheet"), 32, 32, "animalspritesheet"));
ResourceManager::InstantiateSpritesheet("extraspritesheet", new SpriteSheet(ResourceManager::GetTexture("extraspritesheet"), 15, 15, "extraspritesheet"));
ResourceManager::InstantiateSpritesheet("buildspritesheet", new SpriteSheet(ResourceManager::GetTexture("buildspritesheet"), 32, 32, "buildspritesheet"));
ResourceManager::InstantiateSpritesheet("build2spritesheet", new SpriteSheet(ResourceManager::GetTexture("build2spritesheet"), 32, 32, "buildspritesheet"));
ResourceManager::InstantiateSpritesheet("swords", new SpriteSheet(ResourceManager::GetTexture("swords"), 16, 16, "swords"));
ResourceManager::InstantiateSpritesheet("axes", new SpriteSheet(ResourceManager::GetTexture("axes"), 16, 16, "axes"));
ResourceManager::InstantiateSpritesheet("pickaxes", new SpriteSheet(ResourceManager::GetTexture("pickaxes"), 16, 16, "pickaxes"));
ResourceManager::InstantiateSpritesheet("planks", new SpriteSheet(ResourceManager::GetTexture("planks"), 64, 64, "pickaxes"));
//LOAD SHADERS
ResourceManager::InstantiateShader("ui", new Shader("vr_UIShader.vert", "fr_UIShader.frag"));
ResourceManager::InstantiateShader("default", new Shader("VertexShader.vert", "FragmentShader.frag"));
//LOAD SCENES
ResourceManager::InstantiateScene("MainMenuScene", new MainMenuScene("MainMenuScene"));
ResourceManager::InstantiateScene("FarmScene", new FarmScene("FarmScene"));
ResourceManager::InstantiateScene("TownScene", new TownScene("TownScene"));
//LOAD FONTS
LoadFonts();
//LOAD SOUNDS
}
void ResourceManager::Shutdown()
{
for (auto& tex : _textures)
{
unsigned int id = tex.second->GetID();
GLCall(glDeleteTextures(1, &id));
}
_textures.clear();
_shaders.clear();
_scenes.clear();
}
void ResourceManager::LoadFonts()
{
std::ofstream fileStream("./fonts");
_fonts.clear();
DIR* directory = opendir("./fonts");
struct dirent* dirent;
if (directory)
{
while ((dirent = readdir(directory)) != NULL)
{
if (dirent->d_type == 32768)
{
std::string fn = "fonts/" + std::string(dirent->d_name);
InstantiateFont(dirent->d_name, new Font(fn));
std::cout << "Font loaded: " << dirent->d_name << std::endl;
}
}
closedir(directory);
}
}
void ResourceManager::InstantiateTexture(std::string name, Texture2D* texture)
{
_textures[name] = texture;
};
void ResourceManager::InstantiateShader(std::string name, Shader* shader)
{
_shaders[name] = shader;
};
void ResourceManager::InstantiateScene(std::string name, Scene* scene)
{
_scenes[name] = scene;
}
void ResourceManager::InstantiateSpritesheet(std::string name, SpriteSheet* spritesheet)
{
_spritesheets[name] = spritesheet;
}
void ResourceManager::InstantiateFont(std::string name, Font* font)
{
_fonts[name] = font;
} | 51.770833 | 158 | 0.779745 | Timothy-Needs-to-Die |
ef62b91f0ec7b8260e7193f6b28ce8d08b489b88 | 6,197 | cpp | C++ | ionGUI/ionGUI.cpp | iondune/ionEngine | 7ce3394dafbabf0e0bb9f5d07dbfae31161800d4 | [
"MIT"
] | 36 | 2015-06-28T14:53:06.000Z | 2021-10-31T04:26:53.000Z | ionGUI/ionGUI.cpp | iondune/ionEngine | 7ce3394dafbabf0e0bb9f5d07dbfae31161800d4 | [
"MIT"
] | 90 | 2015-05-01T07:21:43.000Z | 2017-08-30T01:16:41.000Z | ionGUI/ionGUI.cpp | iondune/ionEngine | 7ce3394dafbabf0e0bb9f5d07dbfae31161800d4 | [
"MIT"
] | 9 | 2016-04-08T07:48:02.000Z | 2019-07-22T15:13:53.000Z |
#include "ionGUI.h"
using namespace ion;
namespace ImGui
{
bool SliderDouble(const char * label, double * v, double v_min, double v_max, const char * display_format, double power)
{
float temp = (float) *v;
if (SliderFloat(label, &temp, (float) v_min, (float) v_max, display_format, (float) power))
{
*v = (double) temp;
return true;
}
else
{
return false;
}
}
bool ColorEdit3(const char * label, color3f & Color)
{
float c[3] = { Color.Red, Color.Green, Color.Blue };
if (ImGui::ColorEdit3(label, c))
{
Color = color3f(c[0], c[1], c[2]);
return true;
}
return false;
}
bool ColorEdit3(const char * label, color3i & Color)
{
color3f c = Color;
if (ColorEdit3(label, c))
{
Color = c;
return true;
}
return false;
}
bool ColorEdit4(const char * label, color4f & Color)
{
float c[4] = { Color.Red, Color.Green, Color.Blue, Color.Alpha };
if (ImGui::ColorEdit4(label, c))
{
Color = color4f(c[0], c[1], c[2], c[3]);
return true;
}
return false;
}
bool ColorEdit4(const char * label, color4i & Color)
{
color4f c = Color;
if (ColorEdit4(label, c))
{
Color = c;
return true;
}
return false;
}
bool ColorPicker3(const char* label, ion::color3f & Color)
{
float c[3] = { Color.Red, Color.Green, Color.Blue };
if (ImGui::ColorPicker3(label, c))
{
Color = color3f(c[0], c[1], c[2]);
return true;
}
return false;
}
bool ColorPicker3(const char* label, ion::color3i & Color)
{
color3f c = Color;
if (ColorPicker3(label, c))
{
Color = c;
return true;
}
return false;
}
bool ColorPicker4(const char* label, ion::color4f & Color)
{
float c[4] = { Color.Red, Color.Green, Color.Blue, Color.Alpha };
if (ImGui::ColorPicker4(label, c))
{
Color = color4f(c[0], c[1], c[2], c[3]);
return true;
}
return false;
}
bool ColorPicker4(const char* label, ion::color4i & Color)
{
color4f c = Color;
if (ColorPicker4(label, c))
{
Color = c;
return true;
}
return false;
}
bool DragVec2(const char * label, ion::vec2i & v, float v_speed, int v_min, int v_max, const char * display_format)
{
int vals[2] = { v.X, v.Y };
if (ImGui::DragInt2(label, vals, v_speed, v_min, v_max, display_format))
{
v = vec2i(vals[0], vals[1]);
return true;
}
return false;
}
bool DragVec2(const char * label, vec2f & v, float v_speed, float v_min, float v_max, const char * display_format, float power)
{
float vals[2] = { v.X, v.Y };
if (ImGui::DragFloat2(label, vals, v_speed, v_min, v_max, display_format, power))
{
v = vec2f(vals[0], vals[1]);
return true;
}
return false;
}
bool DragVec3(const char * label, ion::vec3i & v, float v_speed, int v_min, int v_max, const char* display_format)
{
int vals[3] = { v.X, v.Y, v.Z };
if (ImGui::DragInt3(label, vals, v_speed, v_min, v_max, display_format))
{
v = vec3i(vals[0], vals[1], vals[2]);
return true;
}
return false;
}
bool DragVec3(const char * label, vec3f & v, float v_speed, float v_min, float v_max, const char * display_format, float power)
{
float vals[3] = { v.X, v.Y, v.Z };
if (ImGui::DragFloat3(label, vals, v_speed, v_min, v_max, display_format, power))
{
v = vec3f(vals[0], vals[1], vals[2]);
return true;
}
return false;
}
bool SliderVec2(const char * label, ion::vec2i & v, int v_min, int v_max, const char * display_format)
{
int vals[2] = { v.X, v.Y };
if (ImGui::SliderInt2(label, vals, v_min, v_max, display_format))
{
v = vec2i(vals[0], vals[1]);
return true;
}
return false;
}
bool SliderVec2(const char * label, ion::vec2f & v, float v_min, float v_max, const char * display_format, float power)
{
float vals[2] = { v.X, v.Y };
if (ImGui::SliderFloat2(label, vals, v_min, v_max, display_format, power))
{
v = vec2f(vals[0], vals[1]);
return true;
}
return false;
}
bool SliderVec3(const char * label, ion::vec3i & v, int v_min, int v_max, const char * display_format)
{
int vals[3] = { v.X, v.Y, v.Z };
if (ImGui::SliderInt3(label, vals, v_min, v_max, display_format))
{
v = vec3i(vals[0], vals[1], vals[2]);
return true;
}
return false;
}
bool SliderVec3(const char * label, ion::vec3f & v, float v_min, float v_max, const char * display_format, float power)
{
float vals[3] = { v.X, v.Y, v.Z };
if (ImGui::SliderFloat3(label, vals, v_min, v_max, display_format, power))
{
v = vec3f(vals[0], vals[1], vals[2]);
return true;
}
return false;
}
bool Combo(const char * label, int * current_item, std::initializer_list<char const *> const & items, int height_in_items)
{
vector<char const *> items_vec = items;
return ImGui::Combo(label, current_item, items_vec.data(), (int) items.size(), height_in_items);
}
bool Combo(const char * label, int * current_item, std::vector<string> const & items, int height_in_items)
{
vector<char const *> items_vec;
for (string const & item : items)
{
items_vec.push_back(item.c_str());
}
return ImGui::Combo(label, current_item, items_vec.data(), (int) items.size(), height_in_items);
}
bool InputText(const char * label, string & buf, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void * user_data)
{
static vector<char> buffer_copy;
static int const ReserveSpace = 32;
if (buffer_copy.size() < buf.size() + ReserveSpace)
{
buffer_copy.resize(buf.size() + ReserveSpace);
}
strcpy(buffer_copy.data(), buf.c_str());
if (ImGui::InputText(label, buffer_copy.data(), buffer_copy.size(), flags, callback, user_data))
{
buf = buffer_copy.data();
return true;
}
return false;
}
scoped_id::scoped_id(char const * const str_id)
{
ImGui::PushID(str_id);
}
scoped_id::scoped_id(int const int_id)
{
ImGui::PushID(int_id);
}
scoped_id::~scoped_id()
{
ImGui::PopID();
}
}
char const * ion::BoolToString(bool const B)
{
return B ? "yes" : "no";
}
| 23.926641 | 129 | 0.611425 | iondune |
ef64365f574ac3238d50fcfda5a9a1f3d4119b5b | 1,664 | cc | C++ | Source/BladeFramework/source/TimeSource.cc | OscarGame/blade | 6987708cb011813eb38e5c262c7a83888635f002 | [
"MIT"
] | 146 | 2018-12-03T08:08:17.000Z | 2022-03-21T06:04:06.000Z | Source/BladeFramework/source/TimeSource.cc | huangx916/blade | 3fa398f4d32215bbc7e292d61e38bb92aad1ee1c | [
"MIT"
] | 1 | 2019-01-18T03:35:49.000Z | 2019-01-18T03:36:08.000Z | Source/BladeFramework/source/TimeSource.cc | huangx916/blade | 3fa398f4d32215bbc7e292d61e38bb92aad1ee1c | [
"MIT"
] | 31 | 2018-12-03T10:32:43.000Z | 2021-10-04T06:31:44.000Z | /********************************************************************
created: 2010/09/08
filename: TimeSource.cc
author: Crazii
purpose:
*********************************************************************/
#include <BladePCH.h>
#include <TimeSource.h>
namespace Blade
{
//////////////////////////////////////////////////////////////////////////
TimeSource::TimeSource()
{
mTimer = ITimeDevice::create();
mLoopCount = 0;
mLoopTime = 0;
mAverageLoopTime = 0;
mLoopTimeLimit = 0;
mLastTime = mTimer->getSeconds();
}
//////////////////////////////////////////////////////////////////////////
TimeSource::~TimeSource()
{
BLADE_DELETE mTimer;
}
//////////////////////////////////////////////////////////////////////////
void TimeSource::reset()
{
mTimer->reset();
mLoopCount = 0;
mAverageLoopTime = 0;
mLoopTime = 0;
mLastTime = mTimer->getSeconds();
}
//////////////////////////////////////////////////////////////////////////
void TimeSource::update()
{
mTimer->update();
mLoopTime = mTimer->getSeconds() - mLastTime;
mLastTime = mTimer->getSeconds();
if( mLoopTime < 0 )
mLoopTime = 0.0;
if( mLoopTimeLimit != 0 && mLoopTime < mLoopTimeLimit )
mLoopTime = mLoopTimeLimit;
mLoopCount++;
if( mTimer->getMilliseconds() > 1000 * 1000 )//floating point precision
{
mTimer->reset();
mLastTime = 0;
mLoopCount = 0;
mAverageLoopTime = mLoopTime;
//ILog::DebugOutput << TEXT("timer reset.") << ILog::endLog;
}
else
mAverageLoopTime = mTimer->getSeconds() / mLoopCount;
//ILog::DebugOutput << uint( ((scalar)1.0/mLoopTime) ) << ILog::endLog;
}
}//namespace Blade | 24.470588 | 75 | 0.478365 | OscarGame |
ef66959690a9d751b28f80e30ba86dcd4364e351 | 3,963 | cpp | C++ | externals/pantheios-1.0.1-beta214/src/core/api.exitprocess.cpp | betasheet/diffingo | 285d21b16c118155e5c149b20fcb20a20276f3d7 | [
"MIT"
] | null | null | null | externals/pantheios-1.0.1-beta214/src/core/api.exitprocess.cpp | betasheet/diffingo | 285d21b16c118155e5c149b20fcb20a20276f3d7 | [
"MIT"
] | null | null | null | externals/pantheios-1.0.1-beta214/src/core/api.exitprocess.cpp | betasheet/diffingo | 285d21b16c118155e5c149b20fcb20a20276f3d7 | [
"MIT"
] | null | null | null | /* /////////////////////////////////////////////////////////////////////////
* File: src/core/api.exitprocess.cpp
*
* Purpose: Implementation file for Pantheios core API.
*
* Created: 21st June 2005
* Updated: 20th March 2012
*
* Home: http://www.pantheios.org/
*
* Copyright (c) 2005-2012, Matthew Wilson and Synesis Software
* Copyright (c) 1999-2005, Synesis Software and Matthew Wilson
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name(s) of Matthew Wilson and Synesis Software nor the
* names of any contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ////////////////////////////////////////////////////////////////////// */
/* Pantheios header files
*
* NOTE: We do _not_ include pantheios/pantheios.hpp here, since we are
* not using any of the Application Layer.
*/
#include <pantheios/pantheios.h>
#include <pantheios/internal/lean.h>
#include <platformstl/platformstl.h>
#if defined(PLATFORMSTL_OS_IS_WINDOWS)
# include <windows.h>
#else /* ? OS */
# include <stdlib.h>
# include <unistd.h>
#endif /* OS */
/* /////////////////////////////////////////////////////////////////////////
* Namespace
*/
#if !defined(PANTHEIOS_NO_NAMESPACE)
namespace pantheios
{
#endif /* !PANTHEIOS_NO_NAMESPACE */
/* /////////////////////////////////////////////////////////////////////////
* Core functions
*/
#if !defined(PANTHEIOS_NO_NAMESPACE)
namespace core
{
#endif /* !PANTHEIOS_NO_NAMESPACE */
PANTHEIOS_CALL(void) pantheios_exitProcess(int code)
{
#if defined(PLATFORMSTL_OS_IS_WINDOWS)
// By rights, Windows programs should use exit() to close down. However,
// pantheios_exit_process() is not a general substitute for exit(). It is
// specifically intended to Get-Out-Of-Dodge asap, in the rare case where
// Pantheios cannot be initialised.
//
// NOTE: May need to revisit this in the future, in cases where a
// sophisticated back-end, e.g. log4cxx, does not initialise.
::ExitProcess(static_cast<DWORD>(code));
#else /* ? operating system */
::_exit(code);
#endif /* operating system */
}
#if !defined(PANTHEIOS_NO_NAMESPACE)
} /* namespace core */
#endif /* !PANTHEIOS_NO_NAMESPACE */
/* /////////////////////////////////////////////////////////////////////////
* Namespace
*/
#if !defined(PANTHEIOS_NO_NAMESPACE)
} /* namespace pantheios */
#endif /* !PANTHEIOS_NO_NAMESPACE */
/* ///////////////////////////// end of file //////////////////////////// */
| 35.383929 | 78 | 0.629069 | betasheet |
ef6d55e7afa2d0ba1283ba681a4d5d5e8a423379 | 1,107 | hpp | C++ | include/Parser.hpp | Electrux/alacrity-lang | 2931533c0f393cf2d2500ac0848da452fbc19295 | [
"BSD-3-Clause"
] | 15 | 2019-03-21T14:37:17.000Z | 2021-11-14T20:35:46.000Z | include/Parser.hpp | Electrux/alacrity-lang | 2931533c0f393cf2d2500ac0848da452fbc19295 | [
"BSD-3-Clause"
] | null | null | null | include/Parser.hpp | Electrux/alacrity-lang | 2931533c0f393cf2d2500ac0848da452fbc19295 | [
"BSD-3-Clause"
] | 5 | 2019-02-02T10:18:04.000Z | 2021-05-06T16:34:04.000Z | /*
Copyright (c) 2019, Electrux
All rights reserved.
Using the BSD 3-Clause license for the project,
main LICENSE file resides in project's root directory.
Please read that file and understand the license terms
before using or altering the project.
*/
#ifndef PARSER_HPP
#define PARSER_HPP
#include <variant>
#include "Lexer/Lexer.hpp"
#include "Parser/Stmt.hpp"
namespace Parser
{
class ParseTree
{
std::vector< Stmt * > m_stmts;
public:
ParseTree();
explicit ParseTree( const std::vector< Stmt * > & stmts );
ParseTree( ParseTree && original );
ParseTree( ParseTree & original );
ParseTree( ParseTree const & original ) = delete;
ParseTree & operator =( ParseTree original );
friend void swap( ParseTree & stmt1, ParseTree & stmt2 );
Stmt * operator []( const size_t loc );
void push_back( Stmt * const stmt );
void pop_back();
size_t size() const;
// iteration
const std::vector< Stmt * > & GetStmts() const;
~ParseTree();
};
void swap( ParseTree & stmt1, ParseTree & stmt2 );
std::variant< int, ParseTree > ParseTokens( const LexSymVec & tokens );
}
#endif // PARSER_HPP | 22.14 | 71 | 0.710027 | Electrux |
ef757c4c99b400e488caa342cf57e5c0f9eb2d3c | 15,471 | hh | C++ | db/slt3/var.hh | codesloop/codesloop | d66e51c2d898a72624306f611a90364c76deed06 | [
"BSD-2-Clause"
] | 3 | 2016-05-09T15:29:29.000Z | 2017-11-22T06:16:18.000Z | db/slt3/var.hh | codesloop/codesloop | d66e51c2d898a72624306f611a90364c76deed06 | [
"BSD-2-Clause"
] | null | null | null | db/slt3/var.hh | codesloop/codesloop | d66e51c2d898a72624306f611a90364c76deed06 | [
"BSD-2-Clause"
] | null | null | null | /*
Copyright (c) 2008,2009,2010, CodeSLoop Team
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _csl_db_var_hh_included_
#define _csl_db_var_hh_included_
/**
@file var.hh
@brief slt3 var
implementation of slt3 variables that helps 'instrumenting' classes to easily use the
simple object relational mapping provided by slt3. these variables bind member variables to
database fields.
*/
#include "codesloop/common/pvlist.hh"
#include "codesloop/common/pbuf.hh"
#include "codesloop/common/int64.hh"
#include "codesloop/common/dbl.hh"
#include "codesloop/common/binry.hh"
#include "codesloop/common/ustr.hh"
#include "codesloop/db/slt3/query.hh"
#ifdef __cplusplus
#include <vector>
namespace csl
{
namespace db
{
namespace slt3
{
class obj;
/**
@brief slt3::var is the base class of other slt3 variable mappers
slt3::var variables represents the mapping between member variables of classes and database fields.
this is part of the object relational mapping facilities of slt3. the mapping is done with the help of
member variables that are registered by var::helper.
the ORM mapping facilities are: sql::helper , reg::helper and var_base::helper they register ORM
variables, generate SQL strings and maps database columns to variables.
*/
class var_base
{
public:
/* abstract functions */
/**
@brief abtract function for setting the ORM-property variable from the result of an SQL query
@param ch is a pointer to column header data as returned from the database query
@param fd is a pointer to field data as returned from the database query
@return true if successful
*/
virtual bool set_value(query::colhead * ch,query::field * fd) = 0;
/** @brief abstract function to get the internal variable (common::var) */
virtual const common::var * get_value() const = 0;
/** @brief returns the variable's type as specified in common variables or query::colhead enumeration (same) */
virtual int type() = 0;
/** @brief destructor */
inline virtual ~var_base() {}
/** @brief initializing constructor */
inline var_base(obj & prn) : parent_(&prn) {}
protected:
/**
@brief register a variable with both sql::helper and var_base::helper
@param v is a pointer to the variable to be initialized
@param name is the database column name associated with the variable
@param coltype is the database column type like (INTEGER, REAL, BLOB, ...)
@param parent is a pointer to the actual class instance
@param flags are the misc properties of the database column like (UNIQUE, DEFAULT, PRIMARY KEY, etc...)
*/
virtual void register_variable(var_base * v, const char * name, const char * coltype, slt3::obj & parent, const char * flags);
/** @brief returns a pointer to the parent object */
inline virtual obj * parent() { return parent_; }
obj * parent_;
public:
/**
@brief var_base::helper keeps track of variables and helps the ORM functionality
*/
class helper
{
public:
/**
@brief registers a database variable
@param name is the variable's database column name
@param v is a reference to the given variable
*/
bool add_field(const char * name, var_base & v);
/** @brief represents a data field */
struct data
{
const char * name_;
var_base * var_;
data(const char * nm,var_base & v) : name_(nm), var_(&v) {}
};
typedef common::pvlist< 32,data,common::delete_destructor<data> > datalist_t;
/**
@brief initializes the database table associated with the object
@param t is the transaction context to be used
@param sql_query as generated by sql::helper
@return true if successful
the net result of this call is a CREATE TABLE ... SQL call
*/
bool init(tran & t, const char * sql_query);
/**
@brief creates an instance of the given object in the database
@param t is the transaction context to be used
@param sql_query as generated by sql::helper
@return true if successful
the net result of this call is a INSERT ... SQL call
it will also call the objects set_id() call to register the
identifier of the given instance.
*/
bool create(tran & t, const char * sql_query);
/**
@brief updates an instance of the given object in the database
@param t is the transaction context to be used
@param sql_query as generated by sql::helper
@return true if successful
the net result of this call is a UPDATE ... SQL call
*/
bool save(tran & t, const char * sql_query);
/**
@brief deletes an instance of the given object from the database
@param t is the transaction context to be used
@param sql_query as generated by sql::helper
@return true if successful
the net result of this call is a DELETE ... SQL call
*/
bool remove(tran & t, const char * sql_query);
/**
@brief finds an instance of the given object in the database
@param t is the transaction context to be used
@param sql_query as generated by sql::helper
@return true if successful
the net result of this call is a SELECT ... SQL call
the object's database variables will be filled with the returned data
*/
bool find_by_id(tran & t, const char * sql_query);
/**
@brief finds an instance of the given object in the database
@param t is the transaction context to be used
@param sql_query as generated by sql::helper
@param field1 to be put into the where conditions
@param field2 to be put into the where conditions (if not -1)
@param field3 to be put into the where conditions (if not -1)
@param field4 to be put into the where conditions (if not -1)
@param field5 to be put into the where conditions (if not -1)
@return true if successful
the net result of this call is a SELECT ... SQL call
the object's database variables will be filled with the returned data. the
fieldx variables will be used as condition variables. the fields with non-default
values represent a variable by index. indexing start from zero. the variables
given are logically AND'ed together.
to select on the 3rd and 4th variable of the given object one must first set those
variables to the desired values to be searched for, and then call this function
with field1=2 and field2=3.
*/
bool find_by(tran & t,
const char * sql_query,
int field1,
int field2=-1,
int field3=-1,
int field4=-1,
int field5=-1);
/**
@brief helper that sets the instance id
@param id is the id to be set
please note that this function assumes that the first variable is the id to be set
*/
void set_id(long long id);
private:
datalist_t dtalst_;
};
private:
/* not allowed to call these */
var_base() {}
var_base(const var_base & other) {}
var_base & operator=(const var_base & other) { return *this; }
};
/** @brief helper to statically determine the SQL column type string based on the template parameter */
template <typename T> struct var_col_type {};
template <> struct var_col_type<common::int64> { static const char * coltype_s; };
template <> struct var_col_type<common::dbl> { static const char * coltype_s; };
template <> struct var_col_type<common::ustr> { static const char * coltype_s; };
template <> struct var_col_type<common::binry> { static const char * coltype_s; };
/**
@brief templated variable type that respresents a variable in the ORM user object
the varT type is basically a common::var family type plus a name and flags. these
together represent a column in the database. the ORM mapper maps classes to tables and
member variables to table-columns. the mapping is done through various helper classes
like:
@li @em sql::helper that generates the SQL query strings
@li @em reg::helper that helps in locating the database for the given class
@li @em var_base::helper associates the member variables with DB columns and converts between the DB and the variables
*/
template <typename T> class varT : public var_base
{
public:
/**
@brief initializing constructor
@param name is the column name to be used
@param parent is a refernce to the class whose member is the variable
@param flags is the database flags associated with the database column (like UNIQUE, PRIMARY KEY, AUTO_INCREMENT etc...)
this constructor registers the variable instance with the sql::helper and the var_base::helper instance
*/
inline varT(const char * name, slt3::obj & prn,const char * flags="") : var_base(prn)
{
register_variable(this,name,var_col_type<T>::coltype_s,prn,flags);
}
/** @brief the variable types are one of common::var family types */
enum { type_v = T::var_type_v };
/** @brief returns the variable's type */
inline int type() { return type_v; }
/**
@brief sets the variable's content based on info returned from DB query
@param ch represents a column header
@param fd is the field's data
*/
inline bool set_value(query::colhead * ch,query::field * fd)
{
if( !ch || !fd ) return false;
bool ret = value_.from_var(*fd);
// parent()->on_change(); TODO : check this!!!
return ret;
}
typedef T tval_t;
typedef typename T::value_t value_t;
/** @brief returns the variable's value in the original representation
that is one of:
@li long long
@li doube
@li char *
@li tbuf<>
*/
inline value_t get() const { return value_.value(); }
/**
@brief forwards the get() operation to the value's get() operation
@see common::var for more information
*/
template <typename V> inline bool get(V & v) const { return value_.get(v); }
/**
@brief forwards the set() operation to the value's set() operation
@see common::var for more information
*/
template <typename V> inline bool set(V & v)
{
bool ret = value_.set(v);
if( ret ) parent()->on_change();
return ret;
}
/** @brief forward operator checks for equality */
template <typename V> inline bool operator==(V & other) const
{
return (value_ == other);
}
/** @brief copy constructor (initialize from char * string) */
inline varT & operator=(const char * other)
{
bool success = value_.from_string(other);
if( success ) parent()->on_change();
return *this;
}
/** @brief copy constructor (initialize from wide char string) */
inline varT & operator=(const wchar_t * other)
{
bool success = value_.from_string(other);
if( success ) parent()->on_change();
return *this;
}
/** @brief copy constructor (initialize from an ther variable) */
inline varT & operator=(const T & other)
{
bool success = value_.from_var(other);
if( success ) parent()->on_change();
return *this;
}
/** @brief copy constructor (initialize from an other variable - varT) */
inline varT & operator=(const varT & other)
{
bool success = value_.from_var(other.value_);
if( success ) parent()->on_change();
return *this;
}
/** @brief copy constructor (initialize from binary buffer) */
inline varT & operator=(const common::binry::buf_t & other)
{
bool success = value_.from_binary(other.data(),other.size());
if( success ) parent()->on_change();
return *this;
}
/** @brief copy constructor (initialize from binary buffer) */
template <typename X>
inline varT & operator=(const X & other)
{
T tmp(other);
bool success = value_.from_var(tmp);
if( success ) parent()->on_change();
return *this;
}
/** @brief copy constructor (initialize from unsigned char vector) */
inline varT & operator=(const std::vector<unsigned char> & vref)
{
bool success = value_.from_binary( &(vref[0]), vref.size() );
if( success ) parent()->on_change();
return *this;
}
/** @brief returns a pointer to the internal value */
inline const common::var * get_value() const { return &value_; }
private:
T value_;
};
typedef varT<common::int64> intvar; ///<int64 variable (long long)
typedef varT<common::dbl> doublevar; ///<dbl variable (double)
typedef varT<common::ustr> strvar; ///<ustr variable (char string)
typedef varT<common::binry> blobvar; ///<binry variable (tbuf based binary value)
} /* end of slt3 namespace */
} /* end of db namespace */
} /* end of csl namespace */
#endif /* __cplusplus */
#endif /* _csl_db_var_hh_included_ */
| 38.105911 | 134 | 0.6136 | codesloop |
ef75b739187f4073199194f217cc6cb0915e7c4a | 126 | cpp | C++ | source/ion/ecs/component.cpp | dvdbrink/ion | a5fe2aba7927b7a90e913cbf72325a04172fc494 | [
"MIT"
] | null | null | null | source/ion/ecs/component.cpp | dvdbrink/ion | a5fe2aba7927b7a90e913cbf72325a04172fc494 | [
"MIT"
] | null | null | null | source/ion/ecs/component.cpp | dvdbrink/ion | a5fe2aba7927b7a90e913cbf72325a04172fc494 | [
"MIT"
] | null | null | null | #include <ion/ecs/component.hpp>
namespace ion { namespace ecs
{
BaseComponent::Family BaseComponent::next_family = 0;
}} | 21 | 57 | 0.738095 | dvdbrink |
ef7bf9b91a1d1b22cdc00210840d14dee0d80daa | 163 | cpp | C++ | src/rendering/engine/engine/resources/pipeline.cpp | Bargor/tempest | 94837c6dcfef036827076446101e59afb7792f5d | [
"Apache-2.0",
"MIT"
] | null | null | null | src/rendering/engine/engine/resources/pipeline.cpp | Bargor/tempest | 94837c6dcfef036827076446101e59afb7792f5d | [
"Apache-2.0",
"MIT"
] | 1 | 2019-12-02T20:17:52.000Z | 2019-12-02T20:17:52.000Z | src/rendering/engine/engine/resources/pipeline.cpp | Bargor/tempest | 94837c6dcfef036827076446101e59afb7792f5d | [
"Apache-2.0",
"MIT"
] | null | null | null | // This file is part of Tempest project
// Author: Karol Kontny
#include "pipeline.h"
namespace tst {
namespace engine {} // namespace engine
} // namespace tst
| 18.111111 | 39 | 0.717791 | Bargor |
ef7ea1008a8c8e331ef658e1214d65c362b8bda2 | 3,283 | cpp | C++ | examples/utility/workpool/example_file_open_pool.cpp | vipalade/solidframe | cff130652127ca9607019b4db508bc67f8bbecff | [
"BSL-1.0"
] | 26 | 2015-08-25T16:07:58.000Z | 2019-07-05T15:21:22.000Z | examples/utility/workpool/example_file_open_pool.cpp | vipalade/solidframe | cff130652127ca9607019b4db508bc67f8bbecff | [
"BSL-1.0"
] | 5 | 2016-10-15T22:55:15.000Z | 2017-09-19T12:41:10.000Z | examples/utility/workpool/example_file_open_pool.cpp | vipalade/solidframe | cff130652127ca9607019b4db508bc67f8bbecff | [
"BSL-1.0"
] | 5 | 2016-09-15T10:34:52.000Z | 2018-10-30T11:46:46.000Z | // example_file_open_pool.cpp
//
// Copyright (c) 2007, 2008, 2018 Valentin Palade (vipalade @ gmail . com)
//
// This file is part of SolidFrame framework.
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.
//
#include "solid/system/filedevice.hpp"
#include "solid/system/memory.hpp"
#include "solid/utility/workpool.hpp"
#include <cerrno>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
using namespace std;
using namespace solid;
namespace {
template <class T>
static T align(T _v, solid::ulong _by);
template <class T>
static T* align(T* _v, const solid::ulong _by)
{
if ((size_t)_v % _by) {
return _v + (_by - ((size_t)_v % _by));
} else {
return _v;
}
}
template <class T>
static T align(T _v, const solid::ulong _by)
{
if (_v % _by) {
return _v + (_by - (_v % _by));
} else {
return _v;
}
}
const uint32_t pagesize = memory_page_size();
using FileDeuqeT = std::deque<FileDevice>;
struct Context {
Context()
: readsz(4 * pagesize)
, bf(new char[readsz + pagesize])
, buf(align(bf, pagesize))
{
}
~Context()
{
delete[] bf;
}
const solid::ulong readsz;
char* bf;
char* buf;
};
} //namespace
int main(int argc, char* argv[])
{
if (argc != 4) {
cout << "./file_open_pool /path/to/folder file-count folder-count" << endl;
return 0;
}
//char c;
char name[1024];
int filecnt = atoi(argv[2]);
int foldercnt = atoi(argv[3]);
sprintf(name, "%s", argv[1]);
char* fldname = name + strlen(argv[1]);
char* fname = name + strlen(argv[1]) + 1 + 8;
FileDeuqeT fdq;
int cnt = 0;
uint64_t totsz = 0;
for (int i = foldercnt; i; --i) {
sprintf(fldname, "/%08u", i);
*fname = 0;
for (int j = filecnt; j; --j) {
sprintf(fname, "/%08u.txt", j);
++cnt;
fdq.push_back(FileDevice());
if (fdq.back().open(name, FileDevice::ReadWriteE)) {
cout << "error " << strerror(errno) << " " << cnt << endl;
cout << "failed to open file " << name << endl;
return 0;
} else {
//cout<<"name = "<<name<<" size = "<<fdq.back().size()<<endl;
totsz += fdq.back().size();
}
}
}
cout << "fdq size = " << fdq.size() << " total size " << totsz << endl;
//return 0;
using WorkPoolT = lockfree::WorkPool<FileDevice*, void>;
WorkPoolT wp{
solid::WorkPoolConfiguration(),
[](FileDevice* _pfile, Context&& _rctx) {
int64_t sz = _pfile->size();
int toread;
int cnt = 0;
while (sz > 0) {
toread = _rctx.readsz;
if (toread > sz)
toread = sz;
int rv = _pfile->read(_rctx.buf, toread);
cnt += rv;
sz -= rv;
}
},
Context()};
for (FileDeuqeT::iterator it(fdq.begin()); it != fdq.end(); ++it) {
wp.push(&(*it));
}
return 0;
}
| 25.449612 | 89 | 0.514164 | vipalade |
ef7f7edbc30bb01f0314d4d5a6f7cf3ef88d5c6f | 122,193 | cc | C++ | processors/IA32/bochs/cpu/sse.cc | pavel-krivanek/opensmalltalk-vm | 694dfe3ed015e16f5b8e9cf17d37e4bdd32bea16 | [
"MIT"
] | 445 | 2016-06-30T08:19:11.000Z | 2022-03-28T06:09:49.000Z | processors/IA32/bochs/cpu/sse.cc | pavel-krivanek/opensmalltalk-vm | 694dfe3ed015e16f5b8e9cf17d37e4bdd32bea16 | [
"MIT"
] | 439 | 2016-06-29T20:14:36.000Z | 2022-03-17T19:59:58.000Z | processors/IA32/bochs/cpu/sse.cc | pavel-krivanek/opensmalltalk-vm | 694dfe3ed015e16f5b8e9cf17d37e4bdd32bea16 | [
"MIT"
] | 137 | 2016-07-02T17:32:07.000Z | 2022-03-20T11:17:25.000Z | /////////////////////////////////////////////////////////////////////////
// $Id: sse.cc,v 1.62 2008/08/11 18:53:23 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2003 Stanislav Shwartsman
// Written by Stanislav Shwartsman [sshwarts at sourceforge net]
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
/////////////////////////////////////////////////////////////////////////
#define NEED_CPU_REG_SHORTCUTS 1
#include "bochs.h"
#include "cpu.h"
#define LOG_THIS BX_CPU_THIS_PTR
/* ********************************************** */
/* SSE Integer Operations (128bit MMX extensions) */
/* ********************************************** */
// for 3-byte opcodes
#if (BX_SUPPORT_SSE >= 4) || (BX_SUPPORT_SSE >= 3 && BX_SUPPORT_SSE_EXTENSION > 0)
/* 66 0F 38 00 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSHUFB_VdqWdq(bxInstruction_c *i)
{
#if (BX_SUPPORT_SSE >= 4) || (BX_SUPPORT_SSE >= 3 && BX_SUPPORT_SSE_EXTENSION > 0)
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
for(unsigned j=0; j<16; j++)
{
unsigned mask = op2.xmmubyte(j);
if (mask & 0x80)
result.xmmubyte(j) = 0;
else
result.xmmubyte(j) = op1.xmmubyte(mask & 0xf);
}
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PSHUFB_VdqWdq: required SSE3E, use --enable-sse and --enable-sse-extension options"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 01 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PHADDW_VdqWdq(bxInstruction_c *i)
{
#if (BX_SUPPORT_SSE >= 4) || (BX_SUPPORT_SSE >= 3 && BX_SUPPORT_SSE_EXTENSION > 0)
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
result.xmm16u(0) = op1.xmm16u(0) + op1.xmm16u(1);
result.xmm16u(1) = op1.xmm16u(2) + op1.xmm16u(3);
result.xmm16u(2) = op1.xmm16u(4) + op1.xmm16u(5);
result.xmm16u(3) = op1.xmm16u(6) + op1.xmm16u(7);
result.xmm16u(4) = op2.xmm16u(0) + op2.xmm16u(1);
result.xmm16u(5) = op2.xmm16u(2) + op2.xmm16u(3);
result.xmm16u(6) = op2.xmm16u(4) + op2.xmm16u(5);
result.xmm16u(7) = op2.xmm16u(6) + op2.xmm16u(7);
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PHADDW_VdqWdq: required SSE3E, use --enable-sse and --enable-sse-extension options"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 02 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PHADDD_VdqWdq(bxInstruction_c *i)
{
#if (BX_SUPPORT_SSE >= 4) || (BX_SUPPORT_SSE >= 3 && BX_SUPPORT_SSE_EXTENSION > 0)
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
result.xmm32u(0) = op1.xmm32u(0) + op1.xmm32u(1);
result.xmm32u(1) = op1.xmm32u(2) + op1.xmm32u(3);
result.xmm32u(2) = op2.xmm32u(0) + op2.xmm32u(1);
result.xmm32u(3) = op2.xmm32u(2) + op2.xmm32u(3);
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PHADDD_VdqWdq: required SSE3E, use --enable-sse and --enable-sse-extension options"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 03 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PHADDSW_VdqWdq(bxInstruction_c *i)
{
#if (BX_SUPPORT_SSE >= 4) || (BX_SUPPORT_SSE >= 3 && BX_SUPPORT_SSE_EXTENSION > 0)
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
result.xmm16s(0) = SaturateDwordSToWordS(Bit32s(op1.xmm16s(0)) + Bit32s(op1.xmm16s(1)));
result.xmm16s(1) = SaturateDwordSToWordS(Bit32s(op1.xmm16s(2)) + Bit32s(op1.xmm16s(3)));
result.xmm16s(2) = SaturateDwordSToWordS(Bit32s(op1.xmm16s(4)) + Bit32s(op1.xmm16s(5)));
result.xmm16s(3) = SaturateDwordSToWordS(Bit32s(op1.xmm16s(6)) + Bit32s(op1.xmm16s(7)));
result.xmm16s(4) = SaturateDwordSToWordS(Bit32s(op2.xmm16s(0)) + Bit32s(op2.xmm16s(1)));
result.xmm16s(5) = SaturateDwordSToWordS(Bit32s(op2.xmm16s(2)) + Bit32s(op2.xmm16s(3)));
result.xmm16s(6) = SaturateDwordSToWordS(Bit32s(op2.xmm16s(4)) + Bit32s(op2.xmm16s(5)));
result.xmm16s(7) = SaturateDwordSToWordS(Bit32s(op2.xmm16s(6)) + Bit32s(op2.xmm16s(7)));
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PHADDSW_VdqWdq: required SSE3E, use --enable-sse and --enable-sse-extension options"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 04 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PMADDUBSW_VdqWdq(bxInstruction_c *i)
{
#if (BX_SUPPORT_SSE >= 4) || (BX_SUPPORT_SSE >= 3 && BX_SUPPORT_SSE_EXTENSION > 0)
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
for(unsigned j=0; j<8; j++)
{
Bit32s temp = Bit32s(op1.xmmubyte(j*2+0))*Bit32s(op2.xmmsbyte(j*2+0)) +
Bit32s(op1.xmmubyte(j*2+1))*Bit32s(op2.xmmsbyte(j*2+1));
result.xmm16s(j) = SaturateDwordSToWordS(temp);
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PMADDUBSW_VdqWdq: required SSE3E, use --enable-sse and --enable-sse-extension options"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 05 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PHSUBSW_VdqWdq(bxInstruction_c *i)
{
#if (BX_SUPPORT_SSE >= 4) || (BX_SUPPORT_SSE >= 3 && BX_SUPPORT_SSE_EXTENSION > 0)
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
result.xmm16s(0) = SaturateDwordSToWordS(Bit32s(op1.xmm16s(0)) - Bit32s(op1.xmm16s(1)));
result.xmm16s(1) = SaturateDwordSToWordS(Bit32s(op1.xmm16s(2)) - Bit32s(op1.xmm16s(3)));
result.xmm16s(2) = SaturateDwordSToWordS(Bit32s(op1.xmm16s(4)) - Bit32s(op1.xmm16s(5)));
result.xmm16s(3) = SaturateDwordSToWordS(Bit32s(op1.xmm16s(6)) - Bit32s(op1.xmm16s(7)));
result.xmm16s(4) = SaturateDwordSToWordS(Bit32s(op2.xmm16s(0)) - Bit32s(op2.xmm16s(1)));
result.xmm16s(5) = SaturateDwordSToWordS(Bit32s(op2.xmm16s(2)) - Bit32s(op2.xmm16s(3)));
result.xmm16s(6) = SaturateDwordSToWordS(Bit32s(op2.xmm16s(4)) - Bit32s(op2.xmm16s(5)));
result.xmm16s(7) = SaturateDwordSToWordS(Bit32s(op2.xmm16s(6)) - Bit32s(op2.xmm16s(7)));
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PHSUBSW_VdqWdq: required SSE3E, use --enable-sse and --enable-sse-extension options"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 05 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PHSUBW_VdqWdq(bxInstruction_c *i)
{
#if (BX_SUPPORT_SSE >= 4) || (BX_SUPPORT_SSE >= 3 && BX_SUPPORT_SSE_EXTENSION > 0)
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
result.xmm16u(0) = op1.xmm16u(0) - op1.xmm16u(1);
result.xmm16u(1) = op1.xmm16u(2) - op1.xmm16u(3);
result.xmm16u(2) = op1.xmm16u(4) - op1.xmm16u(5);
result.xmm16u(3) = op1.xmm16u(6) - op1.xmm16u(7);
result.xmm16u(4) = op2.xmm16u(0) - op2.xmm16u(1);
result.xmm16u(5) = op2.xmm16u(2) - op2.xmm16u(3);
result.xmm16u(6) = op2.xmm16u(4) - op2.xmm16u(5);
result.xmm16u(7) = op2.xmm16u(6) - op2.xmm16u(7);
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PHSUBW_VdqWdq: required SSE3E, use --enable-sse and --enable-sse-extension options"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 06 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PHSUBD_VdqWdq(bxInstruction_c *i)
{
#if (BX_SUPPORT_SSE >= 4) || (BX_SUPPORT_SSE >= 3 && BX_SUPPORT_SSE_EXTENSION > 0)
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
result.xmm32u(0) = op1.xmm32u(0) - op1.xmm32u(1);
result.xmm32u(1) = op1.xmm32u(2) - op1.xmm32u(3);
result.xmm32u(2) = op2.xmm32u(0) - op2.xmm32u(1);
result.xmm32u(3) = op2.xmm32u(2) - op2.xmm32u(3);
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PHSUBD_VdqWdq: required SSE3E, use --enable-sse and --enable-sse-extension options"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 08 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSIGNB_VdqWdq(bxInstruction_c *i)
{
#if (BX_SUPPORT_SSE >= 4) || (BX_SUPPORT_SSE >= 3 && BX_SUPPORT_SSE_EXTENSION > 0)
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
for(unsigned j=0; j<16; j++) {
int sign = (op2.xmmsbyte(j) > 0) - (op2.xmmsbyte(j) < 0);
op1.xmmsbyte(j) *= sign;
}
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PSIGNB_VdqWdq: required SSE3E, use --enable-sse and --enable-sse-extension options"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 09 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSIGNW_VdqWdq(bxInstruction_c *i)
{
#if (BX_SUPPORT_SSE >= 4) || (BX_SUPPORT_SSE >= 3 && BX_SUPPORT_SSE_EXTENSION > 0)
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
for(unsigned j=0; j<8; j++) {
int sign = (op2.xmm16s(j) > 0) - (op2.xmm16s(j) < 0);
op1.xmm16s(j) *= sign;
}
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PSIGNW_VdqWdq: required SSE3E, use --enable-sse and --enable-sse-extension options"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 0A */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSIGND_VdqWdq(bxInstruction_c *i)
{
#if (BX_SUPPORT_SSE >= 4) || (BX_SUPPORT_SSE >= 3 && BX_SUPPORT_SSE_EXTENSION > 0)
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
for(unsigned j=0; j<4; j++) {
int sign = (op2.xmm32s(j) > 0) - (op2.xmm32s(j) < 0);
op1.xmm32s(j) *= sign;
}
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PSIGND_VdqWdq: required SSE3E, use --enable-sse and --enable-sse-extension options"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 0B */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PMULHRSW_VdqWdq(bxInstruction_c *i)
{
#if (BX_SUPPORT_SSE >= 4) || (BX_SUPPORT_SSE >= 3 && BX_SUPPORT_SSE_EXTENSION > 0)
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
op1.xmm16u(0) = (((op1.xmm16s(0) * op2.xmm16s(0)) >> 14) + 1) >> 1;
op1.xmm16u(1) = (((op1.xmm16s(1) * op2.xmm16s(1)) >> 14) + 1) >> 1;
op1.xmm16u(2) = (((op1.xmm16s(2) * op2.xmm16s(2)) >> 14) + 1) >> 1;
op1.xmm16u(3) = (((op1.xmm16s(3) * op2.xmm16s(3)) >> 14) + 1) >> 1;
op1.xmm16u(4) = (((op1.xmm16s(4) * op2.xmm16s(4)) >> 14) + 1) >> 1;
op1.xmm16u(5) = (((op1.xmm16s(5) * op2.xmm16s(5)) >> 14) + 1) >> 1;
op1.xmm16u(6) = (((op1.xmm16s(6) * op2.xmm16s(6)) >> 14) + 1) >> 1;
op1.xmm16u(7) = (((op1.xmm16s(7) * op2.xmm16s(7)) >> 14) + 1) >> 1;
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PMULHRSW_VdqWdq: required SSE3E, use --enable-sse and --enable-sse-extension options"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 1C */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PABSB_VdqWdq(bxInstruction_c *i)
{
#if (BX_SUPPORT_SSE >= 4) || (BX_SUPPORT_SSE >= 3 && BX_SUPPORT_SSE_EXTENSION > 0)
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op;
if (i->modC0()) {
op = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op);
}
if(op.xmmsbyte(0x0) < 0) op.xmmubyte(0x0) = -op.xmmsbyte(0x0);
if(op.xmmsbyte(0x1) < 0) op.xmmubyte(0x1) = -op.xmmsbyte(0x1);
if(op.xmmsbyte(0x2) < 0) op.xmmubyte(0x2) = -op.xmmsbyte(0x2);
if(op.xmmsbyte(0x3) < 0) op.xmmubyte(0x3) = -op.xmmsbyte(0x3);
if(op.xmmsbyte(0x4) < 0) op.xmmubyte(0x4) = -op.xmmsbyte(0x4);
if(op.xmmsbyte(0x5) < 0) op.xmmubyte(0x5) = -op.xmmsbyte(0x5);
if(op.xmmsbyte(0x6) < 0) op.xmmubyte(0x6) = -op.xmmsbyte(0x6);
if(op.xmmsbyte(0x7) < 0) op.xmmubyte(0x7) = -op.xmmsbyte(0x7);
if(op.xmmsbyte(0x8) < 0) op.xmmubyte(0x8) = -op.xmmsbyte(0x8);
if(op.xmmsbyte(0x9) < 0) op.xmmubyte(0x9) = -op.xmmsbyte(0x9);
if(op.xmmsbyte(0xa) < 0) op.xmmubyte(0xa) = -op.xmmsbyte(0xa);
if(op.xmmsbyte(0xb) < 0) op.xmmubyte(0xb) = -op.xmmsbyte(0xb);
if(op.xmmsbyte(0xc) < 0) op.xmmubyte(0xc) = -op.xmmsbyte(0xc);
if(op.xmmsbyte(0xd) < 0) op.xmmubyte(0xd) = -op.xmmsbyte(0xd);
if(op.xmmsbyte(0xe) < 0) op.xmmubyte(0xe) = -op.xmmsbyte(0xe);
if(op.xmmsbyte(0xf) < 0) op.xmmubyte(0xf) = -op.xmmsbyte(0xf);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op);
#else
BX_INFO(("PABSB_VdqWdq: required SSE3E, use --enable-sse and --enable-sse-extension options"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 1D */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PABSW_VdqWdq(bxInstruction_c *i)
{
#if (BX_SUPPORT_SSE >= 4) || (BX_SUPPORT_SSE >= 3 && BX_SUPPORT_SSE_EXTENSION > 0)
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op;
if (i->modC0()) {
op = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op);
}
if(op.xmm16s(0) < 0) op.xmm16u(0) = -op.xmm16s(0);
if(op.xmm16s(1) < 0) op.xmm16u(1) = -op.xmm16s(1);
if(op.xmm16s(2) < 0) op.xmm16u(2) = -op.xmm16s(2);
if(op.xmm16s(3) < 0) op.xmm16u(3) = -op.xmm16s(3);
if(op.xmm16s(4) < 0) op.xmm16u(4) = -op.xmm16s(4);
if(op.xmm16s(5) < 0) op.xmm16u(5) = -op.xmm16s(5);
if(op.xmm16s(6) < 0) op.xmm16u(6) = -op.xmm16s(6);
if(op.xmm16s(7) < 0) op.xmm16u(7) = -op.xmm16s(7);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op);
#else
BX_INFO(("PABSW_VdqWdq: required SSE3E, use --enable-sse and --enable-sse-extension options"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 1E */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PABSD_VdqWdq(bxInstruction_c *i)
{
#if (BX_SUPPORT_SSE >= 4) || (BX_SUPPORT_SSE >= 3 && BX_SUPPORT_SSE_EXTENSION > 0)
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op;
if (i->modC0()) {
op = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op);
}
if(op.xmm32s(0) < 0) op.xmm32u(0) = -op.xmm32s(0);
if(op.xmm32s(1) < 0) op.xmm32u(1) = -op.xmm32s(1);
if(op.xmm32s(2) < 0) op.xmm32u(2) = -op.xmm32s(2);
if(op.xmm32s(3) < 0) op.xmm32u(3) = -op.xmm32s(3);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op);
#else
BX_INFO(("PABSD_VdqWdq: required SSE3E, use --enable-sse and --enable-sse-extension options"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 10 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PBLENDVB_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2,
mask = BX_READ_XMM_REG(0); // XMM0
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
for(unsigned j=0; j<16; j++)
if (mask.xmmubyte(j) & 0x80) op1.xmmubyte(j) = op2.xmmubyte(j);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PBLENDVB_VdqWdq: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 14 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BLENDVPS_VpsWps(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2,
mask = BX_READ_XMM_REG(0); // XMM0
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
if (mask.xmm32u(0) & 0x80000000) op1.xmm32u(0) = op2.xmm32u(0);
if (mask.xmm32u(1) & 0x80000000) op1.xmm32u(1) = op2.xmm32u(1);
if (mask.xmm32u(2) & 0x80000000) op1.xmm32u(2) = op2.xmm32u(2);
if (mask.xmm32u(3) & 0x80000000) op1.xmm32u(3) = op2.xmm32u(3);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("BLENDVPS_VpsWps: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 15 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BLENDVPD_VpdWpd(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2,
mask = BX_READ_XMM_REG(0); // XMM0
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
if (mask.xmm32u(1) & 0x80000000) op1.xmm64u(0) = op2.xmm64u(0);
if (mask.xmm32u(3) & 0x80000000) op1.xmm64u(1) = op2.xmm64u(1);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("BLENDVPD_VpdWpd: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 17 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PTEST_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
unsigned result = 0;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
if ((op2.xmm64u(0) & op1.xmm64u(0)) == 0 &&
(op2.xmm64u(1) & op1.xmm64u(1)) == 0) result |= EFlagsZFMask;
if ((op2.xmm64u(0) & ~op1.xmm64u(0)) == 0 &&
(op2.xmm64u(1) & ~op1.xmm64u(1)) == 0) result |= EFlagsCFMask;
setEFlagsOSZAPC(result);
#else
BX_INFO(("PTEST_VdqWdq: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 28 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PMULDQ_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
result.xmm64s(0) = Bit64s(op1.xmm32s(0)) * Bit64s(op2.xmm32s(0));
result.xmm64s(1) = Bit64s(op1.xmm32s(2)) * Bit64s(op2.xmm32s(2));
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PMULDQ_VdqWdq: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 29 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PCMPEQQ_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
op1.xmm64u(0) = (op1.xmm64u(0) == op2.xmm64u(0)) ?
BX_CONST64(0xffffffffffffffff) : 0;
op1.xmm64u(1) = (op1.xmm64u(1) == op2.xmm64u(1)) ?
BX_CONST64(0xffffffffffffffff) : 0;
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PCMPEQQ_VdqWdq: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 2B */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PACKUSDW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
result.xmm16u(0) = SaturateDwordSToWordU(op1.xmm32s(0));
result.xmm16u(1) = SaturateDwordSToWordU(op1.xmm32s(1));
result.xmm16u(2) = SaturateDwordSToWordU(op1.xmm32s(2));
result.xmm16u(3) = SaturateDwordSToWordU(op1.xmm32s(3));
result.xmm16u(4) = SaturateDwordSToWordU(op2.xmm32s(0));
result.xmm16u(5) = SaturateDwordSToWordU(op2.xmm32s(1));
result.xmm16u(6) = SaturateDwordSToWordU(op2.xmm32s(2));
result.xmm16u(7) = SaturateDwordSToWordU(op2.xmm32s(3));
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PACKUSDW_VdqWdq: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 37 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PCMPGTQ_VdqWdq(bxInstruction_c *i)
{
#if (BX_SUPPORT_SSE > 4) || (BX_SUPPORT_SSE >= 4 && BX_SUPPORT_SSE_EXTENSION > 0)
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
op1.xmm64u(0) = (op1.xmm64u(0) > op2.xmm64u(0)) ?
BX_CONST64(0xffffffffffffffff) : 0;
op1.xmm64u(1) = (op1.xmm64u(1) > op2.xmm64u(1)) ?
BX_CONST64(0xffffffffffffffff) : 0;
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PCMPGTQ_VdqWdq: required SSE4.2, use --enable-sse and --enable-sse-extension options"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 38 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PMINSB_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
for(unsigned j=0; j<16; j++) {
if(op2.xmmsbyte(j) < op1.xmmsbyte(j)) op1.xmmubyte(j) = op2.xmmubyte(j);
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PMINSB_VdqWdq: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 39 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PMINSD_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
if(op2.xmm32s(0) < op1.xmm32s(0)) op1.xmm32u(0) = op2.xmm32u(0);
if(op2.xmm32s(1) < op1.xmm32s(1)) op1.xmm32u(1) = op2.xmm32u(1);
if(op2.xmm32s(2) < op1.xmm32s(2)) op1.xmm32u(2) = op2.xmm32u(2);
if(op2.xmm32s(3) < op1.xmm32s(3)) op1.xmm32u(3) = op2.xmm32u(3);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PMINSD_VdqWdq: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 3A */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PMINUW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
if(op2.xmm16u(0) < op1.xmm16u(0)) op1.xmm16u(0) = op2.xmm16u(0);
if(op2.xmm16u(1) < op1.xmm16u(1)) op1.xmm16u(1) = op2.xmm16u(1);
if(op2.xmm16u(2) < op1.xmm16u(2)) op1.xmm16u(2) = op2.xmm16u(2);
if(op2.xmm16u(3) < op1.xmm16u(3)) op1.xmm16u(3) = op2.xmm16u(3);
if(op2.xmm16u(4) < op1.xmm16u(4)) op1.xmm16u(4) = op2.xmm16u(4);
if(op2.xmm16u(5) < op1.xmm16u(5)) op1.xmm16u(5) = op2.xmm16u(5);
if(op2.xmm16u(6) < op1.xmm16u(6)) op1.xmm16u(6) = op2.xmm16u(6);
if(op2.xmm16u(7) < op1.xmm16u(7)) op1.xmm16u(7) = op2.xmm16u(7);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PMINUW_VdqWdq: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 3B */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PMINUD_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
if(op2.xmm32u(0) < op1.xmm32u(0)) op1.xmm32u(0) = op2.xmm32u(0);
if(op2.xmm32u(1) < op1.xmm32u(1)) op1.xmm32u(1) = op2.xmm32u(1);
if(op2.xmm32u(2) < op1.xmm32u(2)) op1.xmm32u(2) = op2.xmm32u(2);
if(op2.xmm32u(3) < op1.xmm32u(3)) op1.xmm32u(3) = op2.xmm32u(3);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PMINUD_VdqWdq: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 3C */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PMAXSB_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
for(unsigned j=0; j<16; j++) {
if(op2.xmmsbyte(j) > op1.xmmsbyte(j)) op1.xmmubyte(j) = op2.xmmubyte(j);
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PMAXSB_VdqWdq: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 3D */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PMAXSD_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
if(op2.xmm32s(0) > op1.xmm32s(0)) op1.xmm32u(0) = op2.xmm32u(0);
if(op2.xmm32s(1) > op1.xmm32s(1)) op1.xmm32u(1) = op2.xmm32u(1);
if(op2.xmm32s(2) > op1.xmm32s(2)) op1.xmm32u(2) = op2.xmm32u(2);
if(op2.xmm32s(3) > op1.xmm32s(3)) op1.xmm32u(3) = op2.xmm32u(3);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PMAXSD_VdqWdq: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 3E */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PMAXUW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
if(op2.xmm16u(0) > op1.xmm16u(0)) op1.xmm16u(0) = op2.xmm16u(0);
if(op2.xmm16u(1) > op1.xmm16u(1)) op1.xmm16u(1) = op2.xmm16u(1);
if(op2.xmm16u(2) > op1.xmm16u(2)) op1.xmm16u(2) = op2.xmm16u(2);
if(op2.xmm16u(3) > op1.xmm16u(3)) op1.xmm16u(3) = op2.xmm16u(3);
if(op2.xmm16u(4) > op1.xmm16u(4)) op1.xmm16u(4) = op2.xmm16u(4);
if(op2.xmm16u(5) > op1.xmm16u(5)) op1.xmm16u(5) = op2.xmm16u(5);
if(op2.xmm16u(6) > op1.xmm16u(6)) op1.xmm16u(6) = op2.xmm16u(6);
if(op2.xmm16u(7) > op1.xmm16u(7)) op1.xmm16u(7) = op2.xmm16u(7);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PMAXUW_VdqWdq: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 3F */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PMAXUD_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
if(op2.xmm32u(0) > op1.xmm32u(0)) op1.xmm32u(0) = op2.xmm32u(0);
if(op2.xmm32u(1) > op1.xmm32u(1)) op1.xmm32u(1) = op2.xmm32u(1);
if(op2.xmm32u(2) > op1.xmm32u(2)) op1.xmm32u(2) = op2.xmm32u(2);
if(op2.xmm32u(3) > op1.xmm32u(3)) op1.xmm32u(3) = op2.xmm32u(3);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PMAXUD_VdqWdq: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 40 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PMULLD_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
Bit64s product1 = Bit64s(op1.xmm32s(0)) * Bit64s(op2.xmm32s(0));
Bit64s product2 = Bit64s(op1.xmm32s(1)) * Bit64s(op2.xmm32s(1));
Bit64s product3 = Bit64s(op1.xmm32s(2)) * Bit64s(op2.xmm32s(2));
Bit64s product4 = Bit64s(op1.xmm32s(3)) * Bit64s(op2.xmm32s(3));
op1.xmm32u(0) = (Bit32u)(product1 & 0xFFFFFFFF);
op1.xmm32u(1) = (Bit32u)(product2 & 0xFFFFFFFF);
op1.xmm32u(2) = (Bit32u)(product3 & 0xFFFFFFFF);
op1.xmm32u(3) = (Bit32u)(product4 & 0xFFFFFFFF);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PMULLD_VdqWdq: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 38 41 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PHMINPOSUW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op);
}
unsigned min = 0;
for (unsigned j=1; j < 8; j++) {
if (op.xmm16u(j) < op.xmm16u(min)) min = j;
}
result.xmm16u(0) = op.xmm16u(min);
result.xmm16u(1) = min;
result.xmm32u(1) = 0;
result.xmm64u(1) = 0;
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PHMINPOSUW_VdqWdq: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 3A 0C */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BLENDPS_VpsWpsIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
Bit8u mask = i->Ib();
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
if (mask & 0x1) op1.xmm32u(0) = op2.xmm32u(0);
if (mask & 0x2) op1.xmm32u(1) = op2.xmm32u(1);
if (mask & 0x4) op1.xmm32u(2) = op2.xmm32u(2);
if (mask & 0x8) op1.xmm32u(3) = op2.xmm32u(3);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("BLENDPS_VpsWpsIb: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 3A 0D */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::BLENDPD_VpdWpdIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
Bit8u mask = i->Ib();
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
if (mask & 0x1) op1.xmm64u(0) = op2.xmm64u(0);
if (mask & 0x2) op1.xmm64u(1) = op2.xmm64u(1);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("BLENDPD_VpdWpdIb: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 3A 0E */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PBLENDW_VdqWdqIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
Bit8u mask = i->Ib();
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
if (mask & 0x01) op1.xmm16u(0) = op2.xmm16u(0);
if (mask & 0x02) op1.xmm16u(1) = op2.xmm16u(1);
if (mask & 0x04) op1.xmm16u(2) = op2.xmm16u(2);
if (mask & 0x08) op1.xmm16u(3) = op2.xmm16u(3);
if (mask & 0x10) op1.xmm16u(4) = op2.xmm16u(4);
if (mask & 0x20) op1.xmm16u(5) = op2.xmm16u(5);
if (mask & 0x40) op1.xmm16u(6) = op2.xmm16u(6);
if (mask & 0x80) op1.xmm16u(7) = op2.xmm16u(7);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PBLENDW_VdqWdqIb: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 3A 14 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PEXTRB_HbdUdqIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op = BX_READ_XMM_REG(i->rm());
Bit8u result = op.xmmubyte(i->Ib() & 0xF);
/* result is a register or memory reference */
if (i->modC0()) {
BX_WRITE_32BIT_REGZ(i->nnn(), result);
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
write_virtual_byte(i->seg(), eaddr, result);
}
#else
BX_INFO(("PEXTRB_HbdUdqIb: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 3A 15 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PEXTRW_HwdUdqIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op = BX_READ_XMM_REG(i->rm());
Bit16u result = op.xmm16u(i->Ib() & 7);
/* result is a register or memory reference */
if (i->modC0()) {
BX_WRITE_32BIT_REGZ(i->nnn(), result);
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
write_virtual_word(i->seg(), eaddr, result);
}
#else
BX_INFO(("PEXTRW_HwdUdqIb: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 3A 16 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PEXTRD_HdUdqIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op = BX_READ_XMM_REG(i->rm());
#if BX_SUPPORT_X86_64
if (i->os64L()) /* 64 bit operand size mode */
{
Bit64u result = op.xmm64u(i->Ib() & 1);
/* result is a register or memory reference */
if (i->modC0()) {
BX_WRITE_64BIT_REG(i->nnn(), result);
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
write_virtual_qword_64(i->seg(), eaddr, result);
}
}
else
#endif
{
Bit32u result = op.xmm32u(i->Ib() & 3);
/* result is a register or memory reference */
if (i->modC0()) {
BX_WRITE_32BIT_REGZ(i->nnn(), result);
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
write_virtual_dword(i->seg(), eaddr, result);
}
}
#else
BX_INFO(("PEXTRD_HdUdqIb: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 3A 17 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::EXTRACTPS_HdUpsIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op = BX_READ_XMM_REG(i->rm());
Bit32u result = op.xmm32u(i->Ib() & 3);
/* result is a register or memory reference */
if (i->modC0()) {
BX_WRITE_32BIT_REGZ(i->nnn(), result);
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
write_virtual_dword(i->seg(), eaddr, result);
}
#else
BX_INFO(("EXTRACTPS_HdUpsIb: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 3A 20 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PINSRB_VdqEbIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn());
Bit8u op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_16BIT_REG(i->rm()); // won't allow reading of AH/CH/BH/DH
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
op2 = read_virtual_byte(i->seg(), eaddr);
}
op1.xmmubyte(i->Ib() & 0xF) = op2;
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PINSRB_VdqEbIb: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 3A 21 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::INSERTPS_VpsWssIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn());
Bit8u control = i->Ib();
Bit32u op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
BxPackedXmmRegister temp = BX_READ_XMM_REG(i->rm());
op2 = temp.xmm32u((control >> 6) & 3);
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
op2 = read_virtual_dword(i->seg(), eaddr);
}
op1.xmm32u((control >> 4) & 3) = op2;
if (control & 1) op1.xmm32u(0) = 0;
if (control & 2) op1.xmm32u(1) = 0;
if (control & 4) op1.xmm32u(2) = 0;
if (control & 8) op1.xmm32u(3) = 0;
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("INSERTPS_VpsWssIb: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 3A 22 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PINSRD_VdqEdIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn());
#if BX_SUPPORT_X86_64
if (i->os64L()) /* 64 bit operand size mode */
{
Bit64u op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_64BIT_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
op2 = read_virtual_qword_64(i->seg(), eaddr);
}
op1.xmm64u(i->Ib() & 1) = op2;
}
else
#endif
{
Bit32u op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_32BIT_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
op2 = read_virtual_dword(i->seg(), eaddr);
}
op1.xmm32u(i->Ib() & 3) = op2;
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PINSRD_VdqEdIb: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 3A 42 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::MPSADBW_VdqWdqIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 4
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
unsigned src_offset = (i->Ib() & 3) * 4;
unsigned dst_offset = ((i->Ib() >> 2) & 1) * 4;
for (unsigned j=0; j < 8; j++)
{
result.xmm16u(j) = 0;
for (unsigned k=0; k < 4; k++) {
Bit8u temp1 = op1.xmmubyte(j + k + dst_offset);
Bit8u temp2 = op2.xmmubyte( k + src_offset);
if (temp1 > temp2)
result.xmm16u(j) += (temp1 - temp2);
else
result.xmm16u(j) += (temp2 - temp1);
}
}
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("MPSADBW_VdqWdqIb: required SSE4, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
#endif // (BX_SUPPORT_SSE >= 4 || (BX_SUPPORT_SSE >= 3 && BX_SUPPORT_SSE_EXTENSION > 0)
/* 66 0F 60 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PUNPCKLBW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
result.xmmubyte(0x0) = op1.xmmubyte(0);
result.xmmubyte(0x1) = op2.xmmubyte(0);
result.xmmubyte(0x2) = op1.xmmubyte(1);
result.xmmubyte(0x3) = op2.xmmubyte(1);
result.xmmubyte(0x4) = op1.xmmubyte(2);
result.xmmubyte(0x5) = op2.xmmubyte(2);
result.xmmubyte(0x6) = op1.xmmubyte(3);
result.xmmubyte(0x7) = op2.xmmubyte(3);
result.xmmubyte(0x8) = op1.xmmubyte(4);
result.xmmubyte(0x9) = op2.xmmubyte(4);
result.xmmubyte(0xA) = op1.xmmubyte(5);
result.xmmubyte(0xB) = op2.xmmubyte(5);
result.xmmubyte(0xC) = op1.xmmubyte(6);
result.xmmubyte(0xD) = op2.xmmubyte(6);
result.xmmubyte(0xE) = op1.xmmubyte(7);
result.xmmubyte(0xF) = op2.xmmubyte(7);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PUNPCKLBW_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 61 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PUNPCKLWD_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
result.xmm16u(0) = op1.xmm16u(0);
result.xmm16u(1) = op2.xmm16u(0);
result.xmm16u(2) = op1.xmm16u(1);
result.xmm16u(3) = op2.xmm16u(1);
result.xmm16u(4) = op1.xmm16u(2);
result.xmm16u(5) = op2.xmm16u(2);
result.xmm16u(6) = op1.xmm16u(3);
result.xmm16u(7) = op2.xmm16u(3);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PUNPCKLWD_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* UNPCKLPS: 0F 14 */
/* PUNPCKLDQ: 66 0F 62 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::UNPCKLPS_VpsWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 1
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
result.xmm32u(0) = op1.xmm32u(0);
result.xmm32u(1) = op2.xmm32u(0);
result.xmm32u(2) = op1.xmm32u(1);
result.xmm32u(3) = op2.xmm32u(1);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("UNPCKLPS_VpsWdq: required SSE, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 63 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PACKSSWB_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
result.xmmsbyte(0x0) = SaturateWordSToByteS(op1.xmm16s(0));
result.xmmsbyte(0x1) = SaturateWordSToByteS(op1.xmm16s(1));
result.xmmsbyte(0x2) = SaturateWordSToByteS(op1.xmm16s(2));
result.xmmsbyte(0x3) = SaturateWordSToByteS(op1.xmm16s(3));
result.xmmsbyte(0x4) = SaturateWordSToByteS(op1.xmm16s(4));
result.xmmsbyte(0x5) = SaturateWordSToByteS(op1.xmm16s(5));
result.xmmsbyte(0x6) = SaturateWordSToByteS(op1.xmm16s(6));
result.xmmsbyte(0x7) = SaturateWordSToByteS(op1.xmm16s(7));
result.xmmsbyte(0x8) = SaturateWordSToByteS(op2.xmm16s(0));
result.xmmsbyte(0x9) = SaturateWordSToByteS(op2.xmm16s(1));
result.xmmsbyte(0xA) = SaturateWordSToByteS(op2.xmm16s(2));
result.xmmsbyte(0xB) = SaturateWordSToByteS(op2.xmm16s(3));
result.xmmsbyte(0xC) = SaturateWordSToByteS(op2.xmm16s(4));
result.xmmsbyte(0xD) = SaturateWordSToByteS(op2.xmm16s(5));
result.xmmsbyte(0xE) = SaturateWordSToByteS(op2.xmm16s(6));
result.xmmsbyte(0xF) = SaturateWordSToByteS(op2.xmm16s(7));
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PACKSSWB_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 64 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PCMPGTB_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
for(unsigned j=0; j<16; j++) {
op1.xmmubyte(j) = (op1.xmmsbyte(j) > op2.xmmsbyte(j)) ? 0xff : 0;
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PCMPGTB_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 65 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PCMPGTW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
op1.xmm16u(0) = (op1.xmm16s(0) > op2.xmm16s(0)) ? 0xffff : 0;
op1.xmm16u(1) = (op1.xmm16s(1) > op2.xmm16s(1)) ? 0xffff : 0;
op1.xmm16u(2) = (op1.xmm16s(2) > op2.xmm16s(2)) ? 0xffff : 0;
op1.xmm16u(3) = (op1.xmm16s(3) > op2.xmm16s(3)) ? 0xffff : 0;
op1.xmm16u(4) = (op1.xmm16s(4) > op2.xmm16s(4)) ? 0xffff : 0;
op1.xmm16u(5) = (op1.xmm16s(5) > op2.xmm16s(5)) ? 0xffff : 0;
op1.xmm16u(6) = (op1.xmm16s(6) > op2.xmm16s(6)) ? 0xffff : 0;
op1.xmm16u(7) = (op1.xmm16s(7) > op2.xmm16s(7)) ? 0xffff : 0;
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PCMPGTW_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 66 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PCMPGTD_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
op1.xmm32u(0) = (op1.xmm32s(0) > op2.xmm32s(0)) ? 0xffffffff : 0;
op1.xmm32u(1) = (op1.xmm32s(1) > op2.xmm32s(1)) ? 0xffffffff : 0;
op1.xmm32u(2) = (op1.xmm32s(2) > op2.xmm32s(2)) ? 0xffffffff : 0;
op1.xmm32u(3) = (op1.xmm32s(3) > op2.xmm32s(3)) ? 0xffffffff : 0;
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PCMPGTD_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 67 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PACKUSWB_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
result.xmmubyte(0x0) = SaturateWordSToByteU(op1.xmm16s(0));
result.xmmubyte(0x1) = SaturateWordSToByteU(op1.xmm16s(1));
result.xmmubyte(0x2) = SaturateWordSToByteU(op1.xmm16s(2));
result.xmmubyte(0x3) = SaturateWordSToByteU(op1.xmm16s(3));
result.xmmubyte(0x4) = SaturateWordSToByteU(op1.xmm16s(4));
result.xmmubyte(0x5) = SaturateWordSToByteU(op1.xmm16s(5));
result.xmmubyte(0x6) = SaturateWordSToByteU(op1.xmm16s(6));
result.xmmubyte(0x7) = SaturateWordSToByteU(op1.xmm16s(7));
result.xmmubyte(0x8) = SaturateWordSToByteU(op2.xmm16s(0));
result.xmmubyte(0x9) = SaturateWordSToByteU(op2.xmm16s(1));
result.xmmubyte(0xA) = SaturateWordSToByteU(op2.xmm16s(2));
result.xmmubyte(0xB) = SaturateWordSToByteU(op2.xmm16s(3));
result.xmmubyte(0xC) = SaturateWordSToByteU(op2.xmm16s(4));
result.xmmubyte(0xD) = SaturateWordSToByteU(op2.xmm16s(5));
result.xmmubyte(0xE) = SaturateWordSToByteU(op2.xmm16s(6));
result.xmmubyte(0xF) = SaturateWordSToByteU(op2.xmm16s(7));
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PACKUSWB_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 68 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PUNPCKHBW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
result.xmmubyte(0x0) = op1.xmmubyte(0x8);
result.xmmubyte(0x1) = op2.xmmubyte(0x8);
result.xmmubyte(0x2) = op1.xmmubyte(0x9);
result.xmmubyte(0x3) = op2.xmmubyte(0x9);
result.xmmubyte(0x4) = op1.xmmubyte(0xA);
result.xmmubyte(0x5) = op2.xmmubyte(0xA);
result.xmmubyte(0x6) = op1.xmmubyte(0xB);
result.xmmubyte(0x7) = op2.xmmubyte(0xB);
result.xmmubyte(0x8) = op1.xmmubyte(0xC);
result.xmmubyte(0x9) = op2.xmmubyte(0xC);
result.xmmubyte(0xA) = op1.xmmubyte(0xD);
result.xmmubyte(0xB) = op2.xmmubyte(0xD);
result.xmmubyte(0xC) = op1.xmmubyte(0xE);
result.xmmubyte(0xD) = op2.xmmubyte(0xE);
result.xmmubyte(0xE) = op1.xmmubyte(0xF);
result.xmmubyte(0xF) = op2.xmmubyte(0xF);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PUNPCKHBW_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 69 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PUNPCKHWD_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
result.xmm16u(0) = op1.xmm16u(4);
result.xmm16u(1) = op2.xmm16u(4);
result.xmm16u(2) = op1.xmm16u(5);
result.xmm16u(3) = op2.xmm16u(5);
result.xmm16u(4) = op1.xmm16u(6);
result.xmm16u(5) = op2.xmm16u(6);
result.xmm16u(6) = op1.xmm16u(7);
result.xmm16u(7) = op2.xmm16u(7);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PUNPCKHWD_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* UNPCKHPS: 0F 15 */
/* PUNPCKHDQ: 66 0F 6A */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::UNPCKHPS_VpsWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 1
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
result.xmm32u(0) = op1.xmm32u(2);
result.xmm32u(1) = op2.xmm32u(2);
result.xmm32u(2) = op1.xmm32u(3);
result.xmm32u(3) = op2.xmm32u(3);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("UNPCKHPS_VpsWdq: required SSE, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 6B */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PACKSSDW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
result.xmm16s(0) = SaturateDwordSToWordS(op1.xmm32s(0));
result.xmm16s(1) = SaturateDwordSToWordS(op1.xmm32s(1));
result.xmm16s(2) = SaturateDwordSToWordS(op1.xmm32s(2));
result.xmm16s(3) = SaturateDwordSToWordS(op1.xmm32s(3));
result.xmm16s(4) = SaturateDwordSToWordS(op2.xmm32s(0));
result.xmm16s(5) = SaturateDwordSToWordS(op2.xmm32s(1));
result.xmm16s(6) = SaturateDwordSToWordS(op2.xmm32s(2));
result.xmm16s(7) = SaturateDwordSToWordS(op2.xmm32s(3));
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PACKSSDW_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* UNPCKLPD: 66 0F 14 */
/* PUNPCKLQDQ: 66 0F 6C */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PUNPCKLQDQ_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
op1.xmm64u(1) = op2.xmm64u(0);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PUNPCKLQDQ_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* UNPCKHPD: 66 0F 15 */
/* PUNPCKHQDQ: 66 0F 6D */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PUNPCKHQDQ_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
result.xmm64u(0) = op1.xmm64u(1);
result.xmm64u(1) = op2.xmm64u(1);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PUNPCKHQDQ_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 70 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSHUFD_VdqWdqIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op, result;
Bit8u order = i->Ib();
/* op is a register or memory reference */
if (i->modC0()) {
op = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op);
}
result.xmm32u(0) = op.xmm32u((order >> 0) & 0x3);
result.xmm32u(1) = op.xmm32u((order >> 2) & 0x3);
result.xmm32u(2) = op.xmm32u((order >> 4) & 0x3);
result.xmm32u(3) = op.xmm32u((order >> 6) & 0x3);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PSHUFD_VdqWdqIb: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* F2 0F 70 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSHUFHW_VdqWdqIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op, result;
Bit8u order = i->Ib();
/* op is a register or memory reference */
if (i->modC0()) {
op = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op);
}
result.xmm64u(0) = op.xmm64u(0);
result.xmm16u(4) = op.xmm16u(4 + ((order >> 0) & 0x3));
result.xmm16u(5) = op.xmm16u(4 + ((order >> 2) & 0x3));
result.xmm16u(6) = op.xmm16u(4 + ((order >> 4) & 0x3));
result.xmm16u(7) = op.xmm16u(4 + ((order >> 6) & 0x3));
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PSHUFHW_VdqWdqIb: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* F3 0F 70 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSHUFLW_VdqWdqIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op, result;
Bit8u order = i->Ib();
/* op is a register or memory reference */
if (i->modC0()) {
op = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op);
}
result.xmm16u(0) = op.xmm16u((order >> 0) & 0x3);
result.xmm16u(1) = op.xmm16u((order >> 2) & 0x3);
result.xmm16u(2) = op.xmm16u((order >> 4) & 0x3);
result.xmm16u(3) = op.xmm16u((order >> 6) & 0x3);
result.xmm64u(1) = op.xmm64u(1);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PSHUFLW_VdqWdqIb: required SSE, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 74 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PCMPEQB_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
for(unsigned j=0; j<16; j++) {
op1.xmmubyte(j) = (op1.xmmubyte(j) == op2.xmmubyte(j)) ? 0xff : 0;
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PCMPEQB_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 75 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PCMPEQW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
op1.xmm16u(0) = (op1.xmm16u(0) == op2.xmm16u(0)) ? 0xffff : 0;
op1.xmm16u(1) = (op1.xmm16u(1) == op2.xmm16u(1)) ? 0xffff : 0;
op1.xmm16u(2) = (op1.xmm16u(2) == op2.xmm16u(2)) ? 0xffff : 0;
op1.xmm16u(3) = (op1.xmm16u(3) == op2.xmm16u(3)) ? 0xffff : 0;
op1.xmm16u(4) = (op1.xmm16u(4) == op2.xmm16u(4)) ? 0xffff : 0;
op1.xmm16u(5) = (op1.xmm16u(5) == op2.xmm16u(5)) ? 0xffff : 0;
op1.xmm16u(6) = (op1.xmm16u(6) == op2.xmm16u(6)) ? 0xffff : 0;
op1.xmm16u(7) = (op1.xmm16u(7) == op2.xmm16u(7)) ? 0xffff : 0;
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PCMPEQW_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 76 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PCMPEQD_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
op1.xmm32u(0) = (op1.xmm32u(0) == op2.xmm32u(0)) ? 0xffffffff : 0;
op1.xmm32u(1) = (op1.xmm32u(1) == op2.xmm32u(1)) ? 0xffffffff : 0;
op1.xmm32u(2) = (op1.xmm32u(2) == op2.xmm32u(2)) ? 0xffffffff : 0;
op1.xmm32u(3) = (op1.xmm32u(3) == op2.xmm32u(3)) ? 0xffffffff : 0;
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PCMPEQD_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F C4 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PINSRW_VdqEwIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn());
Bit16u op2;
Bit8u count = i->Ib() & 0x7;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_16BIT_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
op2 = read_virtual_word(i->seg(), eaddr);
}
op1.xmm16u(count) = op2;
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PINSRW_VdqEdIb: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F C5 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PEXTRW_GdUdqIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op = BX_READ_XMM_REG(i->rm());
Bit8u count = i->Ib() & 0x7;
Bit32u result = (Bit32u) op.xmm16u(count);
BX_WRITE_32BIT_REGZ(i->nnn(), result);
#else
BX_INFO(("PEXTRW_GdUdqIb: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 0F C6 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SHUFPS_VpsWpsIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 1
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
Bit8u order = i->Ib();
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
result.xmm32u(0) = op1.xmm32u((order >> 0) & 0x3);
result.xmm32u(1) = op1.xmm32u((order >> 2) & 0x3);
result.xmm32u(2) = op2.xmm32u((order >> 4) & 0x3);
result.xmm32u(3) = op2.xmm32u((order >> 6) & 0x3);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("SHUFPS_VpsWpsIb: required SSE, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F C6 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::SHUFPD_VpdWpdIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
Bit8u order = i->Ib();
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
result.xmm64u(0) = op1.xmm64u((order >> 0) & 0x1);
result.xmm64u(1) = op2.xmm64u((order >> 1) & 0x1);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("SHUFPD_VpdWpdIb: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F D1 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSRLW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
if(op2.xmm64u(0) > 15) /* looking only to low 64 bits */
{
op1.xmm64u(0) = 0;
op1.xmm64u(1) = 0;
}
else
{
Bit8u shift = op2.xmmubyte(0);
op1.xmm16u(0) >>= shift;
op1.xmm16u(1) >>= shift;
op1.xmm16u(2) >>= shift;
op1.xmm16u(3) >>= shift;
op1.xmm16u(4) >>= shift;
op1.xmm16u(5) >>= shift;
op1.xmm16u(6) >>= shift;
op1.xmm16u(7) >>= shift;
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PSRLW_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F D2 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSRLD_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
if(op2.xmm64u(0) > 31) /* looking only to low 64 bits */
{
op1.xmm64u(0) = 0;
op1.xmm64u(1) = 0;
}
else
{
Bit8u shift = op2.xmmubyte(0);
op1.xmm32u(0) >>= shift;
op1.xmm32u(1) >>= shift;
op1.xmm32u(2) >>= shift;
op1.xmm32u(3) >>= shift;
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PSRLD_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F D3 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSRLQ_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
if(op2.xmm64u(0) > 63) /* looking only to low 64 bits */
{
op1.xmm64u(0) = 0;
op1.xmm64u(1) = 0;
}
else
{
Bit8u shift = op2.xmmubyte(0);
op1.xmm64u(0) >>= shift;
op1.xmm64u(1) >>= shift;
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PSRLQ_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F D4 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PADDQ_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
op1.xmm64u(0) += op2.xmm64u(0);
op1.xmm64u(1) += op2.xmm64u(1);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PADDQ_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F D5 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PMULLW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
Bit32u product1 = Bit32u(op1.xmm16u(0)) * Bit32u(op2.xmm16u(0));
Bit32u product2 = Bit32u(op1.xmm16u(1)) * Bit32u(op2.xmm16u(1));
Bit32u product3 = Bit32u(op1.xmm16u(2)) * Bit32u(op2.xmm16u(2));
Bit32u product4 = Bit32u(op1.xmm16u(3)) * Bit32u(op2.xmm16u(3));
Bit32u product5 = Bit32u(op1.xmm16u(4)) * Bit32u(op2.xmm16u(4));
Bit32u product6 = Bit32u(op1.xmm16u(5)) * Bit32u(op2.xmm16u(5));
Bit32u product7 = Bit32u(op1.xmm16u(6)) * Bit32u(op2.xmm16u(6));
Bit32u product8 = Bit32u(op1.xmm16u(7)) * Bit32u(op2.xmm16u(7));
op1.xmm16u(0) = product1 & 0xffff;
op1.xmm16u(1) = product2 & 0xffff;
op1.xmm16u(2) = product3 & 0xffff;
op1.xmm16u(3) = product4 & 0xffff;
op1.xmm16u(4) = product5 & 0xffff;
op1.xmm16u(5) = product6 & 0xffff;
op1.xmm16u(6) = product7 & 0xffff;
op1.xmm16u(7) = product8 & 0xffff;
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PMULLW_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F D8 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSUBUSB_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
result.xmm64u(0) = result.xmm64u(1) = 0;
for(unsigned j=0; j<16; j++)
{
if(op1.xmmubyte(j) > op2.xmmubyte(j))
{
result.xmmubyte(j) = op1.xmmubyte(j) - op2.xmmubyte(j);
}
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PSUBUSB_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F D9 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSUBUSW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
result.xmm64u(0) = result.xmm64u(1) = 0;
for(unsigned j=0; j<8; j++)
{
if(op1.xmm16u(j) > op2.xmm16u(j))
{
result.xmm16u(j) = op1.xmm16u(j) - op2.xmm16u(j);
}
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PSUBUSW_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F DA */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PMINUB_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
for(unsigned j=0; j<16; j++) {
if(op2.xmmubyte(j) < op1.xmmubyte(j)) op1.xmmubyte(j) = op2.xmmubyte(j);
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PMINUB_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* ANDPS: 0F 54 */
/* ANDPD: 66 0F 54 */
/* PAND: 66 0F DB */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::ANDPS_VpsWps(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 1
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
op1.xmm64u(0) &= op2.xmm64u(0);
op1.xmm64u(1) &= op2.xmm64u(1);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("ANDPS_VpsWps: required SSE, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F DC */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PADDUSB_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
for(unsigned j=0; j<16; j++) {
op1.xmmubyte(j) = SaturateWordSToByteU(Bit16s(op1.xmmubyte(j)) + Bit16s(op2.xmmubyte(j)));
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PADDUSB_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F DD */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PADDUSW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
op1.xmm16u(0) = SaturateDwordSToWordU(Bit32s(op1.xmm16u(0)) + Bit32s(op2.xmm16u(0)));
op1.xmm16u(1) = SaturateDwordSToWordU(Bit32s(op1.xmm16u(1)) + Bit32s(op2.xmm16u(1)));
op1.xmm16u(2) = SaturateDwordSToWordU(Bit32s(op1.xmm16u(2)) + Bit32s(op2.xmm16u(2)));
op1.xmm16u(3) = SaturateDwordSToWordU(Bit32s(op1.xmm16u(3)) + Bit32s(op2.xmm16u(3)));
op1.xmm16u(4) = SaturateDwordSToWordU(Bit32s(op1.xmm16u(4)) + Bit32s(op2.xmm16u(4)));
op1.xmm16u(5) = SaturateDwordSToWordU(Bit32s(op1.xmm16u(5)) + Bit32s(op2.xmm16u(5)));
op1.xmm16u(6) = SaturateDwordSToWordU(Bit32s(op1.xmm16u(6)) + Bit32s(op2.xmm16u(6)));
op1.xmm16u(7) = SaturateDwordSToWordU(Bit32s(op1.xmm16u(7)) + Bit32s(op2.xmm16u(7)));
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PADDUSW_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F DE */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PMAXUB_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
for(unsigned j=0; j<16; j++) {
if(op2.xmmubyte(j) > op1.xmmubyte(j)) op1.xmmubyte(j) = op2.xmmubyte(j);
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PMAXUB_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* ANDNPS: 0F 55 */
/* ANDNPD: 66 0F 55 */
/* PANDN: 66 0F DF */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::ANDNPS_VpsWps(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 1
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
op1.xmm64u(0) = ~(op1.xmm64u(0)) & op2.xmm64u(0);
op1.xmm64u(1) = ~(op1.xmm64u(1)) & op2.xmm64u(1);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("ANDNPS_VpsWps: required SSE, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F E0 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PAVGB_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
for(unsigned j=0; j<16; j++) {
op1.xmmubyte(j) = (op1.xmmubyte(j) + op2.xmmubyte(j) + 1) >> 1;
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PAVGB_VdqWdq: required SSE, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F E1 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSRAW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
if(op2.xmm64u(0) == 0) return;
if(op2.xmm64u(0) > 15) /* looking only to low 64 bits */
{
result.xmm16u(0) = (op1.xmm16u(0) & 0x8000) ? 0xffff : 0;
result.xmm16u(1) = (op1.xmm16u(1) & 0x8000) ? 0xffff : 0;
result.xmm16u(2) = (op1.xmm16u(2) & 0x8000) ? 0xffff : 0;
result.xmm16u(3) = (op1.xmm16u(3) & 0x8000) ? 0xffff : 0;
result.xmm16u(4) = (op1.xmm16u(4) & 0x8000) ? 0xffff : 0;
result.xmm16u(5) = (op1.xmm16u(5) & 0x8000) ? 0xffff : 0;
result.xmm16u(6) = (op1.xmm16u(6) & 0x8000) ? 0xffff : 0;
result.xmm16u(7) = (op1.xmm16u(7) & 0x8000) ? 0xffff : 0;
}
else
{
Bit8u shift = op2.xmmubyte(0);
result.xmm16u(0) = op1.xmm16u(0) >> shift;
result.xmm16u(1) = op1.xmm16u(1) >> shift;
result.xmm16u(2) = op1.xmm16u(2) >> shift;
result.xmm16u(3) = op1.xmm16u(3) >> shift;
result.xmm16u(4) = op1.xmm16u(4) >> shift;
result.xmm16u(5) = op1.xmm16u(5) >> shift;
result.xmm16u(6) = op1.xmm16u(6) >> shift;
result.xmm16u(7) = op1.xmm16u(7) >> shift;
if(op1.xmm16u(0) & 0x8000) result.xmm16u(0) |= (0xffff << (16 - shift));
if(op1.xmm16u(1) & 0x8000) result.xmm16u(1) |= (0xffff << (16 - shift));
if(op1.xmm16u(2) & 0x8000) result.xmm16u(2) |= (0xffff << (16 - shift));
if(op1.xmm16u(3) & 0x8000) result.xmm16u(3) |= (0xffff << (16 - shift));
if(op1.xmm16u(4) & 0x8000) result.xmm16u(4) |= (0xffff << (16 - shift));
if(op1.xmm16u(5) & 0x8000) result.xmm16u(5) |= (0xffff << (16 - shift));
if(op1.xmm16u(6) & 0x8000) result.xmm16u(6) |= (0xffff << (16 - shift));
if(op1.xmm16u(7) & 0x8000) result.xmm16u(7) |= (0xffff << (16 - shift));
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PSRAW_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F E2 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSRAD_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
if(op2.xmm64u(0) == 0) return;
if(op2.xmm64u(0) > 31) /* looking only to low 64 bits */
{
result.xmm32u(0) = (op1.xmm32u(0) & 0x80000000) ? 0xffffffff : 0;
result.xmm32u(1) = (op1.xmm32u(1) & 0x80000000) ? 0xffffffff : 0;
result.xmm32u(2) = (op1.xmm32u(2) & 0x80000000) ? 0xffffffff : 0;
result.xmm32u(3) = (op1.xmm32u(3) & 0x80000000) ? 0xffffffff : 0;
}
else
{
Bit8u shift = op2.xmmubyte(0);
result.xmm32u(0) = op1.xmm32u(0) >> shift;
result.xmm32u(1) = op1.xmm32u(1) >> shift;
result.xmm32u(2) = op1.xmm32u(2) >> shift;
result.xmm32u(3) = op1.xmm32u(3) >> shift;
if(op1.xmm32u(0) & 0x80000000) result.xmm32u(0) |= (0xffffffff << (32-shift));
if(op1.xmm32u(1) & 0x80000000) result.xmm32u(1) |= (0xffffffff << (32-shift));
if(op1.xmm32u(2) & 0x80000000) result.xmm32u(2) |= (0xffffffff << (32-shift));
if(op1.xmm32u(3) & 0x80000000) result.xmm32u(3) |= (0xffffffff << (32-shift));
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PSRAD_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F E3 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PAVGW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
op1.xmm16u(0) = (op1.xmm16u(0) + op2.xmm16u(0) + 1) >> 1;
op1.xmm16u(1) = (op1.xmm16u(1) + op2.xmm16u(1) + 1) >> 1;
op1.xmm16u(2) = (op1.xmm16u(2) + op2.xmm16u(2) + 1) >> 1;
op1.xmm16u(3) = (op1.xmm16u(3) + op2.xmm16u(3) + 1) >> 1;
op1.xmm16u(4) = (op1.xmm16u(4) + op2.xmm16u(4) + 1) >> 1;
op1.xmm16u(5) = (op1.xmm16u(5) + op2.xmm16u(5) + 1) >> 1;
op1.xmm16u(6) = (op1.xmm16u(6) + op2.xmm16u(6) + 1) >> 1;
op1.xmm16u(7) = (op1.xmm16u(7) + op2.xmm16u(7) + 1) >> 1;
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PAVGW_VdqWdq: required SSE, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F E4 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PMULHUW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
Bit32u product1 = Bit32u(op1.xmm16u(0)) * Bit32u(op2.xmm16u(0));
Bit32u product2 = Bit32u(op1.xmm16u(1)) * Bit32u(op2.xmm16u(1));
Bit32u product3 = Bit32u(op1.xmm16u(2)) * Bit32u(op2.xmm16u(2));
Bit32u product4 = Bit32u(op1.xmm16u(3)) * Bit32u(op2.xmm16u(3));
Bit32u product5 = Bit32u(op1.xmm16u(4)) * Bit32u(op2.xmm16u(4));
Bit32u product6 = Bit32u(op1.xmm16u(5)) * Bit32u(op2.xmm16u(5));
Bit32u product7 = Bit32u(op1.xmm16u(6)) * Bit32u(op2.xmm16u(6));
Bit32u product8 = Bit32u(op1.xmm16u(7)) * Bit32u(op2.xmm16u(7));
op1.xmm16u(0) = (Bit16u)(product1 >> 16);
op1.xmm16u(1) = (Bit16u)(product2 >> 16);
op1.xmm16u(2) = (Bit16u)(product3 >> 16);
op1.xmm16u(3) = (Bit16u)(product4 >> 16);
op1.xmm16u(4) = (Bit16u)(product5 >> 16);
op1.xmm16u(5) = (Bit16u)(product6 >> 16);
op1.xmm16u(6) = (Bit16u)(product7 >> 16);
op1.xmm16u(7) = (Bit16u)(product8 >> 16);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PMULHUW_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F E5 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PMULHW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
Bit32s product1 = Bit32s(op1.xmm16s(0)) * Bit32s(op2.xmm16s(0));
Bit32s product2 = Bit32s(op1.xmm16s(1)) * Bit32s(op2.xmm16s(1));
Bit32s product3 = Bit32s(op1.xmm16s(2)) * Bit32s(op2.xmm16s(2));
Bit32s product4 = Bit32s(op1.xmm16s(3)) * Bit32s(op2.xmm16s(3));
Bit32s product5 = Bit32s(op1.xmm16s(4)) * Bit32s(op2.xmm16s(4));
Bit32s product6 = Bit32s(op1.xmm16s(5)) * Bit32s(op2.xmm16s(5));
Bit32s product7 = Bit32s(op1.xmm16s(6)) * Bit32s(op2.xmm16s(6));
Bit32s product8 = Bit32s(op1.xmm16s(7)) * Bit32s(op2.xmm16s(7));
op1.xmm16u(0) = (Bit16u)(product1 >> 16);
op1.xmm16u(1) = (Bit16u)(product2 >> 16);
op1.xmm16u(2) = (Bit16u)(product3 >> 16);
op1.xmm16u(3) = (Bit16u)(product4 >> 16);
op1.xmm16u(4) = (Bit16u)(product5 >> 16);
op1.xmm16u(5) = (Bit16u)(product6 >> 16);
op1.xmm16u(6) = (Bit16u)(product7 >> 16);
op1.xmm16u(7) = (Bit16u)(product8 >> 16);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PMULHW_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F E8 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSUBSB_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
for(unsigned j=0; j<16; j++) {
op1.xmmsbyte(j) = SaturateWordSToByteS(Bit16s(op1.xmmsbyte(j)) - Bit16s(op2.xmmsbyte(j)));
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PSUBSB_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F E9 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSUBSW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
op1.xmm16s(0) = SaturateDwordSToWordS(Bit32s(op1.xmm16s(0)) - Bit32s(op2.xmm16s(0)));
op1.xmm16s(1) = SaturateDwordSToWordS(Bit32s(op1.xmm16s(1)) - Bit32s(op2.xmm16s(1)));
op1.xmm16s(2) = SaturateDwordSToWordS(Bit32s(op1.xmm16s(2)) - Bit32s(op2.xmm16s(2)));
op1.xmm16s(3) = SaturateDwordSToWordS(Bit32s(op1.xmm16s(3)) - Bit32s(op2.xmm16s(3)));
op1.xmm16s(4) = SaturateDwordSToWordS(Bit32s(op1.xmm16s(4)) - Bit32s(op2.xmm16s(4)));
op1.xmm16s(5) = SaturateDwordSToWordS(Bit32s(op1.xmm16s(5)) - Bit32s(op2.xmm16s(5)));
op1.xmm16s(6) = SaturateDwordSToWordS(Bit32s(op1.xmm16s(6)) - Bit32s(op2.xmm16s(6)));
op1.xmm16s(7) = SaturateDwordSToWordS(Bit32s(op1.xmm16s(7)) - Bit32s(op2.xmm16s(7)));
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PSUBSW_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F EA */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PMINSW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
if(op2.xmm16s(0) < op1.xmm16s(0)) op1.xmm16s(0) = op2.xmm16s(0);
if(op2.xmm16s(1) < op1.xmm16s(1)) op1.xmm16s(1) = op2.xmm16s(1);
if(op2.xmm16s(2) < op1.xmm16s(2)) op1.xmm16s(2) = op2.xmm16s(2);
if(op2.xmm16s(3) < op1.xmm16s(3)) op1.xmm16s(3) = op2.xmm16s(3);
if(op2.xmm16s(4) < op1.xmm16s(4)) op1.xmm16s(4) = op2.xmm16s(4);
if(op2.xmm16s(5) < op1.xmm16s(5)) op1.xmm16s(5) = op2.xmm16s(5);
if(op2.xmm16s(6) < op1.xmm16s(6)) op1.xmm16s(6) = op2.xmm16s(6);
if(op2.xmm16s(7) < op1.xmm16s(7)) op1.xmm16s(7) = op2.xmm16s(7);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PMINSW_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* ORPS: 0F 56 */
/* ORPD: 66 0F 56 */
/* POR: 66 0F EB */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::ORPS_VpsWps(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 1
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
op1.xmm64u(0) |= op2.xmm64u(0);
op1.xmm64u(1) |= op2.xmm64u(1);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("ORPS_VpsWps: required SSE, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F EC */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PADDSB_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
for(unsigned j=0; j<16; j++) {
op1.xmmsbyte(j) = SaturateWordSToByteS(Bit16s(op1.xmmsbyte(j)) + Bit16s(op2.xmmsbyte(j)));
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PADDSB_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F ED */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PADDSW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
op1.xmm16s(0) = SaturateDwordSToWordS(Bit32s(op1.xmm16s(0)) + Bit32s(op2.xmm16s(0)));
op1.xmm16s(1) = SaturateDwordSToWordS(Bit32s(op1.xmm16s(1)) + Bit32s(op2.xmm16s(1)));
op1.xmm16s(2) = SaturateDwordSToWordS(Bit32s(op1.xmm16s(2)) + Bit32s(op2.xmm16s(2)));
op1.xmm16s(3) = SaturateDwordSToWordS(Bit32s(op1.xmm16s(3)) + Bit32s(op2.xmm16s(3)));
op1.xmm16s(4) = SaturateDwordSToWordS(Bit32s(op1.xmm16s(4)) + Bit32s(op2.xmm16s(4)));
op1.xmm16s(5) = SaturateDwordSToWordS(Bit32s(op1.xmm16s(5)) + Bit32s(op2.xmm16s(5)));
op1.xmm16s(6) = SaturateDwordSToWordS(Bit32s(op1.xmm16s(6)) + Bit32s(op2.xmm16s(6)));
op1.xmm16s(7) = SaturateDwordSToWordS(Bit32s(op1.xmm16s(7)) + Bit32s(op2.xmm16s(7)));
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PADDSW_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F EE */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PMAXSW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
if(op2.xmm16s(0) > op1.xmm16s(0)) op1.xmm16s(0) = op2.xmm16s(0);
if(op2.xmm16s(1) > op1.xmm16s(1)) op1.xmm16s(1) = op2.xmm16s(1);
if(op2.xmm16s(2) > op1.xmm16s(2)) op1.xmm16s(2) = op2.xmm16s(2);
if(op2.xmm16s(3) > op1.xmm16s(3)) op1.xmm16s(3) = op2.xmm16s(3);
if(op2.xmm16s(4) > op1.xmm16s(4)) op1.xmm16s(4) = op2.xmm16s(4);
if(op2.xmm16s(5) > op1.xmm16s(5)) op1.xmm16s(5) = op2.xmm16s(5);
if(op2.xmm16s(6) > op1.xmm16s(6)) op1.xmm16s(6) = op2.xmm16s(6);
if(op2.xmm16s(7) > op1.xmm16s(7)) op1.xmm16s(7) = op2.xmm16s(7);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PMAXSW_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* XORPS: 0F 57 */
/* XORPD: 66 0F 57 */
/* PXOR: 66 0F EF */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::XORPS_VpsWps(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 1
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
op1.xmm64u(0) ^= op2.xmm64u(0);
op1.xmm64u(1) ^= op2.xmm64u(1);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("XORPS_VpsWps: required SSE, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F F1 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSLLW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
if(op2.xmm64u(0) > 15) /* looking only to low 64 bits */
{
op1.xmm64u(0) = 0;
op1.xmm64u(1) = 0;
}
else
{
Bit8u shift = op2.xmmubyte(0);
op1.xmm16u(0) <<= shift;
op1.xmm16u(1) <<= shift;
op1.xmm16u(2) <<= shift;
op1.xmm16u(3) <<= shift;
op1.xmm16u(4) <<= shift;
op1.xmm16u(5) <<= shift;
op1.xmm16u(6) <<= shift;
op1.xmm16u(7) <<= shift;
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PSLLW_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F F2 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSLLD_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
if(op2.xmm64u(0) > 31) /* looking only to low 64 bits */
{
op1.xmm64u(0) = 0;
op1.xmm64u(1) = 0;
}
else
{
Bit8u shift = op2.xmmubyte(0);
op1.xmm32u(0) <<= shift;
op1.xmm32u(1) <<= shift;
op1.xmm32u(2) <<= shift;
op1.xmm32u(3) <<= shift;
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PSLLD_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F F3 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSLLQ_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
if(op2.xmm64u(0) > 63) /* looking only to low 64 bits */
{
op1.xmm64u(0) = 0;
op1.xmm64u(1) = 0;
}
else
{
Bit8u shift = op2.xmmubyte(0);
op1.xmm64u(0) <<= shift;
op1.xmm64u(1) <<= shift;
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PSLLQ_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F F4 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PMULUDQ_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
result.xmm64u(0) = Bit64u(op1.xmm32u(0)) * Bit64u(op2.xmm32u(0));
result.xmm64u(1) = Bit64u(op1.xmm32u(2)) * Bit64u(op2.xmm32u(2));
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PMULUDQ_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F F5 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PMADDWD_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2, result;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
for(unsigned j=0; j<4; j++)
{
if(op1.xmm32u(j) == 0x80008000 && op2.xmm32u(j) == 0x80008000) {
result.xmm32u(j) = 0x80000000;
}
else {
result.xmm32u(j) =
Bit32s(op1.xmm16s(2*j+0)) * Bit32s(op2.xmm16s(2*j+0)) +
Bit32s(op1.xmm16s(2*j+1)) * Bit32s(op2.xmm16s(2*j+1));
}
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), result);
#else
BX_INFO(("PMADDWD_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F F6 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSADBW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
Bit16u temp1 = 0, temp2 = 0;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
temp1 += abs(op1.xmmubyte(0x0) - op2.xmmubyte(0x0));
temp1 += abs(op1.xmmubyte(0x1) - op2.xmmubyte(0x1));
temp1 += abs(op1.xmmubyte(0x2) - op2.xmmubyte(0x2));
temp1 += abs(op1.xmmubyte(0x3) - op2.xmmubyte(0x3));
temp1 += abs(op1.xmmubyte(0x4) - op2.xmmubyte(0x4));
temp1 += abs(op1.xmmubyte(0x5) - op2.xmmubyte(0x5));
temp1 += abs(op1.xmmubyte(0x6) - op2.xmmubyte(0x6));
temp1 += abs(op1.xmmubyte(0x7) - op2.xmmubyte(0x7));
temp2 += abs(op1.xmmubyte(0x8) - op2.xmmubyte(0x8));
temp2 += abs(op1.xmmubyte(0x9) - op2.xmmubyte(0x9));
temp2 += abs(op1.xmmubyte(0xA) - op2.xmmubyte(0xA));
temp2 += abs(op1.xmmubyte(0xB) - op2.xmmubyte(0xB));
temp2 += abs(op1.xmmubyte(0xC) - op2.xmmubyte(0xC));
temp2 += abs(op1.xmmubyte(0xD) - op2.xmmubyte(0xD));
temp2 += abs(op1.xmmubyte(0xE) - op2.xmmubyte(0xE));
temp2 += abs(op1.xmmubyte(0xF) - op2.xmmubyte(0xF));
op1.xmm64u(0) = Bit64u(temp1);
op1.xmm64u(1) = Bit64u(temp2);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PSADBW_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F F8 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSUBB_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
for(unsigned j=0; j<16; j++) {
op1.xmmubyte(j) -= op2.xmmubyte(j);
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PSUBB_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F F9 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSUBW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
op1.xmm16u(0) -= op2.xmm16u(0);
op1.xmm16u(1) -= op2.xmm16u(1);
op1.xmm16u(2) -= op2.xmm16u(2);
op1.xmm16u(3) -= op2.xmm16u(3);
op1.xmm16u(4) -= op2.xmm16u(4);
op1.xmm16u(5) -= op2.xmm16u(5);
op1.xmm16u(6) -= op2.xmm16u(6);
op1.xmm16u(7) -= op2.xmm16u(7);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PSUBW_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F FA */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSUBD_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
op1.xmm32u(0) -= op2.xmm32u(0);
op1.xmm32u(1) -= op2.xmm32u(1);
op1.xmm32u(2) -= op2.xmm32u(2);
op1.xmm32u(3) -= op2.xmm32u(3);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PSUBD_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F FB */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSUBQ_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
op1.xmm64u(0) -= op2.xmm64u(0);
op1.xmm64u(1) -= op2.xmm64u(1);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PSUBQ_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F FC */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PADDB_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
for(unsigned j=0; j<16; j++) {
op1.xmmubyte(j) += op2.xmmubyte(j);
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PADDB_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F FD */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PADDW_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
op1.xmm16u(0) += op2.xmm16u(0);
op1.xmm16u(1) += op2.xmm16u(1);
op1.xmm16u(2) += op2.xmm16u(2);
op1.xmm16u(3) += op2.xmm16u(3);
op1.xmm16u(4) += op2.xmm16u(4);
op1.xmm16u(5) += op2.xmm16u(5);
op1.xmm16u(6) += op2.xmm16u(6);
op1.xmm16u(7) += op2.xmm16u(7);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PADDW_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F FE */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PADDD_VdqWdq(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op1 = BX_READ_XMM_REG(i->nnn()), op2;
/* op2 is a register or memory reference */
if (i->modC0()) {
op2 = BX_READ_XMM_REG(i->rm());
}
else {
bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
/* pointer, segment address pair */
readVirtualDQwordAligned(i->seg(), eaddr, (Bit8u *) &op2);
}
op1.xmm32u(0) += op2.xmm32u(0);
op1.xmm32u(1) += op2.xmm32u(1);
op1.xmm32u(2) += op2.xmm32u(2);
op1.xmm32u(3) += op2.xmm32u(3);
/* now write result back to destination */
BX_WRITE_XMM_REG(i->nnn(), op1);
#else
BX_INFO(("PADDD_VdqWdq: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 71 Grp12 010 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSRLW_UdqIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op = BX_READ_XMM_REG(i->rm());
Bit8u shift = i->Ib();
if(shift > 15) {
op.xmm64u(0) = 0;
op.xmm64u(1) = 0;
}
else {
op.xmm16u(0) >>= shift;
op.xmm16u(1) >>= shift;
op.xmm16u(2) >>= shift;
op.xmm16u(3) >>= shift;
op.xmm16u(4) >>= shift;
op.xmm16u(5) >>= shift;
op.xmm16u(6) >>= shift;
op.xmm16u(7) >>= shift;
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->rm(), op);
#else
BX_INFO(("PSRLW_UdqIb: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 0F 71 Grp12 100 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSRAW_UdqIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op = BX_READ_XMM_REG(i->rm()), result;
Bit8u shift = i->Ib();
if(shift == 0) return;
if(shift > 15) {
result.xmm16u(0) = (op.xmm16u(0) & 0x8000) ? 0xffff : 0;
result.xmm16u(1) = (op.xmm16u(1) & 0x8000) ? 0xffff : 0;
result.xmm16u(2) = (op.xmm16u(2) & 0x8000) ? 0xffff : 0;
result.xmm16u(3) = (op.xmm16u(3) & 0x8000) ? 0xffff : 0;
result.xmm16u(4) = (op.xmm16u(4) & 0x8000) ? 0xffff : 0;
result.xmm16u(5) = (op.xmm16u(5) & 0x8000) ? 0xffff : 0;
result.xmm16u(6) = (op.xmm16u(6) & 0x8000) ? 0xffff : 0;
result.xmm16u(7) = (op.xmm16u(7) & 0x8000) ? 0xffff : 0;
}
else {
result.xmm16u(0) = op.xmm16u(0) >> shift;
result.xmm16u(1) = op.xmm16u(1) >> shift;
result.xmm16u(2) = op.xmm16u(2) >> shift;
result.xmm16u(3) = op.xmm16u(3) >> shift;
result.xmm16u(4) = op.xmm16u(4) >> shift;
result.xmm16u(5) = op.xmm16u(5) >> shift;
result.xmm16u(6) = op.xmm16u(6) >> shift;
result.xmm16u(7) = op.xmm16u(7) >> shift;
if(op.xmm16u(0) & 0x8000) result.xmm16u(0) |= (0xffff << (16 - shift));
if(op.xmm16u(1) & 0x8000) result.xmm16u(1) |= (0xffff << (16 - shift));
if(op.xmm16u(2) & 0x8000) result.xmm16u(2) |= (0xffff << (16 - shift));
if(op.xmm16u(3) & 0x8000) result.xmm16u(3) |= (0xffff << (16 - shift));
if(op.xmm16u(4) & 0x8000) result.xmm16u(4) |= (0xffff << (16 - shift));
if(op.xmm16u(5) & 0x8000) result.xmm16u(5) |= (0xffff << (16 - shift));
if(op.xmm16u(6) & 0x8000) result.xmm16u(6) |= (0xffff << (16 - shift));
if(op.xmm16u(7) & 0x8000) result.xmm16u(7) |= (0xffff << (16 - shift));
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->rm(), result);
#else
BX_INFO(("PSRAW_UdqIb: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 71 Grp12 110 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSLLW_UdqIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op = BX_READ_XMM_REG(i->rm());
Bit8u shift = i->Ib();
if(shift > 15) {
op.xmm64u(0) = 0;
op.xmm64u(1) = 0;
}
else {
op.xmm16u(0) <<= shift;
op.xmm16u(1) <<= shift;
op.xmm16u(2) <<= shift;
op.xmm16u(3) <<= shift;
op.xmm16u(4) <<= shift;
op.xmm16u(5) <<= shift;
op.xmm16u(6) <<= shift;
op.xmm16u(7) <<= shift;
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->rm(), op);
#else
BX_INFO(("PSLLW_UdqIb: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 72 Grp13 010 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSRLD_UdqIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op = BX_READ_XMM_REG(i->rm());
Bit8u shift = i->Ib();
if(shift > 31) {
op.xmm64u(0) = 0;
op.xmm64u(1) = 0;
}
else {
op.xmm32u(0) >>= shift;
op.xmm32u(1) >>= shift;
op.xmm32u(2) >>= shift;
op.xmm32u(3) >>= shift;
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->rm(), op);
#else
BX_INFO(("PSRLD_UdqIb: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 0F 72 Grp13 100 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSRAD_UdqIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op = BX_READ_XMM_REG(i->rm()), result;
Bit8u shift = i->Ib();
if(shift == 0) return;
if(shift > 31) {
result.xmm32u(0) = (op.xmm32u(0) & 0x80000000) ? 0xffffffff : 0;
result.xmm32u(1) = (op.xmm32u(1) & 0x80000000) ? 0xffffffff : 0;
result.xmm32u(2) = (op.xmm32u(2) & 0x80000000) ? 0xffffffff : 0;
result.xmm32u(3) = (op.xmm32u(3) & 0x80000000) ? 0xffffffff : 0;
}
else {
result.xmm32u(0) = op.xmm32u(0) >> shift;
result.xmm32u(1) = op.xmm32u(1) >> shift;
result.xmm32u(2) = op.xmm32u(2) >> shift;
result.xmm32u(3) = op.xmm32u(3) >> shift;
if(op.xmm32u(0) & 0x80000000) result.xmm32u(0) |= (0xffffffff << (32-shift));
if(op.xmm32u(1) & 0x80000000) result.xmm32u(1) |= (0xffffffff << (32-shift));
if(op.xmm32u(2) & 0x80000000) result.xmm32u(2) |= (0xffffffff << (32-shift));
if(op.xmm32u(3) & 0x80000000) result.xmm32u(3) |= (0xffffffff << (32-shift));
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->rm(), result);
#else
BX_INFO(("PSRAD_UdqIb: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 72 Grp13 110 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSLLD_UdqIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op = BX_READ_XMM_REG(i->rm());
Bit8u shift = i->Ib();
if(shift > 31) {
op.xmm64u(0) = 0;
op.xmm64u(1) = 0;
}
else {
op.xmm32u(0) <<= shift;
op.xmm32u(1) <<= shift;
op.xmm32u(2) <<= shift;
op.xmm32u(3) <<= shift;
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->rm(), op);
#else
BX_INFO(("PSLLD_UdqIb: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 73 Grp14 010 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSRLQ_UdqIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op = BX_READ_XMM_REG(i->rm());
Bit8u shift = i->Ib();
if(shift > 63) {
op.xmm64u(0) = 0;
op.xmm64u(1) = 0;
}
else {
op.xmm64u(0) >>= shift;
op.xmm64u(1) >>= shift;
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->rm(), op);
#else
BX_INFO(("PSRLQ_UdqIb: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 73 Grp14 011 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSRLDQ_UdqIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op = BX_READ_XMM_REG(i->rm()), result;
Bit8u shift = i->Ib();
result.xmm64u(0) = result.xmm64u(1) = 0;
for(unsigned j=shift; j<16; j++) {
result.xmmubyte(j-shift) = op.xmmubyte(j);
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->rm(), result);
#else
BX_INFO(("PSRLDQ_UdqIb: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 73 Grp14 110 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSLLQ_UdqIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op = BX_READ_XMM_REG(i->rm());
Bit8u shift = i->Ib();
if(shift > 63) {
op.xmm64u(0) = 0;
op.xmm64u(1) = 0;
}
else {
op.xmm64u(0) <<= shift;
op.xmm64u(1) <<= shift;
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->rm(), op);
#else
BX_INFO(("PSLLQ_UdqIb: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
/* 66 0F 73 Grp14 111 */
void BX_CPP_AttrRegparmN(1) BX_CPU_C::PSLLDQ_UdqIb(bxInstruction_c *i)
{
#if BX_SUPPORT_SSE >= 2
BX_CPU_THIS_PTR prepareSSE();
BxPackedXmmRegister op = BX_READ_XMM_REG(i->rm()), result;
Bit8u shift = i->Ib();
result.xmm64u(0) = result.xmm64u(1) = 0;
for(unsigned j=shift; j<16; j++) {
result.xmmubyte(j) = op.xmmubyte(j-shift);
}
/* now write result back to destination */
BX_WRITE_XMM_REG(i->rm(), result);
#else
BX_INFO(("PSLLDQ_UdqIb: required SSE2, use --enable-sse option"));
exception(BX_UD_EXCEPTION, 0, 0);
#endif
}
| 30.245792 | 101 | 0.654399 | pavel-krivanek |
ef821a915e4496f4b87de51ce0211e94400c8404 | 1,563 | cpp | C++ | test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp | caiohamamura/libcxx | 27c836ff3a9c505deb9fd1616012924de8ff9279 | [
"MIT"
] | 1,244 | 2015-01-02T21:08:56.000Z | 2022-03-22T21:34:16.000Z | test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp | caiohamamura/libcxx | 27c836ff3a9c505deb9fd1616012924de8ff9279 | [
"MIT"
] | 125 | 2015-01-22T01:08:00.000Z | 2020-05-25T08:28:17.000Z | test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp | caiohamamura/libcxx | 27c836ff3a9c505deb9fd1616012924de8ff9279 | [
"MIT"
] | 124 | 2015-01-12T15:06:17.000Z | 2022-03-26T07:48:53.000Z | //===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
// test move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class NCDeleter
{
int state_;
NCDeleter(NCDeleter&);
NCDeleter& operator=(NCDeleter&);
public:
NCDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(A* p) {delete [] p;}
};
std::unique_ptr<A[]>
source1()
{
return std::unique_ptr<A[]>(new A[3]);
}
void sink1(std::unique_ptr<A[]> p)
{
}
std::unique_ptr<A[], Deleter<A[]> >
source2()
{
return std::unique_ptr<A[], Deleter<A[]> >(new A[3]);
}
void sink2(std::unique_ptr<A[], Deleter<A[]> > p)
{
}
std::unique_ptr<A[], NCDeleter&>
source3()
{
static NCDeleter d;
return std::unique_ptr<A[], NCDeleter&>(new A[3], d);
}
void sink3(std::unique_ptr<A[], NCDeleter&> p)
{
}
int main()
{
sink1(source1());
sink2(source2());
sink3(source3());
assert(A::count == 0);
}
| 17.761364 | 80 | 0.540627 | caiohamamura |
ef8384dfd2ab7e23d4c854917133686efed4604b | 2,736 | cpp | C++ | src/GameData.cpp | dem1980/EmulationStation | 019e78d0486178520e0ee36322a212b9c9451052 | [
"MIT"
] | null | null | null | src/GameData.cpp | dem1980/EmulationStation | 019e78d0486178520e0ee36322a212b9c9451052 | [
"MIT"
] | null | null | null | src/GameData.cpp | dem1980/EmulationStation | 019e78d0486178520e0ee36322a212b9c9451052 | [
"MIT"
] | 1 | 2021-02-24T23:00:44.000Z | 2021-02-24T23:00:44.000Z | #include "GameData.h"
#include <boost/filesystem.hpp>
#include <iostream>
const std::string GameData::xmlTagGameList = "gameList";
const std::string GameData::xmlTagGame = "game";
const std::string GameData::xmlTagName = "name";
const std::string GameData::xmlTagPath = "path";
const std::string GameData::xmlTagDescription = "desc";
const std::string GameData::xmlTagImagePath = "image";
const std::string GameData::xmlTagRating = "rating";
const std::string GameData::xmlTagUserRating = "userrating";
const std::string GameData::xmlTagTimesPlayed = "timesplayed";
const std::string GameData::xmlTagLastPlayed = "lastplayed";
GameData::GameData(SystemData* system, std::string path, std::string name)
: mSystem(system), mPath(path), mName(name), mRating(0.0f), mUserRating(0.0f), mTimesPlayed(0), mLastPlayed(0)
{
}
bool GameData::isFolder() const
{
return false;
}
const std::string & GameData::getName() const
{
return mName;
}
void GameData::setName(const std::string & name)
{
mName = name;
}
const std::string & GameData::getPath() const
{
return mPath;
}
void GameData::setPath(const std::string & path)
{
mPath = path;
}
const std::string & GameData::getDescription() const
{
return mDescription;
}
void GameData::setDescription(const std::string & description)
{
mDescription = description;
}
const std::string & GameData::getImagePath() const
{
return mImagePath;
}
void GameData::setImagePath(const std::string & imagePath)
{
mImagePath = imagePath;
}
float GameData::getRating() const
{
return mRating;
}
void GameData::setRating(float rating)
{
mRating = rating;
}
float GameData::getUserRating() const
{
return mUserRating;
}
void GameData::setUserRating(float rating)
{
mUserRating = rating;
}
size_t GameData::getTimesPlayed() const
{
return mTimesPlayed;
}
void GameData::setTimesPlayed(size_t timesPlayed)
{
mTimesPlayed = timesPlayed;
}
std::time_t GameData::getLastPlayed() const
{
return mLastPlayed;
}
void GameData::setLastPlayed(std::time_t lastPlayed)
{
mLastPlayed = lastPlayed;
}
std::string GameData::getBashPath() const
{
//a quick and dirty way to insert a backslash before most characters that would mess up a bash path
std::string path = mPath;
const char* invalidChars = " '\"\\!$^&*(){}[]?;<>";
for(unsigned int i = 0; i < path.length(); i++)
{
char c;
unsigned int charNum = 0;
do {
c = invalidChars[charNum];
if(path[i] == c)
{
path.insert(i, "\\");
i++;
break;
}
charNum++;
} while(c != '\0');
}
return path;
}
//returns the boost::filesystem stem of our path - e.g. for "/foo/bar.rom" returns "bar"
std::string GameData::getBaseName() const
{
boost::filesystem::path path(mPath);
return path.stem().string();
}
| 19.683453 | 111 | 0.703947 | dem1980 |
ef84a29ef3afd61450620e6687cf4cf220c7f7e4 | 7,898 | hpp | C++ | include/geometricks/data_structure/quad_tree.hpp | mitthy/TCC | 4c48eb11cafd50334c5faef93edc5f03bc7fc171 | [
"MIT"
] | null | null | null | include/geometricks/data_structure/quad_tree.hpp | mitthy/TCC | 4c48eb11cafd50334c5faef93edc5f03bc7fc171 | [
"MIT"
] | null | null | null | include/geometricks/data_structure/quad_tree.hpp | mitthy/TCC | 4c48eb11cafd50334c5faef93edc5f03bc7fc171 | [
"MIT"
] | null | null | null | #ifndef GEOMETRICKS_DATA_STRUCTURE_QUAD_TREE_HPP
#define GEOMETRICKS_DATA_STRUCTURE_QUAD_TREE_HPP
//C stdlib includes
#include <stdint.h>
#include <assert.h>
//C++ stdlib includesca
#include <type_traits>
//Project includes
#include "shapes.hpp"
#include "geometricks/memory/allocator.hpp"
#include "internal/small_vector.hpp"
namespace geometricks {
struct quad_tree_traits {
static constexpr int max_depth = 10;
static constexpr int leaf_size = 4;
};
template< typename T,
typename Traits = quad_tree_traits >
struct quad_tree {
quad_tree( geometricks::rectangle rect, geometricks::allocator alloc = geometricks::allocator{} ): m_root_rect( rect ),
m_nodes( alloc ),
m_element_ref( alloc ),
m_elements( alloc ) {
m_nodes.push_back( __make_leaf__() );
}
bool insert( const T& element ) {
geometricks::rectangle bounding_rect = geometricks::make_rectangle( element );
if( !m_root_rect.contains( bounding_rect ) ) {
return false;
}
auto id = m_elements.push_back( std::make_pair( element, bounding_rect ) );
__insert__( { 0 }, m_root_rect, id, 0 );
return true;
}
private:
struct node_index_t {
int32_t m_value;
operator int32_t() const {
return m_value;
}
};
struct element_index_t {
int32_t m_value;
operator int32_t() const {
return m_value;
}
};
struct node {
//Indexes values in the quad tree. Last bit is used to represent if the value is a leaf or not.
struct index_t {
operator element_index_t() const {
return { static_cast<int32_t>( ( m_value & 0x7FFFFFFF ) - 1 ) };
}
operator node_index_t() const {
return { static_cast<int32_t>( m_value ) };
}
uint32_t m_value;
};
bool
is_leaf() const {
return m_first_child.m_value >> 31;
}
node& operator=( element_index_t leaf_index ) {
m_first_child.m_value = 0x80000000 | ( leaf_index + 1 );
return *this;
}
node& operator=( node_index_t node_index ) {
m_first_child.m_value = node_index;
return *this;
}
index_t m_first_child;
};
//Since each element might be on more than one quadrant of the quad tree, we store 1 index to the element for each type it appears.
//TODO: think if we have to store the rectangle for each element. (Probably a yes).
struct element_t {
int32_t id;
int32_t next;
};
//TODO: SFINAE this to set default value in case leaf_size is not found.
static constexpr int LEAF_SIZE = Traits::leaf_size;
//TODO: SFINAE this to set default value in case max_depth is not found.
static constexpr int MAX_DEPTH = Traits::max_depth;
static constexpr typename node::index_t EMPTY_LEAF = { 0x80000000 };
geometricks::rectangle m_root_rect;
geometricks::small_vector<node, 1> m_nodes; //Index 0 represents the root.
geometricks::small_vector<element_t, LEAF_SIZE> m_element_ref;
geometricks::small_vector<std::pair<T, geometricks::rectangle>, LEAF_SIZE> m_elements;
static node
__make_leaf__() {
return node{ EMPTY_LEAF };
}
struct __split_ret__ {
geometricks::rectangle first;
geometricks::rectangle second;
geometricks::rectangle third;
geometricks::rectangle fourth;
};
__split_ret__
__split_rect__( const geometricks::rectangle& rect ) {
auto half_width = rect.width / 2;
auto half_height = rect.height / 2;
return { geometricks::rectangle{ rect.x_left, rect.y_top, half_width, half_height },
geometricks::rectangle{ rect.x_left + half_width + 1, rect.y_top, rect.width - half_width - 1, half_height },
geometricks::rectangle{ rect.x_left, rect.y_top + half_height + 1, half_width, rect.height - half_height - 1 },
geometricks::rectangle{ rect.x_left + half_width + 1, rect.y_top + half_height + 1, rect.width - half_width - 1, rect.height - half_height - 1 } };
}
int
__count_leaf_objects__( int32_t index ) {
int ret = 0;
while( index != -1 ) {
index = m_element_ref[ index ].next;
++ret;
}
return ret;
}
//TODO
void
__split_node__( node_index_t cur_node, const geometricks::rectangle& rect, int depth ) {
//Create 4 new nodes. Edit small vector class to allow insertion of more than 1 object at a time.
auto [ first, second, third, fourth ] = __split_rect__( rect );
element_index_t first_child = m_nodes[ cur_node ].m_first_child;
int32_t index = first_child;
node_index_t first_node = { m_nodes.push_back( __make_leaf__() ) };
m_nodes.push_back( __make_leaf__() );
m_nodes.push_back( __make_leaf__() );
m_nodes.push_back( __make_leaf__() );
assert( m_nodes[ cur_node ].is_leaf() );
m_nodes[ cur_node ] = first_node;
assert( !m_nodes[ cur_node ].is_leaf() );
while( index != -1 ) {
auto actual_id = m_element_ref[ index ].id;
geometricks::rectangle element_rect = m_elements[ actual_id ].second;
if( geometricks::intersects_with( first, element_rect ) ) {;
__insert__( first_node, first, actual_id, depth + 1 );
}
if( geometricks::intersects_with( second, element_rect ) ) {
__insert__( { first_node + 1 }, second, actual_id, depth + 1 );
}
if( geometricks::intersects_with( third, element_rect ) ) {
__insert__( { first_node + 2 }, third, actual_id, depth + 1 );
}
if( geometricks::intersects_with( fourth, element_rect ) ) {
__insert__( { first_node + 3 }, fourth, actual_id, depth + 1 );
}
index = m_element_ref[ index ].next;
}
}
void
__insert__( node_index_t cur_node, const geometricks::rectangle& rect, int32_t object_id, int depth ) {
if( !m_nodes[ cur_node ].is_leaf() ) {
auto [ first, second, third, fourth ] = __split_rect__( rect );
node_index_t first_node_child = m_nodes[ cur_node ].m_first_child;
if( geometricks::intersects_with( first, m_elements[ object_id ].second ) ) {
__insert__( first_node_child, first, object_id, depth + 1 );
}
if( geometricks::intersects_with( second, m_elements[ object_id ].second ) ) {
__insert__( { first_node_child + 1 }, second, object_id, depth + 1 );
}
if( geometricks::intersects_with( third, m_elements[ object_id ].second ) ) {
__insert__( { first_node_child + 2 }, third, object_id, depth + 1 );
}
if( geometricks::intersects_with( fourth, m_elements[ object_id ].second ) ) {
__insert__( { first_node_child + 3 }, fourth, object_id, depth + 1 );
}
}
else {
element_index_t last_element_index = m_nodes[ cur_node ].m_first_child;
element_t new_el{ object_id, last_element_index };
element_index_t element_id = { m_element_ref.push_back( new_el ) };
m_nodes[ cur_node ] = element_id;
if( !( depth == MAX_DEPTH || rect.height < 3 || rect.width < 3 ) ) {
auto count = __count_leaf_objects__( element_id );
if( count > LEAF_SIZE ) {
assert( m_nodes[ cur_node ].is_leaf() );
__split_node__( cur_node, rect, depth );
assert( !m_nodes[ cur_node ].is_leaf() );
}
}
}
}
};
} //namespace geometricks
#endif //GEOMETRICKS_DATA_STRUCTURE_QUAD_TREE_HPP
| 34.190476 | 162 | 0.609775 | mitthy |
ef8627edd1d9bc81fe84b0e6c41e724cbe8e3ff1 | 2,533 | hpp | C++ | Example/Toturial-3/5 - thread - producer consumer list/thread - producer consumer list/MTLibrary/LockList.hpp | orenccl/Winsock-Multi-Client-Server | 143bb3b6c856270249632dc01f5223f65180ca89 | [
"MIT"
] | 2 | 2019-11-11T01:03:02.000Z | 2019-11-11T01:04:54.000Z | Example/Toturial-3/5 - thread - producer consumer list/thread - producer consumer list/MTLibrary/LockList.hpp | orenccl/MintServer | 143bb3b6c856270249632dc01f5223f65180ca89 | [
"MIT"
] | null | null | null | Example/Toturial-3/5 - thread - producer consumer list/thread - producer consumer list/MTLibrary/LockList.hpp | orenccl/MintServer | 143bb3b6c856270249632dc01f5223f65180ca89 | [
"MIT"
] | null | null | null | #pragma once
#include "List/TMPSinglyList.hpp"
#include "List/TMPDoublyList.hpp"
#include "Lock.h"
template < class DATA_TYPE >
class TMPSinglyLockList : public TMPSinglyList< DATA_TYPE >
{
public:
CLock Locker;
inline void Create(UINT object_max)
{
TMPSinglyList< DATA_TYPE >::Create(object_max);
Locker.Create();
}
inline TSNode< DATA_TYPE >* LockGetNode()
{
Locker.Lock();
TSNode< DATA_TYPE >* node = TMPSinglyList< DATA_TYPE >::GetNode();
Locker.Unlock();
return node;
}
inline void LockLink(TSNode< DATA_TYPE >* link_node)
{
Locker.Lock();
TMPSinglyList< DATA_TYPE >::Link(link_node);
Locker.Unlock();
}
inline void LockUnlink(TSNode< DATA_TYPE >* unlink_node)
{
Locker.Lock();
TMPSinglyList< DATA_TYPE >::Unlink(unlink_node);
Locker.Unlock();
}
inline void LockFreeNode(TSNode< DATA_TYPE >*& release_node)
{
Locker.Lock();
TMPSinglyList< DATA_TYPE >::FreeNode(release_node);
Locker.Unlock();
}
inline TSNode< DATA_TYPE >* LockGetHeadNode()
{
Locker.Lock();
TSNode< DATA_TYPE >* node = TMPSinglyList< DATA_TYPE >::pHeadNode;
Locker.Unlock();
return node;
}
inline void LockUnlinkFreeNode(TSNode< DATA_TYPE >*& node)
{
Locker.Lock();
TMPSinglyList< DATA_TYPE >::Unlink(node);
TMPSinglyList< DATA_TYPE >::FreeNode(node);
Locker.Unlock();
}
};
template < class DATA_TYPE >
class TMPDoublyLockList : public TMPDoublyList< DATA_TYPE >
{
public:
CLock Locker;
inline void Create(UINT object_max)
{
TMPDoublyList< DATA_TYPE >::Create(object_max);
Locker.Create();
}
inline TDNode< DATA_TYPE >* LockGetNode()
{
Locker.Lock();
TDNode< DATA_TYPE >* node = TMPDoublyList< DATA_TYPE >::GetNode();
Locker.Unlock();
return node;
}
inline void LockLink(TDNode< DATA_TYPE >* link_node)
{
Locker.Lock();
TMPDoublyList< DATA_TYPE >::Link(link_node);
Locker.Unlock();
}
inline void LockUnlink(TDNode< DATA_TYPE >* unlink_node)
{
Locker.Lock();
TMPDoublyList< DATA_TYPE >::Unlink(unlink_node);
Locker.Unlock();
}
inline void LockFreeNode(TDNode< DATA_TYPE >*& release_node)
{
Locker.Lock();
TMPDoublyList< DATA_TYPE >::FreeNode(release_node);
Locker.Unlock();
}
inline TDNode< DATA_TYPE >* LockGetHeadNode()
{
Locker.Lock();
TDNode< DATA_TYPE >* node = TMPDoublyList< DATA_TYPE >::pHeadNode;
Locker.Unlock();
return node;
}
inline void LockUnlinkFreeNode(TDNode< DATA_TYPE >*& node)
{
Locker.Lock();
TMPSinglyList< DATA_TYPE >::Unlink(node);
TMPSinglyList< DATA_TYPE >::FreeNode(node);
Locker.Unlock();
}
}; | 23.238532 | 68 | 0.703514 | orenccl |
ef87588eef357ff09ac11b86790d501435602102 | 2,813 | cpp | C++ | tester.cpp | ReinaldoDiasAbreu/TestesAutomatizados | 06ce12a3af585d3f3ffadf0e9966346112460c2f | [
"MIT"
] | null | null | null | tester.cpp | ReinaldoDiasAbreu/TestesAutomatizados | 06ce12a3af585d3f3ffadf0e9966346112460c2f | [
"MIT"
] | null | null | null | tester.cpp | ReinaldoDiasAbreu/TestesAutomatizados | 06ce12a3af585d3f3ffadf0e9966346112460c2f | [
"MIT"
] | null | null | null | #include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
using namespace std;
/*
Programa de Automatização de Testes
*/
void help()
{
cout << endl << " TESTER" << endl << endl;
cout << " Executa comparaçoes entre as entradas e saídas especificadas." << endl << endl;
cout << " Comando: " << endl << endl;
cout << " ./tester exec dir N D" << endl << endl;
cout << " exec -> Arquivo executável." << endl;
cout << " dir -> Diretório de arquivos de entrada e saída (.in, .sol)." << endl;
cout << " N -> Quantidade de testes." << endl;
cout << " D -> Remove arquivos de resposta se 1 (.res)." << endl;
cout << endl << " Os arquivos de entrada e saída devem ser nomedados da seguinte maneira:" << endl << endl;
cout << " 0.in - 0.sol" << endl;
cout << " 1.in - 1.sol" << endl;
cout << endl << " Todos os arquivos devem ficar no mesmo diretorio (dir) e numerados" << endl;
cout << " em sequência de execuçao (De 0 a N-1)." << endl;
cout << " O executavel deve ficar no mesmo diretório do tester." << endl << endl;
cout << " Exemplo: ./tester myprogram testes 5 1" << endl << endl;
}
int main(int argc, char *argv[])
{
if(argc > 1)
{
if(argc == 2)
{
if(strcmp(argv[1], "--help") == 0)
{
help();
}
}
else
{
cout << " TESTER" << endl;
cout << "Exec: " << argv[1] << " -> Pasta: /" << argv[2] << " -> Quant: " << argv[3] << endl << endl;
string exec = string(argv[1]);
string pasta = string(argv[2]);
for(int i = 0; i < atoi(argv[3]); i++)
{
string ind = to_string(i);
string cexec = "./" + exec + " < " + pasta + "/" + ind + ".in" + " > " + pasta + "/" + ind + ".res" ;
string ccomp = "diff -q " + pasta + "/" + ind + ".res " + pasta + "/" + ind + ".sol";
if(system(cexec.c_str()) == 0)
{
if(system(ccomp.c_str()) == 0)
cout << "TEST " << i << " -> PASSED" << endl;
else
cout << "TEST " << i << " -> NOT IDENTICAL" << endl;
}
else cout << "TEST " << i << " -> EXECUTION ERROR" << endl;
}
string clean = "rm " + pasta + "/*.res";
if(argv[4])
system(clean.c_str());
}
}
else
{
cout << "Parametros Invalidos" << endl << endl;
help();
}
cout << endl << "FINISHED" << endl;
return 0;
}
| 35.607595 | 118 | 0.424102 | ReinaldoDiasAbreu |
ef8b264cd7a612e3c1bfe6c2f13a18893deaf7b6 | 1,630 | cpp | C++ | add_strings.cpp | shirishbahirat/algorithm | ec743d4c16ab4f429f22bd6f71540341b3905b3b | [
"Apache-2.0"
] | null | null | null | add_strings.cpp | shirishbahirat/algorithm | ec743d4c16ab4f429f22bd6f71540341b3905b3b | [
"Apache-2.0"
] | null | null | null | add_strings.cpp | shirishbahirat/algorithm | ec743d4c16ab4f429f22bd6f71540341b3905b3b | [
"Apache-2.0"
] | null | null | null | #include <iostream>
#include <sstream>
using namespace std;
class Solution
{
public:
string addStrings(string num1, string num2)
{
int n1 = 0, n2 = 0;
int i, j;
int carry = 0;
int sum;
string results = "";
string str1, str2;
for (i = (num1.size() - 1), j = (num2.size() - 1); (i >= 0) && (j >= 0);
--i, --j)
{
stringstream s1, s2;
s1 << num1[i];
s2 << num2[j];
str1 = s1.str();
str2 = s2.str();
n1 = stoi(str1);
n2 = stoi(str2);
sum = n1 + n2 + carry;
if (sum > 9)
{
carry = 1;
sum %= 10;
}
else
{
carry = 0;
}
results = to_string(sum) + results;
}
while (j >= 0)
{
stringstream s2;
s2 << num2[j];
str2 = s2.str();
n2 = stoi(str2);
sum = n2 + carry;
if (sum > 9)
{
carry = 1;
sum %= 10;
}
else
{
carry = 0;
}
results = to_string(sum) + results;
--j;
}
while (i >= 0)
{
stringstream s1;
s1 << num1[i];
str1 = s1.str();
n1 = stoi(str1);
sum = n1 + carry;
if (sum > 9)
{
carry = 1;
sum %= 10;
}
else
{
carry = 0;
}
results = to_string(sum) + results;
--i;
}
if (carry)
{
results = to_string(carry) + results;
}
return results;
}
};
int main(int argc, char const *argv[])
{
Solution *obj = new Solution();
string results = obj->addStrings("408", "5");
cout << results << endl;
return 0;
}
| 14.684685 | 76 | 0.423313 | shirishbahirat |
ef8bc7dabcb3e35dfd2bb55ab965a44577b48b70 | 20,488 | cpp | C++ | src/plugProjectNishimuraU/KurageMgr.cpp | projectPiki/pikmin2 | a431d992acde856d092889a515ecca0e07a3ea7c | [
"Unlicense"
] | 33 | 2021-12-08T11:10:59.000Z | 2022-03-26T19:59:37.000Z | src/plugProjectNishimuraU/KurageMgr.cpp | projectPiki/pikmin2 | a431d992acde856d092889a515ecca0e07a3ea7c | [
"Unlicense"
] | 6 | 2021-12-22T17:54:31.000Z | 2022-01-07T21:43:18.000Z | src/plugProjectNishimuraU/KurageMgr.cpp | projectPiki/pikmin2 | a431d992acde856d092889a515ecca0e07a3ea7c | [
"Unlicense"
] | 2 | 2022-01-04T06:00:49.000Z | 2022-01-26T07:27:28.000Z | #include "types.h"
/*
Generated from dpostproc
.section .rodata # 0x804732E0 - 0x8049E220
.global lbl_80489A38
lbl_80489A38:
.asciz "246-KurageMgr"
.skip 2
.global lbl_80489A48
lbl_80489A48:
.4byte 0x834E8389
.4byte 0x83518368
.4byte 0x8362834E
.4byte 0x838A837D
.4byte 0x836C815B
.4byte 0x83578383
.4byte 0x00000000
.4byte 0x456E656D
.4byte 0x79506172
.4byte 0x6D734261
.4byte 0x73650000
.4byte 0x94F28D73
.4byte 0x8D8282B3
.4byte 0x00000000
.4byte 0x8FE38FB8
.4byte 0x8C579094
.4byte 0x00000000
.4byte 0x926E8FE3
.4byte 0x83458346
.4byte 0x83438367
.4byte 0x8E9E8AD4
.4byte 0x00000000
.4byte 0x8B7A82A2
.4byte 0x8D9E82DD
.4byte 0x8E9E8AD4
.4byte 0x00000000
.4byte 0x8B7A82A2
.4byte 0x8D9E82DD
.4byte 0x8A6D97A6
.4byte 0x00000000
.4byte 0x905595A5
.4byte 0x978E89BA
.4byte 0x8E9E8AD4
.4byte 0x00000000
.4byte 0x978E89BA
.4byte 0x8DC592E1
.4byte 0x8373834C
.4byte 0x90940000
.4byte 0x8B7A82A2
.4byte 0x8D9E82DD
.4byte 0x8373834C
.4byte 0x90940000
.4byte 0x43726561
.4byte 0x74757265
.4byte 0x3A3A5072
.4byte 0x6F706572
.4byte 0x74790000
.4byte 0x66726963
.4byte 0x74696F6E
.4byte 0x286E6F74
.4byte 0x20757365
.4byte 0x64290000
.4byte 0x77616C6C
.4byte 0x5265666C
.4byte 0x65637469
.4byte 0x6F6E0000
.4byte 0x66616365
.4byte 0x44697241
.4byte 0x646A7573
.4byte 0x74000000
.4byte 0x626F756E
.4byte 0x63654661
.4byte 0x63746F72
.4byte 0x00000000
.4byte 0x83898343
.4byte 0x837482CC
.4byte 0x8D8282B3
.4byte 0x00000000
.4byte 0x83898343
.4byte 0x837489F1
.4byte 0x959C97A6
.4byte 0x00000000
.4byte 0x8C7889FA
.4byte 0x83898343
.4byte 0x83740000
.4byte 0x837D8362
.4byte 0x837682C6
.4byte 0x82CC9396
.4byte 0x82E80000
.4byte 0x837D8362
.4byte 0x837682C6
.4byte 0x82CC82A0
.4byte 0x82BD82E8
.4byte 0x837C838A
.4byte 0x83538393
.4byte 0x82CC9149
.4byte 0x92E80000
.4byte 0x8373834E
.4byte 0x837E8393
.4byte 0x82C682CC
.4byte 0x82A082BD
.4byte 0x82E80000
.4byte 0x835F8381
.4byte 0x815B8357
.4byte 0x83588350
.4byte 0x815B838B
.4byte 0x585A0000
.4byte 0x835F8381
.4byte 0x815B8357
.4byte 0x83588350
.4byte 0x815B838B
.4byte 0x59000000
.4byte 0x835F8381
.4byte 0x815B8357
.4byte 0x8374838C
.4byte 0x815B8380
.4byte 0x00000000
.4byte 0x89F1935D
.4byte 0x91AC9378
.4byte 0x97A60000
.4byte 0x89F1935D
.4byte 0x8DC591E5
.4byte 0x91AC9378
.4byte 0x00000000
.4byte 0x8365838A
.4byte 0x8367838A
.4byte 0x815B0000
.4byte 0x837A815B
.4byte 0x838094CD
.4byte 0x88CD0000
.4byte 0x83768389
.4byte 0x83438378
.4byte 0x815B8367
.4byte 0x8B9797A3
.4byte 0x00000000
.4byte 0x8E8B8A45
.4byte 0x8B9797A3
.4byte 0x00000000
.4byte 0x8E8B8A45
.4byte 0x8A709378
.4byte 0x00000000
.4byte 0x92548DF5
.4byte 0x8B9797A3
.4byte 0x00000000
.4byte 0x92548DF5
.4byte 0x8A709378
.4byte 0x00000000
.4byte 0x905582E8
.4byte 0x95A582A2
.4byte 0x97CD0000
.4byte 0x905582E8
.4byte 0x95A582A2
.4byte 0x835F8381
.4byte 0x815B8357
.4byte 0x00000000
.4byte 0x905582E8
.4byte 0x95A582A2
.4byte 0x94CD88CD
.4byte 0x00000000
.4byte 0x905582E8
.4byte 0x95A582A2
.4byte 0x97A60000
.4byte 0x8D558C82
.4byte 0x89C2945C
.4byte 0x94CD88CD
.4byte 0x00000000
.4byte 0x8D558C82
.4byte 0x89C2945C
.4byte 0x8A709378
.4byte 0x00000000
.4byte 0x8D558C82
.4byte 0x83718362
.4byte 0x836794CD
.4byte 0x88CD0000
.4byte 0x8D558C82
.4byte 0x83718362
.4byte 0x83678A70
.4byte 0x93780000
.4byte 0x8C7889FA
.4byte 0x8E9E8AD4
.4byte 0x00000000
.4byte 0x90CE89BB
.4byte 0x8E9E8AD4
.4byte 0x00000000
.4byte 0x83718362
.4byte 0x83768368
.4byte 0x838D8362
.4byte 0x8376835F
.4byte 0x8381815B
.4byte 0x83570000
.4byte 0x926E906B
.4byte 0x8B4390E2
.4byte 0x8A6D97A7
.4byte 0x00000000
.4byte 0x926E906B
.4byte 0x8B4390E2
.4byte 0x8E9E8AD4
.4byte 0x00000000
.4byte 0x905582E8
.4byte 0x95A582A2
.4byte 0x91C58C82
.4byte 0x82600000
.4byte 0x905582E8
.4byte 0x95A582A2
.4byte 0x92A39574
.4byte 0x82500000
.4byte 0x905582E8
.4byte 0x95A582A2
.4byte 0x91C58C82
.4byte 0x82610000
.4byte 0x905582E8
.4byte 0x95A582A2
.4byte 0x92A39574
.4byte 0x82510000
.4byte 0x905582E8
.4byte 0x95A582A2
.4byte 0x91C58C82
.4byte 0x82620000
.4byte 0x905582E8
.4byte 0x95A582A2
.4byte 0x92A39574
.4byte 0x82520000
.4byte 0x905582E8
.4byte 0x95A582A2
.4byte 0x91C58C82
.4byte 0x82630000
.section .data, "wa" # 0x8049E220 - 0x804EFC20
.global __vt__Q34Game6Kurage3Mgr
__vt__Q34Game6Kurage3Mgr:
.4byte 0
.4byte 0
.4byte doAnimation__Q24Game12EnemyMgrBaseFv
.4byte doEntry__Q24Game12EnemyMgrBaseFv
.4byte doSetView__Q24Game12EnemyMgrBaseFi
.4byte doViewCalc__Q24Game12EnemyMgrBaseFv
.4byte doSimulation__Q24Game12EnemyMgrBaseFf
.4byte doDirectDraw__Q24Game12EnemyMgrBaseFR8Graphics
.4byte doSimpleDraw__16GenericObjectMgrFP8Viewport
.4byte loadResources__16GenericObjectMgrFv
.4byte resetMgr__16GenericObjectMgrFv
.4byte pausable__16GenericObjectMgrFv
.4byte frozenable__16GenericObjectMgrFv
.4byte getMatrixLoadType__16GenericObjectMgrFv
.4byte 0
.4byte 0
.4byte "@4@__dt__Q34Game6Kurage3MgrFv"
.4byte getChildCount__5CNodeFv
.4byte "@4@getObject__Q24Game12EnemyMgrBaseFPv"
.4byte "@4@getNext__Q24Game12EnemyMgrBaseFPv"
.4byte "@4@getStart__Q24Game12EnemyMgrBaseFv"
.4byte "@4@getEnd__Q24Game12EnemyMgrBaseFv"
.4byte __dt__Q34Game6Kurage3MgrFv
.4byte getObject__Q24Game12EnemyMgrBaseFPv
.4byte getNext__Q24Game12EnemyMgrBaseFPv
.4byte getStart__Q24Game12EnemyMgrBaseFv
.4byte getEnd__Q24Game12EnemyMgrBaseFv
.4byte alloc__Q24Game12EnemyMgrBaseFv
.4byte birth__Q24Game12EnemyMgrBaseFRQ24Game13EnemyBirthArg
.4byte getJ3DModelData__Q24Game12EnemyMgrBaseCFv
.4byte getGenerator__Q24Game12EnemyMgrBaseCFv
.4byte killAll__Q24Game12EnemyMgrBaseFPQ24Game15CreatureKillArg
.4byte setupSoundViewerAndBas__Q24Game12EnemyMgrBaseFv
.4byte setDebugParm__Q24Game12EnemyMgrBaseFUl
.4byte resetDebugParm__Q24Game12EnemyMgrBaseFUl
.4byte getMaxObjects__Q24Game12EnemyMgrBaseCFv
.4byte startMovie__Q24Game12EnemyMgrBaseFv
.4byte endMovie__Q24Game12EnemyMgrBaseFv
.4byte get__Q24Game12EnemyMgrBaseFPv
.4byte isAlwaysMovieActor__Q24Game12EnemyMgrBaseFv
.4byte createObj__Q34Game6Kurage3MgrFi
.4byte getEnemy__Q34Game6Kurage3MgrFi
.4byte doAlloc__Q34Game6Kurage3MgrFv
.4byte getEnemyTypeID__Q34Game6Kurage3MgrFv
.4byte createModel__Q24Game12EnemyMgrBaseFv
.4byte initParms__Q24Game12EnemyMgrBaseFv
.4byte loadResource__Q24Game12EnemyMgrBaseFv
.4byte initObjects__Q24Game12EnemyMgrBaseFv
.4byte initStoneSetting__Q24Game12EnemyMgrBaseFv
.4byte loadModelData__Q24Game12EnemyMgrBaseFP10JKRArchive
.4byte loadModelData__Q34Game6Kurage3MgrFv
.4byte loadAnimData__Q24Game12EnemyMgrBaseFv
.4byte loadTexData__Q24Game12EnemyMgrBaseFv
.4byte doLoadBmd__Q34Game6Kurage3MgrFPv
.4byte doLoadBdl__Q24Game12EnemyMgrBaseFPv
.4byte initGenerator__Q24Game12EnemyMgrBaseFv
.global __vt__Q34Game6Kurage5Parms
__vt__Q34Game6Kurage5Parms:
.4byte 0
.4byte 0
.4byte read__Q34Game6Kurage5ParmsFR6Stream
.4byte 0
.section .sdata2, "a" # 0x80516360 - 0x80520E40
.global lbl_8051C0A0
lbl_8051C0A0:
.4byte 0x42B40000
.global lbl_8051C0A4
lbl_8051C0A4:
.4byte 0x00000000
.global lbl_8051C0A8
lbl_8051C0A8:
.4byte 0x43160000
.global lbl_8051C0AC
lbl_8051C0AC:
.float 1.0
.global lbl_8051C0B0
lbl_8051C0B0:
.4byte 0x41200000
.global lbl_8051C0B4
lbl_8051C0B4:
.4byte 0x40400000
.global lbl_8051C0B8
lbl_8051C0B8:
.4byte 0x40A00000
.global lbl_8051C0BC
lbl_8051C0BC:
.4byte 0x3CCCCCCD
*/
namespace Game {
/*
* --INFO--
* Address: 802AD104
* Size: 000050
*/
Kurage::Mgr::Mgr(int, unsigned char)
{
/*
stwu r1, -0x10(r1)
mflr r0
stw r0, 0x14(r1)
stw r31, 0xc(r1)
mr r31, r3
bl __ct__Q24Game12EnemyMgrBaseFiUc
lis r3, __vt__Q34Game6Kurage3Mgr@ha
lis r4, lbl_80489A48@ha
addi r5, r3, __vt__Q34Game6Kurage3Mgr@l
mr r3, r31
stw r5, 0(r31)
addi r5, r5, 0x38
addi r0, r4, lbl_80489A48@l
stw r5, 4(r31)
stw r0, 0x18(r31)
lwz r31, 0xc(r1)
lwz r0, 0x14(r1)
mtlr r0
addi r1, r1, 0x10
blr
*/
}
/*
* --INFO--
* Address: 802AD154
* Size: 000048
*/
void Kurage::Mgr::doAlloc()
{
/*
stwu r1, -0x10(r1)
mflr r0
stw r0, 0x14(r1)
stw r31, 0xc(r1)
mr r31, r3
li r3, 0x948
bl __nw__FUl
or. r4, r3, r3
beq lbl_802AD180
bl __ct__Q34Game6Kurage5ParmsFv
mr r4, r3
lbl_802AD180:
mr r3, r31
bl init__Q24Game12EnemyMgrBaseFPQ24Game14EnemyParmsBase
lwz r0, 0x14(r1)
lwz r31, 0xc(r1)
mtlr r0
addi r1, r1, 0x10
blr
*/
}
/*
* --INFO--
* Address: 802AD19C
* Size: 000048
*/
Kurage::Parms::Parms()
{
/*
stwu r1, -0x10(r1)
mflr r0
stw r0, 0x14(r1)
stw r31, 0xc(r1)
mr r31, r3
bl __ct__Q24Game14EnemyParmsBaseFv
lis r4, __vt__Q34Game6Kurage5Parms@ha
addi r3, r31, 0x7f8
addi r0, r4, __vt__Q34Game6Kurage5Parms@l
li r4, 1
stw r0, 0xd8(r31)
bl __ct__Q44Game6Kurage5Parms11ProperParmsFv
lwz r0, 0x14(r1)
mr r3, r31
lwz r31, 0xc(r1)
mtlr r0
addi r1, r1, 0x10
blr
*/
}
/*
* --INFO--
* Address: 802AD1E4
* Size: 00023C
*/
Kurage::Parms::ProperParms::ProperParms()
{
/*
stwu r1, -0x10(r1)
mflr r0
stw r0, 0x14(r1)
extsh. r0, r4
lis r4, lbl_80489A38@ha
stw r31, 0xc(r1)
addi r31, r4, lbl_80489A38@l
stw r30, 8(r1)
mr r30, r3
beq lbl_802AD214
addi r0, r30, 0x14c
stw r0, 0(r30)
lbl_802AD214:
li r0, 0
lis r5, 0x66703031@ha
stw r0, 4(r30)
addi r0, r31, 0x2c
mr r4, r30
addi r3, r30, 0xc
stw r0, 8(r30)
addi r5, r5, 0x66703031@l
addi r6, r31, 0x3c
bl __ct__8BaseParmFP10ParametersUlPc
lis r3, "__vt__7Parm<f>"@ha
lis r5, 0x66703032@ha
addi r0, r3, "__vt__7Parm<f>"@l
lfs f0, lbl_8051C0A0@sda21(r2)
stw r0, 0xc(r30)
mr r4, r30
lfs f1, lbl_8051C0A4@sda21(r2)
addi r3, r30, 0x34
stfs f0, 0x24(r30)
addi r5, r5, 0x66703032@l
lfs f0, lbl_8051C0A8@sda21(r2)
addi r6, r31, 0x48
stfs f1, 0x2c(r30)
stfs f0, 0x30(r30)
bl __ct__8BaseParmFP10ParametersUlPc
lis r3, "__vt__7Parm<f>"@ha
lis r5, 0x66703130@ha
addi r0, r3, "__vt__7Parm<f>"@l
lfs f0, lbl_8051C0AC@sda21(r2)
stw r0, 0x34(r30)
mr r4, r30
lfs f1, lbl_8051C0A4@sda21(r2)
addi r3, r30, 0x5c
stfs f0, 0x4c(r30)
addi r5, r5, 0x66703130@l
lfs f0, lbl_8051C0B0@sda21(r2)
addi r6, r31, 0x54
stfs f1, 0x54(r30)
stfs f0, 0x58(r30)
bl __ct__8BaseParmFP10ParametersUlPc
lis r3, "__vt__7Parm<f>"@ha
lis r5, 0x66703131@ha
addi r0, r3, "__vt__7Parm<f>"@l
lfs f0, lbl_8051C0B4@sda21(r2)
stw r0, 0x5c(r30)
mr r4, r30
lfs f1, lbl_8051C0A4@sda21(r2)
addi r3, r30, 0x84
stfs f0, 0x74(r30)
addi r5, r5, 0x66703131@l
lfs f0, lbl_8051C0B0@sda21(r2)
addi r6, r31, 0x68
stfs f1, 0x7c(r30)
stfs f0, 0x80(r30)
bl __ct__8BaseParmFP10ParametersUlPc
lis r3, "__vt__7Parm<f>"@ha
lis r5, 0x66703132@ha
addi r0, r3, "__vt__7Parm<f>"@l
lfs f0, lbl_8051C0B8@sda21(r2)
stw r0, 0x84(r30)
mr r4, r30
lfs f1, lbl_8051C0A4@sda21(r2)
addi r3, r30, 0xac
stfs f0, 0x9c(r30)
addi r5, r5, 0x66703132@l
lfs f0, lbl_8051C0B0@sda21(r2)
addi r6, r31, 0x78
stfs f1, 0xa4(r30)
stfs f0, 0xa8(r30)
bl __ct__8BaseParmFP10ParametersUlPc
lis r3, "__vt__7Parm<f>"@ha
lis r5, 0x66703034@ha
addi r0, r3, "__vt__7Parm<f>"@l
lfs f0, lbl_8051C0BC@sda21(r2)
stw r0, 0xac(r30)
mr r4, r30
lfs f1, lbl_8051C0A4@sda21(r2)
addi r3, r30, 0xd4
stfs f0, 0xc4(r30)
addi r5, r5, 0x66703034@l
lfs f0, lbl_8051C0AC@sda21(r2)
addi r6, r31, 0x88
stfs f1, 0xcc(r30)
stfs f0, 0xd0(r30)
bl __ct__8BaseParmFP10ParametersUlPc
lis r3, "__vt__7Parm<f>"@ha
lis r5, 0x69703031@ha
addi r0, r3, "__vt__7Parm<f>"@l
lfs f0, lbl_8051C0B4@sda21(r2)
stw r0, 0xd4(r30)
mr r4, r30
lfs f1, lbl_8051C0A4@sda21(r2)
addi r3, r30, 0xfc
stfs f0, 0xec(r30)
addi r5, r5, 0x69703031@l
lfs f0, lbl_8051C0B0@sda21(r2)
addi r6, r31, 0x98
stfs f1, 0xf4(r30)
stfs f0, 0xf8(r30)
bl __ct__8BaseParmFP10ParametersUlPc
lis r3, "__vt__7Parm<i>"@ha
lis r5, 0x69703131@ha
addi r0, r3, "__vt__7Parm<i>"@l
li r3, 0xa
stw r0, 0xfc(r30)
li r7, 1
li r0, 0x32
mr r4, r30
stw r3, 0x114(r30)
addi r3, r30, 0x124
addi r5, r5, 0x69703131@l
addi r6, r31, 0xa8
stw r7, 0x11c(r30)
stw r0, 0x120(r30)
bl __ct__8BaseParmFP10ParametersUlPc
lis r3, "__vt__7Parm<i>"@ha
li r5, 0xa
addi r0, r3, "__vt__7Parm<i>"@l
li r4, 1
stw r0, 0x124(r30)
li r0, 0x64
mr r3, r30
stw r5, 0x13c(r30)
stw r4, 0x144(r30)
stw r0, 0x148(r30)
lwz r31, 0xc(r1)
lwz r30, 8(r1)
lwz r0, 0x14(r1)
mtlr r0
addi r1, r1, 0x10
blr
*/
}
/*
* --INFO--
* Address: 802AD420
* Size: 000060
*/
void Kurage::Mgr::createObj(int)
{
/*
stwu r1, -0x10(r1)
mflr r0
stw r0, 0x14(r1)
stw r31, 0xc(r1)
mr r31, r4
stw r30, 8(r1)
mr r30, r3
mulli r3, r31, 0x30c
addi r3, r3, 0x10
bl __nwa__FUl
lis r4, __ct__Q34Game6Kurage3ObjFv@ha
lis r5, __dt__Q34Game6Kurage3ObjFv@ha
addi r4, r4, __ct__Q34Game6Kurage3ObjFv@l
mr r7, r31
addi r5, r5, __dt__Q34Game6Kurage3ObjFv@l
li r6, 0x30c
bl __construct_new_array
stw r3, 0x44(r30)
lwz r0, 0x14(r1)
lwz r31, 0xc(r1)
lwz r30, 8(r1)
mtlr r0
addi r1, r1, 0x10
blr
*/
}
/*
* --INFO--
* Address: 802AD480
* Size: 0000BC
*/
Kurage::Obj::~Obj()
{
/*
stwu r1, -0x10(r1)
mflr r0
stw r0, 0x14(r1)
stw r31, 0xc(r1)
or. r31, r3, r3
stw r30, 8(r1)
mr r30, r4
beq lbl_802AD520
lis r3, __vt__Q34Game6Kurage3Obj@ha
addi r0, r31, 0x2fc
addi r4, r3, __vt__Q34Game6Kurage3Obj@l
stw r4, 0(r31)
addi r3, r4, 0x1b0
addi r4, r4, 0x2fc
stw r3, 0x178(r31)
lwz r3, 0x17c(r31)
stw r4, 0(r3)
lwz r3, 0x17c(r31)
subf r0, r3, r0
stw r0, 0xc(r3)
beq lbl_802AD510
lis r3, __vt__Q24Game9EnemyBase@ha
addi r0, r31, 0x2bc
addi r4, r3, __vt__Q24Game9EnemyBase@l
addi r3, r31, 0x290
stw r4, 0(r31)
addi r5, r4, 0x1b0
addi r6, r4, 0x2f8
li r4, -1
stw r5, 0x178(r31)
lwz r5, 0x17c(r31)
stw r6, 0(r5)
lwz r5, 0x17c(r31)
subf r0, r5, r0
stw r0, 0xc(r5)
bl __dt__5CNodeFv
lbl_802AD510:
extsh. r0, r30
ble lbl_802AD520
mr r3, r31
bl __dl__FPv
lbl_802AD520:
lwz r0, 0x14(r1)
mr r3, r31
lwz r31, 0xc(r1)
lwz r30, 8(r1)
mtlr r0
addi r1, r1, 0x10
blr
*/
}
/*
* --INFO--
* Address: 802AD53C
* Size: 000010
*/
void Kurage::Mgr::getEnemy(int)
{
/*
mulli r0, r4, 0x30c
lwz r3, 0x44(r3)
add r3, r3, r0
blr
*/
}
/*
* --INFO--
* Address: 802AD54C
* Size: 000068
*/
void Kurage::Mgr::loadModelData()
{
/*
stwu r1, -0x10(r1)
mflr r0
stw r0, 0x14(r1)
stw r31, 0xc(r1)
mr r31, r3
bl loadModelData__Q24Game12EnemyMgrBaseFv
li r5, 0
b lbl_802AD58C
lbl_802AD56C:
lwz r3, 0x80(r4)
rlwinm r0, r5, 2, 0xe, 0x1d
addi r5, r5, 1
lwzx r3, r3, r0
lwz r0, 0xc(r3)
rlwinm r0, r0, 0, 0x14, 0xf
ori r0, r0, 0x2000
stw r0, 0xc(r3)
lbl_802AD58C:
lwz r4, 0x1c(r31)
clrlwi r0, r5, 0x10
lhz r3, 0x7c(r4)
cmplw r0, r3
blt lbl_802AD56C
lwz r0, 0x14(r1)
lwz r31, 0xc(r1)
mtlr r0
addi r1, r1, 0x10
blr
*/
}
/*
* --INFO--
* Address: 802AD5B4
* Size: 0000B0
*/
Kurage::Mgr::~Mgr()
{
/*
stwu r1, -0x10(r1)
mflr r0
stw r0, 0x14(r1)
stw r31, 0xc(r1)
mr r31, r4
stw r30, 8(r1)
or. r30, r3, r3
beq lbl_802AD648
lis r3, __vt__Q34Game6Kurage3Mgr@ha
addi r3, r3, __vt__Q34Game6Kurage3Mgr@l
stw r3, 0(r30)
addi r0, r3, 0x38
stw r0, 4(r30)
beq lbl_802AD638
lis r3, __vt__Q24Game12EnemyMgrBase@ha
addi r3, r3, __vt__Q24Game12EnemyMgrBase@l
stw r3, 0(r30)
addi r0, r3, 0x38
stw r0, 4(r30)
beq lbl_802AD638
lis r3, __vt__Q24Game13IEnemyMgrBase@ha
addic. r0, r30, 4
addi r3, r3, __vt__Q24Game13IEnemyMgrBase@l
stw r3, 0(r30)
addi r0, r3, 0x38
stw r0, 4(r30)
beq lbl_802AD638
lis r4, __vt__16GenericContainer@ha
addi r3, r30, 4
addi r0, r4, __vt__16GenericContainer@l
li r4, 0
stw r0, 4(r30)
bl __dt__5CNodeFv
lbl_802AD638:
extsh. r0, r31
ble lbl_802AD648
mr r3, r30
bl __dl__FPv
lbl_802AD648:
lwz r0, 0x14(r1)
mr r3, r30
lwz r31, 0xc(r1)
lwz r30, 8(r1)
mtlr r0
addi r1, r1, 0x10
blr
*/
}
/*
* --INFO--
* Address: 802AD664
* Size: 000008
*/
u32 Kurage::Mgr::getEnemyTypeID() { return 0x39; }
/*
* --INFO--
* Address: 802AD66C
* Size: 00002C
*/
void Kurage::Mgr::doLoadBmd(void*)
{
/*
stwu r1, -0x10(r1)
mflr r0
lis r5, 0x20240030@ha
mr r3, r4
stw r0, 0x14(r1)
addi r4, r5, 0x20240030@l
bl load__22J3DModelLoaderDataBaseFPCvUl
lwz r0, 0x14(r1)
mtlr r0
addi r1, r1, 0x10
blr
*/
}
/*
* --INFO--
* Address: 802AD698
* Size: 000050
*/
void Kurage::Parms::read(Stream&)
{
/*
stwu r1, -0x10(r1)
mflr r0
stw r0, 0x14(r1)
stw r31, 0xc(r1)
mr r31, r4
stw r30, 8(r1)
mr r30, r3
bl read__10ParametersFR6Stream
mr r4, r31
addi r3, r30, 0xe0
bl read__10ParametersFR6Stream
mr r4, r31
addi r3, r30, 0x7f8
bl read__10ParametersFR6Stream
lwz r0, 0x14(r1)
lwz r31, 0xc(r1)
lwz r30, 8(r1)
mtlr r0
addi r1, r1, 0x10
blr
*/
}
/*
* --INFO--
* Address: 802AD6E8
* Size: 000008
*/
Kurage::Mgr::@4 @~Mgr()
{
/*
addi r3, r3, -4
b __dt__Q34Game6Kurage3MgrFv
*/
}
} // namespace Game
| 23.906651 | 71 | 0.600693 | projectPiki |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.