blob_id
stringlengths
40
40
directory_id
stringlengths
40
40
path
stringlengths
4
721
content_id
stringlengths
40
40
detected_licenses
listlengths
0
57
license_type
stringclasses
2 values
repo_name
stringlengths
5
91
snapshot_id
stringlengths
40
40
revision_id
stringlengths
40
40
branch_name
stringclasses
321 values
visit_date
timestamp[ns]date
2016-08-12 09:31:09
2023-09-06 10:45:07
revision_date
timestamp[ns]date
2010-09-28 14:01:40
2023-09-06 06:22:19
committer_date
timestamp[ns]date
2010-09-28 14:01:40
2023-09-06 06:22:19
github_id
int64
426
681M
star_events_count
int64
101
243k
fork_events_count
int64
0
110k
gha_license_id
stringclasses
23 values
gha_event_created_at
timestamp[ns]date
2012-06-28 18:51:49
2023-09-14 21:59:16
gha_created_at
timestamp[ns]date
2008-02-11 22:55:26
2023-08-10 11:14:58
gha_language
stringclasses
147 values
src_encoding
stringclasses
26 values
language
stringclasses
2 values
is_vendor
bool
2 classes
is_generated
bool
2 classes
length_bytes
int64
6
10.2M
extension
stringclasses
115 values
filename
stringlengths
3
113
content
stringlengths
6
10.2M
3f8fcae29fc15cf3dd1883e9bfad7c2fa0e35e89
35ece1a78314060ee6f815745db24f85012a6c77
/texlive/texk/xdvik/print-internal.c
dfa6f9a4ff8b66148d7b52c5a965e53e249fd5b0
[ "LicenseRef-scancode-other-permissive" ]
permissive
clerkma/ptex-ng
dabc12a3df48aef6107efd1b4555f0141f858e12
a646d1cfe835712601b7edcfa96ad90c2549778b
refs/heads/master
2023-08-16T23:10:11.143532
2023-08-13T06:52:31
2023-08-13T06:52:31
24,095,177
260
46
null
2022-06-22T04:57:30
2014-09-16T10:25:01
C
UTF-8
C
false
false
25,908
c
print-internal.c
/* * Copyright (c) 2002-2004 Paul Vojta and the xdvik development team * * 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 * PAUL VOJTA OR ANY OTHER AUTHOR OF THIS SOFTWARE 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. */ /* * SU: Printing/saving backend code (all the non-GUI stuff), * adapted from non-k xdvi's popups.c. * * Implementation notes: * All inter-process communication happens in an asynchronous * fasion, so that the GUI remains responsive. This means that if * there are several processes in sequence (e.g. dvips invocation, * then ps2pdf invocation), the latter must be called by the child * watching procedure of the former (e.g. ps2pdf_exited by the * fork_process() callback in call_ps2pdf()), else we can't catch its * return status, do cleanup afterwards etc., because the code inside * the caller may be executed *before* the child has finished. (Note * e.g. how unlink()ing the temporary PS file is done inside * ps2pdf_exited() and not in the callers). This is the reason why we * often need to pass information to the subprocess via a data pointer. */ #include "xdvi-config.h" #include "xdvi.h" #include "dvisel.h" /* for select_pages_info struct */ #include "print-internal.h" #include "print-log.h" #include "search-internal.h" #include "events.h" #include "message-window.h" #include "util.h" #include "x_util.h" #include "string-utils.h" #include "my-snprintf.h" #include <errno.h> #include <signal.h> #include <sys/stat.h> /* if POSIX O_NONBLOCK is not available, use O_NDELAY */ #if !defined(O_NONBLOCK) && defined(O_NDELAY) # define O_NONBLOCK O_NDELAY #endif #ifdef EWOULDBLOCK # ifdef EAGAIN # define AGAIN_CONDITION (errno == EWOULDBLOCK || errno == EAGAIN) # else # define AGAIN_CONDITION (errno == EWOULDBLOCK) # endif #else /* EWOULDBLOCK */ # ifdef EAGAIN # define AGAIN_CONDITION (errno == EAGAIN) # endif #endif /* EWOULDBLOCK */ #if HAVE_POLL # include <poll.h> # define XIO_IN POLLIN # define XIO_OUT POLLOUT #else # define XIO_IN 1 # define XIO_OUT 2 #endif /* HAVE_POLL */ static struct xchild print_child = {NULL, 0, "dvips", NULL, NULL, SIGKILL, NULL }; static char *read_from_dvips(int, void *); static struct xio print_xio = { NULL, 0, XIO_IN, #if HAVE_POLL NULL, #endif read_from_dvips, NULL, /* write proc - not needed */ NULL /* data */ }; static void dvips_alarm(struct xtimer *this, void *data); static struct xtimer dvips_timer = {NULL, {0, 0}, XTM_DEFAULT, dvips_alarm, NULL #if XDVI_XT_TIMER_HACK , NULL, NULL #endif }; static int dvips_sig; /* SIGINT or SIGKILL */ static int dvips_status; static const int DVIPS_STAT_NONE = 0; static const int DVIPS_STAT_RUN = 1; static const int DVIPS_STAT_WAIT = 2; /* FIXME: implement this in terms of fork_process()! Currently it doesn't work since the DVI file and the output file are realized via redirecting stdin/stdout. This also obscures the log output (the I/O redirection isn't visible to users). TODO: Remove the detailed log output, and implement a progress window that only shows the page numbers. The detailed log should go to an `xdvi log output' page. */ static void fork_dvips(char **argv, struct save_or_print_info *info, childProcT proc) { int print_io[2]; int i; struct file_info *finfo = info->finfo; /* printlog_append(argv[0], strlen(argv[0])); */ FILE *fout = NULL; if (info->act == FILE_SAVE || info->print_target == TO_FILE) { /* printing to PS file, open file for writing */ const char *out_file; if (info->print_target == TO_FILE || info->fmt == FMT_PS) out_file = finfo->out_file; else out_file = finfo->tmp_ps_file; if ((fout = XFOPEN(out_file, "w")) == NULL) { popup_message(globals.widgets.top_level, MSG_ERR, NULL, "Could not open %s for writing: %s.", out_file, strerror(errno)); return; } } printlog_popup(info); printlog_append_str(info, "Calling: `"); printlog_append_str(info, argv[0]); for (i = 1; argv[i] != NULL; i++) { printlog_append_str(info, " "); printlog_append_str(info, argv[i]); } printlog_append_str(info, "'\n"); if (xpipe(print_io) != 0) { perror("[xdvi] pipe"); return; } /* Fork process */ /* flush output buffers to avoid double buffering (i.e. data waiting in the output buffer being written twice, by the parent and the child) */ fflush(stderr); fflush(stdout); print_child.name = xstrdup(argv[0]); print_child.proc = proc; print_child.data = info; print_child.pid = fork(); if (print_child.pid == 0) { /* if child */ /* change into dir of DVI file so that included image files etc. are found */ (void)chdir(globals.dvi_file.dirname); /* make the input file pointer the STDIN of the dvips process */ if (info->page_selection == PAGE_MARKED) { /* printing selected pages from temporary file */ ASSERT(finfo->tmp_dvi_fp != NULL, "tmp fp mustn't be NULL!"); (void)dup2(fileno(finfo->tmp_dvi_fp), STDIN_FILENO); } else { /* printing from main or backup file */ (void)dup2(fileno(finfo->in_fp), STDIN_FILENO); } (void)lseek(0, 0, SEEK_SET); if (fout != NULL) { /* printing to file, make stdout of child go to fout */ (void)dup2(fileno(fout), STDOUT_FILENO); (void)close(fileno(fout)); } else { /* printing to printer, make stdout of child go to print_io[1] */ (void)dup2(print_io[1], STDOUT_FILENO); } /* make stderr of child go to print_io[1] */ (void)dup2(print_io[1], STDERR_FILENO); (void)close(print_io[1]); (void)close(print_io[0]); if (setsid() == -1) { /* so we can kill the process group */ perror("setsid"); fflush(stderr); _exit(1); } (void)execvp(*argv, argv); popup_message(globals.widgets.top_level, MSG_ERR, NULL, "Execution of \"%s\" failed: %s.\n", *argv, strerror(errno)); fflush(stderr); _exit(1); } if (fout != NULL) fclose(fout); if (print_child.pid == -1) { /* error */ perror("[xdvi] vfork"); return; } set_chld(&print_child); dvips_sig = SIGINT; (void)close(print_io[1]); /* Set up file descriptor for non-blocking I/O */ prep_fd(print_io[0], True); print_xio.fd = print_io[0]; print_xio.data = info; set_io(&print_xio); dvips_status = DVIPS_STAT_RUN; /* running */ } /* * Create an argument list for dvips, using information from info * and X resources. Returns the result list in freshly allocated * memory. */ static char ** create_dvips_argv(const struct save_or_print_info *info, Boolean do_pdf) { const struct select_pages_info *pinfo = info->pinfo; size_t argv_len = 128; /* should be ample ... */ char **argv = xmalloc(argv_len * sizeof *argv); size_t idx = 0; const char *printer_options = info->printer_options; const char *dvips_options = info->dvips_options; char from_page[LENGTH_OF_INT]; char to_page[LENGTH_OF_INT]; TRACE_GUI((stderr, "dvips options: |%s|", dvips_options)); argv[idx++] = xstrdup(resource.dvips_path); if (dvips_options != NULL) { char **dvips_args = get_separated_list(dvips_options, " \t", True); /* this allocates dvips_args */ int i; for (i = 0; dvips_args[i] != NULL; i++) { argv[idx++] = dvips_args[i]; } free(dvips_args); } if (do_pdf) argv[idx++] = xstrdup("-Ppdf"); argv[idx++] = xstrdup("-f"); if (info->print_target == TO_PRINTER && printer_options != NULL) { /* printing to printer */ char **printer_args = get_separated_list(printer_options, " \t", True); /* this allocates printer_args */ int i; ASSERT(*printer_args != NULL, "args should contain at least the string \"lpr\""); argv[idx] = xstrdup("-o!"); argv[idx] = xstrcat(argv[idx], printer_args[0]); free(printer_args[0]); /* now append everything to the printer pipe command, so that dvips doesn't see it as an option */ for (i = 1; printer_args[i] != NULL; i++) { argv[idx] = xstrcat(argv[idx], " "); argv[idx] = xstrcat(argv[idx], printer_args[i]); free(printer_args[i]); } free(printer_args); idx++; } if (info->page_selection == PAGE_RANGE) { /* convert back from 0-based to 1-based, also taking globals.pageno_correct into accout * (which is 1 by default, so we need to add 2) */ argv[idx] = xstrdup("-p="); SNPRINTF(from_page, LENGTH_OF_INT, "%d", pinfo->from - globals.pageno_correct + 2); argv[idx] = xstrcat(argv[idx], from_page); idx++; argv[idx] = xstrdup("-l="); SNPRINTF(to_page, LENGTH_OF_INT, "%d", pinfo->to - globals.pageno_correct + 2); argv[idx] = xstrcat(argv[idx], to_page); idx++; } argv[idx] = NULL; /* terminate it */ ASSERT(idx <= argv_len, "Too many elements"); return argv; } /* Check if selecting pages worked, report error else */ static Boolean select_pages_report_error(const struct save_or_print_info *info) { if (info->pinfo->errflag == NO_ERROR) return False; popup_message(globals.widgets.top_level, MSG_INFO, NULL, "Could not save DVI file to %s: %s.", info->finfo->tmp_dvi_file, get_dvi_error(info->pinfo->errflag)); return True; } /* * Collect dvips output, appending to print log. * Currently return value is a dummy (NULL); TODO: return * the output, for later filtering. */ static char * read_from_dvips(int ignored, void *data) { int bytes; char line[80]; struct save_or_print_info *info = data; UNUSED(ignored); for (;;) { #ifndef MOTIF bytes = read(print_xio.fd, line, sizeof line); #else bytes = read(print_xio.fd, line, sizeof line - 1); #endif if (bytes < 0) { if (AGAIN_CONDITION) break; perror("xdvi: read_from_dvips"); break; } if (bytes == 0) break; else { #ifdef MOTIF line[bytes] = '\0'; #endif printlog_append(info, line, bytes); } } return NULL; /* TODO */ } /* * Report dvips exit status, and remove temporary DVI file if needed. */ static void dvips_exited(int exitval, struct xchild *child) { char str[128] = ""; int ms; struct save_or_print_info *info = (struct save_or_print_info *)child->data; read_from_dvips(0, info); clear_io(&print_xio); (void)close(print_xio.fd); if (WIFEXITED(exitval)) { if (WEXITSTATUS(exitval) == 0) { if (info->act == FILE_SAVE || info->print_target == TO_FILE) { printlog_append_str(info, "\nCreated Postscript file "); printlog_append_str(info, info->finfo->out_file); printlog_append_str(info, ".\n"); } else { printlog_append_str(info, "Done.\n"); } /* remove temporary DVI file if it exists */ if (info->finfo->tmp_dvi_file != NULL) { if (globals.debug & DBG_GUI) TRACE_GUI((stderr, "NOT removing temporary DVI file: |%s|", info->finfo->tmp_dvi_file)); else { if (info->finfo->tmp_dvi_fp != NULL) { fclose(info->finfo->tmp_dvi_fp); info->finfo->tmp_dvi_fp = NULL; } unlink(info->finfo->tmp_dvi_file); info->finfo->tmp_dvi_file = NULL; } } } else sprintf(str, "\nDvips returned exit code %d.\n", WEXITSTATUS(exitval)); } else if (WIFSIGNALED(exitval)) sprintf(str, "\nDvips terminated by signal %d.\n", WTERMSIG(exitval)); else sprintf(str, "\nDvips returned unknown status 0x%x.\n", exitval); ms = resource.dvips_hang; if (str[0] != '\0') { xdvi_bell(); ms = resource.dvips_fail_hang; printlog_append_str(info, str); } if (ms > 0) { dvips_timer.data = info; set_timer(&dvips_timer, ms); dvips_status = DVIPS_STAT_WAIT; } else { dvips_status = DVIPS_STAT_NONE; } printlog_enable_closebutton(info); } /* * Report pd2pdf exit status, and remove temporary PS file if needed. */ static void ps2pdf_exited(int status, struct xchild *this) { char *err_msg = NULL; int ms = resource.dvips_hang; struct save_or_print_info *info = (struct save_or_print_info *)this->data; /* if child exited with error and xio struct is available for child, print error text */ if (this->io != NULL && (WIFEXITED(status) != 0)) { if ((WEXITSTATUS(status) != 0) && (err_msg = (this->io->read_proc)(this->io->fd, NULL)) != NULL) { char buf[LENGTH_OF_INT]; SNPRINTF(buf, LENGTH_OF_INT, "%d", WEXITSTATUS(status)); ms = resource.dvips_fail_hang; xdvi_bell(); printlog_append_str(info, "\n\nError calling "); if (this->name != NULL) { printlog_append_str(info, "\""); printlog_append_str(info, this->name); printlog_append_str(info, "\" "); } printlog_append_str(info, "\nCommand exited with error code "); printlog_append_str(info, buf); printlog_append_str(info, ":\n"); printlog_append_str(info, err_msg); free(err_msg); } else { int retval; printlog_append_str(info, "\nCreated PDF file "); printlog_append_str(info, info->finfo->out_file); printlog_append_str(info, ".\n"); TRACE_FILES((stderr, "Removing temporary PS file: `%s'", info->finfo->tmp_ps_file)); retval = unlink(info->finfo->tmp_ps_file); if (retval != 0) { fprintf(stderr, "Could not unlink `%s': %s.\n", info->finfo->tmp_ps_file, strerror(errno)); } } } else { popup_message(globals.widgets.top_level, MSG_ERR, REPORT_XDVI_BUG_TEMPLATE, "Internal error: ps2pdf_exited() called while child still running?"); } if (ms > 0) { dvips_timer.data = info; set_timer(&dvips_timer, ms); dvips_status = DVIPS_STAT_WAIT; } else { dvips_status = DVIPS_STAT_NONE; } printlog_enable_closebutton(info); free(this->name); free(this->io); free(this); } static void call_ps2pdf(const char *path, const struct save_or_print_info *info) { const char *argv[5]; size_t idx = 0; argv[idx++] = path; argv[idx++] = info->finfo->tmp_ps_file; argv[idx++] = info->finfo->out_file; argv[idx++] = NULL; /* need to run this in globals.xdvi_dir again, since the dvips conversion directory globals.dvi_file.dirname may not be writable! */ if (!fork_process("ps2pdf", True, globals.cwd, ps2pdf_exited, (void *)info, 0, (char **)argv)) { popup_message(globals.widgets.top_level, MSG_ERR, NULL, "Couldn't fork %s process: %s\n", argv[0], strerror(errno)); } } static void dvips_ps2pdf(int exitval, struct xchild *child) { char str[128] = ""; int ms; struct save_or_print_info *info = (struct save_or_print_info *)child->data; read_from_dvips(0, info); clear_io(&print_xio); (void)close(print_xio.fd); if (WIFEXITED(exitval)) { if (WEXITSTATUS(exitval) == 0) { /* dvips ended OK; call ps2pdf: */ TRACE_GUI((stderr, "Created temporary PS file |%s|", info->finfo->tmp_ps_file)); printlog_append_str(info, "\nCalling "); printlog_append_str(info, resource.ps2pdf_path); printlog_append_str(info, " ..."); /* remove temporary DVI file if it exists */ if (info->finfo->tmp_dvi_file != NULL) { if (globals.debug & DBG_GUI) TRACE_GUI((stderr, "NOT removing temporary DVI file: |%s|", info->finfo->tmp_dvi_file)); else { if (info->finfo->tmp_dvi_fp != NULL) { fclose(info->finfo->tmp_dvi_fp); info->finfo->tmp_dvi_fp = NULL; } unlink(info->finfo->tmp_dvi_file); info->finfo->tmp_dvi_file = NULL; } } /* invoke ps2pdf conversion */ call_ps2pdf(resource.ps2pdf_path, info); } else sprintf(str, "\nPrint process returned exit code %d.\n", WEXITSTATUS(exitval)); } else if (WIFSIGNALED(exitval)) sprintf(str, "\nPrint process terminated by signal %d.\n", WTERMSIG(exitval)); else sprintf(str, "\nPrint process returned unknown status 0x%x.\n", exitval); /* enable close button only if dvips conversion already failed */ ms = resource.dvips_hang; if (str[0] != '\0') { xdvi_bell(); ms = resource.dvips_fail_hang; printlog_append_str(info, str); if (ms > 0) { dvips_timer.data = info; set_timer(&dvips_timer, ms); dvips_status = DVIPS_STAT_WAIT; } else { dvips_status = DVIPS_STAT_NONE; } printlog_enable_closebutton(info); } } static void dvips_alarm(struct xtimer *this, void *data) { struct save_or_print_info *info = (struct save_or_print_info *)data; UNUSED(this); printlog_popdown(info, False); dvips_status = DVIPS_STAT_NONE; } static void cb_dvips_keep(Widget w, XtPointer client_data, XtPointer call_data) { UNUSED(w); UNUSED(client_data); UNUSED(call_data); /* use negative value so that we don't loose the value itself */ TRACE_GUI((stderr, "toggling resource from %d to %d, %d to %d", resource.dvips_hang, -resource.dvips_hang, resource.dvips_fail_hang, -resource.dvips_fail_hang)); resource.dvips_hang = -resource.dvips_hang; resource.dvips_fail_hang = -resource.dvips_fail_hang; store_preference(NULL, "dvipsHangTime", "%d", resource.dvips_hang); store_preference(NULL, "dvipsFailHangTime", "%d", resource.dvips_fail_hang); if (dvips_status == DVIPS_STAT_WAIT) { dvips_status = DVIPS_STAT_NONE; cancel_timer(&dvips_timer); } } /* if user selects the window manager destroy button */ static void cb_dvips_destroy(Widget w, XtPointer client_data, XtPointer call_data) { struct save_or_print_info *info = (struct save_or_print_info *)client_data; UNUSED(w); UNUSED(call_data); if (dvips_status == DVIPS_STAT_RUN) { kill(print_child.pid, dvips_sig); dvips_sig = SIGKILL; printlog_append_str(info, "^C"); } if (dvips_status == DVIPS_STAT_WAIT) { dvips_status = DVIPS_STAT_NONE; cancel_timer(&dvips_timer); } printlog_reset(info); printlog_popdown(info, True); } static void cb_dvips_cancel(Widget w, XtPointer client_data, XtPointer call_data) { struct save_or_print_info *info = (struct save_or_print_info *)client_data; UNUSED(w); UNUSED(call_data); if (dvips_status != DVIPS_STAT_RUN) return; /* How did we get here? */ kill(print_child.pid, dvips_sig); dvips_sig = SIGKILL; printlog_append_str(info, "^C"); } static void cb_dvips_close(Widget w, XtPointer client_data, XtPointer call_data) { struct save_or_print_info *info = (struct save_or_print_info *)client_data; UNUSED(w); UNUSED(call_data); if (dvips_status == DVIPS_STAT_RUN) return; /* How did we get here? */ if (dvips_status == DVIPS_STAT_WAIT) { dvips_status = DVIPS_STAT_NONE; cancel_timer(&dvips_timer); } printlog_popdown(info, True); } void internal_save(struct save_or_print_info *info) { struct file_info *finfo = info->finfo; static struct callback_info cinfo = { cb_dvips_close, cb_dvips_cancel, cb_dvips_destroy, cb_dvips_keep }; int tmp_fd; char **argv = NULL; int i; childProcT dvips_exit_proc = dvips_exited; /* default procedure to call after fork_dvips() */ Boolean do_pdf = False; /* force `-Ppdf' for dvips? (used for ps2pdf conversion) */ ASSERT(info->fmt != FMT_NONE, "No valid output format selected!"); /* fprintf(stderr, "INTERNAL SAVE - format: %d; selection: %d\n", info->fmt, info->page_selection); */ info->callbacks = &cinfo; switch (info->fmt) { case FMT_DVI: /* here we first create a temporary file, and if that succeeded, move it to the final position */ select_pages(info); if (!select_pages_report_error(info)) { /* * ... else, move the temporary file to its final destination. For that, we * try the more efficient rename() first; if this fails, try copying the file * (rename() will e.g. fail if the tmp directory is on a different file * system). We could perhaps examine errno after the renaming attempt to * find out whether we need to do the copy attempt in the first place, but * that'd be rather error-prone ... */ ASSERT(finfo->tmp_dvi_file != NULL, "filename mustn't be NULL"); if (rename(finfo->tmp_dvi_file, finfo->out_file) != 0 && !copy_file(finfo->tmp_dvi_file, finfo->out_file)) { popup_message(globals.widgets.top_level, MSG_ERR, NULL, "Creating %s failed: %s", finfo->out_file, strerror(errno)); } else { /* moving worked */ TRACE_GUI((stderr, "renamed %s to %s\n", finfo->tmp_dvi_file, finfo->out_file)); if (info->pinfo->warn_files.stack_len > 0) { /* do we need to warn user about referenced files? */ char *warn_files = xstrdup(""); size_t i; for (i = 0; i < info->pinfo->warn_files.stack_len; i++) { warn_files = xstrcat(warn_files, info->pinfo->warn_files.items[i].content); warn_files = xstrcat(warn_files, "\n"); } popup_message(globals.widgets.top_level, MSG_INFO, "The files listed in the message (probably images) are not part " "of the newly created DVI file; they are only referenced by that file. " "Therefore, if you want to distribute this file or use it on a different computer," "you will need to distribute all the referenced files, too.\n\n" "Tip: A better format for distributing files is Postscript or PDF. " "To create a Postscript file, use the `File->Print' menu, " "then select `Print to file' in the dialog window.", "Created %s.\n" "Please note that the following files are referenced by this file, " "and are needed for displaying or printing it correctly:\n%s\n", finfo->out_file, warn_files); free(warn_files); } else { /* char *ptr = strrchr(finfo->out_file, '/'); */ /* if (ptr == NULL) */ /* ptr = finfo->out_file; */ /* else */ /* ptr++; */ popup_message(globals.widgets.top_level, MSG_INFO, NULL, "Created DVI file:\n%s.", finfo->out_file); } if (info->finfo->tmp_dvi_fp != NULL) { fclose(info->finfo->tmp_dvi_fp); info->finfo->tmp_dvi_fp = NULL; } unlink(finfo->tmp_dvi_file); info->finfo->tmp_dvi_file = NULL; } } break; case FMT_PS2PDF: free(finfo->tmp_ps_file); finfo->tmp_ps_file = NULL; tmp_fd = xdvi_temp_fd(&(finfo->tmp_ps_file)); /* this allocates finfo->tmp_ps_file */ if (tmp_fd == -1) { popup_message(globals.widgets.top_level, MSG_ERR, NULL, "Couldn't create temporary PS file for conversion to PDF: %s", strerror(errno)); return; } else { TRACE_GUI((stderr, "name of temporary PS file: |%s|", finfo->tmp_ps_file)); } dvips_exit_proc = dvips_ps2pdf; /* call ps2pdf conversion after dvips exited */ do_pdf = True; /* fall through */ case FMT_PS: if (info->page_selection == PAGE_MARKED) { /* want to save selected pages? */ ASSERT(info->pinfo->callback != NULL, "Callback musn't be NULL!"); ASSERT(finfo->tmp_dvi_fp != NULL, "Temporary file pointer musn't be NULL!"); ASSERT(finfo->tmp_dvi_file != NULL, "Temporary filename musn't be NULL!"); select_pages(info); } if (info->printlog == NULL) printlog_create(info, "Xdvik: Saving", "Automatically close this window after file has been saved"); else printlog_enable_cancelbutton(info); if ((argv = create_dvips_argv(info, do_pdf)) == NULL) { /* something went *really* wrong; assume user has already been warned about it */ return; } fork_dvips(argv, info, dvips_exit_proc); /* dellocate argv */ for (i = 0; argv[i] != NULL; i++) { free(argv[i]); } free(argv); break; case FMT_ISO_8859_1: case FMT_UTF8: if (search_extract_text(info)) { popup_message(globals.widgets.top_level, MSG_INFO, NULL, "Created text file %s.", finfo->out_file); } else { popup_message(globals.widgets.top_level, MSG_INFO, NULL, "Extracting text from DVI file failed!"); } break; case FMT_NONE: break; } } void internal_print(struct save_or_print_info *info) { static struct callback_info cinfo = { cb_dvips_close, cb_dvips_cancel, cb_dvips_destroy, cb_dvips_keep }; char **argv = NULL; int i; info->callbacks = &cinfo; if (info->page_selection == PAGE_MARKED) { /* want to print selected pages? */ ASSERT(info->pinfo->callback != NULL, "Callback musn't be NULL!"); ASSERT(info->finfo->tmp_dvi_fp != NULL, "Temporary file pointer musn't be NULL!"); ASSERT(info->finfo->tmp_dvi_file != NULL, "Temporary filename musn't be NULL!"); select_pages(info); } if (info->printlog == NULL) printlog_create(info, "Xdvik: Printing", "Automatically close this window when printing finishes"); else printlog_enable_cancelbutton(info); if ((argv = create_dvips_argv(info, False)) == NULL) { /* something went *really* wrong; assume user has already been warned about it */ return; } fork_dvips(argv, info, dvips_exited); /* dellocate argv */ for (i = 0; argv[i] != NULL; i++) { free(argv[i]); } free(argv); }
bccbfc5121c6f8b83b5ecbf368d715d77f818a59
5c3160b4c7c0f3ff017c0b0a74a00ea3b4b9b1c1
/Frameworks/IoKit/Sources/PrivateApi/IOKit/hid/IOHIDSession.h
a509afdf9d5fe74bf6cc35624915ed7ce6c92f11
[ "MIT" ]
permissive
avito-tech/Mixbox
65db96299286dd0b77cd6cca29f252b72d6a8049
25e0e91fde1d403479aefc355e434ddff0dbaf0a
refs/heads/master
2023-07-09T16:50:28.958629
2023-07-07T07:42:13
2023-07-07T07:42:13
142,596,513
141
30
MIT
2022-07-20T10:10:12
2018-07-27T15:49:50
Swift
UTF-8
C
false
false
7,282
h
IOHIDSession.h
#if defined(MIXBOX_ENABLE_FRAMEWORK_IO_KIT) && defined(MIXBOX_DISABLE_FRAMEWORK_IO_KIT) #error "IoKit is marked as both enabled and disabled, choose one of the flags" #elif defined(MIXBOX_DISABLE_FRAMEWORK_IO_KIT) || (!defined(MIXBOX_ENABLE_ALL_FRAMEWORKS) && !defined(MIXBOX_ENABLE_FRAMEWORK_IO_KIT)) // The compilation is disabled #else /* IOHIDSession.h ... I/O Kit HID Session Copyright (c) 2010 KennyTM~ <kennytm@gmail.com> All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the KennyTM~ nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef IOHID_NOTIFICATION_H #define IOHID_NOTIFICATION_H #include <CoreFoundation/CoreFoundation.h> #include "IOHIDDisplay.h" #include "IOHIDService.h" #include "IOHIDEvent.h" __BEGIN_DECLS typedef struct IOHIDSessionWorkSpace { uint64_t value; } IOHIDSessionWorkSpace; typedef struct __IOHIDSession #if 0 { CFRuntimeBase _base; // 0, 4 int isOpen; // 8 CFTypeRef client; // c IOHIDSessionCallback callback; // 10 void* refcon; // 14 IOHIDSessionWorkSpace workSpace; // 18, 1c CFRunLoopRef runloop; // 20 pthread_mutex_t lock; // 24 pthread_cond_t cond; // 50 pthread_mutexattr_t attr; // 6c CFMutableSetRef services; // 78 CFMutableSetRef displays; // 7c CFMutableSetRef ALSStates; // 80 CFMutableDictionaryRef properties; // 84 Boolean displayStatus; // 88, initially = true float factor; // brightnessFactor. 8c, initially = 1 float deviceAmbient; // 94, initially = 0.5 float interval; // displayInternval. 98, initially = 0.402 float ALSIntPeriod; // 9c, initially = 5.5 float xa4; // a4, initially = 0 float xa8; // a8, initially = 5.5 float xac; // ac, initially = -1 float xb0; // b0, initially = 1 float backlight; // b4, initially = 1 CFTypeRef xe0; // e0 int displayOrientation; // e8, initially = 1 Boolean orientationEnabled; // ec, initially = false Boolean ALSIntPeriodOrientationEnabled; // ed, initially = false float ALSIntPeriodOrientationPortrait; // f0, initially = 5.5 float ALSIntPeriodOrientationPortraitInv; // f4, initially = 0 float ALSIntPeriodOrientationLandscape; // f8, initially = 0 int lockStateToken; // fc. (for the "com.apple.springboard.lockstate" Darwin notification) uint64_t lockState; // 100, 104 mach_port_t lockStateNotifyPort; // 108 (leads to __IOHIDSessionLockCallback) int bootedCleanlyToken; // 10c (for the "com.apple.springboard.bootedcleanly" Darwin notification) mach_port_t bootedCleanlyNotifyPort; // 118 (leads to __IOHIDSessionBootCallback) int displayStatusToken; // 11c (for the "com.apple.iokit.hid.displayStatus" Darwin notification) int substantialTransitionToken; // 12c (for the "com.apple.mobile.SubstantialTransition" Darwin notification) mach_port_t substantialTransitionNotifyPort; // 130 (leads to __IOHIDSessionTransitionCallback) int thermalNotificationToken; // 134 (for the kOSThermalNotificationName Darwin notification) mach_port_t thermalNotificationNotifyPort; // 138 (leads to __IOHIDSessionThermalCallback) int thermalLevel; // 13c, initially = OSThermalNotificationCurrentLevel() int logLevel; // 144, initially = 6 } #endif * IOHIDSessionRef; typedef void(*IOHIDSessionCallback)(CFTypeRef client, void* refcon, IOHIDServiceRef service, IOHIDEventRef event); #pragma mark - #pragma mark Creators CFTypeID IOHIDSessionGetTypeID(void); IOHIDSessionRef IOHIDSessionCreate(CFAllocatorRef allocator); #pragma mark - #pragma mark Accessors CFTypeRef IOHIDSessionGetProperty(IOHIDSessionRef session, CFStringRef key); Boolean IOHIDSessionSetProperty(IOHIDSessionRef session, CFStringRef key, CFTypeRef value); IOHIDSessionWorkSpace IOHIDSessionGetWorkSpace(IOHIDSessionRef session); void IOHIDSessionSetWorkSpace(IOHIDSessionRef session, IOHIDSessionWorkSpace workSpace); Boolean IOHIDSessionGetLockState(IOHIDSessionRef session); void IOHIDSessionSetLockState(IOHIDSessionRef session, Boolean lockState); #pragma mark - #pragma mark Actions Boolean IOHIDSessionOpen(IOHIDSessionRef session, CFTypeRef client, IOHIDSessionCallback callback, void* refcon) void IOHIDSessionClose(IOHIDSessionRef session, CFTypeRef client); void IOHIDSessionAddService(IOHIDSessionRef, IOHIDServiceRef service); void IOHIDSessionRemoveService(IOHIDSessionRef, IOHIDServiceRef service); void IOHIDSessionAddDisplay(IOHIDSessionRef, IOHIDDisplayRef display); void IOHIDSessionRemoveDisplay(IOHIDSessionRef session, IOHIDDisplayRef display); IOHIDEventRef IOHIDSessionCopyEvent(IOHIDSessionRef session, IOHIDEventType type, IOHIDEventRef event, IOOptionBits options); #pragma mark - #pragma mark Constants static const CFStringRef kIOHIDSessionPropertyDisplayOrientation = CFSTR("DisplayOrientation"); static const CFStringRef kIOHIDSessionPropertyDisplayBrightnessFactor = CFSTR("DisplayBrightnessFactor"); static const CFStringRef kIOHIDSessionPropertyDisplayBrightnessFactorWithFade = CFSTR("DisplayBrightnessFactorWithFade"); static const CFStringRef kIOHIDSessionPropertyDisplayBrightnessFactorPending = CFSTR("DisplayBrightnessFactorPending"); static const CFStringRef kIOHIDSessionPropertyLogLevel = CFSTR("LogLevel"); static const CFStringRef kIOHIDSessionPropertyALSIntPeriodOrientationEnabled = CFSTR("ALSIntPeriodOrientationEnabled"); static const CFStringRef kIOHIDSessionPropertyALSIntPeriod = CFSTR("ALSIntPeriod"); static const CFStringRef kIOHIDSessionPropertyALSIntPeriodOrientationPortrait = CFSTR("ALSIntPeriodOrientationPortrait"); static const CFStringRef kIOHIDSessionPropertyALSIntPeriodOrientationPortraitInv = CFSTR("ALSIntPeriodOrientationPortraitInv"); static const CFStringRef kIOHIDSessionPropertyALSIntPeriodOrientationLandscape = CFSTR("ALSIntPeriodOrientationLandscape"); __END_DECLS #endif #endif
e16e44f42ca6faa93163ac6a9999b679a9c1ff5e
57d291312405dd9093fbca45743984ab56c549d0
/include/siri/async.h
91fc8fa56d11f96cd287ea126ca57465e3d7af5e
[ "MIT" ]
permissive
SiriDB/siridb-server
159f9cc8f0f53401a5507e0394929f828f80a244
f0edd48c02bc18a39c8bdfd53b9b179b8c216f86
refs/heads/master
2023-08-19T09:17:38.075457
2023-03-21T10:24:13
2023-03-21T10:24:13
55,093,657
176
24
MIT
2022-09-17T06:59:52
2016-03-30T19:58:40
C
UTF-8
C
false
false
432
h
async.h
/* * async.h - SiriDB async wrapper. */ #ifndef SIRI_ASYC_H_ #define SIRI_ASYC_H_ typedef struct siri_async_s siri_async_t; #include <uv.h> #include <inttypes.h> void siri_async_close(uv_handle_t * handle); void siri_async_decref(uv_async_t ** handle); #define siri_async_incref(HANDLE__) ((siri_async_t *) HANDLE__->data)->ref++ struct siri_async_s { uv_close_cb free_cb; uint8_t ref; }; #endif /* SIRI_ASYC_H_ */
8f70ab9dec72eda25ce471ea5ba2dd521236939d
29f2c40392489fc1656010f2c9b384fd0b090847
/play/memcex/in/test2.c
32a09f2741d70c1a33a850def790b985c8308b02
[ "BSD-3-Clause", "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-warranty-disclaimer" ]
permissive
seahorn/seahorn
6498777c0d12716379035c0bc102b9baec6f28f9
2bab7831960766a0a16f149adcdce55f0651eb8f
refs/heads/main
2023-08-25T13:51:48.354660
2023-08-11T00:48:27
2023-08-14T16:43:13
31,487,486
423
126
NOASSERTION
2023-09-08T21:30:09
2015-03-01T05:08:17
C
UTF-8
C
false
false
202
c
test2.c
#include "memcex.h" // reading nondet pointer to a simple struct int main(void) { struct st *p; p = __VERIFIER_nondet_st(); if (p > 0) { __VERIFIER_error(); } return 0; }
9ae558f4d7f24f34c6c2c3ffb2502c168b085265
e1d9c54e9925e30e388a255b53a93cccad0b94cb
/kubernetes/model/v1_node_config_source.h
62b76bea1d100ea2aa26d5c57065c8623e710bcc
[ "Apache-2.0", "curl" ]
permissive
kubernetes-client/c
dd4fd8095485c083e0f40f2b48159b1609a6141b
5ac5ff25e9809a92a48111b1f77574b6d040b711
refs/heads/master
2023-08-13T10:51:03.702497
2023-08-07T19:18:32
2023-08-07T19:18:32
247,958,425
127
47
Apache-2.0
2023-09-07T20:07:00
2020-03-17T11:59:05
C
UTF-8
C
false
false
1,084
h
v1_node_config_source.h
/* * v1_node_config_source.h * * NodeConfigSource specifies a source of node configuration. Exactly one subfield (excluding metadata) must be non-nil. This API is deprecated since 1.22 */ #ifndef _v1_node_config_source_H_ #define _v1_node_config_source_H_ #include <string.h> #include "../external/cJSON.h" #include "../include/list.h" #include "../include/keyValuePair.h" #include "../include/binary.h" typedef struct v1_node_config_source_t v1_node_config_source_t; #include "v1_config_map_node_config_source.h" typedef struct v1_node_config_source_t { struct v1_config_map_node_config_source_t *config_map; //model } v1_node_config_source_t; v1_node_config_source_t *v1_node_config_source_create( v1_config_map_node_config_source_t *config_map ); void v1_node_config_source_free(v1_node_config_source_t *v1_node_config_source); v1_node_config_source_t *v1_node_config_source_parseFromJSON(cJSON *v1_node_config_sourceJSON); cJSON *v1_node_config_source_convertToJSON(v1_node_config_source_t *v1_node_config_source); #endif /* _v1_node_config_source_H_ */
966ad63771befbf437a02b1b20a8ff480f0d3b61
05a4d2bf45b32798d2f6820c4ec001dd8ef13e4a
/tests/multithreaded/peer/rpma_peer_cfg_from_descriptor.c
48572553c1cf25bee2a4f1134ccf9f987379b8cd
[ "BSD-3-Clause", "LicenseRef-scancode-unknown-license-reference" ]
permissive
pmem/rpma
207ee08f465a22341f92c80b15132a9617e57596
93d31224fd69786d4b1ace0084108aa270e4c263
refs/heads/main
2023-09-01T05:29:34.609582
2023-06-13T12:12:10
2023-06-13T12:12:10
240,216,867
115
63
NOASSERTION
2023-09-05T14:31:33
2020-02-13T08:59:31
C
UTF-8
C
false
false
4,535
c
rpma_peer_cfg_from_descriptor.c
// SPDX-License-Identifier: BSD-3-Clause /* Copyright 2021-2022, Intel Corporation */ /* * rpma_peer_cfg_from_descriptor.c -- multithreaded test */ #include <assert.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <pthread.h> #include <librpma.h> #define DIRECT_WRITE_TO_PMEM_SUPPORTED true #define DESCRIPTORS_MAX_SIZE 512 struct thread_args { int thread_num; const void *desc; size_t desc_size; }; static const char *api_name = "rpma_peer_cfg_from_descriptor"; static void * thread_main(void *arg) { int ret; bool direct_write_to_pmem = false; /* RPMA resources */ struct rpma_peer_cfg *pcfg = NULL; /* parameters */ struct thread_args *p_thread_args = (struct thread_args *)arg; /* Create a remote peer configuration structure from input descriptor */ ret = rpma_peer_cfg_from_descriptor(p_thread_args->desc, p_thread_args->desc_size, &pcfg); if (ret) { fprintf(stderr, "[thread #%d] %s failed: %s\n", p_thread_args->thread_num, api_name, rpma_err_2str(ret)); exit(-1); } /* * check if the direct write to PMEM is as expected (supported or not). */ ret = rpma_peer_cfg_get_direct_write_to_pmem(pcfg, &direct_write_to_pmem); if (ret) { fprintf(stderr, "[thread #%d] rpma_peer_cfg_get_direct_write_to_pmem failed: %s\n", p_thread_args->thread_num, rpma_err_2str(ret)); exit(-1); } if (direct_write_to_pmem != DIRECT_WRITE_TO_PMEM_SUPPORTED) { fprintf(stderr, "[thread #%d] rpma_peer_cfg_get_direct_write_to_pmem: unexpected direct_write_to_pmem = %d\n", p_thread_args->thread_num, direct_write_to_pmem); exit(-1); } ret = rpma_peer_cfg_delete(&pcfg); if (ret) { fprintf(stderr, "[thread #%d] rpma_peer_cfg_delete failed: %s\n", p_thread_args->thread_num, rpma_err_2str(ret)); exit(-1); } return NULL; } int main(int argc, char *argv[]) { if (argc < 2) { fprintf(stderr, "usage: %s <thread_num>\n", argv[0]); return -1; } /* configure logging thresholds to see more details */ rpma_log_set_threshold(RPMA_LOG_THRESHOLD, RPMA_LOG_LEVEL_INFO); rpma_log_set_threshold(RPMA_LOG_THRESHOLD_AUX, RPMA_LOG_LEVEL_INFO); /* parameters */ int ret = 0; int i; int thread_num = (int)strtoul(argv[1], NULL, 10); pthread_t *p_threads; p_threads = calloc((size_t)thread_num, sizeof(pthread_t)); if (p_threads == NULL) { fprintf(stderr, "calloc() failed\n"); return -1; } struct thread_args *threads_args = calloc((size_t)thread_num, sizeof(struct thread_args)); if (threads_args == NULL) { fprintf(stderr, "calloc() failed\n"); ret = -1; goto err_free_p_threads; } /* create a peer configuration structure */ struct rpma_peer_cfg *pcfg = NULL; ret = rpma_peer_cfg_new(&pcfg); if (ret) { fprintf(stderr, "rpma_peer_cfg_new() failed\n"); goto err_free_threads_args; } /* set direct write to PMEM supported */ ret = rpma_peer_cfg_set_direct_write_to_pmem(pcfg, DIRECT_WRITE_TO_PMEM_SUPPORTED); if (ret) { fprintf(stderr, "rpma_peer_cfg_set_direct_write_to_pmem() failed\n"); goto err_peer_cfg_delete; } /* get size of the peer config descriptor */ size_t desc_size; ret = rpma_peer_cfg_get_descriptor_size(pcfg, &desc_size); if (ret) { fprintf(stderr, "rpma_peer_cfg_get_descriptor_size() failed\n"); goto err_peer_cfg_delete; } if (desc_size > DESCRIPTORS_MAX_SIZE) { fprintf(stderr, "rpma_peer_cfg_get_descriptor_size() return desc_size > DESCRIPTORS_MAX_SIZE\n"); goto err_peer_cfg_delete; } char descriptors[DESCRIPTORS_MAX_SIZE]; ret = rpma_peer_cfg_get_descriptor(pcfg, &descriptors[0]); if (ret) { fprintf(stderr, "rpma_peer_cfg_get_descriptor() failed\n"); goto err_peer_cfg_delete; } for (i = 0; i < thread_num; i++) { threads_args[i].thread_num = i; threads_args[i].desc = (void *)(&descriptors[0]); threads_args[i].desc_size = desc_size; } for (i = 0; i < thread_num; i++) { ret = pthread_create(&p_threads[i], NULL, thread_main, &threads_args[i]); if (ret != 0) { fprintf(stderr, "Cannot start the thread #%d: %s\n", i, strerror(ret)); /* * Set thread_num to the number of already created * threads to join them below. */ thread_num = i; /* return -1 on error */ ret = -1; break; } } for (i = thread_num - 1; i >= 0; i--) pthread_join(p_threads[i], NULL); err_peer_cfg_delete: ret = rpma_peer_cfg_delete(&pcfg); if (ret) { fprintf(stderr, "rpma_peer_cfg_delete failed: %s\n", rpma_err_2str(ret)); } err_free_threads_args: free(threads_args); err_free_p_threads: free(p_threads); return ret; }
e0b1e129753573f4aa3eff9580302a15bff14175
cb6d0a660cfcb28ee9e8a1c0266925f8f541edfb
/libbpf-tools/softirqs.c
66c0f0f48137783b4b635095efafe4f2a65c639e
[ "Apache-2.0" ]
permissive
iovisor/bcc
0e002769364523caeb731216021b0a3c881a723f
ec49363e2e9daec026ee6cae4c5fc316f8fab0ff
refs/heads/master
2023-09-03T22:37:47.238198
2023-08-31T14:44:55
2023-09-01T11:21:30
34,921,116
18,467
3,907
Apache-2.0
2023-09-13T21:22:53
2015-05-01T19:52:32
C
UTF-8
C
false
false
6,254
c
softirqs.c
// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) // Copyright (c) 2020 Wenbo Zhang // // Based on softirq(8) from BCC by Brendan Gregg & Sasha Goldshtein. // 15-Aug-2020 Wenbo Zhang Created this. #include <argp.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <unistd.h> #include <bpf/libbpf.h> #include <bpf/bpf.h> #include "softirqs.h" #include "softirqs.skel.h" #include "trace_helpers.h" struct env { bool distributed; bool nanoseconds; bool count; time_t interval; int times; bool timestamp; bool verbose; } env = { .interval = 99999999, .times = 99999999, .count = false, }; static volatile bool exiting; const char *argp_program_version = "softirqs 0.1"; const char *argp_program_bug_address = "https://github.com/iovisor/bcc/tree/master/libbpf-tools"; const char argp_program_doc[] = "Summarize soft irq event time as histograms.\n" "\n" "USAGE: softirqs [--help] [-T] [-N] [-d] [interval] [count]\n" "\n" "EXAMPLES:\n" " softirqs # sum soft irq event time\n" " softirqs -d # show soft irq event time as histograms\n" " softirqs 1 10 # print 1 second summaries, 10 times\n" " softirqs -NT 1 # 1s summaries, nanoseconds, and timestamps\n"; static const struct argp_option opts[] = { { "distributed", 'd', NULL, 0, "Show distributions as histograms" }, { "timestamp", 'T', NULL, 0, "Include timestamp on output" }, { "nanoseconds", 'N', NULL, 0, "Output in nanoseconds" }, { "count", 'C', NULL, 0, "Show event counts with timing" }, { "verbose", 'v', NULL, 0, "Verbose debug output" }, { NULL, 'h', NULL, OPTION_HIDDEN, "Show the full help" }, {}, }; static error_t parse_arg(int key, char *arg, struct argp_state *state) { static int pos_args; switch (key) { case 'h': argp_state_help(state, stderr, ARGP_HELP_STD_HELP); break; case 'v': env.verbose = true; break; case 'd': env.distributed = true; break; case 'N': env.nanoseconds = true; break; case 'T': env.timestamp = true; break; case 'C': env.count = true; break; case ARGP_KEY_ARG: errno = 0; if (pos_args == 0) { env.interval = strtol(arg, NULL, 10); if (errno) { fprintf(stderr, "invalid internal\n"); argp_usage(state); } } else if (pos_args == 1) { env.times = strtol(arg, NULL, 10); if (errno) { fprintf(stderr, "invalid times\n"); argp_usage(state); } } else { fprintf(stderr, "unrecognized positional argument: %s\n", arg); argp_usage(state); } pos_args++; break; default: return ARGP_ERR_UNKNOWN; } return 0; } static int libbpf_print_fn(enum libbpf_print_level level, const char *format, va_list args) { if (level == LIBBPF_DEBUG && !env.verbose) return 0; return vfprintf(stderr, format, args); } static void sig_handler(int sig) { exiting = true; } enum { HI_SOFTIRQ = 0, TIMER_SOFTIRQ = 1, NET_TX_SOFTIRQ = 2, NET_RX_SOFTIRQ = 3, BLOCK_SOFTIRQ = 4, IRQ_POLL_SOFTIRQ = 5, TASKLET_SOFTIRQ = 6, SCHED_SOFTIRQ = 7, HRTIMER_SOFTIRQ = 8, RCU_SOFTIRQ = 9, NR_SOFTIRQS = 10, }; static char *vec_names[] = { [HI_SOFTIRQ] = "hi", [TIMER_SOFTIRQ] = "timer", [NET_TX_SOFTIRQ] = "net_tx", [NET_RX_SOFTIRQ] = "net_rx", [BLOCK_SOFTIRQ] = "block", [IRQ_POLL_SOFTIRQ] = "irq_poll", [TASKLET_SOFTIRQ] = "tasklet", [SCHED_SOFTIRQ] = "sched", [HRTIMER_SOFTIRQ] = "hrtimer", [RCU_SOFTIRQ] = "rcu", }; static int print_count(struct softirqs_bpf__bss *bss) { const char *units = env.nanoseconds ? "nsecs" : "usecs"; __u64 count, time; __u32 vec; printf("%-16s %-6s%-5s %-11s\n", "SOFTIRQ", "TOTAL_", units, env.count?"TOTAL_count":""); for (vec = 0; vec < NR_SOFTIRQS; vec++) { time = __atomic_exchange_n(&bss->time[vec], 0, __ATOMIC_RELAXED); count = __atomic_exchange_n(&bss->counts[vec], 0, __ATOMIC_RELAXED); if (count > 0) { printf("%-16s %11llu", vec_names[vec], time); if (env.count) { printf(" %11llu", count); } printf("\n"); } } return 0; } static struct hist zero; static int print_hist(struct softirqs_bpf__bss *bss) { const char *units = env.nanoseconds ? "nsecs" : "usecs"; __u32 vec; for (vec = 0; vec < NR_SOFTIRQS; vec++) { struct hist hist = bss->hists[vec]; bss->hists[vec] = zero; if (!memcmp(&zero, &hist, sizeof(hist))) continue; printf("softirq = %s\n", vec_names[vec]); print_log2_hist(hist.slots, MAX_SLOTS, units); printf("\n"); } return 0; } int main(int argc, char **argv) { static const struct argp argp = { .options = opts, .parser = parse_arg, .doc = argp_program_doc, }; struct softirqs_bpf *obj; struct tm *tm; char ts[32]; time_t t; int err; err = argp_parse(&argp, argc, argv, 0, NULL, NULL); if (err) return err; libbpf_set_print(libbpf_print_fn); obj = softirqs_bpf__open(); if (!obj) { fprintf(stderr, "failed to open BPF object\n"); return 1; } if (probe_tp_btf("softirq_entry")) { bpf_program__set_autoload(obj->progs.softirq_entry, false); bpf_program__set_autoload(obj->progs.softirq_exit, false); } else { bpf_program__set_autoload(obj->progs.softirq_entry_btf, false); bpf_program__set_autoload(obj->progs.softirq_exit_btf, false); } /* initialize global data (filtering options) */ obj->rodata->targ_dist = env.distributed; obj->rodata->targ_ns = env.nanoseconds; err = softirqs_bpf__load(obj); if (err) { fprintf(stderr, "failed to load BPF object: %d\n", err); goto cleanup; } if (!obj->bss) { fprintf(stderr, "Memory-mapping BPF maps is supported starting from Linux 5.7, please upgrade.\n"); goto cleanup; } err = softirqs_bpf__attach(obj); if (err) { fprintf(stderr, "failed to attach BPF programs\n"); goto cleanup; } signal(SIGINT, sig_handler); printf("Tracing soft irq event time... Hit Ctrl-C to end.\n"); /* main: poll */ while (1) { sleep(env.interval); printf("\n"); if (env.timestamp) { time(&t); tm = localtime(&t); strftime(ts, sizeof(ts), "%H:%M:%S", tm); printf("%-8s\n", ts); } if (!env.distributed) err = print_count(obj->bss); else err = print_hist(obj->bss); if (err) break; if (exiting || --env.times == 0) break; } cleanup: softirqs_bpf__destroy(obj); return err != 0; }
8eff3c5ff525aabc37ca7cfbcbf4f02f29d26634
9907672fcd81ab73ac63b2a83422a82bf31eadde
/tyama_PG110502-UVa10018-codechefDPC206_mod.c
0b93f4f3d50756275ab0506bde0f7d11cf3a4baa
[ "0BSD" ]
permissive
cielavenir/procon
bbe1974b9bddb51b76d58722a0686a5b477c4456
746e1a91f574f20647e8aaaac0d9e6173f741176
refs/heads/master
2023-06-21T23:11:24.562546
2023-06-11T13:15:15
2023-06-11T13:15:15
7,557,464
137
136
null
2020-10-20T09:35:52
2013-01-11T09:40:26
C++
UTF-8
C
false
false
427
c
tyama_PG110502-UVa10018-codechefDPC206_mod.c
//tyama070521reverse.c #include <stdio.h> inline unsigned reverse(unsigned u){ unsigned ret=0; while(u){ ret=(ret<<3)+(ret<<1)+u%10; u/=10; } return ret; } int main(){ unsigned u,t; int n,count; scanf("%d", &n); for(;n;n--){ scanf("%u", &u); count^=count; t=reverse(u); while(u^t){ u+=t; t=reverse(u); count++; }; printf("%d %u\n",count,u); } return 0; }
d4b40c5aa68de2f7c6c29b9dd6f446376fcdc698
68e115d504decf90cf8adaf1c373a220c059d8d7
/Include/LittleVgl/core/lv_fonts/lv_font_dejavu_10.c
f90844ece42397b51e8f2f3f4657cc40acb2d1ca
[ "GPL-1.0-or-later", "GPL-2.0-only", "BSD-2-Clause", "MIT" ]
permissive
WOA-Project/Lumia950XLPkg
24fcad187d71488270b853d08fcdff542bbac5a2
0e7e24adb2ac80672ade1e56f9b538d99941328f
refs/heads/master
2023-08-11T09:20:00.600571
2022-09-14T09:09:51
2022-09-14T09:09:51
132,070,715
264
64
BSD-2-Clause
2022-12-18T20:27:21
2018-05-04T01:44:48
C
UTF-8
C
false
false
134,788
c
lv_font_dejavu_10.c
#include "../lv_misc/lv_font.h" #if USE_LV_FONT_DEJAVU_10 != 0 /*Can be enabled in lv_conf.h*/ /*********************************************************************************** * DejaVuSans.ttf 10 px Font in U+0020 ( ) .. U+007e (~) range with 1 bpp ***********************************************************************************/ /*Store the image of the letters (glyph)*/ static const uint8_t lv_font_dejavu_10_glyph_bitmap[] = { #if USE_LV_FONT_DEJAVU_10 == 1 /*Unicode: U+0020 ( ) , Width: 3 */ 0x00, //... 0x00, //... 0x00, //... 0x00, //... 0x00, //... 0x00, //... 0x00, //... 0x00, //... 0x00, //... 0x00, //... /*Unicode: U+0021 (!) , Width: 1 */ 0x00, //. 0x80, //@ 0x80, //@ 0x80, //@ 0x80, //@ 0x00, //. 0x80, //@ 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+0022 (") , Width: 3 */ 0x00, //... 0xa0, //@.@ 0xa0, //@.@ 0x00, //... 0x00, //... 0x00, //... 0x00, //... 0x00, //... 0x00, //... 0x00, //... /*Unicode: U+0023 (#) , Width: 5 */ 0x20, //..%+. 0x10, //..+%. 0xf8, //%@@@@ 0x50, //.%.%. 0xf8, //@@@@% 0x40, //.%+.. 0x20, //.+%.. 0x00, //..... 0x00, //..... 0x00, //..... /*Unicode: U+0024 ($) , Width: 5 */ 0x00, //..... 0x20, //..@.. 0x78, //+@@@@ 0xa0, //@+@.. 0x70, //+%@@+ 0x28, //..@.@ 0xf0, //@@@@+ 0x20, //..@.. 0x00, //..... 0x00, //..... /*Unicode: U+0025 (%) , Width: 7 */ 0x00, //....... 0xe8, //%@%.@+. 0xa8, //@+@+@.. 0xf0, //%@%@+.. 0x1e, //..+@%@% 0x2a, //..@+@+@ 0x2e, //.+@.%@% 0x00, //....... 0x00, //....... 0x00, //....... /*Unicode: U+0026 (&) , Width: 5 */ 0x00, //..... 0x70, //.%@@. 0x40, //.@... 0x60, //.@%.. 0xf8, //%%@%@ 0xb0, //@+@@. 0x78, //+@%%% 0x00, //..... 0x00, //..... 0x00, //..... /*Unicode: U+0027 (') , Width: 1 */ 0x00, //. 0x80, //@ 0x80, //@ 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+0028 (() , Width: 2 */ 0x40, //.% 0x80, //%+ 0x80, //@. 0x80, //@. 0x80, //@. 0x80, //%+ 0x40, //.% 0x00, //.. 0x00, //.. 0x00, //.. /*Unicode: U+0029 ()) , Width: 2 */ 0x80, //%. 0x40, //+% 0x40, //.@ 0x40, //.@ 0x40, //.@ 0x40, //+% 0x80, //%. 0x00, //.. 0x00, //.. 0x00, //.. /*Unicode: U+002a (*) , Width: 5 */ 0x00, //..... 0xa8, //%.@.% 0x70, //.%@%. 0x70, //.%@%. 0xa8, //%.@.% 0x00, //..... 0x00, //..... 0x00, //..... 0x00, //..... 0x00, //..... /*Unicode: U+002b (+) , Width: 5 */ 0x00, //..... 0x00, //..... 0x20, //..@.. 0x20, //..@.. 0xf8, //@@@@@ 0x20, //..@.. 0x20, //..@.. 0x00, //..... 0x00, //..... 0x00, //..... /*Unicode: U+002c (,) , Width: 1 */ 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x80, //@ 0x80, //@ 0x00, //. 0x00, //. /*Unicode: U+002d (-) , Width: 2 */ 0x00, //.. 0x00, //.. 0x00, //.. 0x00, //.. 0xc0, //@@ 0x00, //.. 0x00, //.. 0x00, //.. 0x00, //.. 0x00, //.. /*Unicode: U+002e (.) , Width: 1 */ 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x80, //@ 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+002f (/) , Width: 3 */ 0x00, //... 0x20, //..@ 0x20, //.+% 0x40, //.%+ 0x40, //.@. 0x40, //+%. 0x80, //%+. 0x80, //@.. 0x00, //... 0x00, //... /*Unicode: U+0030 (0) , Width: 4 */ 0x00, //.... 0x60, //.@@. 0x90, //@++@ 0x90, //@..@ 0x90, //@..@ 0x90, //@++@ 0x60, //.@@. 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0031 (1) , Width: 3 */ 0x00, //... 0xc0, //@@. 0x40, //.@. 0x40, //.@. 0x40, //.@. 0x40, //.@. 0xe0, //@@@ 0x00, //... 0x00, //... 0x00, //... /*Unicode: U+0032 (2) , Width: 5 */ 0x00, //..... 0xe0, //@@@+. 0x10, //...@. 0x10, //..+%. 0x20, //.+@.. 0x40, //+@... 0xf0, //@@@@. 0x00, //..... 0x00, //..... 0x00, //..... /*Unicode: U+0033 (3) , Width: 4 */ 0x00, //.... 0xe0, //@@@+ 0x10, //...@ 0x10, //...@ 0x60, //.@@+ 0x10, //..+@ 0xe0, //@@@+ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0034 (4) , Width: 4 */ 0x00, //.... 0x20, //..@. 0x60, //.%@. 0x60, //.@@. 0xa0, //%+@. 0xf0, //@@@@ 0x20, //..@. 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0035 (5) , Width: 4 */ 0x00, //.... 0xf0, //@@@@ 0x80, //@... 0xe0, //@@@+ 0x10, //..+@ 0x10, //..+@ 0xe0, //@@@+ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0036 (6) , Width: 4 */ 0x00, //.... 0x70, //.%@@ 0xc0, //%%.. 0x80, //@... 0xf0, //@%@% 0x90, //@..@ 0x60, //.@@+ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0037 (7) , Width: 4 */ 0x00, //.... 0xf0, //@@@@ 0x10, //..+% 0x20, //..@+ 0x20, //..@. 0x20, //.+%. 0x40, //.@.. 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0038 (8) , Width: 4 */ 0x00, //.... 0x60, //+@@+ 0x90, //@..@ 0x90, //@..@ 0x60, //+@@+ 0x90, //@..@ 0xf0, //%@@% 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0039 (9) , Width: 4 */ 0x00, //.... 0x60, //+@@. 0x90, //@..@ 0xf0, //%@%@ 0x10, //...@ 0x30, //..%% 0xe0, //@@%. 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+003a (:) , Width: 1 */ 0x00, //. 0x00, //. 0x00, //. 0x80, //@ 0x00, //. 0x00, //. 0x80, //@ 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+003b (;) , Width: 1 */ 0x00, //. 0x00, //. 0x00, //. 0x80, //@ 0x00, //. 0x00, //. 0x80, //@ 0x80, //@ 0x00, //. 0x00, //. /*Unicode: U+003c (<) , Width: 5 */ 0x00, //..... 0x00, //..... 0x08, //...+@ 0x70, //+@@%. 0x70, //+@@%. 0x08, //...+@ 0x00, //..... 0x00, //..... 0x00, //..... 0x00, //..... /*Unicode: U+003d (=) , Width: 5 */ 0x00, //..... 0x00, //..... 0x00, //..... 0xf8, //@@@@@ 0x00, //..... 0xf8, //@@@@@ 0x00, //..... 0x00, //..... 0x00, //..... 0x00, //..... /*Unicode: U+003e (>) , Width: 5 */ 0x00, //..... 0x00, //..... 0x80, //@+... 0x70, //.%@@+ 0x70, //.%@@+ 0x80, //@+... 0x00, //..... 0x00, //..... 0x00, //..... 0x00, //..... /*Unicode: U+003f (?) , Width: 3 */ 0x00, //... 0xe0, //@@% 0x20, //..@ 0x40, //.%. 0x40, //.@. 0x00, //... 0x40, //.@. 0x00, //... 0x00, //... 0x00, //... /*Unicode: U+0040 (@) , Width: 7 */ 0x00, //....... 0x38, //.+@@@+. 0x46, //+@+..%% 0xba, //@.%%@.@ 0xaa, //@.@+@+@ 0xbc, //@.%%@%. 0x40, //+@+.+.. 0x30, //.+@@+.. 0x00, //....... 0x00, //....... /*Unicode: U+0041 (A) , Width: 5 */ 0x00, //..... 0x20, //..@.. 0x20, //.+@+. 0x70, //.@%@. 0x50, //.@.@. 0x70, //+@@@+ 0x88, //@...@ 0x00, //..... 0x00, //..... 0x00, //..... /*Unicode: U+0042 (B) , Width: 4 */ 0x00, //.... 0xe0, //@@@+ 0x90, //@..@ 0x90, //@..@ 0xe0, //@@@+ 0x90, //@..@ 0xf0, //@@@% 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0043 (C) , Width: 5 */ 0x00, //..... 0x70, //.%@@+ 0xc8, //%%..% 0x80, //@.... 0x80, //@.... 0xc8, //%%..% 0x70, //.%@@+ 0x00, //..... 0x00, //..... 0x00, //..... /*Unicode: U+0044 (D) , Width: 5 */ 0x00, //..... 0xf0, //@@@%. 0x98, //@..%% 0x88, //@...@ 0x88, //@...@ 0x98, //@..%% 0xf0, //@@@%. 0x00, //..... 0x00, //..... 0x00, //..... /*Unicode: U+0045 (E) , Width: 4 */ 0x00, //.... 0xf0, //@@@@ 0x80, //@... 0x80, //@... 0xf0, //@@@@ 0x80, //@... 0xf0, //@@@@ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0046 (F) , Width: 3 */ 0x00, //... 0xe0, //@@@ 0x80, //@.. 0x80, //@.. 0xe0, //@@@ 0x80, //@.. 0x80, //@.. 0x00, //... 0x00, //... 0x00, //... /*Unicode: U+0047 (G) , Width: 5 */ 0x00, //..... 0x70, //.%@@+ 0xc8, //%%..% 0x98, //@..@@ 0x88, //@...@ 0xc8, //%%..@ 0x70, //.%@@+ 0x00, //..... 0x00, //..... 0x00, //..... /*Unicode: U+0048 (H) , Width: 4 */ 0x00, //.... 0x90, //@..@ 0x90, //@..@ 0x90, //@..@ 0xf0, //@@@@ 0x90, //@..@ 0x90, //@..@ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0049 (I) , Width: 1 */ 0x00, //. 0x80, //@ 0x80, //@ 0x80, //@ 0x80, //@ 0x80, //@ 0x80, //@ 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+004a (J) , Width: 2 */ 0x00, //.. 0x40, //.@ 0x40, //.@ 0x40, //.@ 0x40, //.@ 0x40, //.@ 0x40, //.@ 0x40, //.@ 0x80, //@+ 0x00, //.. /*Unicode: U+004b (K) , Width: 5 */ 0x00, //..... 0x90, //@..@+ 0xa0, //@+@+. 0xc0, //@@... 0xe0, //@@+.. 0xb0, //@.@+. 0x90, //@..@+ 0x00, //..... 0x00, //..... 0x00, //..... /*Unicode: U+004c (L) , Width: 4 */ 0x00, //.... 0x80, //@... 0x80, //@... 0x80, //@... 0x80, //@... 0x80, //@... 0xf0, //@@@@ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+004d (M) , Width: 5 */ 0x00, //..... 0xd8, //@@.@@ 0xd8, //@@+@@ 0xf8, //@%@+@ 0xa8, //@.@.@ 0xa8, //@.@.@ 0x88, //@...@ 0x00, //..... 0x00, //..... 0x00, //..... /*Unicode: U+004e (N) , Width: 4 */ 0x00, //.... 0x90, //@+.@ 0xd0, //@@.@ 0xd0, //@%+@ 0xb0, //@+@@ 0xb0, //@.@@ 0x90, //@.+@ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+004f (O) , Width: 5 */ 0x00, //..... 0x70, //.%@%. 0xd8, //%%.%% 0x88, //@...@ 0x88, //@...@ 0xd8, //%%.%% 0x70, //.%@%. 0x00, //..... 0x00, //..... 0x00, //..... /*Unicode: U+0050 (P) , Width: 4 */ 0x00, //.... 0xe0, //@@@+ 0x90, //@..@ 0xe0, //@@@+ 0x80, //@... 0x80, //@... 0x80, //@... 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0051 (Q) , Width: 5 */ 0x00, //..... 0x70, //.%@%. 0xd8, //%%.%% 0x88, //@...@ 0x88, //@...@ 0xd8, //%%.%% 0x70, //.%@%. 0x10, //...@. 0x00, //..... 0x00, //..... /*Unicode: U+0052 (R) , Width: 5 */ 0x00, //..... 0xf0, //@@@%. 0x90, //@..@. 0xe0, //@@@+. 0xb0, //@.%%. 0x90, //@..@. 0x88, //@..+% 0x00, //..... 0x00, //..... 0x00, //..... /*Unicode: U+0053 (S) , Width: 4 */ 0x00, //.... 0x70, //+@@@ 0x80, //@... 0xe0, //%@%. 0x30, //..%@ 0x10, //...@ 0xe0, //@@@+ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0054 (T) , Width: 5 */ 0x00, //..... 0xf8, //@@@@@ 0x20, //..@.. 0x20, //..@.. 0x20, //..@.. 0x20, //..@.. 0x20, //..@.. 0x00, //..... 0x00, //..... 0x00, //..... /*Unicode: U+0055 (U) , Width: 4 */ 0x00, //.... 0x90, //@..@ 0x90, //@..@ 0x90, //@..@ 0x90, //@..@ 0x90, //@++@ 0x60, //+@@+ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0056 (V) , Width: 5 */ 0x00, //..... 0x88, //@...@ 0x50, //+%.%+ 0x50, //.@.@. 0x70, //.@%@. 0x20, //.+@+. 0x20, //..@.. 0x00, //..... 0x00, //..... 0x00, //..... /*Unicode: U+0057 (W) , Width: 7 */ 0x00, //....... 0x92, //@.+@+.@ 0xba, //%+%%%+% 0x6c, //+%@.@%+ 0x6c, //.@@.@@. 0x6c, //.@%.%@. 0x44, //.%+.+%. 0x00, //....... 0x00, //....... 0x00, //....... /*Unicode: U+0058 (X) , Width: 5 */ 0x00, //..... 0xd8, //%%.%% 0x50, //.@+@. 0x20, //.+@+. 0x20, //.+@+. 0x50, //.@+@. 0x88, //%+.+% 0x00, //..... 0x00, //..... 0x00, //..... /*Unicode: U+0059 (Y) , Width: 5 */ 0x00, //..... 0xd8, //%+.+% 0x50, //.@+@. 0x20, //.+@+. 0x20, //..@.. 0x20, //..@.. 0x20, //..@.. 0x00, //..... 0x00, //..... 0x00, //..... /*Unicode: U+005a (Z) , Width: 5 */ 0x00, //..... 0xf8, //@@@@@ 0x10, //...@+ 0x20, //..@+. 0x60, //.%%.. 0x40, //+@... 0xf8, //@@@@@ 0x00, //..... 0x00, //..... 0x00, //..... /*Unicode: U+005b ([) , Width: 2 */ 0x00, //.. 0xc0, //@@ 0x80, //@. 0x80, //@. 0x80, //@. 0x80, //@. 0x80, //@. 0xc0, //@@ 0x00, //.. 0x00, //.. /*Unicode: U+005c (\) , Width: 3 */ 0x00, //... 0x80, //@.. 0x80, //%+. 0x40, //+%. 0x40, //.@. 0x40, //.%+ 0x20, //.+% 0x20, //..@ 0x00, //... 0x00, //... /*Unicode: U+005d (]) , Width: 2 */ 0x00, //.. 0xc0, //@@ 0x40, //.@ 0x40, //.@ 0x40, //.@ 0x40, //.@ 0x40, //.@ 0xc0, //@@ 0x00, //.. 0x00, //.. /*Unicode: U+005e (^) , Width: 5 */ 0x00, //..... 0x20, //.+@+. 0x00, //++.++ 0x00, //..... 0x00, //..... 0x00, //..... 0x00, //..... 0x00, //..... 0x00, //..... 0x00, //..... /*Unicode: U+005f (_) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0x00, //.... 0x00, //.... 0x00, //.... 0x00, //.... 0x00, //.... 0xf0, //@@@@ 0x00, //.... /*Unicode: U+0060 (`) , Width: 2 */ 0x00, //.. 0x00, //++ 0x00, //.. 0x00, //.. 0x00, //.. 0x00, //.. 0x00, //.. 0x00, //.. 0x00, //.. 0x00, //.. /*Unicode: U+0061 (a) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0x70, //.@@% 0x70, //+@@@ 0x90, //@..@ 0xf0, //%@%@ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0062 (b) , Width: 4 */ 0x80, //@... 0x80, //@... 0x80, //@... 0xe0, //@%@+ 0x90, //@..@ 0x90, //@..@ 0xe0, //@%@+ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0063 (c) , Width: 3 */ 0x00, //... 0x00, //... 0x00, //... 0x60, //+@@ 0x80, //@.. 0x80, //@.. 0x60, //+@@ 0x00, //... 0x00, //... 0x00, //... /*Unicode: U+0064 (d) , Width: 4 */ 0x10, //...@ 0x10, //...@ 0x10, //...@ 0x70, //+@%@ 0x90, //@..@ 0x90, //@..@ 0x70, //+@%@ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0065 (e) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0x70, //+@@% 0xf0, //@@@@ 0x80, //@+.. 0x70, //+@@@ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0066 (f) , Width: 3 */ 0x20, //.+@ 0x40, //.@. 0x40, //.@. 0xe0, //@@@ 0x40, //.@. 0x40, //.@. 0x40, //.@. 0x00, //... 0x00, //... 0x00, //... /*Unicode: U+0067 (g) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0x70, //+@%@ 0x90, //@..@ 0x90, //@..@ 0x70, //+@%@ 0x10, //..+@ 0x60, //.@@+ 0x00, //.... /*Unicode: U+0068 (h) , Width: 4 */ 0x80, //@... 0x80, //@... 0x80, //@... 0xf0, //@%@% 0x90, //@..@ 0x90, //@..@ 0x90, //@..@ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0069 (i) , Width: 1 */ 0x00, //. 0x80, //@ 0x00, //. 0x80, //@ 0x80, //@ 0x80, //@ 0x80, //@ 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+006a (j) , Width: 2 */ 0x00, //.. 0x40, //.@ 0x00, //.. 0x40, //.@ 0x40, //.@ 0x40, //.@ 0x40, //.@ 0x40, //.@ 0xc0, //@% 0x00, //.. /*Unicode: U+006b (k) , Width: 4 */ 0x80, //@... 0x80, //@... 0x80, //@... 0xa0, //@.@+ 0xc0, //@@.. 0xc0, //@@+. 0xa0, //@.@+ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+006c (l) , Width: 1 */ 0x80, //@ 0x80, //@ 0x80, //@ 0x80, //@ 0x80, //@ 0x80, //@ 0x80, //@ 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+006d (m) , Width: 7 */ 0x00, //....... 0x00, //....... 0x00, //....... 0xee, //@%@+%@+ 0x92, //@..@..@ 0x92, //@..@..@ 0x92, //@..@..@ 0x00, //....... 0x00, //....... 0x00, //....... /*Unicode: U+006e (n) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0xf0, //@%@% 0x90, //@..@ 0x90, //@..@ 0x90, //@..@ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+006f (o) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0x60, //+@@+ 0x90, //@..@ 0x90, //@..@ 0x60, //+@@+ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0070 (p) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0xe0, //@%@+ 0x90, //@..@ 0x90, //@..@ 0xe0, //@%@+ 0x80, //@... 0x80, //@... 0x00, //.... /*Unicode: U+0071 (q) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0x70, //+@%@ 0x90, //@..@ 0x90, //@..@ 0x70, //+@%@ 0x10, //...@ 0x10, //...@ 0x00, //.... /*Unicode: U+0072 (r) , Width: 3 */ 0x00, //... 0x00, //... 0x00, //... 0xe0, //@%@ 0x80, //@+. 0x80, //@.. 0x80, //@.. 0x00, //... 0x00, //... 0x00, //... /*Unicode: U+0073 (s) , Width: 3 */ 0x00, //... 0x00, //... 0x00, //... 0xe0, //%@@ 0xc0, //@@+ 0x20, //.+@ 0xe0, //@@% 0x00, //... 0x00, //... 0x00, //... /*Unicode: U+0074 (t) , Width: 3 */ 0x00, //... 0x00, //... 0x40, //.@. 0xe0, //@@@ 0x40, //.@. 0x40, //.@. 0x60, //.%@ 0x00, //... 0x00, //... 0x00, //... /*Unicode: U+0075 (u) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0x90, //@..@ 0x90, //@..@ 0x90, //@..@ 0xf0, //%@%@ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0076 (v) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0x90, //@++@ 0x60, //+%%+ 0x60, //.@@. 0x60, //.%%. 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0077 (w) , Width: 6 */ 0x00, //...... 0x00, //...... 0x00, //...... 0xb4, //@.@@.@ 0xfc, //%%@@%% 0x48, //+@++@+ 0x48, //.@..@. 0x00, //...... 0x00, //...... 0x00, //...... /*Unicode: U+0078 (x) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0xf0, //%%%% 0x60, //.@@. 0x60, //.@@. 0xf0, //%%%% 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0079 (y) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0x90, //@.+@ 0x60, //+%@+ 0x60, //.@@. 0x40, //.@+. 0x40, //.@.. 0x80, //@+.. 0x00, //.... /*Unicode: U+007a (z) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0xf0, //@@@@ 0x20, //..@+ 0x60, //.@%. 0xf0, //@@@@ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+007b ({) , Width: 3 */ 0x00, //... 0x60, //.%@ 0x40, //.@. 0x40, //.@. 0xc0, //@%. 0x40, //.@. 0x40, //.@. 0x60, //.%@ 0x00, //... 0x00, //... /*Unicode: U+007c (|) , Width: 1 */ 0x00, //. 0x80, //@ 0x80, //@ 0x80, //@ 0x80, //@ 0x80, //@ 0x80, //@ 0x80, //@ 0x80, //@ 0x00, //. /*Unicode: U+007d (}) , Width: 3 */ 0x00, //... 0xc0, //@%. 0x40, //.@. 0x40, //.@. 0x60, //.%@ 0x40, //.@. 0x40, //.@. 0xc0, //@%. 0x00, //... 0x00, //... /*Unicode: U+007e (~) , Width: 5 */ 0x00, //..... 0x00, //..... 0x00, //..... 0x00, //..... 0xe8, //+@%.% 0x38, //+.%@+ 0x00, //..... 0x00, //..... 0x00, //..... 0x00, //..... #elif USE_LV_FONT_DEJAVU_10 == 2 /*Unicode: U+0020 ( ) , Width: 3 */ 0x00, //... 0x00, //... 0x00, //... 0x00, //... 0x00, //... 0x00, //... 0x00, //... 0x00, //... 0x00, //... 0x00, //... /*Unicode: U+0021 (!) , Width: 1 */ 0x00, //. 0xc0, //@ 0xc0, //@ 0xc0, //@ 0xc0, //@ 0x00, //. 0xc0, //@ 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+0022 (") , Width: 3 */ 0x00, //... 0xcc, //@.@ 0xcc, //@.@ 0x00, //... 0x00, //... 0x00, //... 0x00, //... 0x00, //... 0x00, //... 0x00, //... /*Unicode: U+0023 (#) , Width: 5 */ 0x09, 0x00, //..%+. 0x06, 0x00, //..+%. 0xbf, 0xc0, //%@@@@ 0x22, 0x00, //.%.%. 0xff, 0x80, //@@@@% 0x24, 0x00, //.%+.. 0x18, 0x00, //.+%.. 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... /*Unicode: U+0024 ($) , Width: 5 */ 0x00, 0x00, //..... 0x0c, 0x00, //..@.. 0x7f, 0xc0, //+@@@@ 0xdc, 0x00, //@+@.. 0x6f, 0x40, //+%@@+ 0x0c, 0xc0, //..@.@ 0xff, 0x40, //@@@@+ 0x0c, 0x00, //..@.. 0x00, 0x00, //..... 0x00, 0x00, //..... /*Unicode: U+0025 (%) , Width: 7 */ 0x00, 0x00, //....... 0xb8, 0xd0, //%@%.@+. 0xdd, 0xc0, //@+@+@.. 0xbb, 0x40, //%@%@+.. 0x07, 0xb8, //..+@%@% 0x0d, 0xdc, //..@+@+@ 0x1c, 0xb8, //.+@.%@% 0x00, 0x00, //....... 0x00, 0x00, //....... 0x00, 0x00, //....... /*Unicode: U+0026 (&) , Width: 5 */ 0x00, 0x00, //..... 0x2f, 0x00, //.%@@. 0x30, 0x00, //.@... 0x38, 0x00, //.@%.. 0xae, 0xc0, //%%@%@ 0xdf, 0x00, //@+@@. 0x7e, 0x80, //+@%%% 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... /*Unicode: U+0027 (') , Width: 1 */ 0x00, //. 0xc0, //@ 0xc0, //@ 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+0028 (() , Width: 2 */ 0x20, //.% 0x90, //%+ 0xc0, //@. 0xc0, //@. 0xc0, //@. 0x90, //%+ 0x20, //.% 0x00, //.. 0x00, //.. 0x00, //.. /*Unicode: U+0029 ()) , Width: 2 */ 0x80, //%. 0x60, //+% 0x30, //.@ 0x30, //.@ 0x30, //.@ 0x60, //+% 0x80, //%. 0x00, //.. 0x00, //.. 0x00, //.. /*Unicode: U+002a (*) , Width: 5 */ 0x00, 0x00, //..... 0x8c, 0x80, //%.@.% 0x2e, 0x00, //.%@%. 0x2e, 0x00, //.%@%. 0x8c, 0x80, //%.@.% 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... /*Unicode: U+002b (+) , Width: 5 */ 0x00, 0x00, //..... 0x00, 0x00, //..... 0x0c, 0x00, //..@.. 0x0c, 0x00, //..@.. 0xff, 0xc0, //@@@@@ 0x0c, 0x00, //..@.. 0x0c, 0x00, //..@.. 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... /*Unicode: U+002c (,) , Width: 1 */ 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0xc0, //@ 0xc0, //@ 0x00, //. 0x00, //. /*Unicode: U+002d (-) , Width: 2 */ 0x00, //.. 0x00, //.. 0x00, //.. 0x00, //.. 0xf0, //@@ 0x00, //.. 0x00, //.. 0x00, //.. 0x00, //.. 0x00, //.. /*Unicode: U+002e (.) , Width: 1 */ 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0xc0, //@ 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+002f (/) , Width: 3 */ 0x00, //... 0x0c, //..@ 0x18, //.+% 0x24, //.%+ 0x30, //.@. 0x60, //+%. 0x90, //%+. 0xc0, //@.. 0x00, //... 0x00, //... /*Unicode: U+0030 (0) , Width: 4 */ 0x00, //.... 0x3c, //.@@. 0xd7, //@++@ 0xc3, //@..@ 0xc3, //@..@ 0xd7, //@++@ 0x3c, //.@@. 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0031 (1) , Width: 3 */ 0x00, //... 0xf0, //@@. 0x30, //.@. 0x30, //.@. 0x30, //.@. 0x30, //.@. 0xfc, //@@@ 0x00, //... 0x00, //... 0x00, //... /*Unicode: U+0032 (2) , Width: 5 */ 0x00, 0x00, //..... 0xfd, 0x00, //@@@+. 0x03, 0x00, //...@. 0x06, 0x00, //..+%. 0x1c, 0x00, //.+@.. 0x70, 0x00, //+@... 0xff, 0x00, //@@@@. 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... /*Unicode: U+0033 (3) , Width: 4 */ 0x00, //.... 0xfd, //@@@+ 0x03, //...@ 0x03, //...@ 0x3d, //.@@+ 0x07, //..+@ 0xfd, //@@@+ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0034 (4) , Width: 4 */ 0x00, //.... 0x0c, //..@. 0x2c, //.%@. 0x3c, //.@@. 0x9c, //%+@. 0xff, //@@@@ 0x0c, //..@. 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0035 (5) , Width: 4 */ 0x00, //.... 0xff, //@@@@ 0xc0, //@... 0xfd, //@@@+ 0x07, //..+@ 0x07, //..+@ 0xfd, //@@@+ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0036 (6) , Width: 4 */ 0x00, //.... 0x2f, //.%@@ 0xa0, //%%.. 0xc0, //@... 0xee, //@%@% 0xc3, //@..@ 0x3d, //.@@+ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0037 (7) , Width: 4 */ 0x00, //.... 0xff, //@@@@ 0x06, //..+% 0x0d, //..@+ 0x0c, //..@. 0x18, //.+%. 0x30, //.@.. 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0038 (8) , Width: 4 */ 0x00, //.... 0x7d, //+@@+ 0xc3, //@..@ 0xc3, //@..@ 0x7d, //+@@+ 0xc3, //@..@ 0xbe, //%@@% 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0039 (9) , Width: 4 */ 0x00, //.... 0x7c, //+@@. 0xc3, //@..@ 0xbb, //%@%@ 0x03, //...@ 0x0a, //..%% 0xf8, //@@%. 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+003a (:) , Width: 1 */ 0x00, //. 0x00, //. 0x00, //. 0xc0, //@ 0x00, //. 0x00, //. 0xc0, //@ 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+003b (;) , Width: 1 */ 0x00, //. 0x00, //. 0x00, //. 0xc0, //@ 0x00, //. 0x00, //. 0xc0, //@ 0xc0, //@ 0x00, //. 0x00, //. /*Unicode: U+003c (<) , Width: 5 */ 0x00, 0x00, //..... 0x00, 0x00, //..... 0x01, 0xc0, //...+@ 0x7e, 0x00, //+@@%. 0x7e, 0x00, //+@@%. 0x01, 0xc0, //...+@ 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... /*Unicode: U+003d (=) , Width: 5 */ 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... 0xff, 0xc0, //@@@@@ 0x00, 0x00, //..... 0xff, 0xc0, //@@@@@ 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... /*Unicode: U+003e (>) , Width: 5 */ 0x00, 0x00, //..... 0x00, 0x00, //..... 0xd0, 0x00, //@+... 0x2f, 0x40, //.%@@+ 0x2f, 0x40, //.%@@+ 0xd0, 0x00, //@+... 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... /*Unicode: U+003f (?) , Width: 3 */ 0x00, //... 0xf8, //@@% 0x0c, //..@ 0x20, //.%. 0x30, //.@. 0x00, //... 0x30, //.@. 0x00, //... 0x00, //... 0x00, //... /*Unicode: U+0040 (@) , Width: 7 */ 0x00, 0x00, //....... 0x1f, 0xd0, //.+@@@+. 0x74, 0x28, //+@+..%% 0xca, 0xcc, //@.%%@.@ 0xcd, 0xdc, //@.@+@+@ 0xda, 0xe0, //@.%%@%. 0x74, 0x40, //+@+.+.. 0x1f, 0x40, //.+@@+.. 0x00, 0x00, //....... 0x00, 0x00, //....... /*Unicode: U+0041 (A) , Width: 5 */ 0x00, 0x00, //..... 0x0c, 0x00, //..@.. 0x1d, 0x00, //.+@+. 0x3b, 0x00, //.@%@. 0x33, 0x00, //.@.@. 0x7f, 0x40, //+@@@+ 0xc0, 0xc0, //@...@ 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... /*Unicode: U+0042 (B) , Width: 4 */ 0x00, //.... 0xfd, //@@@+ 0xc3, //@..@ 0xc3, //@..@ 0xfd, //@@@+ 0xc3, //@..@ 0xfe, //@@@% 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0043 (C) , Width: 5 */ 0x00, 0x00, //..... 0x2f, 0x40, //.%@@+ 0xa0, 0x80, //%%..% 0xc0, 0x00, //@.... 0xc0, 0x00, //@.... 0xa0, 0x80, //%%..% 0x2f, 0x40, //.%@@+ 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... /*Unicode: U+0044 (D) , Width: 5 */ 0x00, 0x00, //..... 0xfe, 0x00, //@@@%. 0xc2, 0x80, //@..%% 0xc0, 0xc0, //@...@ 0xc0, 0xc0, //@...@ 0xc2, 0x80, //@..%% 0xfe, 0x00, //@@@%. 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... /*Unicode: U+0045 (E) , Width: 4 */ 0x00, //.... 0xff, //@@@@ 0xc0, //@... 0xc0, //@... 0xff, //@@@@ 0xc0, //@... 0xff, //@@@@ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0046 (F) , Width: 3 */ 0x00, //... 0xfc, //@@@ 0xc0, //@.. 0xc0, //@.. 0xfc, //@@@ 0xc0, //@.. 0xc0, //@.. 0x00, //... 0x00, //... 0x00, //... /*Unicode: U+0047 (G) , Width: 5 */ 0x00, 0x00, //..... 0x2f, 0x40, //.%@@+ 0xa0, 0x80, //%%..% 0xc3, 0xc0, //@..@@ 0xc0, 0xc0, //@...@ 0xa0, 0xc0, //%%..@ 0x2f, 0x40, //.%@@+ 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... /*Unicode: U+0048 (H) , Width: 4 */ 0x00, //.... 0xc3, //@..@ 0xc3, //@..@ 0xc3, //@..@ 0xff, //@@@@ 0xc3, //@..@ 0xc3, //@..@ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0049 (I) , Width: 1 */ 0x00, //. 0xc0, //@ 0xc0, //@ 0xc0, //@ 0xc0, //@ 0xc0, //@ 0xc0, //@ 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+004a (J) , Width: 2 */ 0x00, //.. 0x30, //.@ 0x30, //.@ 0x30, //.@ 0x30, //.@ 0x30, //.@ 0x30, //.@ 0x30, //.@ 0xd0, //@+ 0x00, //.. /*Unicode: U+004b (K) , Width: 5 */ 0x00, 0x00, //..... 0xc3, 0x40, //@..@+ 0xdd, 0x00, //@+@+. 0xf0, 0x00, //@@... 0xf8, 0x00, //@@+.. 0xce, 0x00, //@.@+. 0xc3, 0x40, //@..@+ 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... /*Unicode: U+004c (L) , Width: 4 */ 0x00, //.... 0xc0, //@... 0xc0, //@... 0xc0, //@... 0xc0, //@... 0xc0, //@... 0xff, //@@@@ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+004d (M) , Width: 5 */ 0x00, 0x00, //..... 0xf3, 0xc0, //@@.@@ 0xf7, 0xc0, //@@+@@ 0xee, 0xc0, //@%@+@ 0xcc, 0xc0, //@.@.@ 0xcc, 0xc0, //@.@.@ 0xc0, 0xc0, //@...@ 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... /*Unicode: U+004e (N) , Width: 4 */ 0x00, //.... 0xd3, //@+.@ 0xf3, //@@.@ 0xe7, //@%+@ 0xdf, //@+@@ 0xcf, //@.@@ 0xc7, //@.+@ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+004f (O) , Width: 5 */ 0x00, 0x00, //..... 0x2e, 0x00, //.%@%. 0xa2, 0x80, //%%.%% 0xc0, 0xc0, //@...@ 0xc0, 0xc0, //@...@ 0xa2, 0x80, //%%.%% 0x2e, 0x00, //.%@%. 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... /*Unicode: U+0050 (P) , Width: 4 */ 0x00, //.... 0xfd, //@@@+ 0xc3, //@..@ 0xfd, //@@@+ 0xc0, //@... 0xc0, //@... 0xc0, //@... 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0051 (Q) , Width: 5 */ 0x00, 0x00, //..... 0x2e, 0x00, //.%@%. 0xa2, 0x80, //%%.%% 0xc0, 0xc0, //@...@ 0xc0, 0xc0, //@...@ 0xa2, 0x80, //%%.%% 0x2e, 0x00, //.%@%. 0x03, 0x00, //...@. 0x00, 0x00, //..... 0x00, 0x00, //..... /*Unicode: U+0052 (R) , Width: 5 */ 0x00, 0x00, //..... 0xfe, 0x00, //@@@%. 0xc3, 0x00, //@..@. 0xfd, 0x00, //@@@+. 0xca, 0x00, //@.%%. 0xc3, 0x00, //@..@. 0xc1, 0x80, //@..+% 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... /*Unicode: U+0053 (S) , Width: 4 */ 0x00, //.... 0x7f, //+@@@ 0xc0, //@... 0xb8, //%@%. 0x0b, //..%@ 0x03, //...@ 0xfd, //@@@+ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0054 (T) , Width: 5 */ 0x00, 0x00, //..... 0xff, 0xc0, //@@@@@ 0x0c, 0x00, //..@.. 0x0c, 0x00, //..@.. 0x0c, 0x00, //..@.. 0x0c, 0x00, //..@.. 0x0c, 0x00, //..@.. 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... /*Unicode: U+0055 (U) , Width: 4 */ 0x00, //.... 0xc3, //@..@ 0xc3, //@..@ 0xc3, //@..@ 0xc3, //@..@ 0xd7, //@++@ 0x7d, //+@@+ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0056 (V) , Width: 5 */ 0x00, 0x00, //..... 0xc0, 0xc0, //@...@ 0x62, 0x40, //+%.%+ 0x33, 0x00, //.@.@. 0x3b, 0x00, //.@%@. 0x1d, 0x00, //.+@+. 0x0c, 0x00, //..@.. 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... /*Unicode: U+0057 (W) , Width: 7 */ 0x00, 0x00, //....... 0xc7, 0x4c, //@.+@+.@ 0x9a, 0x98, //%+%%%+% 0x6c, 0xe4, //+%@.@%+ 0x3c, 0xf0, //.@@.@@. 0x38, 0xb0, //.@%.%@. 0x24, 0x60, //.%+.+%. 0x00, 0x00, //....... 0x00, 0x00, //....... 0x00, 0x00, //....... /*Unicode: U+0058 (X) , Width: 5 */ 0x00, 0x00, //..... 0xa2, 0x80, //%%.%% 0x37, 0x00, //.@+@. 0x1d, 0x00, //.+@+. 0x1d, 0x00, //.+@+. 0x37, 0x00, //.@+@. 0x91, 0x80, //%+.+% 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... /*Unicode: U+0059 (Y) , Width: 5 */ 0x00, 0x00, //..... 0xa2, 0x80, //%+.+% 0x37, 0x00, //.@+@. 0x1d, 0x00, //.+@+. 0x0c, 0x00, //..@.. 0x0c, 0x00, //..@.. 0x0c, 0x00, //..@.. 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... /*Unicode: U+005a (Z) , Width: 5 */ 0x00, 0x00, //..... 0xff, 0xc0, //@@@@@ 0x03, 0x40, //...@+ 0x0d, 0x00, //..@+. 0x28, 0x00, //.%%.. 0x70, 0x00, //+@... 0xff, 0xc0, //@@@@@ 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... /*Unicode: U+005b ([) , Width: 2 */ 0x00, //.. 0xf0, //@@ 0xc0, //@. 0xc0, //@. 0xc0, //@. 0xc0, //@. 0xc0, //@. 0xf0, //@@ 0x00, //.. 0x00, //.. /*Unicode: U+005c (\) , Width: 3 */ 0x00, //... 0xc0, //@.. 0x90, //%+. 0x60, //+%. 0x30, //.@. 0x24, //.%+ 0x18, //.+% 0x0c, //..@ 0x00, //... 0x00, //... /*Unicode: U+005d (]) , Width: 2 */ 0x00, //.. 0xf0, //@@ 0x30, //.@ 0x30, //.@ 0x30, //.@ 0x30, //.@ 0x30, //.@ 0xf0, //@@ 0x00, //.. 0x00, //.. /*Unicode: U+005e (^) , Width: 5 */ 0x00, 0x00, //..... 0x1d, 0x00, //.+@+. 0x51, 0x40, //++.++ 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... /*Unicode: U+005f (_) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0x00, //.... 0x00, //.... 0x00, //.... 0x00, //.... 0x00, //.... 0xff, //@@@@ 0x00, //.... /*Unicode: U+0060 (`) , Width: 2 */ 0x00, //.. 0x50, //++ 0x00, //.. 0x00, //.. 0x00, //.. 0x00, //.. 0x00, //.. 0x00, //.. 0x00, //.. 0x00, //.. /*Unicode: U+0061 (a) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0x3e, //.@@% 0x7f, //+@@@ 0xc3, //@..@ 0xbb, //%@%@ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0062 (b) , Width: 4 */ 0xc0, //@... 0xc0, //@... 0xc0, //@... 0xed, //@%@+ 0xc3, //@..@ 0xc3, //@..@ 0xed, //@%@+ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0063 (c) , Width: 3 */ 0x00, //... 0x00, //... 0x00, //... 0x7c, //+@@ 0xc0, //@.. 0xc0, //@.. 0x7c, //+@@ 0x00, //... 0x00, //... 0x00, //... /*Unicode: U+0064 (d) , Width: 4 */ 0x03, //...@ 0x03, //...@ 0x03, //...@ 0x7b, //+@%@ 0xc3, //@..@ 0xc3, //@..@ 0x7b, //+@%@ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0065 (e) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0x7e, //+@@% 0xff, //@@@@ 0xd0, //@+.. 0x7f, //+@@@ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0066 (f) , Width: 3 */ 0x1c, //.+@ 0x30, //.@. 0x30, //.@. 0xfc, //@@@ 0x30, //.@. 0x30, //.@. 0x30, //.@. 0x00, //... 0x00, //... 0x00, //... /*Unicode: U+0067 (g) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0x7b, //+@%@ 0xc3, //@..@ 0xc3, //@..@ 0x7b, //+@%@ 0x07, //..+@ 0x3d, //.@@+ 0x00, //.... /*Unicode: U+0068 (h) , Width: 4 */ 0xc0, //@... 0xc0, //@... 0xc0, //@... 0xee, //@%@% 0xc3, //@..@ 0xc3, //@..@ 0xc3, //@..@ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0069 (i) , Width: 1 */ 0x00, //. 0xc0, //@ 0x00, //. 0xc0, //@ 0xc0, //@ 0xc0, //@ 0xc0, //@ 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+006a (j) , Width: 2 */ 0x00, //.. 0x30, //.@ 0x00, //.. 0x30, //.@ 0x30, //.@ 0x30, //.@ 0x30, //.@ 0x30, //.@ 0xe0, //@% 0x00, //.. /*Unicode: U+006b (k) , Width: 4 */ 0xc0, //@... 0xc0, //@... 0xc0, //@... 0xcd, //@.@+ 0xf4, //@@.. 0xf4, //@@+. 0xcd, //@.@+ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+006c (l) , Width: 1 */ 0xc0, //@ 0xc0, //@ 0xc0, //@ 0xc0, //@ 0xc0, //@ 0xc0, //@ 0xc0, //@ 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+006d (m) , Width: 7 */ 0x00, 0x00, //....... 0x00, 0x00, //....... 0x00, 0x00, //....... 0xed, 0xb8, //@%@+%@+ 0xc3, 0x0c, //@..@..@ 0xc3, 0x0c, //@..@..@ 0xc3, 0x0c, //@..@..@ 0x00, 0x00, //....... 0x00, 0x00, //....... 0x00, 0x00, //....... /*Unicode: U+006e (n) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0xee, //@%@% 0xc3, //@..@ 0xc3, //@..@ 0xc3, //@..@ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+006f (o) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0x7d, //+@@+ 0xc3, //@..@ 0xc3, //@..@ 0x7d, //+@@+ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0070 (p) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0xed, //@%@+ 0xc3, //@..@ 0xc3, //@..@ 0xed, //@%@+ 0xc0, //@... 0xc0, //@... 0x00, //.... /*Unicode: U+0071 (q) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0x7b, //+@%@ 0xc3, //@..@ 0xc3, //@..@ 0x7b, //+@%@ 0x03, //...@ 0x03, //...@ 0x00, //.... /*Unicode: U+0072 (r) , Width: 3 */ 0x00, //... 0x00, //... 0x00, //... 0xec, //@%@ 0xd0, //@+. 0xc0, //@.. 0xc0, //@.. 0x00, //... 0x00, //... 0x00, //... /*Unicode: U+0073 (s) , Width: 3 */ 0x00, //... 0x00, //... 0x00, //... 0xbc, //%@@ 0xf4, //@@+ 0x1c, //.+@ 0xf8, //@@% 0x00, //... 0x00, //... 0x00, //... /*Unicode: U+0074 (t) , Width: 3 */ 0x00, //... 0x00, //... 0x30, //.@. 0xfc, //@@@ 0x30, //.@. 0x30, //.@. 0x2c, //.%@ 0x00, //... 0x00, //... 0x00, //... /*Unicode: U+0075 (u) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0xc3, //@..@ 0xc3, //@..@ 0xc3, //@..@ 0xbb, //%@%@ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0076 (v) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0xd7, //@++@ 0x69, //+%%+ 0x3c, //.@@. 0x28, //.%%. 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0077 (w) , Width: 6 */ 0x00, 0x00, //...... 0x00, 0x00, //...... 0x00, 0x00, //...... 0xcf, 0x30, //@.@@.@ 0xbf, 0xe0, //%%@@%% 0x75, 0xd0, //+@++@+ 0x30, 0xc0, //.@..@. 0x00, 0x00, //...... 0x00, 0x00, //...... 0x00, 0x00, //...... /*Unicode: U+0078 (x) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0xaa, //%%%% 0x3c, //.@@. 0x3c, //.@@. 0xaa, //%%%% 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+0079 (y) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0xc7, //@.+@ 0x6d, //+%@+ 0x3c, //.@@. 0x34, //.@+. 0x30, //.@.. 0xd0, //@+.. 0x00, //.... /*Unicode: U+007a (z) , Width: 4 */ 0x00, //.... 0x00, //.... 0x00, //.... 0xff, //@@@@ 0x0d, //..@+ 0x38, //.@%. 0xff, //@@@@ 0x00, //.... 0x00, //.... 0x00, //.... /*Unicode: U+007b ({) , Width: 3 */ 0x00, //... 0x2c, //.%@ 0x30, //.@. 0x30, //.@. 0xe0, //@%. 0x30, //.@. 0x30, //.@. 0x2c, //.%@ 0x00, //... 0x00, //... /*Unicode: U+007c (|) , Width: 1 */ 0x00, //. 0xc0, //@ 0xc0, //@ 0xc0, //@ 0xc0, //@ 0xc0, //@ 0xc0, //@ 0xc0, //@ 0xc0, //@ 0x00, //. /*Unicode: U+007d (}) , Width: 3 */ 0x00, //... 0xe0, //@%. 0x30, //.@. 0x30, //.@. 0x2c, //.%@ 0x30, //.@. 0x30, //.@. 0xe0, //@%. 0x00, //... 0x00, //... /*Unicode: U+007e (~) , Width: 5 */ 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... 0xb8, 0x80, //+@%.% 0x4b, 0x80, //+.%@+ 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... 0x00, 0x00, //..... #elif USE_LV_FONT_DEJAVU_10 == 4 /*Unicode: U+0020 ( ) , Width: 3 */ 0x00, 0x00, //... 0x00, 0x00, //... 0x00, 0x00, //... 0x00, 0x00, //... 0x00, 0x00, //... 0x00, 0x00, //... 0x00, 0x00, //... 0x00, 0x00, //... 0x00, 0x00, //... 0x00, 0x00, //... /*Unicode: U+0021 (!) , Width: 1 */ 0x00, //. 0xf0, //@ 0xf0, //@ 0xf0, //@ 0xd0, //@ 0x00, //. 0xf0, //@ 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+0022 (") , Width: 3 */ 0x00, 0x00, //... 0xf0, 0xf0, //@.@ 0xf0, 0xf0, //@.@ 0x00, 0x00, //... 0x00, 0x00, //... 0x00, 0x00, //... 0x00, 0x00, //... 0x00, 0x00, //... 0x00, 0x00, //... 0x00, 0x00, //... /*Unicode: U+0023 (#) , Width: 5 */ 0x00, 0x86, 0x20, //..%+. 0x03, 0x58, 0x00, //..+%. 0x9f, 0xff, 0xf0, //%@@@@ 0x08, 0x08, 0x00, //.%.%. 0xff, 0xff, 0x90, //@@@@% 0x08, 0x53, 0x00, //.%+.. 0x26, 0x80, 0x00, //.+%.. 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... /*Unicode: U+0024 ($) , Width: 5 */ 0x00, 0x00, 0x00, //..... 0x00, 0xf0, 0x00, //..@.. 0x7e, 0xff, 0xf0, //+@@@@ 0xe7, 0xf0, 0x00, //@+@.. 0x4b, 0xfe, 0x70, //+%@@+ 0x00, 0xf3, 0xf0, //..@.@ 0xff, 0xfe, 0x70, //@@@@+ 0x00, 0xf0, 0x00, //..@.. 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... /*Unicode: U+0025 (%) , Width: 7 */ 0x00, 0x00, 0x00, 0x00, //....... 0x9f, 0x90, 0xc5, 0x00, //%@%.@+. 0xf4, 0xf4, 0xd0, 0x00, //@+@+@.. 0x9f, 0x9c, 0x50, 0x00, //%@%@+.. 0x00, 0x4d, 0x9f, 0x90, //..+@%@% 0x00, 0xc5, 0xf4, 0xf0, //..@+@+@ 0x05, 0xd0, 0x9f, 0x90, //.+@.%@% 0x00, 0x00, 0x00, 0x00, //....... 0x00, 0x00, 0x00, 0x00, //....... 0x00, 0x00, 0x00, 0x00, //....... /*Unicode: U+0026 (&) , Width: 5 */ 0x00, 0x00, 0x00, //..... 0x08, 0xff, 0x00, //.%@@. 0x0f, 0x20, 0x00, //.@... 0x0d, 0x80, 0x00, //.@%.. 0xb9, 0xfa, 0xc0, //%%@%@ 0xe5, 0xdf, 0x30, //@+@@. 0x5e, 0xc9, 0xa0, //+@%%% 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... /*Unicode: U+0027 (') , Width: 1 */ 0x00, //. 0xf0, //@ 0xf0, //@ 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+0028 (() , Width: 2 */ 0x0a, //.% 0x85, //%+ 0xd1, //@. 0xf0, //@. 0xd1, //@. 0x85, //%+ 0x0a, //.% 0x00, //.. 0x00, //.. 0x00, //.. /*Unicode: U+0029 ()) , Width: 2 */ 0xa0, //%. 0x58, //+% 0x1d, //.@ 0x0f, //.@ 0x1d, //.@ 0x58, //+% 0xa0, //%. 0x00, //.. 0x00, //.. 0x00, //.. /*Unicode: U+002a (*) , Width: 5 */ 0x00, 0x00, 0x00, //..... 0x91, 0xf1, 0x90, //%.@.% 0x1a, 0xfa, 0x10, //.%@%. 0x1a, 0xfa, 0x10, //.%@%. 0x91, 0xf1, 0x90, //%.@.% 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... /*Unicode: U+002b (+) , Width: 5 */ 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0xf0, 0x00, //..@.. 0x00, 0xf0, 0x00, //..@.. 0xff, 0xff, 0xf0, //@@@@@ 0x00, 0xf0, 0x00, //..@.. 0x00, 0xf0, 0x00, //..@.. 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... /*Unicode: U+002c (,) , Width: 1 */ 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0xf0, //@ 0xf0, //@ 0x00, //. 0x00, //. /*Unicode: U+002d (-) , Width: 2 */ 0x00, //.. 0x00, //.. 0x00, //.. 0x00, //.. 0xff, //@@ 0x00, //.. 0x00, //.. 0x00, //.. 0x00, //.. 0x00, //.. /*Unicode: U+002e (.) , Width: 1 */ 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0xf0, //@ 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+002f (/) , Width: 3 */ 0x00, 0x00, //... 0x02, 0xd0, //..@ 0x07, 0x90, //.+% 0x0b, 0x40, //.%+ 0x0f, 0x00, //.@. 0x4b, 0x00, //+%. 0x97, 0x00, //%+. 0xd2, 0x00, //@.. 0x00, 0x00, //... 0x00, 0x00, //... /*Unicode: U+0030 (0) , Width: 4 */ 0x00, 0x00, //.... 0x3e, 0xe3, //.@@. 0xc5, 0x5c, //@++@ 0xf0, 0x0f, //@..@ 0xf0, 0x0f, //@..@ 0xc5, 0x5c, //@++@ 0x3e, 0xe3, //.@@. 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+0031 (1) , Width: 3 */ 0x00, 0x00, //... 0xff, 0x00, //@@. 0x0f, 0x00, //.@. 0x0f, 0x00, //.@. 0x0f, 0x00, //.@. 0x0f, 0x00, //.@. 0xff, 0xf0, //@@@ 0x00, 0x00, //... 0x00, 0x00, //... 0x00, 0x00, //... /*Unicode: U+0032 (2) , Width: 5 */ 0x00, 0x00, 0x00, //..... 0xff, 0xe6, 0x00, //@@@+. 0x00, 0x3f, 0x00, //...@. 0x00, 0x4b, 0x00, //..+%. 0x04, 0xd1, 0x00, //.+@.. 0x6e, 0x20, 0x00, //+@... 0xff, 0xff, 0x00, //@@@@. 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... /*Unicode: U+0033 (3) , Width: 4 */ 0x00, 0x00, //.... 0xff, 0xe5, //@@@+ 0x00, 0x3e, //...@ 0x00, 0x3d, //...@ 0x0f, 0xf5, //.@@+ 0x00, 0x4e, //..+@ 0xff, 0xe7, //@@@+ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+0034 (4) , Width: 4 */ 0x00, 0x00, //.... 0x02, 0xf0, //..@. 0x0a, 0xf0, //.%@. 0x2e, 0xf0, //.@@. 0xa7, 0xf0, //%+@. 0xff, 0xff, //@@@@ 0x00, 0xf0, //..@. 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+0035 (5) , Width: 4 */ 0x00, 0x00, //.... 0xff, 0xff, //@@@@ 0xf0, 0x00, //@... 0xff, 0xd4, //@@@+ 0x00, 0x4e, //..+@ 0x00, 0x4e, //..+@ 0xff, 0xd4, //@@@+ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+0036 (6) , Width: 4 */ 0x00, 0x00, //.... 0x1b, 0xff, //.%@@ 0xab, 0x10, //%%.. 0xe3, 0x00, //@... 0xfa, 0xf8, //@%@% 0xc3, 0x3f, //@..@ 0x3d, 0xe7, //.@@+ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+0037 (7) , Width: 4 */ 0x00, 0x00, //.... 0xff, 0xfe, //@@@@ 0x00, 0x79, //..+% 0x00, 0xc4, //..@+ 0x02, 0xe0, //..@. 0x07, 0x90, //.+%. 0x0d, 0x30, //.@.. 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+0038 (8) , Width: 4 */ 0x00, 0x00, //.... 0x6e, 0xe6, //+@@+ 0xe3, 0x3e, //@..@ 0xd3, 0x3d, //@..@ 0x5f, 0xf5, //+@@+ 0xe3, 0x3e, //@..@ 0x8f, 0xf8, //%@@% 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+0039 (9) , Width: 4 */ 0x00, 0x00, //.... 0x7e, 0xd3, //+@@. 0xf3, 0x3c, //@..@ 0x8f, 0xaf, //%@%@ 0x00, 0x3e, //...@ 0x01, 0xba, //..%% 0xff, 0xb1, //@@%. 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+003a (:) , Width: 1 */ 0x00, //. 0x00, //. 0x00, //. 0xf0, //@ 0x00, //. 0x00, //. 0xf0, //@ 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+003b (;) , Width: 1 */ 0x00, //. 0x00, //. 0x00, //. 0xf0, //@ 0x00, //. 0x00, //. 0xf0, //@ 0xf0, //@ 0x00, //. 0x00, //. /*Unicode: U+003c (<) , Width: 5 */ 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x27, 0xd0, //...+@ 0x7c, 0xe9, 0x30, //+@@%. 0x7c, 0xe8, 0x30, //+@@%. 0x00, 0x27, 0xd0, //...+@ 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... /*Unicode: U+003d (=) , Width: 5 */ 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0xff, 0xff, 0xf0, //@@@@@ 0x00, 0x00, 0x00, //..... 0xff, 0xff, 0xf0, //@@@@@ 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... /*Unicode: U+003e (>) , Width: 5 */ 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0xd7, 0x20, 0x00, //@+... 0x39, 0xec, 0x70, //.%@@+ 0x38, 0xec, 0x70, //.%@@+ 0xd7, 0x20, 0x00, //@+... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... /*Unicode: U+003f (?) , Width: 3 */ 0x00, 0x00, //... 0xff, 0x90, //@@% 0x01, 0xd0, //..@ 0x08, 0x20, //.%. 0x0f, 0x00, //.@. 0x00, 0x00, //... 0x0f, 0x00, //.@. 0x00, 0x00, //... 0x00, 0x00, //... 0x00, 0x00, //... /*Unicode: U+0040 (@) , Width: 7 */ 0x00, 0x00, 0x00, 0x00, //....... 0x04, 0xcf, 0xd7, 0x00, //.+@@@+. 0x4e, 0x40, 0x2b, 0x80, //+@+..%% 0xd3, 0xab, 0xf1, 0xe0, //@.%%@.@ 0xf0, 0xf4, 0xf4, 0xd0, //@.@+@+@ 0xd4, 0xab, 0xeb, 0x20, //@.%%@%. 0x5e, 0x40, 0x53, 0x00, //+@+.+.. 0x05, 0xdf, 0x60, 0x00, //.+@@+.. 0x00, 0x00, 0x00, 0x00, //....... 0x00, 0x00, 0x00, 0x00, //....... /*Unicode: U+0041 (A) , Width: 5 */ 0x00, 0x00, 0x00, //..... 0x01, 0xf1, 0x00, //..@.. 0x07, 0xf6, 0x00, //.+@+. 0x0c, 0x8c, 0x00, //.@%@. 0x2e, 0x0e, 0x20, //.@.@. 0x7f, 0xff, 0x70, //+@@@+ 0xd3, 0x03, 0xd0, //@...@ 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... /*Unicode: U+0042 (B) , Width: 4 */ 0x00, 0x00, //.... 0xff, 0xe6, //@@@+ 0xf0, 0x2e, //@..@ 0xf0, 0x2d, //@..@ 0xff, 0xf6, //@@@+ 0xf0, 0x3e, //@..@ 0xff, 0xf8, //@@@% 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+0043 (C) , Width: 5 */ 0x00, 0x00, 0x00, //..... 0x09, 0xee, 0x60, //.%@@+ 0x9a, 0x10, 0x80, //%%..% 0xe1, 0x00, 0x00, //@.... 0xe1, 0x00, 0x00, //@.... 0x9a, 0x10, 0x80, //%%..% 0x09, 0xee, 0x60, //.%@@+ 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... /*Unicode: U+0044 (D) , Width: 5 */ 0x00, 0x00, 0x00, //..... 0xff, 0xea, 0x10, //@@@%. 0xf0, 0x19, 0xa0, //@..%% 0xf0, 0x01, 0xe0, //@...@ 0xf0, 0x01, 0xe0, //@...@ 0xf0, 0x19, 0xa0, //@..%% 0xff, 0xea, 0x10, //@@@%. 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... /*Unicode: U+0045 (E) , Width: 4 */ 0x00, 0x00, //.... 0xff, 0xff, //@@@@ 0xf0, 0x00, //@... 0xf0, 0x00, //@... 0xff, 0xff, //@@@@ 0xf0, 0x00, //@... 0xff, 0xff, //@@@@ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+0046 (F) , Width: 3 */ 0x00, 0x00, //... 0xff, 0xf0, //@@@ 0xf0, 0x00, //@.. 0xf0, 0x00, //@.. 0xff, 0xf0, //@@@ 0xf0, 0x00, //@.. 0xf0, 0x00, //@.. 0x00, 0x00, //... 0x00, 0x00, //... 0x00, 0x00, //... /*Unicode: U+0047 (G) , Width: 5 */ 0x00, 0x00, 0x00, //..... 0x1a, 0xee, 0x60, //.%@@+ 0xa9, 0x11, 0x80, //%%..% 0xe1, 0x0f, 0xf0, //@..@@ 0xe1, 0x00, 0xf0, //@...@ 0xa8, 0x01, 0xf0, //%%..@ 0x1a, 0xee, 0x50, //.%@@+ 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... /*Unicode: U+0048 (H) , Width: 4 */ 0x00, 0x00, //.... 0xf0, 0x0f, //@..@ 0xf0, 0x0f, //@..@ 0xf0, 0x0f, //@..@ 0xff, 0xff, //@@@@ 0xf0, 0x0f, //@..@ 0xf0, 0x0f, //@..@ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+0049 (I) , Width: 1 */ 0x00, //. 0xf0, //@ 0xf0, //@ 0xf0, //@ 0xf0, //@ 0xf0, //@ 0xf0, //@ 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+004a (J) , Width: 2 */ 0x00, //.. 0x0f, //.@ 0x0f, //.@ 0x0f, //.@ 0x0f, //.@ 0x0f, //.@ 0x0f, //.@ 0x2e, //.@ 0xf6, //@+ 0x00, //.. /*Unicode: U+004b (K) , Width: 5 */ 0x00, 0x00, 0x00, //..... 0xf0, 0x3e, 0x60, //@..@+ 0xf4, 0xe5, 0x00, //@+@+. 0xff, 0x30, 0x00, //@@... 0xfc, 0x80, 0x00, //@@+.. 0xf1, 0xd8, 0x00, //@.@+. 0xf0, 0x1d, 0x70, //@..@+ 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... /*Unicode: U+004c (L) , Width: 4 */ 0x00, 0x00, //.... 0xf0, 0x00, //@... 0xf0, 0x00, //@... 0xf0, 0x00, //@... 0xf0, 0x00, //@... 0xf0, 0x00, //@... 0xff, 0xff, //@@@@ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+004d (M) , Width: 5 */ 0x00, 0x00, 0x00, //..... 0xfe, 0x0e, 0xf0, //@@.@@ 0xfc, 0x7c, 0xf0, //@@+@@ 0xf8, 0xf8, 0xf0, //@%@+@ 0xf3, 0xf3, 0xf0, //@.@.@ 0xf0, 0xd0, 0xf0, //@.@.@ 0xf0, 0x00, 0xf0, //@...@ 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... /*Unicode: U+004e (N) , Width: 4 */ 0x00, 0x00, //.... 0xf7, 0x0f, //@+.@ 0xfe, 0x0f, //@@.@ 0xfb, 0x7f, //@%+@ 0xf4, 0xef, //@+@@ 0xf0, 0xdf, //@.@@ 0xf0, 0x6f, //@.+@ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+004f (O) , Width: 5 */ 0x00, 0x00, 0x00, //..... 0x1b, 0xfb, 0x10, //.%@%. 0xa8, 0x08, 0xa0, //%%.%% 0xe1, 0x01, 0xe0, //@...@ 0xe0, 0x01, 0xe0, //@...@ 0xa8, 0x08, 0xa0, //%%.%% 0x1b, 0xfb, 0x10, //.%@%. 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... /*Unicode: U+0050 (P) , Width: 4 */ 0x00, 0x00, //.... 0xff, 0xe7, //@@@+ 0xf0, 0x3f, //@..@ 0xff, 0xe7, //@@@+ 0xf0, 0x00, //@... 0xf0, 0x00, //@... 0xf0, 0x00, //@... 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+0051 (Q) , Width: 5 */ 0x00, 0x00, 0x00, //..... 0x1b, 0xfb, 0x10, //.%@%. 0xa8, 0x08, 0xa0, //%%.%% 0xe1, 0x01, 0xe0, //@...@ 0xe0, 0x01, 0xe0, //@...@ 0xa8, 0x08, 0x90, //%%.%% 0x1b, 0xfb, 0x00, //.%@%. 0x00, 0x3e, 0x10, //...@. 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... /*Unicode: U+0052 (R) , Width: 5 */ 0x00, 0x00, 0x00, //..... 0xff, 0xe8, 0x00, //@@@%. 0xf0, 0x3f, 0x00, //@..@. 0xff, 0xf5, 0x00, //@@@+. 0xf0, 0x8a, 0x00, //@.%%. 0xf0, 0x0e, 0x30, //@..@. 0xf0, 0x06, 0xb0, //@..+% 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... /*Unicode: U+0053 (S) , Width: 4 */ 0x00, 0x00, //.... 0x6e, 0xff, //+@@@ 0xf3, 0x00, //@... 0xbc, 0x81, //%@%. 0x03, 0x9d, //..%@ 0x00, 0x3f, //...@ 0xff, 0xe6, //@@@+ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+0054 (T) , Width: 5 */ 0x00, 0x00, 0x00, //..... 0xff, 0xff, 0xf0, //@@@@@ 0x00, 0xf0, 0x00, //..@.. 0x00, 0xf0, 0x00, //..@.. 0x00, 0xf0, 0x00, //..@.. 0x00, 0xf0, 0x00, //..@.. 0x00, 0xf0, 0x00, //..@.. 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... /*Unicode: U+0055 (U) , Width: 4 */ 0x00, 0x00, //.... 0xf0, 0x0f, //@..@ 0xf0, 0x0f, //@..@ 0xf0, 0x0f, //@..@ 0xf0, 0x0f, //@..@ 0xd4, 0x4d, //@++@ 0x4e, 0xe4, //+@@+ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+0056 (V) , Width: 5 */ 0x00, 0x00, 0x00, //..... 0xd3, 0x03, 0xd0, //@...@ 0x79, 0x09, 0x70, //+%.%+ 0x2e, 0x0e, 0x20, //.@.@. 0x0c, 0x8c, 0x00, //.@%@. 0x07, 0xf6, 0x00, //.+@+. 0x01, 0xf1, 0x00, //..@.. 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... /*Unicode: U+0057 (W) , Width: 7 */ 0x00, 0x00, 0x00, 0x00, //....... 0xe2, 0x7f, 0x72, 0xe0, //@.+@+.@ 0xa5, 0xaa, 0xa5, 0xa0, //%+%%%+% 0x69, 0xe3, 0xe9, 0x60, //+%@.@%+ 0x2e, 0xe0, 0xee, 0x20, //.@@.@@. 0x0f, 0xa0, 0xaf, 0x00, //.@%.%@. 0x0b, 0x60, 0x7b, 0x00, //.%+.+%. 0x00, 0x00, 0x00, 0x00, //....... 0x00, 0x00, 0x00, 0x00, //....... 0x00, 0x00, 0x00, 0x00, //....... /*Unicode: U+0058 (X) , Width: 5 */ 0x00, 0x00, 0x00, //..... 0xa8, 0x08, 0xa0, //%%.%% 0x1e, 0x5e, 0x10, //.@+@. 0x06, 0xf6, 0x00, //.+@+. 0x06, 0xf6, 0x00, //.+@+. 0x1e, 0x4e, 0x10, //.@+@. 0xa7, 0x07, 0xa0, //%+.+% 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... /*Unicode: U+0059 (Y) , Width: 5 */ 0x00, 0x00, 0x00, //..... 0xa8, 0x08, 0xa0, //%+.+% 0x1e, 0x5e, 0x10, //.@+@. 0x06, 0xf6, 0x00, //.+@+. 0x00, 0xf0, 0x00, //..@.. 0x00, 0xf0, 0x00, //..@.. 0x00, 0xf0, 0x00, //..@.. 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... /*Unicode: U+005a (Z) , Width: 5 */ 0x00, 0x00, 0x00, //..... 0xff, 0xff, 0xe0, //@@@@@ 0x00, 0x2f, 0x40, //...@+ 0x00, 0xc7, 0x00, //..@+. 0x09, 0xb0, 0x00, //.%%.. 0x5d, 0x10, 0x00, //+@... 0xef, 0xff, 0xf0, //@@@@@ 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... /*Unicode: U+005b ([) , Width: 2 */ 0x00, //.. 0xff, //@@ 0xf0, //@. 0xf0, //@. 0xf0, //@. 0xf0, //@. 0xf0, //@. 0xff, //@@ 0x00, //.. 0x00, //.. /*Unicode: U+005c (\) , Width: 3 */ 0x00, 0x00, //... 0xd2, 0x00, //@.. 0x97, 0x00, //%+. 0x4b, 0x00, //+%. 0x0f, 0x00, //.@. 0x0b, 0x40, //.%+ 0x07, 0x90, //.+% 0x02, 0xd0, //..@ 0x00, 0x00, //... 0x00, 0x00, //... /*Unicode: U+005d (]) , Width: 2 */ 0x00, //.. 0xff, //@@ 0x0f, //.@ 0x0f, //.@ 0x0f, //.@ 0x0f, //.@ 0x0f, //.@ 0xff, //@@ 0x00, //.. 0x00, //.. /*Unicode: U+005e (^) , Width: 5 */ 0x00, 0x00, 0x00, //..... 0x06, 0xc6, 0x00, //.+@+. 0x76, 0x06, 0x70, //++.++ 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... /*Unicode: U+005f (_) , Width: 4 */ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... 0xff, 0xff, //@@@@ 0x00, 0x00, //.... /*Unicode: U+0060 (`) , Width: 2 */ 0x00, //.. 0x55, //++ 0x00, //.. 0x00, //.. 0x00, //.. 0x00, //.. 0x00, //.. 0x00, //.. 0x00, //.. 0x00, //.. /*Unicode: U+0061 (a) , Width: 4 */ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... 0x0f, 0xf9, //.@@% 0x7e, 0xff, //+@@@ 0xf3, 0x3f, //@..@ 0x9f, 0x9f, //%@%@ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+0062 (b) , Width: 4 */ 0xf0, 0x00, //@... 0xf0, 0x00, //@... 0xf0, 0x00, //@... 0xfa, 0xf6, //@%@+ 0xf3, 0x3e, //@..@ 0xf3, 0x3e, //@..@ 0xfa, 0xf6, //@%@+ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+0063 (c) , Width: 3 */ 0x00, 0x00, //... 0x00, 0x00, //... 0x00, 0x00, //... 0x6e, 0xf0, //+@@ 0xe3, 0x00, //@.. 0xe3, 0x00, //@.. 0x6e, 0xf0, //+@@ 0x00, 0x00, //... 0x00, 0x00, //... 0x00, 0x00, //... /*Unicode: U+0064 (d) , Width: 4 */ 0x00, 0x0f, //...@ 0x00, 0x0f, //...@ 0x00, 0x0f, //...@ 0x6f, 0x9f, //+@%@ 0xe3, 0x3f, //@..@ 0xe3, 0x3f, //@..@ 0x6f, 0x9f, //+@%@ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+0065 (e) , Width: 4 */ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... 0x5e, 0xf8, //+@@% 0xef, 0xff, //@@@@ 0xe4, 0x00, //@+.. 0x4d, 0xff, //+@@@ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+0066 (f) , Width: 3 */ 0x07, 0xf0, //.+@ 0x0e, 0x10, //.@. 0x0f, 0x00, //.@. 0xff, 0xf0, //@@@ 0x0f, 0x00, //.@. 0x0f, 0x00, //.@. 0x0f, 0x00, //.@. 0x00, 0x00, //... 0x00, 0x00, //... 0x00, 0x00, //... /*Unicode: U+0067 (g) , Width: 4 */ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... 0x6f, 0xaf, //+@%@ 0xe3, 0x3f, //@..@ 0xe3, 0x3f, //@..@ 0x6f, 0xaf, //+@%@ 0x00, 0x4d, //..+@ 0x0f, 0xe5, //.@@+ 0x00, 0x00, //.... /*Unicode: U+0068 (h) , Width: 4 */ 0xf0, 0x00, //@... 0xf0, 0x00, //@... 0xf0, 0x00, //@... 0xf9, 0xf8, //@%@% 0xf3, 0x3f, //@..@ 0xf0, 0x0f, //@..@ 0xf0, 0x0f, //@..@ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+0069 (i) , Width: 1 */ 0x00, //. 0xf0, //@ 0x00, //. 0xf0, //@ 0xf0, //@ 0xf0, //@ 0xf0, //@ 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+006a (j) , Width: 2 */ 0x00, //.. 0x0f, //.@ 0x00, //.. 0x0f, //.@ 0x0f, //.@ 0x0f, //.@ 0x0f, //.@ 0x1f, //.@ 0xf8, //@% 0x00, //.. /*Unicode: U+006b (k) , Width: 4 */ 0xf0, 0x00, //@... 0xf0, 0x00, //@... 0xf0, 0x00, //@... 0xf3, 0xe6, //@.@+ 0xfe, 0x40, //@@.. 0xfe, 0x60, //@@+. 0xf2, 0xd7, //@.@+ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+006c (l) , Width: 1 */ 0xf0, //@ 0xf0, //@ 0xf0, //@ 0xf0, //@ 0xf0, //@ 0xf0, //@ 0xf0, //@ 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+006d (m) , Width: 7 */ 0x00, 0x00, 0x00, 0x00, //....... 0x00, 0x00, 0x00, 0x00, //....... 0x00, 0x00, 0x00, 0x00, //....... 0xf9, 0xf7, 0xaf, 0x80, //@%@+%@+ 0xf3, 0x2f, 0x32, 0xf0, //@..@..@ 0xf0, 0x0f, 0x00, 0xf0, //@..@..@ 0xf0, 0x0f, 0x00, 0xf0, //@..@..@ 0x00, 0x00, 0x00, 0x00, //....... 0x00, 0x00, 0x00, 0x00, //....... 0x00, 0x00, 0x00, 0x00, //....... /*Unicode: U+006e (n) , Width: 4 */ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... 0xf9, 0xf8, //@%@% 0xf3, 0x3f, //@..@ 0xf0, 0x0f, //@..@ 0xf0, 0x0f, //@..@ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+006f (o) , Width: 4 */ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... 0x5e, 0xe5, //+@@+ 0xe3, 0x3e, //@..@ 0xe3, 0x3e, //@..@ 0x5e, 0xe5, //+@@+ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+0070 (p) , Width: 4 */ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... 0xfa, 0xf6, //@%@+ 0xf3, 0x3e, //@..@ 0xf3, 0x3e, //@..@ 0xfa, 0xf6, //@%@+ 0xf0, 0x00, //@... 0xf0, 0x00, //@... 0x00, 0x00, //.... /*Unicode: U+0071 (q) , Width: 4 */ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... 0x6f, 0x9f, //+@%@ 0xe3, 0x3f, //@..@ 0xe3, 0x3f, //@..@ 0x6f, 0x9f, //+@%@ 0x00, 0x0f, //...@ 0x00, 0x0f, //...@ 0x00, 0x00, //.... /*Unicode: U+0072 (r) , Width: 3 */ 0x00, 0x00, //... 0x00, 0x00, //... 0x00, 0x00, //... 0xf9, 0xf0, //@%@ 0xf4, 0x00, //@+. 0xf0, 0x00, //@.. 0xf0, 0x00, //@.. 0x00, 0x00, //... 0x00, 0x00, //... 0x00, 0x00, //... /*Unicode: U+0073 (s) , Width: 3 */ 0x00, 0x00, //... 0x00, 0x00, //... 0x00, 0x00, //... 0xaf, 0xf0, //%@@ 0xdc, 0x50, //@@+ 0x05, 0xf0, //.+@ 0xff, 0xa0, //@@% 0x00, 0x00, //... 0x00, 0x00, //... 0x00, 0x00, //... /*Unicode: U+0074 (t) , Width: 3 */ 0x00, 0x00, //... 0x00, 0x00, //... 0x0f, 0x00, //.@. 0xff, 0xf0, //@@@ 0x0f, 0x00, //.@. 0x0f, 0x00, //.@. 0x0a, 0xf0, //.%@ 0x00, 0x00, //... 0x00, 0x00, //... 0x00, 0x00, //... /*Unicode: U+0075 (u) , Width: 4 */ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... 0xf0, 0x0f, //@..@ 0xf0, 0x0f, //@..@ 0xf3, 0x3f, //@..@ 0x8f, 0x9f, //%@%@ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+0076 (v) , Width: 4 */ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... 0xc4, 0x4c, //@++@ 0x6a, 0xa6, //+%%+ 0x0e, 0xe0, //.@@. 0x0a, 0xa0, //.%%. 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+0077 (w) , Width: 6 */ 0x00, 0x00, 0x00, //...... 0x00, 0x00, 0x00, //...... 0x00, 0x00, 0x00, //...... 0xd3, 0xee, 0x3d, //@.@@.@ 0x8c, 0xcc, 0xc8, //%%@@%% 0x4f, 0x77, 0xf4, //+@++@+ 0x0f, 0x22, 0xf0, //.@..@. 0x00, 0x00, 0x00, //...... 0x00, 0x00, 0x00, //...... 0x00, 0x00, 0x00, //...... /*Unicode: U+0078 (x) , Width: 4 */ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... 0x9a, 0xa9, //%%%% 0x0c, 0xc0, //.@@. 0x0d, 0xc0, //.@@. 0xa9, 0xa9, //%%%% 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+0079 (y) , Width: 4 */ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... 0xd3, 0x5c, //@.+@ 0x79, 0xc5, //+%@+ 0x1f, 0xd0, //.@@. 0x0d, 0x60, //.@+. 0x0e, 0x00, //.@.. 0xf7, 0x00, //@+.. 0x00, 0x00, //.... /*Unicode: U+007a (z) , Width: 4 */ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... 0xff, 0xfe, //@@@@ 0x02, 0xe4, //..@+ 0x2e, 0x80, //.@%. 0xef, 0xff, //@@@@ 0x00, 0x00, //.... 0x00, 0x00, //.... 0x00, 0x00, //.... /*Unicode: U+007b ({) , Width: 3 */ 0x00, 0x00, //... 0x0a, 0xf0, //.%@ 0x0f, 0x00, //.@. 0x1f, 0x00, //.@. 0xf8, 0x00, //@%. 0x1f, 0x00, //.@. 0x0f, 0x00, //.@. 0x0a, 0xf0, //.%@ 0x00, 0x00, //... 0x00, 0x00, //... /*Unicode: U+007c (|) , Width: 1 */ 0x00, //. 0xf0, //@ 0xf0, //@ 0xf0, //@ 0xf0, //@ 0xf0, //@ 0xf0, //@ 0xf0, //@ 0xf0, //@ 0x00, //. /*Unicode: U+007d (}) , Width: 3 */ 0x00, 0x00, //... 0xfa, 0x00, //@%. 0x1f, 0x00, //.@. 0x0f, 0x10, //.@. 0x08, 0xf0, //.%@ 0x0f, 0x10, //.@. 0x0f, 0x00, //.@. 0xfa, 0x00, //@%. 0x00, 0x00, //... 0x00, 0x00, //... /*Unicode: U+007e (~) , Width: 5 */ 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x8e, 0x81, 0x80, //+@%.% 0x41, 0x8e, 0x80, //+.%@+ 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, //..... #elif USE_LV_FONT_DEJAVU_10 == 8 /*Unicode: U+0020 ( ) , Width: 3 */ 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... /*Unicode: U+0021 (!) , Width: 1 */ 0x00, //. 0xff, //@ 0xff, //@ 0xfa, //@ 0xdc, //@ 0x00, //. 0xff, //@ 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+0022 (") , Width: 3 */ 0x00, 0x00, 0x00, //... 0xff, 0x00, 0xff, //@.@ 0xff, 0x00, 0xff, //@.@ 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... /*Unicode: U+0023 (#) , Width: 5 */ 0x00, 0x08, 0x88, 0x66, 0x28, //..%+. 0x00, 0x36, 0x5a, 0x8e, 0x02, //..+%. 0x96, 0xff, 0xff, 0xff, 0xff, //%@@@@ 0x00, 0x8a, 0x0c, 0x8c, 0x00, //.%.%. 0xff, 0xff, 0xff, 0xff, 0x96, //@@@@% 0x00, 0x8c, 0x5a, 0x36, 0x00, //.%+.. 0x26, 0x6a, 0x84, 0x08, 0x00, //.+%.. 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... /*Unicode: U+0024 ($) , Width: 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0xff, 0x00, 0x00, //..@.. 0x78, 0xea, 0xff, 0xff, 0xff, //+@@@@ 0xee, 0x70, 0xff, 0x08, 0x00, //@+@.. 0x48, 0xb0, 0xff, 0xee, 0x7e, //+%@@+ 0x00, 0x00, 0xff, 0x30, 0xf2, //..@.@ 0xf8, 0xf0, 0xff, 0xe8, 0x78, //@@@@+ 0x00, 0x00, 0xff, 0x00, 0x00, //..@.. 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... /*Unicode: U+0025 (%) , Width: 7 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //....... 0x90, 0xf4, 0x90, 0x00, 0xc4, 0x56, 0x00, //%@%.@+. 0xf4, 0x42, 0xf4, 0x46, 0xd2, 0x00, 0x00, //@+@+@.. 0x92, 0xf4, 0x94, 0xc8, 0x54, 0x00, 0x00, //%@%@+.. 0x00, 0x00, 0x4c, 0xd2, 0x92, 0xf4, 0x90, //..+@%@% 0x00, 0x00, 0xce, 0x52, 0xf4, 0x42, 0xf4, //..@+@+@ 0x00, 0x52, 0xd0, 0x00, 0x90, 0xf4, 0x90, //.+@.%@% 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //....... 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //....... 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //....... /*Unicode: U+0026 (&) , Width: 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x86, 0xf6, 0xff, 0x00, //.%@@. 0x00, 0xf8, 0x2a, 0x00, 0x00, //.@... 0x06, 0xde, 0x86, 0x00, 0x00, //.@%.. 0xb8, 0x9a, 0xf2, 0xa6, 0xc8, //%%@%@ 0xea, 0x52, 0xde, 0xff, 0x32, //@+@@. 0x54, 0xe0, 0xc0, 0x9c, 0xa6, //+@%%% 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... /*Unicode: U+0027 (') , Width: 1 */ 0x00, //. 0xff, //@ 0xff, //@ 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+0028 (() , Width: 2 */ 0x0e, 0xa2, //.% 0x82, 0x56, //%+ 0xda, 0x18, //@. 0xf8, 0x02, //@. 0xda, 0x18, //@. 0x82, 0x56, //%+ 0x0e, 0xa2, //.% 0x00, 0x00, //.. 0x00, 0x00, //.. 0x00, 0x00, //.. /*Unicode: U+0029 ()) , Width: 2 */ 0xa2, 0x0e, //%. 0x56, 0x82, //+% 0x18, 0xda, //.@ 0x04, 0xf8, //.@ 0x18, 0xda, //.@ 0x56, 0x82, //+% 0xa2, 0x0e, //%. 0x00, 0x00, //.. 0x00, 0x00, //.. 0x00, 0x00, //.. /*Unicode: U+002a (*) , Width: 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x9e, 0x1a, 0xff, 0x1a, 0x9e, //%.@.% 0x1a, 0xa6, 0xff, 0xa6, 0x1a, //.%@%. 0x1a, 0xa6, 0xff, 0xa6, 0x1a, //.%@%. 0x9e, 0x1a, 0xff, 0x1a, 0x9e, //%.@.% 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... /*Unicode: U+002b (+) , Width: 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0xff, 0x00, 0x00, //..@.. 0x00, 0x00, 0xff, 0x00, 0x00, //..@.. 0xff, 0xff, 0xff, 0xff, 0xff, //@@@@@ 0x00, 0x00, 0xff, 0x00, 0x00, //..@.. 0x00, 0x00, 0xff, 0x00, 0x00, //..@.. 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... /*Unicode: U+002c (,) , Width: 1 */ 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0xff, //@ 0xff, //@ 0x00, //. 0x00, //. /*Unicode: U+002d (-) , Width: 2 */ 0x00, 0x00, //.. 0x00, 0x00, //.. 0x00, 0x00, //.. 0x00, 0x00, //.. 0xff, 0xff, //@@ 0x00, 0x00, //.. 0x00, 0x00, //.. 0x00, 0x00, //.. 0x00, 0x00, //.. 0x00, 0x00, //.. /*Unicode: U+002e (.) , Width: 1 */ 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0x00, //. 0xff, //@ 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+002f (/) , Width: 3 */ 0x00, 0x00, 0x00, //... 0x00, 0x2e, 0xda, //..@ 0x00, 0x76, 0x92, //.+% 0x00, 0xbe, 0x4c, //.%+ 0x0a, 0xf2, 0x0a, //.@. 0x4c, 0xbc, 0x00, //+%. 0x94, 0x74, 0x00, //%+. 0xda, 0x2e, 0x00, //@.. 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... /*Unicode: U+0030 (0) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0x3a, 0xe0, 0xe0, 0x3a, //.@@. 0xc4, 0x54, 0x54, 0xc4, //@++@ 0xf2, 0x08, 0x08, 0xf2, //@..@ 0xf2, 0x08, 0x08, 0xf2, //@..@ 0xc4, 0x54, 0x54, 0xc4, //@++@ 0x3a, 0xe0, 0xe0, 0x3a, //.@@. 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0031 (1) , Width: 3 */ 0x00, 0x00, 0x00, //... 0xff, 0xff, 0x00, //@@. 0x00, 0xff, 0x00, //.@. 0x00, 0xff, 0x00, //.@. 0x00, 0xff, 0x00, //.@. 0x00, 0xff, 0x00, //.@. 0xff, 0xff, 0xff, //@@@ 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... /*Unicode: U+0032 (2) , Width: 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0xff, 0xff, 0xe4, 0x66, 0x00, //@@@+. 0x00, 0x00, 0x3e, 0xf0, 0x00, //...@. 0x00, 0x00, 0x44, 0xba, 0x00, //..+%. 0x00, 0x48, 0xda, 0x1e, 0x00, //.+@.. 0x6c, 0xe0, 0x2a, 0x00, 0x00, //+@... 0xff, 0xff, 0xff, 0xff, 0x06, //@@@@. 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... /*Unicode: U+0033 (3) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0xff, 0xff, 0xe0, 0x52, //@@@+ 0x00, 0x00, 0x3e, 0xea, //...@ 0x00, 0x00, 0x3a, 0xd4, //...@ 0x00, 0xff, 0xf6, 0x54, //.@@+ 0x00, 0x00, 0x44, 0xec, //..+@ 0xff, 0xfc, 0xe6, 0x76, //@@@+ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0034 (4) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x24, 0xfa, 0x00, //..@. 0x00, 0xa4, 0xff, 0x00, //.%@. 0x2a, 0xe6, 0xff, 0x00, //.@@. 0xaa, 0x74, 0xff, 0x00, //%+@. 0xfc, 0xff, 0xff, 0xff, //@@@@ 0x00, 0x00, 0xff, 0x00, //..@. 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0035 (5) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0xff, 0xff, 0xff, 0xff, //@@@@ 0xff, 0x00, 0x00, 0x00, //@... 0xff, 0xf0, 0xdc, 0x4a, //@@@+ 0x00, 0x02, 0x4e, 0xe4, //..+@ 0x00, 0x02, 0x4a, 0xe4, //..+@ 0xff, 0xfc, 0xda, 0x4c, //@@@+ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0036 (6) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0x16, 0xb2, 0xf4, 0xff, //.%@@ 0xa6, 0xb6, 0x10, 0x00, //%%.. 0xec, 0x3a, 0x00, 0x00, //@... 0xf2, 0xa4, 0xf2, 0x82, //@%@% 0xc2, 0x3a, 0x3a, 0xf0, //@..@ 0x36, 0xdc, 0xee, 0x78, //.@@+ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0037 (7) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0xff, 0xff, 0xff, 0xea, //@@@@ 0x00, 0x00, 0x72, 0x98, //..+% 0x00, 0x00, 0xca, 0x42, //..@+ 0x00, 0x22, 0xe6, 0x02, //..@. 0x00, 0x7a, 0x94, 0x00, //.+%. 0x00, 0xd2, 0x3e, 0x00, //.@.. 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0038 (8) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0x60, 0xea, 0xea, 0x60, //+@@+ 0xee, 0x32, 0x32, 0xee, //@..@ 0xd4, 0x32, 0x32, 0xd2, //@..@ 0x52, 0xf8, 0xf8, 0x50, //+@@+ 0xee, 0x3a, 0x3a, 0xec, //@..@ 0x86, 0xf0, 0xf0, 0x86, //%@@% 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0039 (9) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0x74, 0xee, 0xdc, 0x36, //+@@. 0xf2, 0x3a, 0x3a, 0xc2, //@..@ 0x86, 0xf2, 0xa6, 0xf0, //%@%@ 0x00, 0x00, 0x3c, 0xec, //...@ 0x00, 0x10, 0xb8, 0xa6, //..%% 0xff, 0xf4, 0xb2, 0x16, //@@%. 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+003a (:) , Width: 1 */ 0x00, //. 0x00, //. 0x00, //. 0xff, //@ 0x00, //. 0x00, //. 0xff, //@ 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+003b (;) , Width: 1 */ 0x00, //. 0x00, //. 0x00, //. 0xff, //@ 0x00, //. 0x00, //. 0xff, //@ 0xff, //@ 0x00, //. 0x00, //. /*Unicode: U+003c (<) , Width: 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x24, 0x7a, 0xd2, //...+@ 0x76, 0xcc, 0xe4, 0x90, 0x36, //+@@%. 0x76, 0xce, 0xe4, 0x8e, 0x36, //+@@%. 0x00, 0x00, 0x24, 0x7c, 0xd2, //...+@ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... /*Unicode: U+003d (=) , Width: 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0xff, 0xff, 0xff, 0xff, 0xff, //@@@@@ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0xff, 0xff, 0xff, 0xff, 0xff, //@@@@@ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... /*Unicode: U+003e (>) , Width: 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0xd2, 0x7a, 0x24, 0x00, 0x00, //@+... 0x36, 0x90, 0xe6, 0xcc, 0x76, //.%@@+ 0x36, 0x8e, 0xe4, 0xce, 0x76, //.%@@+ 0xd2, 0x7c, 0x24, 0x00, 0x00, //@+... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... /*Unicode: U+003f (?) , Width: 3 */ 0x00, 0x00, 0x00, //... 0xff, 0xf8, 0x9c, //@@% 0x00, 0x1a, 0xdc, //..@ 0x00, 0x82, 0x22, //.%. 0x00, 0xf8, 0x00, //.@. 0x00, 0x00, 0x00, //... 0x00, 0xff, 0x00, //.@. 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... /*Unicode: U+0040 (@) , Width: 7 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //....... 0x00, 0x46, 0xcc, 0xf8, 0xde, 0x7a, 0x00, //.+@@@+. 0x4a, 0xe6, 0x42, 0x08, 0x2c, 0xbc, 0x86, //+@+..%% 0xd2, 0x3e, 0xa8, 0xb8, 0xff, 0x12, 0xec, //@.%%@.@ 0xf8, 0x08, 0xf6, 0x42, 0xff, 0x46, 0xd4, //@.@+@+@ 0xd8, 0x40, 0xaa, 0xb8, 0xee, 0xb8, 0x2a, //@.%%@%. 0x56, 0xe0, 0x42, 0x08, 0x58, 0x34, 0x00, //+@+.+.. 0x00, 0x5a, 0xdc, 0xf0, 0x6a, 0x00, 0x00, //.+@@+.. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //....... 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //....... /*Unicode: U+0041 (A) , Width: 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x18, 0xfa, 0x18, 0x00, //..@.. 0x00, 0x70, 0xfc, 0x6e, 0x00, //.+@+. 0x00, 0xc8, 0x8a, 0xc8, 0x00, //.@%@. 0x22, 0xe6, 0x06, 0xe6, 0x20, //.@.@. 0x7a, 0xff, 0xff, 0xff, 0x78, //+@@@+ 0xd2, 0x38, 0x00, 0x38, 0xd2, //@...@ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... /*Unicode: U+0042 (B) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0xff, 0xff, 0xec, 0x6a, //@@@+ 0xff, 0x00, 0x2e, 0xee, //@..@ 0xff, 0x00, 0x2e, 0xdc, //@..@ 0xff, 0xff, 0xfc, 0x64, //@@@+ 0xff, 0x00, 0x30, 0xee, //@..@ 0xff, 0xff, 0xf4, 0x8e, //@@@% 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0043 (C) , Width: 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x0c, 0x9a, 0xe8, 0xea, 0x6e, //.%@@+ 0x9c, 0xa4, 0x18, 0x0e, 0x88, //%%..% 0xea, 0x14, 0x00, 0x00, 0x00, //@.... 0xea, 0x14, 0x00, 0x00, 0x00, //@.... 0x9e, 0xa2, 0x16, 0x0e, 0x88, //%%..% 0x0e, 0x9c, 0xea, 0xea, 0x6e, //.%@@+ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... /*Unicode: U+0044 (D) , Width: 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0xff, 0xff, 0xe6, 0xa4, 0x16, //@@@%. 0xff, 0x00, 0x14, 0x98, 0xaa, //@..%% 0xff, 0x00, 0x00, 0x12, 0xec, //@...@ 0xff, 0x00, 0x00, 0x12, 0xec, //@...@ 0xff, 0x00, 0x14, 0x98, 0xaa, //@..%% 0xff, 0xff, 0xe8, 0xa6, 0x16, //@@@%. 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... /*Unicode: U+0045 (E) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0xff, 0xff, 0xff, 0xff, //@@@@ 0xff, 0x00, 0x00, 0x00, //@... 0xff, 0x00, 0x00, 0x00, //@... 0xff, 0xff, 0xff, 0xff, //@@@@ 0xff, 0x00, 0x00, 0x00, //@... 0xff, 0xff, 0xff, 0xff, //@@@@ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0046 (F) , Width: 3 */ 0x00, 0x00, 0x00, //... 0xff, 0xff, 0xff, //@@@ 0xff, 0x00, 0x00, //@.. 0xff, 0x00, 0x00, //@.. 0xff, 0xff, 0xff, //@@@ 0xff, 0x00, 0x00, //@.. 0xff, 0x00, 0x00, //@.. 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... /*Unicode: U+0047 (G) , Width: 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x10, 0xa4, 0xec, 0xe6, 0x6c, //.%@@+ 0xa2, 0x9c, 0x14, 0x10, 0x8c, //%%..% 0xea, 0x12, 0x00, 0xff, 0xff, //@..@@ 0xec, 0x10, 0x00, 0x00, 0xff, //@...@ 0xa8, 0x8e, 0x0c, 0x1e, 0xff, //%%..@ 0x14, 0xaa, 0xee, 0xe4, 0x5c, //.%@@+ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... /*Unicode: U+0048 (H) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0xff, 0x00, 0x00, 0xff, //@..@ 0xff, 0x00, 0x00, 0xff, //@..@ 0xff, 0x00, 0x00, 0xff, //@..@ 0xff, 0xff, 0xff, 0xff, //@@@@ 0xff, 0x00, 0x00, 0xff, //@..@ 0xff, 0x00, 0x00, 0xff, //@..@ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0049 (I) , Width: 1 */ 0x00, //. 0xff, //@ 0xff, //@ 0xff, //@ 0xff, //@ 0xff, //@ 0xff, //@ 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+004a (J) , Width: 2 */ 0x00, 0x00, //.. 0x00, 0xff, //.@ 0x00, 0xff, //.@ 0x00, 0xff, //.@ 0x00, 0xff, //.@ 0x00, 0xff, //.@ 0x00, 0xfc, //.@ 0x2a, 0xe4, //.@ 0xf2, 0x6a, //@+ 0x00, 0x00, //.. /*Unicode: U+004b (K) , Width: 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0xff, 0x00, 0x30, 0xe2, 0x6e, //@..@+ 0xff, 0x46, 0xe8, 0x50, 0x00, //@+@+. 0xff, 0xf2, 0x38, 0x00, 0x00, //@@... 0xff, 0xce, 0x80, 0x00, 0x00, //@@+.. 0xff, 0x12, 0xd0, 0x80, 0x00, //@.@+. 0xff, 0x00, 0x12, 0xd0, 0x7e, //@..@+ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... /*Unicode: U+004c (L) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0xff, 0x00, 0x00, 0x00, //@... 0xff, 0x00, 0x00, 0x00, //@... 0xff, 0x00, 0x00, 0x00, //@... 0xff, 0x00, 0x00, 0x00, //@... 0xff, 0x00, 0x00, 0x00, //@... 0xff, 0xff, 0xff, 0xff, //@@@@ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+004d (M) , Width: 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0xff, 0xee, 0x08, 0xee, 0xff, //@@.@@ 0xff, 0xca, 0x7c, 0xc8, 0xff, //@@+@@ 0xff, 0x82, 0xf2, 0x80, 0xff, //@%@+@ 0xff, 0x3a, 0xff, 0x3a, 0xff, //@.@.@ 0xff, 0x02, 0xde, 0x02, 0xff, //@.@.@ 0xff, 0x00, 0x00, 0x00, 0xff, //@...@ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... /*Unicode: U+004e (N) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0xff, 0x72, 0x00, 0xff, //@+.@ 0xff, 0xe6, 0x08, 0xff, //@@.@ 0xff, 0xb4, 0x74, 0xff, //@%+@ 0xff, 0x46, 0xe8, 0xff, //@+@@ 0xff, 0x00, 0xd6, 0xff, //@.@@ 0xff, 0x00, 0x6a, 0xff, //@.+@ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+004f (O) , Width: 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x1a, 0xba, 0xf2, 0xba, 0x18, //.%@%. 0xac, 0x86, 0x0c, 0x86, 0xaa, //%%.%% 0xee, 0x10, 0x00, 0x10, 0xec, //@...@ 0xee, 0x0e, 0x00, 0x10, 0xec, //@...@ 0xac, 0x84, 0x0c, 0x84, 0xaa, //%%.%% 0x1a, 0xbc, 0xf2, 0xba, 0x1a, //.%@%. 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... /*Unicode: U+0050 (P) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0xff, 0xff, 0xec, 0x7a, //@@@+ 0xff, 0x00, 0x3e, 0xf0, //@..@ 0xff, 0xff, 0xee, 0x7e, //@@@+ 0xff, 0x00, 0x00, 0x00, //@... 0xff, 0x00, 0x00, 0x00, //@... 0xff, 0x00, 0x00, 0x00, //@... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0051 (Q) , Width: 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x1a, 0xba, 0xf2, 0xbc, 0x1a, //.%@%. 0xac, 0x86, 0x0c, 0x86, 0xae, //%%.%% 0xee, 0x10, 0x00, 0x10, 0xee, //@...@ 0xee, 0x0e, 0x00, 0x10, 0xec, //@...@ 0xac, 0x84, 0x0c, 0x84, 0x98, //%%.%% 0x1c, 0xbe, 0xf8, 0xb6, 0x08, //.%@%. 0x00, 0x00, 0x3e, 0xe4, 0x14, //...@. 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... /*Unicode: U+0052 (R) , Width: 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0xff, 0xff, 0xee, 0x86, 0x00, //@@@%. 0xff, 0x00, 0x32, 0xf0, 0x00, //@..@. 0xff, 0xff, 0xfc, 0x56, 0x00, //@@@+. 0xff, 0x04, 0x8e, 0xaa, 0x00, //@.%%. 0xff, 0x00, 0x08, 0xe2, 0x32, //@..@. 0xff, 0x00, 0x00, 0x64, 0xba, //@..+% 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... /*Unicode: U+0053 (S) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0x64, 0xe4, 0xff, 0xff, //+@@@ 0xf0, 0x36, 0x00, 0x00, //@... 0xb8, 0xce, 0x84, 0x1a, //%@%. 0x02, 0x3e, 0x96, 0xd0, //..%@ 0x00, 0x00, 0x34, 0xf0, //...@ 0xff, 0xff, 0xe8, 0x6c, //@@@+ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0054 (T) , Width: 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0xff, 0xff, 0xff, 0xff, 0xff, //@@@@@ 0x00, 0x00, 0xff, 0x00, 0x00, //..@.. 0x00, 0x00, 0xff, 0x00, 0x00, //..@.. 0x00, 0x00, 0xff, 0x00, 0x00, //..@.. 0x00, 0x00, 0xff, 0x00, 0x00, //..@.. 0x00, 0x00, 0xff, 0x00, 0x00, //..@.. 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... /*Unicode: U+0055 (U) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0xff, 0x00, 0x00, 0xff, //@..@ 0xff, 0x00, 0x00, 0xff, //@..@ 0xff, 0x00, 0x00, 0xff, //@..@ 0xfa, 0x02, 0x02, 0xfa, //@..@ 0xd6, 0x42, 0x44, 0xd6, //@++@ 0x4c, 0xe6, 0xe4, 0x4a, //+@@+ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0056 (V) , Width: 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0xd2, 0x3a, 0x00, 0x3a, 0xd2, //@...@ 0x7a, 0x92, 0x00, 0x94, 0x78, //+%.%+ 0x22, 0xe6, 0x04, 0xe6, 0x20, //.@.@. 0x00, 0xc8, 0x88, 0xc8, 0x00, //.@%@. 0x00, 0x70, 0xfc, 0x6e, 0x00, //.+@+. 0x00, 0x18, 0xfa, 0x18, 0x00, //..@.. 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... /*Unicode: U+0057 (W) , Width: 7 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //....... 0xe0, 0x20, 0x74, 0xfc, 0x74, 0x20, 0xe0, //@.+@+.@ 0xa6, 0x5c, 0xae, 0xae, 0xae, 0x5c, 0xa4, //%+%%%+% 0x6a, 0x98, 0xe8, 0x3a, 0xe8, 0x98, 0x6a, //+%@.@%+ 0x2e, 0xec, 0xe2, 0x00, 0xe2, 0xec, 0x2e, //.@@.@@. 0x02, 0xf0, 0xa8, 0x00, 0xaa, 0xf0, 0x00, //.@%.%@. 0x00, 0xb8, 0x6e, 0x00, 0x70, 0xb8, 0x00, //.%+.+%. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //....... 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //....... 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //....... /*Unicode: U+0058 (X) , Width: 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0xac, 0x84, 0x00, 0x84, 0xac, //%%.%% 0x18, 0xea, 0x58, 0xe8, 0x18, //.@+@. 0x00, 0x66, 0xff, 0x64, 0x00, //.+@+. 0x00, 0x6a, 0xfc, 0x6c, 0x00, //.+@+. 0x1a, 0xe6, 0x4c, 0xea, 0x1a, //.@+@. 0xae, 0x74, 0x00, 0x7c, 0xae, //%+.+% 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... /*Unicode: U+0059 (Y) , Width: 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0xac, 0x80, 0x00, 0x80, 0xac, //%+.+% 0x18, 0xe8, 0x52, 0xe8, 0x18, //.@+@. 0x00, 0x66, 0xff, 0x66, 0x00, //.+@+. 0x00, 0x00, 0xff, 0x00, 0x00, //..@.. 0x00, 0x00, 0xff, 0x00, 0x00, //..@.. 0x00, 0x00, 0xff, 0x00, 0x00, //..@.. 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... /*Unicode: U+005a (Z) , Width: 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0xff, 0xff, 0xff, 0xff, 0xec, //@@@@@ 0x00, 0x00, 0x26, 0xf0, 0x48, //...@+ 0x00, 0x06, 0xce, 0x7e, 0x00, //..@+. 0x00, 0x94, 0xb4, 0x00, 0x00, //.%%.. 0x50, 0xdc, 0x10, 0x00, 0x00, //+@... 0xee, 0xff, 0xff, 0xff, 0xff, //@@@@@ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... /*Unicode: U+005b ([) , Width: 2 */ 0x00, 0x00, //.. 0xff, 0xff, //@@ 0xff, 0x00, //@. 0xff, 0x00, //@. 0xff, 0x00, //@. 0xff, 0x00, //@. 0xff, 0x00, //@. 0xff, 0xff, //@@ 0x00, 0x00, //.. 0x00, 0x00, //.. /*Unicode: U+005c (\) , Width: 3 */ 0x00, 0x00, 0x00, //... 0xda, 0x2e, 0x00, //@.. 0x94, 0x74, 0x00, //%+. 0x4c, 0xbc, 0x00, //+%. 0x0a, 0xf2, 0x0a, //.@. 0x00, 0xbe, 0x4c, //.%+ 0x00, 0x76, 0x92, //.+% 0x00, 0x2e, 0xda, //..@ 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... /*Unicode: U+005d (]) , Width: 2 */ 0x00, 0x00, //.. 0xff, 0xff, //@@ 0x00, 0xff, //.@ 0x00, 0xff, //.@ 0x00, 0xff, //.@ 0x00, 0xff, //.@ 0x00, 0xff, //.@ 0xff, 0xff, //@@ 0x00, 0x00, //.. 0x00, 0x00, //.. /*Unicode: U+005e (^) , Width: 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x68, 0xc4, 0x68, 0x00, //.+@+. 0x70, 0x66, 0x00, 0x66, 0x70, //++.++ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... /*Unicode: U+005f (_) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0xff, 0xff, 0xff, 0xff, //@@@@ 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0060 (`) , Width: 2 */ 0x00, 0x00, //.. 0x5a, 0x5e, //++ 0x00, 0x00, //.. 0x00, 0x00, //.. 0x00, 0x00, //.. 0x00, 0x00, //.. 0x00, 0x00, //.. 0x00, 0x00, //.. 0x00, 0x00, //.. 0x00, 0x00, //.. /*Unicode: U+0061 (a) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0xff, 0xf6, 0x92, //.@@% 0x7a, 0xec, 0xff, 0xfa, //+@@@ 0xf2, 0x38, 0x3e, 0xff, //@..@ 0x96, 0xf0, 0x92, 0xff, //%@%@ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0062 (b) , Width: 4 */ 0xff, 0x00, 0x00, 0x00, //@... 0xff, 0x00, 0x00, 0x00, //@... 0xff, 0x00, 0x00, 0x00, //@... 0xff, 0xa0, 0xf0, 0x64, //@%@+ 0xff, 0x32, 0x32, 0xea, //@..@ 0xff, 0x32, 0x32, 0xea, //@..@ 0xff, 0xa0, 0xf0, 0x66, //@%@+ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0063 (c) , Width: 3 */ 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x60, 0xec, 0xff, //+@@ 0xea, 0x36, 0x00, //@.. 0xea, 0x36, 0x00, //@.. 0x60, 0xec, 0xff, //+@@ 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... /*Unicode: U+0064 (d) , Width: 4 */ 0x00, 0x00, 0x00, 0xff, //...@ 0x00, 0x00, 0x00, 0xff, //...@ 0x00, 0x00, 0x00, 0xff, //...@ 0x64, 0xf0, 0x9e, 0xff, //+@%@ 0xea, 0x32, 0x32, 0xff, //@..@ 0xea, 0x32, 0x32, 0xff, //@..@ 0x66, 0xf0, 0x9e, 0xff, //+@%@ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0065 (e) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x50, 0xe2, 0xf0, 0x84, //+@@% 0xe6, 0xff, 0xff, 0xfa, //@@@@ 0xe6, 0x4a, 0x02, 0x00, //@+.. 0x4a, 0xda, 0xfc, 0xff, //+@@@ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0066 (f) , Width: 3 */ 0x00, 0x72, 0xf4, //.+@ 0x00, 0xe6, 0x1c, //.@. 0x00, 0xfc, 0x00, //.@. 0xff, 0xff, 0xff, //@@@ 0x00, 0xff, 0x00, //.@. 0x00, 0xff, 0x00, //.@. 0x00, 0xff, 0x00, //.@. 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... /*Unicode: U+0067 (g) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x68, 0xf0, 0xa0, 0xff, //+@%@ 0xea, 0x32, 0x32, 0xff, //@..@ 0xea, 0x32, 0x32, 0xff, //@..@ 0x68, 0xf0, 0xa6, 0xf4, //+@%@ 0x00, 0x00, 0x4e, 0xd2, //..+@ 0x00, 0xff, 0xec, 0x52, //.@@+ 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0068 (h) , Width: 4 */ 0xff, 0x00, 0x00, 0x00, //@... 0xff, 0x00, 0x00, 0x00, //@... 0xff, 0x00, 0x00, 0x00, //@... 0xff, 0x94, 0xf4, 0x84, //@%@% 0xff, 0x38, 0x30, 0xf2, //@..@ 0xff, 0x00, 0x00, 0xff, //@..@ 0xff, 0x00, 0x00, 0xff, //@..@ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0069 (i) , Width: 1 */ 0x00, //. 0xff, //@ 0x00, //. 0xff, //@ 0xff, //@ 0xff, //@ 0xff, //@ 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+006a (j) , Width: 2 */ 0x00, 0x00, //.. 0x00, 0xff, //.@ 0x00, 0x00, //.. 0x00, 0xff, //.@ 0x00, 0xff, //.@ 0x00, 0xff, //.@ 0x00, 0xff, //.@ 0x1e, 0xf2, //.@ 0xf4, 0x82, //@% 0x00, 0x00, //.. /*Unicode: U+006b (k) , Width: 4 */ 0xff, 0x00, 0x00, 0x00, //@... 0xff, 0x00, 0x00, 0x00, //@... 0xff, 0x00, 0x00, 0x00, //@... 0xff, 0x3e, 0xe6, 0x68, //@.@+ 0xff, 0xea, 0x40, 0x00, //@@.. 0xff, 0xe2, 0x66, 0x00, //@@+. 0xff, 0x20, 0xdc, 0x76, //@.@+ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+006c (l) , Width: 1 */ 0xff, //@ 0xff, //@ 0xff, //@ 0xff, //@ 0xff, //@ 0xff, //@ 0xff, //@ 0x00, //. 0x00, //. 0x00, //. /*Unicode: U+006d (m) , Width: 7 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //....... 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //....... 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //....... 0xff, 0x94, 0xf4, 0x70, 0xa2, 0xf4, 0x80, //@%@+%@+ 0xff, 0x3a, 0x28, 0xfc, 0x38, 0x2e, 0xf2, //@..@..@ 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, //@..@..@ 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, //@..@..@ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //....... 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //....... 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //....... /*Unicode: U+006e (n) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0xff, 0x94, 0xf4, 0x84, //@%@% 0xff, 0x38, 0x30, 0xf2, //@..@ 0xff, 0x00, 0x00, 0xff, //@..@ 0xff, 0x00, 0x00, 0xff, //@..@ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+006f (o) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x5a, 0xe8, 0xe8, 0x5a, //+@@+ 0xe8, 0x32, 0x34, 0xe8, //@..@ 0xe8, 0x32, 0x32, 0xe8, //@..@ 0x5a, 0xe8, 0xe8, 0x5a, //+@@+ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0070 (p) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0xff, 0xa0, 0xf0, 0x64, //@%@+ 0xff, 0x32, 0x32, 0xea, //@..@ 0xff, 0x32, 0x32, 0xea, //@..@ 0xff, 0xa0, 0xf0, 0x66, //@%@+ 0xff, 0x00, 0x00, 0x00, //@... 0xff, 0x00, 0x00, 0x00, //@... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0071 (q) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x64, 0xf0, 0x9e, 0xff, //+@%@ 0xea, 0x32, 0x32, 0xff, //@..@ 0xea, 0x32, 0x32, 0xff, //@..@ 0x66, 0xf0, 0x9e, 0xff, //+@%@ 0x00, 0x00, 0x00, 0xff, //...@ 0x00, 0x00, 0x00, 0xff, //...@ 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0072 (r) , Width: 3 */ 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0xff, 0x90, 0xf8, //@%@ 0xff, 0x48, 0x00, //@+. 0xff, 0x00, 0x00, //@.. 0xff, 0x00, 0x00, //@.. 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... /*Unicode: U+0073 (s) , Width: 3 */ 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0xa6, 0xf8, 0xff, //%@@ 0xd8, 0xce, 0x5e, //@@+ 0x06, 0x5a, 0xfa, //.+@ 0xff, 0xf8, 0xa4, //@@% 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... /*Unicode: U+0074 (t) , Width: 3 */ 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0xff, 0x00, //.@. 0xff, 0xff, 0xff, //@@@ 0x00, 0xff, 0x00, //.@. 0x00, 0xfa, 0x0a, //.@. 0x00, 0xac, 0xfa, //.%@ 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... /*Unicode: U+0075 (u) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0xff, 0x00, 0x00, 0xff, //@..@ 0xff, 0x00, 0x00, 0xff, //@..@ 0xf2, 0x30, 0x3a, 0xff, //@..@ 0x84, 0xf4, 0x92, 0xff, //%@%@ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0076 (v) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0xcc, 0x44, 0x44, 0xcc, //@++@ 0x6a, 0xa6, 0xa6, 0x6a, //+%%+ 0x0e, 0xee, 0xee, 0x0e, //.@@. 0x00, 0xa4, 0xa4, 0x00, //.%%. 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0077 (w) , Width: 6 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //...... 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //...... 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //...... 0xd8, 0x36, 0xee, 0xee, 0x36, 0xd8, //@.@@.@ 0x8e, 0xc0, 0xc2, 0xc4, 0xc0, 0x8e, //%%@@%% 0x42, 0xff, 0x78, 0x78, 0xff, 0x42, //+@++@+ 0x04, 0xf2, 0x2c, 0x2c, 0xf2, 0x04, //.@..@. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //...... 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //...... 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //...... /*Unicode: U+0078 (x) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x96, 0xac, 0xac, 0x96, //%%%% 0x04, 0xc2, 0xc2, 0x04, //.@@. 0x0a, 0xd6, 0xcc, 0x06, //.@@. 0xa0, 0x9e, 0xa4, 0x9c, //%%%% 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+0079 (y) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0xd0, 0x3c, 0x50, 0xc4, //@.+@ 0x76, 0x96, 0xc4, 0x50, //+%@+ 0x1c, 0xf4, 0xda, 0x00, //.@@. 0x00, 0xd0, 0x68, 0x00, //.@+. 0x04, 0xe4, 0x08, 0x00, //.@.. 0xfa, 0x78, 0x00, 0x00, //@+.. 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+007a (z) , Width: 4 */ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0xff, 0xff, 0xff, 0xe8, //@@@@ 0x00, 0x28, 0xe6, 0x46, //..@+ 0x24, 0xe4, 0x8c, 0x00, //.@%. 0xe0, 0xff, 0xff, 0xff, //@@@@ 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... 0x00, 0x00, 0x00, 0x00, //.... /*Unicode: U+007b ({) , Width: 3 */ 0x00, 0x00, 0x00, //... 0x00, 0xa2, 0xf6, //.%@ 0x00, 0xf8, 0x0e, //.@. 0x14, 0xf6, 0x00, //.@. 0xff, 0x8c, 0x00, //@%. 0x1e, 0xf4, 0x00, //.@. 0x00, 0xf8, 0x0e, //.@. 0x00, 0xa4, 0xf8, //.%@ 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... /*Unicode: U+007c (|) , Width: 1 */ 0x00, //. 0xff, //@ 0xff, //@ 0xff, //@ 0xff, //@ 0xff, //@ 0xff, //@ 0xff, //@ 0xff, //@ 0x00, //. /*Unicode: U+007d (}) , Width: 3 */ 0x00, 0x00, 0x00, //... 0xf6, 0xa2, 0x00, //@%. 0x10, 0xf8, 0x00, //.@. 0x00, 0xf6, 0x14, //.@. 0x00, 0x8c, 0xff, //.%@ 0x00, 0xf4, 0x1e, //.@. 0x0e, 0xf8, 0x00, //.@. 0xf8, 0xa4, 0x00, //@%. 0x00, 0x00, 0x00, //... 0x00, 0x00, 0x00, //... /*Unicode: U+007e (~) , Width: 5 */ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x80, 0xec, 0x88, 0x10, 0x82, //+@%.% 0x4e, 0x10, 0x8a, 0xec, 0x80, //+.%@+ 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... 0x00, 0x00, 0x00, 0x00, 0x00, //..... #endif }; /*Store the glyph descriptions*/ static const lv_font_glyph_dsc_t lv_font_dejavu_10_glyph_dsc[] = { #if USE_LV_FONT_DEJAVU_10 == 1 {.w_px = 3, .glyph_index = 0}, /*Unicode: U+0020 ( )*/ {.w_px = 1, .glyph_index = 10}, /*Unicode: U+0021 (!)*/ {.w_px = 3, .glyph_index = 20}, /*Unicode: U+0022 (")*/ {.w_px = 5, .glyph_index = 30}, /*Unicode: U+0023 (#)*/ {.w_px = 5, .glyph_index = 40}, /*Unicode: U+0024 ($)*/ {.w_px = 7, .glyph_index = 50}, /*Unicode: U+0025 (%)*/ {.w_px = 5, .glyph_index = 60}, /*Unicode: U+0026 (&)*/ {.w_px = 1, .glyph_index = 70}, /*Unicode: U+0027 (')*/ {.w_px = 2, .glyph_index = 80}, /*Unicode: U+0028 (()*/ {.w_px = 2, .glyph_index = 90}, /*Unicode: U+0029 ())*/ {.w_px = 5, .glyph_index = 100}, /*Unicode: U+002a (*)*/ {.w_px = 5, .glyph_index = 110}, /*Unicode: U+002b (+)*/ {.w_px = 1, .glyph_index = 120}, /*Unicode: U+002c (,)*/ {.w_px = 2, .glyph_index = 130}, /*Unicode: U+002d (-)*/ {.w_px = 1, .glyph_index = 140}, /*Unicode: U+002e (.)*/ {.w_px = 3, .glyph_index = 150}, /*Unicode: U+002f (/)*/ {.w_px = 4, .glyph_index = 160}, /*Unicode: U+0030 (0)*/ {.w_px = 3, .glyph_index = 170}, /*Unicode: U+0031 (1)*/ {.w_px = 5, .glyph_index = 180}, /*Unicode: U+0032 (2)*/ {.w_px = 4, .glyph_index = 190}, /*Unicode: U+0033 (3)*/ {.w_px = 4, .glyph_index = 200}, /*Unicode: U+0034 (4)*/ {.w_px = 4, .glyph_index = 210}, /*Unicode: U+0035 (5)*/ {.w_px = 4, .glyph_index = 220}, /*Unicode: U+0036 (6)*/ {.w_px = 4, .glyph_index = 230}, /*Unicode: U+0037 (7)*/ {.w_px = 4, .glyph_index = 240}, /*Unicode: U+0038 (8)*/ {.w_px = 4, .glyph_index = 250}, /*Unicode: U+0039 (9)*/ {.w_px = 1, .glyph_index = 260}, /*Unicode: U+003a (:)*/ {.w_px = 1, .glyph_index = 270}, /*Unicode: U+003b (;)*/ {.w_px = 5, .glyph_index = 280}, /*Unicode: U+003c (<)*/ {.w_px = 5, .glyph_index = 290}, /*Unicode: U+003d (=)*/ {.w_px = 5, .glyph_index = 300}, /*Unicode: U+003e (>)*/ {.w_px = 3, .glyph_index = 310}, /*Unicode: U+003f (?)*/ {.w_px = 7, .glyph_index = 320}, /*Unicode: U+0040 (@)*/ {.w_px = 5, .glyph_index = 330}, /*Unicode: U+0041 (A)*/ {.w_px = 4, .glyph_index = 340}, /*Unicode: U+0042 (B)*/ {.w_px = 5, .glyph_index = 350}, /*Unicode: U+0043 (C)*/ {.w_px = 5, .glyph_index = 360}, /*Unicode: U+0044 (D)*/ {.w_px = 4, .glyph_index = 370}, /*Unicode: U+0045 (E)*/ {.w_px = 3, .glyph_index = 380}, /*Unicode: U+0046 (F)*/ {.w_px = 5, .glyph_index = 390}, /*Unicode: U+0047 (G)*/ {.w_px = 4, .glyph_index = 400}, /*Unicode: U+0048 (H)*/ {.w_px = 1, .glyph_index = 410}, /*Unicode: U+0049 (I)*/ {.w_px = 2, .glyph_index = 420}, /*Unicode: U+004a (J)*/ {.w_px = 5, .glyph_index = 430}, /*Unicode: U+004b (K)*/ {.w_px = 4, .glyph_index = 440}, /*Unicode: U+004c (L)*/ {.w_px = 5, .glyph_index = 450}, /*Unicode: U+004d (M)*/ {.w_px = 4, .glyph_index = 460}, /*Unicode: U+004e (N)*/ {.w_px = 5, .glyph_index = 470}, /*Unicode: U+004f (O)*/ {.w_px = 4, .glyph_index = 480}, /*Unicode: U+0050 (P)*/ {.w_px = 5, .glyph_index = 490}, /*Unicode: U+0051 (Q)*/ {.w_px = 5, .glyph_index = 500}, /*Unicode: U+0052 (R)*/ {.w_px = 4, .glyph_index = 510}, /*Unicode: U+0053 (S)*/ {.w_px = 5, .glyph_index = 520}, /*Unicode: U+0054 (T)*/ {.w_px = 4, .glyph_index = 530}, /*Unicode: U+0055 (U)*/ {.w_px = 5, .glyph_index = 540}, /*Unicode: U+0056 (V)*/ {.w_px = 7, .glyph_index = 550}, /*Unicode: U+0057 (W)*/ {.w_px = 5, .glyph_index = 560}, /*Unicode: U+0058 (X)*/ {.w_px = 5, .glyph_index = 570}, /*Unicode: U+0059 (Y)*/ {.w_px = 5, .glyph_index = 580}, /*Unicode: U+005a (Z)*/ {.w_px = 2, .glyph_index = 590}, /*Unicode: U+005b ([)*/ {.w_px = 3, .glyph_index = 600}, /*Unicode: U+005c (\)*/ {.w_px = 2, .glyph_index = 610}, /*Unicode: U+005d (])*/ {.w_px = 5, .glyph_index = 620}, /*Unicode: U+005e (^)*/ {.w_px = 4, .glyph_index = 630}, /*Unicode: U+005f (_)*/ {.w_px = 2, .glyph_index = 640}, /*Unicode: U+0060 (`)*/ {.w_px = 4, .glyph_index = 650}, /*Unicode: U+0061 (a)*/ {.w_px = 4, .glyph_index = 660}, /*Unicode: U+0062 (b)*/ {.w_px = 3, .glyph_index = 670}, /*Unicode: U+0063 (c)*/ {.w_px = 4, .glyph_index = 680}, /*Unicode: U+0064 (d)*/ {.w_px = 4, .glyph_index = 690}, /*Unicode: U+0065 (e)*/ {.w_px = 3, .glyph_index = 700}, /*Unicode: U+0066 (f)*/ {.w_px = 4, .glyph_index = 710}, /*Unicode: U+0067 (g)*/ {.w_px = 4, .glyph_index = 720}, /*Unicode: U+0068 (h)*/ {.w_px = 1, .glyph_index = 730}, /*Unicode: U+0069 (i)*/ {.w_px = 2, .glyph_index = 740}, /*Unicode: U+006a (j)*/ {.w_px = 4, .glyph_index = 750}, /*Unicode: U+006b (k)*/ {.w_px = 1, .glyph_index = 760}, /*Unicode: U+006c (l)*/ {.w_px = 7, .glyph_index = 770}, /*Unicode: U+006d (m)*/ {.w_px = 4, .glyph_index = 780}, /*Unicode: U+006e (n)*/ {.w_px = 4, .glyph_index = 790}, /*Unicode: U+006f (o)*/ {.w_px = 4, .glyph_index = 800}, /*Unicode: U+0070 (p)*/ {.w_px = 4, .glyph_index = 810}, /*Unicode: U+0071 (q)*/ {.w_px = 3, .glyph_index = 820}, /*Unicode: U+0072 (r)*/ {.w_px = 3, .glyph_index = 830}, /*Unicode: U+0073 (s)*/ {.w_px = 3, .glyph_index = 840}, /*Unicode: U+0074 (t)*/ {.w_px = 4, .glyph_index = 850}, /*Unicode: U+0075 (u)*/ {.w_px = 4, .glyph_index = 860}, /*Unicode: U+0076 (v)*/ {.w_px = 6, .glyph_index = 870}, /*Unicode: U+0077 (w)*/ {.w_px = 4, .glyph_index = 880}, /*Unicode: U+0078 (x)*/ {.w_px = 4, .glyph_index = 890}, /*Unicode: U+0079 (y)*/ {.w_px = 4, .glyph_index = 900}, /*Unicode: U+007a (z)*/ {.w_px = 3, .glyph_index = 910}, /*Unicode: U+007b ({)*/ {.w_px = 1, .glyph_index = 920}, /*Unicode: U+007c (|)*/ {.w_px = 3, .glyph_index = 930}, /*Unicode: U+007d (})*/ {.w_px = 5, .glyph_index = 940}, /*Unicode: U+007e (~)*/ #elif USE_LV_FONT_DEJAVU_10 == 2 {.w_px = 3, .glyph_index = 0}, /*Unicode: U+0020 ( )*/ {.w_px = 1, .glyph_index = 10}, /*Unicode: U+0021 (!)*/ {.w_px = 3, .glyph_index = 20}, /*Unicode: U+0022 (")*/ {.w_px = 5, .glyph_index = 30}, /*Unicode: U+0023 (#)*/ {.w_px = 5, .glyph_index = 50}, /*Unicode: U+0024 ($)*/ {.w_px = 7, .glyph_index = 70}, /*Unicode: U+0025 (%)*/ {.w_px = 5, .glyph_index = 90}, /*Unicode: U+0026 (&)*/ {.w_px = 1, .glyph_index = 110}, /*Unicode: U+0027 (')*/ {.w_px = 2, .glyph_index = 120}, /*Unicode: U+0028 (()*/ {.w_px = 2, .glyph_index = 130}, /*Unicode: U+0029 ())*/ {.w_px = 5, .glyph_index = 140}, /*Unicode: U+002a (*)*/ {.w_px = 5, .glyph_index = 160}, /*Unicode: U+002b (+)*/ {.w_px = 1, .glyph_index = 180}, /*Unicode: U+002c (,)*/ {.w_px = 2, .glyph_index = 190}, /*Unicode: U+002d (-)*/ {.w_px = 1, .glyph_index = 200}, /*Unicode: U+002e (.)*/ {.w_px = 3, .glyph_index = 210}, /*Unicode: U+002f (/)*/ {.w_px = 4, .glyph_index = 220}, /*Unicode: U+0030 (0)*/ {.w_px = 3, .glyph_index = 230}, /*Unicode: U+0031 (1)*/ {.w_px = 5, .glyph_index = 240}, /*Unicode: U+0032 (2)*/ {.w_px = 4, .glyph_index = 260}, /*Unicode: U+0033 (3)*/ {.w_px = 4, .glyph_index = 270}, /*Unicode: U+0034 (4)*/ {.w_px = 4, .glyph_index = 280}, /*Unicode: U+0035 (5)*/ {.w_px = 4, .glyph_index = 290}, /*Unicode: U+0036 (6)*/ {.w_px = 4, .glyph_index = 300}, /*Unicode: U+0037 (7)*/ {.w_px = 4, .glyph_index = 310}, /*Unicode: U+0038 (8)*/ {.w_px = 4, .glyph_index = 320}, /*Unicode: U+0039 (9)*/ {.w_px = 1, .glyph_index = 330}, /*Unicode: U+003a (:)*/ {.w_px = 1, .glyph_index = 340}, /*Unicode: U+003b (;)*/ {.w_px = 5, .glyph_index = 350}, /*Unicode: U+003c (<)*/ {.w_px = 5, .glyph_index = 370}, /*Unicode: U+003d (=)*/ {.w_px = 5, .glyph_index = 390}, /*Unicode: U+003e (>)*/ {.w_px = 3, .glyph_index = 410}, /*Unicode: U+003f (?)*/ {.w_px = 7, .glyph_index = 420}, /*Unicode: U+0040 (@)*/ {.w_px = 5, .glyph_index = 440}, /*Unicode: U+0041 (A)*/ {.w_px = 4, .glyph_index = 460}, /*Unicode: U+0042 (B)*/ {.w_px = 5, .glyph_index = 470}, /*Unicode: U+0043 (C)*/ {.w_px = 5, .glyph_index = 490}, /*Unicode: U+0044 (D)*/ {.w_px = 4, .glyph_index = 510}, /*Unicode: U+0045 (E)*/ {.w_px = 3, .glyph_index = 520}, /*Unicode: U+0046 (F)*/ {.w_px = 5, .glyph_index = 530}, /*Unicode: U+0047 (G)*/ {.w_px = 4, .glyph_index = 550}, /*Unicode: U+0048 (H)*/ {.w_px = 1, .glyph_index = 560}, /*Unicode: U+0049 (I)*/ {.w_px = 2, .glyph_index = 570}, /*Unicode: U+004a (J)*/ {.w_px = 5, .glyph_index = 580}, /*Unicode: U+004b (K)*/ {.w_px = 4, .glyph_index = 600}, /*Unicode: U+004c (L)*/ {.w_px = 5, .glyph_index = 610}, /*Unicode: U+004d (M)*/ {.w_px = 4, .glyph_index = 630}, /*Unicode: U+004e (N)*/ {.w_px = 5, .glyph_index = 640}, /*Unicode: U+004f (O)*/ {.w_px = 4, .glyph_index = 660}, /*Unicode: U+0050 (P)*/ {.w_px = 5, .glyph_index = 670}, /*Unicode: U+0051 (Q)*/ {.w_px = 5, .glyph_index = 690}, /*Unicode: U+0052 (R)*/ {.w_px = 4, .glyph_index = 710}, /*Unicode: U+0053 (S)*/ {.w_px = 5, .glyph_index = 720}, /*Unicode: U+0054 (T)*/ {.w_px = 4, .glyph_index = 740}, /*Unicode: U+0055 (U)*/ {.w_px = 5, .glyph_index = 750}, /*Unicode: U+0056 (V)*/ {.w_px = 7, .glyph_index = 770}, /*Unicode: U+0057 (W)*/ {.w_px = 5, .glyph_index = 790}, /*Unicode: U+0058 (X)*/ {.w_px = 5, .glyph_index = 810}, /*Unicode: U+0059 (Y)*/ {.w_px = 5, .glyph_index = 830}, /*Unicode: U+005a (Z)*/ {.w_px = 2, .glyph_index = 850}, /*Unicode: U+005b ([)*/ {.w_px = 3, .glyph_index = 860}, /*Unicode: U+005c (\)*/ {.w_px = 2, .glyph_index = 870}, /*Unicode: U+005d (])*/ {.w_px = 5, .glyph_index = 880}, /*Unicode: U+005e (^)*/ {.w_px = 4, .glyph_index = 900}, /*Unicode: U+005f (_)*/ {.w_px = 2, .glyph_index = 910}, /*Unicode: U+0060 (`)*/ {.w_px = 4, .glyph_index = 920}, /*Unicode: U+0061 (a)*/ {.w_px = 4, .glyph_index = 930}, /*Unicode: U+0062 (b)*/ {.w_px = 3, .glyph_index = 940}, /*Unicode: U+0063 (c)*/ {.w_px = 4, .glyph_index = 950}, /*Unicode: U+0064 (d)*/ {.w_px = 4, .glyph_index = 960}, /*Unicode: U+0065 (e)*/ {.w_px = 3, .glyph_index = 970}, /*Unicode: U+0066 (f)*/ {.w_px = 4, .glyph_index = 980}, /*Unicode: U+0067 (g)*/ {.w_px = 4, .glyph_index = 990}, /*Unicode: U+0068 (h)*/ {.w_px = 1, .glyph_index = 1000}, /*Unicode: U+0069 (i)*/ {.w_px = 2, .glyph_index = 1010}, /*Unicode: U+006a (j)*/ {.w_px = 4, .glyph_index = 1020}, /*Unicode: U+006b (k)*/ {.w_px = 1, .glyph_index = 1030}, /*Unicode: U+006c (l)*/ {.w_px = 7, .glyph_index = 1040}, /*Unicode: U+006d (m)*/ {.w_px = 4, .glyph_index = 1060}, /*Unicode: U+006e (n)*/ {.w_px = 4, .glyph_index = 1070}, /*Unicode: U+006f (o)*/ {.w_px = 4, .glyph_index = 1080}, /*Unicode: U+0070 (p)*/ {.w_px = 4, .glyph_index = 1090}, /*Unicode: U+0071 (q)*/ {.w_px = 3, .glyph_index = 1100}, /*Unicode: U+0072 (r)*/ {.w_px = 3, .glyph_index = 1110}, /*Unicode: U+0073 (s)*/ {.w_px = 3, .glyph_index = 1120}, /*Unicode: U+0074 (t)*/ {.w_px = 4, .glyph_index = 1130}, /*Unicode: U+0075 (u)*/ {.w_px = 4, .glyph_index = 1140}, /*Unicode: U+0076 (v)*/ {.w_px = 6, .glyph_index = 1150}, /*Unicode: U+0077 (w)*/ {.w_px = 4, .glyph_index = 1170}, /*Unicode: U+0078 (x)*/ {.w_px = 4, .glyph_index = 1180}, /*Unicode: U+0079 (y)*/ {.w_px = 4, .glyph_index = 1190}, /*Unicode: U+007a (z)*/ {.w_px = 3, .glyph_index = 1200}, /*Unicode: U+007b ({)*/ {.w_px = 1, .glyph_index = 1210}, /*Unicode: U+007c (|)*/ {.w_px = 3, .glyph_index = 1220}, /*Unicode: U+007d (})*/ {.w_px = 5, .glyph_index = 1230}, /*Unicode: U+007e (~)*/ #elif USE_LV_FONT_DEJAVU_10 == 4 {.w_px = 3, .glyph_index = 0}, /*Unicode: U+0020 ( )*/ {.w_px = 1, .glyph_index = 20}, /*Unicode: U+0021 (!)*/ {.w_px = 3, .glyph_index = 30}, /*Unicode: U+0022 (")*/ {.w_px = 5, .glyph_index = 50}, /*Unicode: U+0023 (#)*/ {.w_px = 5, .glyph_index = 80}, /*Unicode: U+0024 ($)*/ {.w_px = 7, .glyph_index = 110}, /*Unicode: U+0025 (%)*/ {.w_px = 5, .glyph_index = 150}, /*Unicode: U+0026 (&)*/ {.w_px = 1, .glyph_index = 180}, /*Unicode: U+0027 (')*/ {.w_px = 2, .glyph_index = 190}, /*Unicode: U+0028 (()*/ {.w_px = 2, .glyph_index = 200}, /*Unicode: U+0029 ())*/ {.w_px = 5, .glyph_index = 210}, /*Unicode: U+002a (*)*/ {.w_px = 5, .glyph_index = 240}, /*Unicode: U+002b (+)*/ {.w_px = 1, .glyph_index = 270}, /*Unicode: U+002c (,)*/ {.w_px = 2, .glyph_index = 280}, /*Unicode: U+002d (-)*/ {.w_px = 1, .glyph_index = 290}, /*Unicode: U+002e (.)*/ {.w_px = 3, .glyph_index = 300}, /*Unicode: U+002f (/)*/ {.w_px = 4, .glyph_index = 320}, /*Unicode: U+0030 (0)*/ {.w_px = 3, .glyph_index = 340}, /*Unicode: U+0031 (1)*/ {.w_px = 5, .glyph_index = 360}, /*Unicode: U+0032 (2)*/ {.w_px = 4, .glyph_index = 390}, /*Unicode: U+0033 (3)*/ {.w_px = 4, .glyph_index = 410}, /*Unicode: U+0034 (4)*/ {.w_px = 4, .glyph_index = 430}, /*Unicode: U+0035 (5)*/ {.w_px = 4, .glyph_index = 450}, /*Unicode: U+0036 (6)*/ {.w_px = 4, .glyph_index = 470}, /*Unicode: U+0037 (7)*/ {.w_px = 4, .glyph_index = 490}, /*Unicode: U+0038 (8)*/ {.w_px = 4, .glyph_index = 510}, /*Unicode: U+0039 (9)*/ {.w_px = 1, .glyph_index = 530}, /*Unicode: U+003a (:)*/ {.w_px = 1, .glyph_index = 540}, /*Unicode: U+003b (;)*/ {.w_px = 5, .glyph_index = 550}, /*Unicode: U+003c (<)*/ {.w_px = 5, .glyph_index = 580}, /*Unicode: U+003d (=)*/ {.w_px = 5, .glyph_index = 610}, /*Unicode: U+003e (>)*/ {.w_px = 3, .glyph_index = 640}, /*Unicode: U+003f (?)*/ {.w_px = 7, .glyph_index = 660}, /*Unicode: U+0040 (@)*/ {.w_px = 5, .glyph_index = 700}, /*Unicode: U+0041 (A)*/ {.w_px = 4, .glyph_index = 730}, /*Unicode: U+0042 (B)*/ {.w_px = 5, .glyph_index = 750}, /*Unicode: U+0043 (C)*/ {.w_px = 5, .glyph_index = 780}, /*Unicode: U+0044 (D)*/ {.w_px = 4, .glyph_index = 810}, /*Unicode: U+0045 (E)*/ {.w_px = 3, .glyph_index = 830}, /*Unicode: U+0046 (F)*/ {.w_px = 5, .glyph_index = 850}, /*Unicode: U+0047 (G)*/ {.w_px = 4, .glyph_index = 880}, /*Unicode: U+0048 (H)*/ {.w_px = 1, .glyph_index = 900}, /*Unicode: U+0049 (I)*/ {.w_px = 2, .glyph_index = 910}, /*Unicode: U+004a (J)*/ {.w_px = 5, .glyph_index = 920}, /*Unicode: U+004b (K)*/ {.w_px = 4, .glyph_index = 950}, /*Unicode: U+004c (L)*/ {.w_px = 5, .glyph_index = 970}, /*Unicode: U+004d (M)*/ {.w_px = 4, .glyph_index = 1000}, /*Unicode: U+004e (N)*/ {.w_px = 5, .glyph_index = 1020}, /*Unicode: U+004f (O)*/ {.w_px = 4, .glyph_index = 1050}, /*Unicode: U+0050 (P)*/ {.w_px = 5, .glyph_index = 1070}, /*Unicode: U+0051 (Q)*/ {.w_px = 5, .glyph_index = 1100}, /*Unicode: U+0052 (R)*/ {.w_px = 4, .glyph_index = 1130}, /*Unicode: U+0053 (S)*/ {.w_px = 5, .glyph_index = 1150}, /*Unicode: U+0054 (T)*/ {.w_px = 4, .glyph_index = 1180}, /*Unicode: U+0055 (U)*/ {.w_px = 5, .glyph_index = 1200}, /*Unicode: U+0056 (V)*/ {.w_px = 7, .glyph_index = 1230}, /*Unicode: U+0057 (W)*/ {.w_px = 5, .glyph_index = 1270}, /*Unicode: U+0058 (X)*/ {.w_px = 5, .glyph_index = 1300}, /*Unicode: U+0059 (Y)*/ {.w_px = 5, .glyph_index = 1330}, /*Unicode: U+005a (Z)*/ {.w_px = 2, .glyph_index = 1360}, /*Unicode: U+005b ([)*/ {.w_px = 3, .glyph_index = 1370}, /*Unicode: U+005c (\)*/ {.w_px = 2, .glyph_index = 1390}, /*Unicode: U+005d (])*/ {.w_px = 5, .glyph_index = 1400}, /*Unicode: U+005e (^)*/ {.w_px = 4, .glyph_index = 1430}, /*Unicode: U+005f (_)*/ {.w_px = 2, .glyph_index = 1450}, /*Unicode: U+0060 (`)*/ {.w_px = 4, .glyph_index = 1460}, /*Unicode: U+0061 (a)*/ {.w_px = 4, .glyph_index = 1480}, /*Unicode: U+0062 (b)*/ {.w_px = 3, .glyph_index = 1500}, /*Unicode: U+0063 (c)*/ {.w_px = 4, .glyph_index = 1520}, /*Unicode: U+0064 (d)*/ {.w_px = 4, .glyph_index = 1540}, /*Unicode: U+0065 (e)*/ {.w_px = 3, .glyph_index = 1560}, /*Unicode: U+0066 (f)*/ {.w_px = 4, .glyph_index = 1580}, /*Unicode: U+0067 (g)*/ {.w_px = 4, .glyph_index = 1600}, /*Unicode: U+0068 (h)*/ {.w_px = 1, .glyph_index = 1620}, /*Unicode: U+0069 (i)*/ {.w_px = 2, .glyph_index = 1630}, /*Unicode: U+006a (j)*/ {.w_px = 4, .glyph_index = 1640}, /*Unicode: U+006b (k)*/ {.w_px = 1, .glyph_index = 1660}, /*Unicode: U+006c (l)*/ {.w_px = 7, .glyph_index = 1670}, /*Unicode: U+006d (m)*/ {.w_px = 4, .glyph_index = 1710}, /*Unicode: U+006e (n)*/ {.w_px = 4, .glyph_index = 1730}, /*Unicode: U+006f (o)*/ {.w_px = 4, .glyph_index = 1750}, /*Unicode: U+0070 (p)*/ {.w_px = 4, .glyph_index = 1770}, /*Unicode: U+0071 (q)*/ {.w_px = 3, .glyph_index = 1790}, /*Unicode: U+0072 (r)*/ {.w_px = 3, .glyph_index = 1810}, /*Unicode: U+0073 (s)*/ {.w_px = 3, .glyph_index = 1830}, /*Unicode: U+0074 (t)*/ {.w_px = 4, .glyph_index = 1850}, /*Unicode: U+0075 (u)*/ {.w_px = 4, .glyph_index = 1870}, /*Unicode: U+0076 (v)*/ {.w_px = 6, .glyph_index = 1890}, /*Unicode: U+0077 (w)*/ {.w_px = 4, .glyph_index = 1920}, /*Unicode: U+0078 (x)*/ {.w_px = 4, .glyph_index = 1940}, /*Unicode: U+0079 (y)*/ {.w_px = 4, .glyph_index = 1960}, /*Unicode: U+007a (z)*/ {.w_px = 3, .glyph_index = 1980}, /*Unicode: U+007b ({)*/ {.w_px = 1, .glyph_index = 2000}, /*Unicode: U+007c (|)*/ {.w_px = 3, .glyph_index = 2010}, /*Unicode: U+007d (})*/ {.w_px = 5, .glyph_index = 2030}, /*Unicode: U+007e (~)*/ #elif USE_LV_FONT_DEJAVU_10 == 8 {.w_px = 3, .glyph_index = 0}, /*Unicode: U+0020 ( )*/ {.w_px = 1, .glyph_index = 30}, /*Unicode: U+0021 (!)*/ {.w_px = 3, .glyph_index = 40}, /*Unicode: U+0022 (")*/ {.w_px = 5, .glyph_index = 70}, /*Unicode: U+0023 (#)*/ {.w_px = 5, .glyph_index = 120}, /*Unicode: U+0024 ($)*/ {.w_px = 7, .glyph_index = 170}, /*Unicode: U+0025 (%)*/ {.w_px = 5, .glyph_index = 240}, /*Unicode: U+0026 (&)*/ {.w_px = 1, .glyph_index = 290}, /*Unicode: U+0027 (')*/ {.w_px = 2, .glyph_index = 300}, /*Unicode: U+0028 (()*/ {.w_px = 2, .glyph_index = 320}, /*Unicode: U+0029 ())*/ {.w_px = 5, .glyph_index = 340}, /*Unicode: U+002a (*)*/ {.w_px = 5, .glyph_index = 390}, /*Unicode: U+002b (+)*/ {.w_px = 1, .glyph_index = 440}, /*Unicode: U+002c (,)*/ {.w_px = 2, .glyph_index = 450}, /*Unicode: U+002d (-)*/ {.w_px = 1, .glyph_index = 470}, /*Unicode: U+002e (.)*/ {.w_px = 3, .glyph_index = 480}, /*Unicode: U+002f (/)*/ {.w_px = 4, .glyph_index = 510}, /*Unicode: U+0030 (0)*/ {.w_px = 3, .glyph_index = 550}, /*Unicode: U+0031 (1)*/ {.w_px = 5, .glyph_index = 580}, /*Unicode: U+0032 (2)*/ {.w_px = 4, .glyph_index = 630}, /*Unicode: U+0033 (3)*/ {.w_px = 4, .glyph_index = 670}, /*Unicode: U+0034 (4)*/ {.w_px = 4, .glyph_index = 710}, /*Unicode: U+0035 (5)*/ {.w_px = 4, .glyph_index = 750}, /*Unicode: U+0036 (6)*/ {.w_px = 4, .glyph_index = 790}, /*Unicode: U+0037 (7)*/ {.w_px = 4, .glyph_index = 830}, /*Unicode: U+0038 (8)*/ {.w_px = 4, .glyph_index = 870}, /*Unicode: U+0039 (9)*/ {.w_px = 1, .glyph_index = 910}, /*Unicode: U+003a (:)*/ {.w_px = 1, .glyph_index = 920}, /*Unicode: U+003b (;)*/ {.w_px = 5, .glyph_index = 930}, /*Unicode: U+003c (<)*/ {.w_px = 5, .glyph_index = 980}, /*Unicode: U+003d (=)*/ {.w_px = 5, .glyph_index = 1030}, /*Unicode: U+003e (>)*/ {.w_px = 3, .glyph_index = 1080}, /*Unicode: U+003f (?)*/ {.w_px = 7, .glyph_index = 1110}, /*Unicode: U+0040 (@)*/ {.w_px = 5, .glyph_index = 1180}, /*Unicode: U+0041 (A)*/ {.w_px = 4, .glyph_index = 1230}, /*Unicode: U+0042 (B)*/ {.w_px = 5, .glyph_index = 1270}, /*Unicode: U+0043 (C)*/ {.w_px = 5, .glyph_index = 1320}, /*Unicode: U+0044 (D)*/ {.w_px = 4, .glyph_index = 1370}, /*Unicode: U+0045 (E)*/ {.w_px = 3, .glyph_index = 1410}, /*Unicode: U+0046 (F)*/ {.w_px = 5, .glyph_index = 1440}, /*Unicode: U+0047 (G)*/ {.w_px = 4, .glyph_index = 1490}, /*Unicode: U+0048 (H)*/ {.w_px = 1, .glyph_index = 1530}, /*Unicode: U+0049 (I)*/ {.w_px = 2, .glyph_index = 1540}, /*Unicode: U+004a (J)*/ {.w_px = 5, .glyph_index = 1560}, /*Unicode: U+004b (K)*/ {.w_px = 4, .glyph_index = 1610}, /*Unicode: U+004c (L)*/ {.w_px = 5, .glyph_index = 1650}, /*Unicode: U+004d (M)*/ {.w_px = 4, .glyph_index = 1700}, /*Unicode: U+004e (N)*/ {.w_px = 5, .glyph_index = 1740}, /*Unicode: U+004f (O)*/ {.w_px = 4, .glyph_index = 1790}, /*Unicode: U+0050 (P)*/ {.w_px = 5, .glyph_index = 1830}, /*Unicode: U+0051 (Q)*/ {.w_px = 5, .glyph_index = 1880}, /*Unicode: U+0052 (R)*/ {.w_px = 4, .glyph_index = 1930}, /*Unicode: U+0053 (S)*/ {.w_px = 5, .glyph_index = 1970}, /*Unicode: U+0054 (T)*/ {.w_px = 4, .glyph_index = 2020}, /*Unicode: U+0055 (U)*/ {.w_px = 5, .glyph_index = 2060}, /*Unicode: U+0056 (V)*/ {.w_px = 7, .glyph_index = 2110}, /*Unicode: U+0057 (W)*/ {.w_px = 5, .glyph_index = 2180}, /*Unicode: U+0058 (X)*/ {.w_px = 5, .glyph_index = 2230}, /*Unicode: U+0059 (Y)*/ {.w_px = 5, .glyph_index = 2280}, /*Unicode: U+005a (Z)*/ {.w_px = 2, .glyph_index = 2330}, /*Unicode: U+005b ([)*/ {.w_px = 3, .glyph_index = 2350}, /*Unicode: U+005c (\)*/ {.w_px = 2, .glyph_index = 2380}, /*Unicode: U+005d (])*/ {.w_px = 5, .glyph_index = 2400}, /*Unicode: U+005e (^)*/ {.w_px = 4, .glyph_index = 2450}, /*Unicode: U+005f (_)*/ {.w_px = 2, .glyph_index = 2490}, /*Unicode: U+0060 (`)*/ {.w_px = 4, .glyph_index = 2510}, /*Unicode: U+0061 (a)*/ {.w_px = 4, .glyph_index = 2550}, /*Unicode: U+0062 (b)*/ {.w_px = 3, .glyph_index = 2590}, /*Unicode: U+0063 (c)*/ {.w_px = 4, .glyph_index = 2620}, /*Unicode: U+0064 (d)*/ {.w_px = 4, .glyph_index = 2660}, /*Unicode: U+0065 (e)*/ {.w_px = 3, .glyph_index = 2700}, /*Unicode: U+0066 (f)*/ {.w_px = 4, .glyph_index = 2730}, /*Unicode: U+0067 (g)*/ {.w_px = 4, .glyph_index = 2770}, /*Unicode: U+0068 (h)*/ {.w_px = 1, .glyph_index = 2810}, /*Unicode: U+0069 (i)*/ {.w_px = 2, .glyph_index = 2820}, /*Unicode: U+006a (j)*/ {.w_px = 4, .glyph_index = 2840}, /*Unicode: U+006b (k)*/ {.w_px = 1, .glyph_index = 2880}, /*Unicode: U+006c (l)*/ {.w_px = 7, .glyph_index = 2890}, /*Unicode: U+006d (m)*/ {.w_px = 4, .glyph_index = 2960}, /*Unicode: U+006e (n)*/ {.w_px = 4, .glyph_index = 3000}, /*Unicode: U+006f (o)*/ {.w_px = 4, .glyph_index = 3040}, /*Unicode: U+0070 (p)*/ {.w_px = 4, .glyph_index = 3080}, /*Unicode: U+0071 (q)*/ {.w_px = 3, .glyph_index = 3120}, /*Unicode: U+0072 (r)*/ {.w_px = 3, .glyph_index = 3150}, /*Unicode: U+0073 (s)*/ {.w_px = 3, .glyph_index = 3180}, /*Unicode: U+0074 (t)*/ {.w_px = 4, .glyph_index = 3210}, /*Unicode: U+0075 (u)*/ {.w_px = 4, .glyph_index = 3250}, /*Unicode: U+0076 (v)*/ {.w_px = 6, .glyph_index = 3290}, /*Unicode: U+0077 (w)*/ {.w_px = 4, .glyph_index = 3350}, /*Unicode: U+0078 (x)*/ {.w_px = 4, .glyph_index = 3390}, /*Unicode: U+0079 (y)*/ {.w_px = 4, .glyph_index = 3430}, /*Unicode: U+007a (z)*/ {.w_px = 3, .glyph_index = 3470}, /*Unicode: U+007b ({)*/ {.w_px = 1, .glyph_index = 3500}, /*Unicode: U+007c (|)*/ {.w_px = 3, .glyph_index = 3510}, /*Unicode: U+007d (})*/ {.w_px = 5, .glyph_index = 3540}, /*Unicode: U+007e (~)*/ #endif }; lv_font_t lv_font_dejavu_10 = { .unicode_first = 32, /*First Unicode letter in this font*/ .unicode_last = 126, /*Last Unicode letter in this font*/ .h_px = 10, /*Font height in pixels*/ .glyph_cnt = 95, /*Number of glyphs in the font*/ .glyph_bitmap = lv_font_dejavu_10_glyph_bitmap, /*Bitmap of glyphs*/ .glyph_dsc = lv_font_dejavu_10_glyph_dsc, /*Description of glyphs*/ .unicode_list = NULL, /*Every character in the font from 'unicode_first' to 'unicode_last'*/ .get_bitmap = lv_font_get_bitmap_continuous, /*Function pointer to get glyph's bitmap*/ .get_width = lv_font_get_width_continuous, /*Function pointer to get glyph's width*/ #if USE_LV_FONT_DEJAVU_10 == 1 .bpp = 1, /*Bit per pixel*/ #elif USE_LV_FONT_DEJAVU_10 == 2 .bpp = 2, /*Bit per pixel*/ #elif USE_LV_FONT_DEJAVU_10 == 4 .bpp = 4, /*Bit per pixel*/ #elif USE_LV_FONT_DEJAVU_10 == 8 .bpp = 8, /*Bit per pixel*/ #endif .monospace = 0, .next_page = NULL, /*Pointer to a font extension*/ }; #endif /*USE_LV_FONT_DEJAVU_10*/
0a3852722deaa3d89b5fb0aca1a9f35dacdb5f26
0744dcc5394cebf57ebcba343747af6871b67017
/external/iotjs/deps/jerry/jerry-core/debugger/debugger.c
a3235b8048b9bd9b5e5d253937ee82805a73c46c
[ "Apache-2.0", "MIT", "LicenseRef-scancode-dco-1.1" ]
permissive
Samsung/TizenRT
96abf62f1853f61fcf91ff14671a5e0c6ca48fdb
1a5c2e00a4b1bbf4c505bbf5cc6a8259e926f686
refs/heads/master
2023-08-31T08:59:33.327998
2023-08-08T06:09:20
2023-08-31T04:38:20
82,517,252
590
719
Apache-2.0
2023-09-14T06:54:49
2017-02-20T04:38:30
C
UTF-8
C
false
false
34,640
c
debugger.c
/* Copyright JS Foundation and other contributors, http://js.foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define _XOPEN_SOURCE 500 /* Required macro for sleep functions */ #include "byte-code.h" #include "debugger.h" #include "ecma-builtin-helpers.h" #include "ecma-conversion.h" #include "ecma-eval.h" #include "ecma-objects.h" #include "jcontext.h" #include "lit-char-helpers.h" #ifdef JERRY_DEBUGGER #ifdef HAVE_TIME_H #include <time.h> #elif defined (HAVE_UNISTD_H) #include <unistd.h> #endif /* HAVE_TIME_H */ /** * Type cast the debugger send buffer into a specific type. */ #define JERRY_DEBUGGER_SEND_BUFFER_AS(type, name_p) \ type *name_p = (type *) (&JERRY_CONTEXT (debugger_send_buffer)) /** * Type cast the debugger receive buffer into a specific type. */ #define JERRY_DEBUGGER_RECEIVE_BUFFER_AS(type, name_p) \ type *name_p = ((type *) recv_buffer_p) /** * Free all unreferenced byte code structures which * were not acknowledged by the debugger client. */ void jerry_debugger_free_unreferenced_byte_code (void) { jerry_debugger_byte_code_free_t *byte_code_free_p; byte_code_free_p = JMEM_CP_GET_POINTER (jerry_debugger_byte_code_free_t, JERRY_CONTEXT (debugger_byte_code_free_tail)); while (byte_code_free_p != NULL) { jerry_debugger_byte_code_free_t *prev_byte_code_free_p; prev_byte_code_free_p = JMEM_CP_GET_POINTER (jerry_debugger_byte_code_free_t, byte_code_free_p->prev_cp); jmem_heap_free_block (byte_code_free_p, ((size_t) byte_code_free_p->size) << JMEM_ALIGNMENT_LOG); byte_code_free_p = prev_byte_code_free_p; } } /* jerry_debugger_free_unreferenced_byte_code */ /** * Send backtrace. */ static void jerry_debugger_send_backtrace (uint8_t *recv_buffer_p) /**< pointer the the received data */ { JERRY_DEBUGGER_RECEIVE_BUFFER_AS (jerry_debugger_receive_get_backtrace_t, get_backtrace_p); uint32_t max_depth; memcpy (&max_depth, get_backtrace_p->max_depth, sizeof (uint32_t)); if (max_depth == 0) { max_depth = UINT32_MAX; } JERRY_DEBUGGER_SEND_BUFFER_AS (jerry_debugger_send_backtrace_t, backtrace_p); JERRY_DEBUGGER_INIT_SEND_MESSAGE (backtrace_p); JERRY_DEBUGGER_SET_SEND_MESSAGE_SIZE_FROM_TYPE (backtrace_p, jerry_debugger_send_backtrace_t); backtrace_p->type = JERRY_DEBUGGER_BACKTRACE; vm_frame_ctx_t *frame_ctx_p = JERRY_CONTEXT (vm_top_context_p); uint32_t current_frame = 0; while (frame_ctx_p != NULL && max_depth > 0) { if (frame_ctx_p->bytecode_header_p->status_flags & CBC_CODE_FLAGS_DEBUGGER_IGNORE) { frame_ctx_p = frame_ctx_p->prev_context_p; continue; } if (current_frame >= JERRY_DEBUGGER_SEND_MAX (jerry_debugger_frame_t)) { if (!jerry_debugger_send (sizeof (jerry_debugger_send_backtrace_t))) { return; } current_frame = 0; } jerry_debugger_frame_t *frame_p = backtrace_p->frames + current_frame; jmem_cpointer_t byte_code_cp; JMEM_CP_SET_NON_NULL_POINTER (byte_code_cp, frame_ctx_p->bytecode_header_p); memcpy (frame_p->byte_code_cp, &byte_code_cp, sizeof (jmem_cpointer_t)); uint32_t offset = (uint32_t) (frame_ctx_p->byte_code_p - (uint8_t *) frame_ctx_p->bytecode_header_p); memcpy (frame_p->offset, &offset, sizeof (uint32_t)); frame_ctx_p = frame_ctx_p->prev_context_p; current_frame++; max_depth--; } size_t message_size = current_frame * sizeof (jerry_debugger_frame_t); JERRY_DEBUGGER_SET_SEND_MESSAGE_SIZE (backtrace_p, 1 + message_size); backtrace_p->type = JERRY_DEBUGGER_BACKTRACE_END; jerry_debugger_send (sizeof (jerry_debugger_send_type_t) + message_size); } /* jerry_debugger_send_backtrace */ /** * Send result of evaluated expression. * * @return true - if no error is occured * false - otherwise */ static bool jerry_debugger_send_eval (const lit_utf8_byte_t *eval_string_p, /**< evaluated string */ size_t eval_string_size) /**< evaluated string size */ { JERRY_ASSERT (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED); JERRY_ASSERT (!(JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_VM_IGNORE)); JERRY_CONTEXT (debugger_flags) = (uint8_t) (JERRY_CONTEXT (debugger_flags) | JERRY_DEBUGGER_VM_IGNORE); ecma_value_t result = ecma_op_eval_chars_buffer (eval_string_p, eval_string_size, true, false); JERRY_CONTEXT (debugger_flags) = (uint8_t) (JERRY_CONTEXT (debugger_flags) & ~JERRY_DEBUGGER_VM_IGNORE); if (!ECMA_IS_VALUE_ERROR (result)) { ecma_value_t to_string_value = ecma_op_to_string (result); ecma_free_value (result); result = to_string_value; } ecma_value_t message = result; uint8_t type = JERRY_DEBUGGER_EVAL_OK; if (ECMA_IS_VALUE_ERROR (result)) { type = JERRY_DEBUGGER_EVAL_ERROR; if (ecma_is_value_object (result)) { ecma_string_t *message_string_p = ecma_get_magic_string (LIT_MAGIC_STRING_MESSAGE); message = ecma_op_object_find (ecma_get_object_from_value (result), message_string_p); ecma_deref_ecma_string (message_string_p); if (!ecma_is_value_string (message) || ecma_string_is_empty (ecma_get_string_from_value (message))) { ecma_free_value (message); lit_magic_string_id_t id = ecma_object_get_class_name (ecma_get_object_from_value (result)); ecma_free_value (result); const lit_utf8_byte_t *string_p = lit_get_magic_string_utf8 (id); return jerry_debugger_send_string (JERRY_DEBUGGER_EVAL_RESULT, type, string_p, strlen ((const char *) string_p)); } } else { /* Primitve type. */ message = ecma_op_to_string (result); JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (message)); } ecma_free_value (result); } ecma_string_t *string_p = ecma_get_string_from_value (message); ECMA_STRING_TO_UTF8_STRING (string_p, buffer_p, buffer_size); bool success = jerry_debugger_send_string (JERRY_DEBUGGER_EVAL_RESULT, type, buffer_p, buffer_size); ECMA_FINALIZE_UTF8_STRING (buffer_p, buffer_size); ecma_free_value (message); return success; } /* jerry_debugger_send_eval */ /** * Suspend execution for a given time. * Note: If the platform does not have nanosleep or usleep, this function does not sleep at all. */ void jerry_debugger_sleep (void) { #ifdef HAVE_TIME_H nanosleep (&(const struct timespec) { JERRY_DEBUGGER_TIMEOUT / 1000, (JERRY_DEBUGGER_TIMEOUT % 1000) * 1000000L /* Seconds, nanoseconds */ } , NULL); #elif defined (HAVE_UNISTD_H) usleep ((useconds_t) JERRY_DEBUGGER_TIMEOUT * 1000); #endif /* HAVE_TIME_H */ } /* jerry_debugger_sleep */ /** * Check received packet size. */ #define JERRY_DEBUGGER_CHECK_PACKET_SIZE(type) \ if (message_size != sizeof (type)) \ { \ jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Invalid message size\n"); \ jerry_debugger_close_connection (); \ return false; \ } /** * Receive message from the client. * * @return true - if message is processed successfully * false - otherwise */ inline bool __attr_always_inline___ jerry_debugger_process_message (uint8_t *recv_buffer_p, /**< pointer the the received data */ uint32_t message_size, /**< message size */ bool *resume_exec_p, /**< pointer to the resume exec flag */ uint8_t *expected_message_type_p, /**< message type */ jerry_debugger_uint8_data_t **message_data_p) /**< custom message data */ { /* Process the received message. */ if (recv_buffer_p[0] >= JERRY_DEBUGGER_CONTINUE && !(JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_BREAKPOINT_MODE)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Message requires breakpoint mode\n"); jerry_debugger_close_connection (); return false; } if (*expected_message_type_p != 0) { JERRY_ASSERT (*expected_message_type_p == JERRY_DEBUGGER_EVAL_PART || *expected_message_type_p == JERRY_DEBUGGER_CLIENT_SOURCE_PART); jerry_debugger_uint8_data_t *uint8_data_p = (jerry_debugger_uint8_data_t *) *message_data_p; if (recv_buffer_p[0] != *expected_message_type_p) { jmem_heap_free_block (uint8_data_p, uint8_data_p->uint8_size + sizeof (jerry_debugger_uint8_data_t)); jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Unexpected message\n"); jerry_debugger_close_connection (); return false; } JERRY_DEBUGGER_RECEIVE_BUFFER_AS (jerry_debugger_receive_uint8_data_part_t, uint8_data_part_p); if (message_size < sizeof (jerry_debugger_receive_uint8_data_part_t) + 1) { jmem_heap_free_block (uint8_data_p, uint8_data_p->uint8_size + sizeof (jerry_debugger_uint8_data_t)); jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Invalid message size\n"); jerry_debugger_close_connection (); return false; } uint32_t expected_data = uint8_data_p->uint8_size - uint8_data_p->uint8_offset; message_size -= (uint32_t) sizeof (jerry_debugger_receive_uint8_data_part_t); if (message_size > expected_data) { jmem_heap_free_block (uint8_data_p, uint8_data_p->uint8_size + sizeof (jerry_debugger_uint8_data_t)); jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Invalid message size\n"); jerry_debugger_close_connection (); return false; } lit_utf8_byte_t *string_p = (lit_utf8_byte_t *) (uint8_data_p + 1); memcpy (string_p + uint8_data_p->uint8_offset, (lit_utf8_byte_t *) (uint8_data_part_p + 1), message_size); if (message_size < expected_data) { uint8_data_p->uint8_offset += message_size; return true; } bool result = false; if (*expected_message_type_p == JERRY_DEBUGGER_EVAL_PART) { result = jerry_debugger_send_eval (string_p, uint8_data_p->uint8_size); } else { result = true; JERRY_CONTEXT (debugger_flags) = (uint8_t) (JERRY_CONTEXT (debugger_flags) & ~JERRY_DEBUGGER_CLIENT_SOURCE_MODE); *resume_exec_p = true; } *expected_message_type_p = 0; return result; } switch (recv_buffer_p[0]) { case JERRY_DEBUGGER_FREE_BYTE_CODE_CP: { JERRY_DEBUGGER_CHECK_PACKET_SIZE (jerry_debugger_receive_byte_code_cp_t); JERRY_DEBUGGER_RECEIVE_BUFFER_AS (jerry_debugger_receive_byte_code_cp_t, byte_code_p); jmem_cpointer_t byte_code_free_cp; memcpy (&byte_code_free_cp, byte_code_p->byte_code_cp, sizeof (jmem_cpointer_t)); if (byte_code_free_cp != JERRY_CONTEXT (debugger_byte_code_free_tail)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Invalid byte code free order\n"); jerry_debugger_close_connection (); return false; } jerry_debugger_byte_code_free_t *byte_code_free_p; byte_code_free_p = JMEM_CP_GET_NON_NULL_POINTER (jerry_debugger_byte_code_free_t, byte_code_free_cp); if (byte_code_free_p->prev_cp != ECMA_NULL_POINTER) { JERRY_CONTEXT (debugger_byte_code_free_tail) = byte_code_free_p->prev_cp; } else { JERRY_CONTEXT (debugger_byte_code_free_head) = ECMA_NULL_POINTER; JERRY_CONTEXT (debugger_byte_code_free_tail) = ECMA_NULL_POINTER; } #ifdef JMEM_STATS jmem_stats_free_byte_code_bytes (((size_t) byte_code_free_p->size) << JMEM_ALIGNMENT_LOG); #endif /* JMEM_STATS */ jmem_heap_free_block (byte_code_free_p, ((size_t) byte_code_free_p->size) << JMEM_ALIGNMENT_LOG); return true; } case JERRY_DEBUGGER_UPDATE_BREAKPOINT: { JERRY_DEBUGGER_CHECK_PACKET_SIZE (jerry_debugger_receive_update_breakpoint_t); JERRY_DEBUGGER_RECEIVE_BUFFER_AS (jerry_debugger_receive_update_breakpoint_t, update_breakpoint_p); jmem_cpointer_t byte_code_cp; memcpy (&byte_code_cp, update_breakpoint_p->byte_code_cp, sizeof (jmem_cpointer_t)); uint8_t *byte_code_p = JMEM_CP_GET_NON_NULL_POINTER (uint8_t, byte_code_cp); uint32_t offset; memcpy (&offset, update_breakpoint_p->offset, sizeof (uint32_t)); byte_code_p += offset; JERRY_ASSERT (*byte_code_p == CBC_BREAKPOINT_ENABLED || *byte_code_p == CBC_BREAKPOINT_DISABLED); *byte_code_p = update_breakpoint_p->is_set_breakpoint ? CBC_BREAKPOINT_ENABLED : CBC_BREAKPOINT_DISABLED; return true; } case JERRY_DEBUGGER_MEMSTATS: { JERRY_DEBUGGER_CHECK_PACKET_SIZE (jerry_debugger_receive_type_t); jerry_debugger_send_memstats (); return true; } case JERRY_DEBUGGER_STOP: { JERRY_DEBUGGER_CHECK_PACKET_SIZE (jerry_debugger_receive_type_t); JERRY_CONTEXT (debugger_flags) = (uint8_t) (JERRY_CONTEXT (debugger_flags) | JERRY_DEBUGGER_VM_STOP); JERRY_CONTEXT (debugger_stop_context) = NULL; *resume_exec_p = false; return true; } case JERRY_DEBUGGER_CONTINUE: { JERRY_DEBUGGER_CHECK_PACKET_SIZE (jerry_debugger_receive_type_t); JERRY_CONTEXT (debugger_flags) = (uint8_t) (JERRY_CONTEXT (debugger_flags) & ~JERRY_DEBUGGER_VM_STOP); JERRY_CONTEXT (debugger_stop_context) = NULL; *resume_exec_p = true; return true; } case JERRY_DEBUGGER_STEP: { JERRY_DEBUGGER_CHECK_PACKET_SIZE (jerry_debugger_receive_type_t); JERRY_CONTEXT (debugger_flags) = (uint8_t) (JERRY_CONTEXT (debugger_flags) | JERRY_DEBUGGER_VM_STOP); JERRY_CONTEXT (debugger_stop_context) = NULL; *resume_exec_p = true; return true; } case JERRY_DEBUGGER_NEXT: { JERRY_DEBUGGER_CHECK_PACKET_SIZE (jerry_debugger_receive_type_t); JERRY_CONTEXT (debugger_flags) = (uint8_t) (JERRY_CONTEXT (debugger_flags) | JERRY_DEBUGGER_VM_STOP); JERRY_CONTEXT (debugger_stop_context) = JERRY_CONTEXT (vm_top_context_p); *resume_exec_p = true; return true; } case JERRY_DEBUGGER_GET_BACKTRACE: { JERRY_DEBUGGER_CHECK_PACKET_SIZE (jerry_debugger_receive_get_backtrace_t); jerry_debugger_send_backtrace (recv_buffer_p); return true; } case JERRY_DEBUGGER_EXCEPTION_CONFIG: { JERRY_DEBUGGER_CHECK_PACKET_SIZE (jerry_debugger_receive_exception_config_t); JERRY_DEBUGGER_RECEIVE_BUFFER_AS (jerry_debugger_receive_exception_config_t, exception_config_p); uint8_t debugger_flags = JERRY_CONTEXT (debugger_flags); if (exception_config_p->enable == 0) { debugger_flags = (uint8_t) (debugger_flags | JERRY_DEBUGGER_VM_IGNORE_EXCEPTION); jerry_port_log (JERRY_LOG_LEVEL_DEBUG, "Stop at exception disabled\n"); } else { debugger_flags = (uint8_t) (debugger_flags & ~JERRY_DEBUGGER_VM_IGNORE_EXCEPTION); jerry_port_log (JERRY_LOG_LEVEL_DEBUG, "Stop at exception enabled\n"); } JERRY_CONTEXT (debugger_flags) = debugger_flags; return true; } case JERRY_DEBUGGER_EVAL: { if (message_size < sizeof (jerry_debugger_receive_eval_first_t) + 1) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Invalid message size\n"); jerry_debugger_close_connection (); return false; } JERRY_DEBUGGER_RECEIVE_BUFFER_AS (jerry_debugger_receive_eval_first_t, eval_first_p); uint32_t eval_size; memcpy (&eval_size, eval_first_p->eval_size, sizeof (uint32_t)); if (eval_size <= JERRY_DEBUGGER_MAX_RECEIVE_SIZE - sizeof (jerry_debugger_receive_eval_first_t)) { if (eval_size != message_size - sizeof (jerry_debugger_receive_eval_first_t)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Invalid message size\n"); jerry_debugger_close_connection (); return false; } return jerry_debugger_send_eval ((lit_utf8_byte_t *) (eval_first_p + 1), eval_size); } jerry_debugger_uint8_data_t *eval_uint8_data_p; size_t eval_data_size = sizeof (jerry_debugger_uint8_data_t) + eval_size; eval_uint8_data_p = (jerry_debugger_uint8_data_t *) jmem_heap_alloc_block (eval_data_size); eval_uint8_data_p->uint8_size = eval_size; eval_uint8_data_p->uint8_offset = (uint32_t) (message_size - sizeof (jerry_debugger_receive_eval_first_t)); lit_utf8_byte_t *eval_string_p = (lit_utf8_byte_t *) (eval_uint8_data_p + 1); memcpy (eval_string_p, (lit_utf8_byte_t *) (eval_first_p + 1), message_size - sizeof (jerry_debugger_receive_eval_first_t)); *message_data_p = eval_uint8_data_p; *expected_message_type_p = JERRY_DEBUGGER_EVAL_PART; return true; } case JERRY_DEBUGGER_CLIENT_SOURCE: { if (message_size <= sizeof (jerry_debugger_receive_client_source_first_t)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Invalid message size\n"); jerry_debugger_close_connection (); return false; } if (!(JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CLIENT_SOURCE_MODE)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Not in client source mode\n"); jerry_debugger_close_connection (); return false; } JERRY_DEBUGGER_RECEIVE_BUFFER_AS (jerry_debugger_receive_client_source_first_t, client_source_first_p); uint32_t client_source_size; memcpy (&client_source_size, client_source_first_p->code_size, sizeof (uint32_t)); if (client_source_size <= JERRY_DEBUGGER_MAX_RECEIVE_SIZE - sizeof (jerry_debugger_receive_client_source_first_t) && client_source_size != message_size - sizeof (jerry_debugger_receive_client_source_first_t)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Invalid message size\n"); jerry_debugger_close_connection (); return false; } jerry_debugger_uint8_data_t *client_source_data_p; size_t client_source_data_size = sizeof (jerry_debugger_uint8_data_t) + client_source_size; client_source_data_p = (jerry_debugger_uint8_data_t *) jmem_heap_alloc_block (client_source_data_size); client_source_data_p->uint8_size = client_source_size; client_source_data_p->uint8_offset = (uint32_t) (message_size - sizeof (jerry_debugger_receive_client_source_first_t)); lit_utf8_byte_t *client_source_string_p = (lit_utf8_byte_t *) (client_source_data_p + 1); memcpy (client_source_string_p, (lit_utf8_byte_t *) (client_source_first_p + 1), message_size - sizeof (jerry_debugger_receive_client_source_first_t)); *message_data_p = client_source_data_p; if (client_source_data_p->uint8_size != client_source_data_p->uint8_offset) { *expected_message_type_p = JERRY_DEBUGGER_CLIENT_SOURCE_PART; } else { JERRY_CONTEXT (debugger_flags) = (uint8_t) (JERRY_CONTEXT (debugger_flags) & ~JERRY_DEBUGGER_CLIENT_SOURCE_MODE); *resume_exec_p = true; } return true; } case JERRY_DEBUGGER_NO_MORE_SOURCES: { if (!(JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CLIENT_SOURCE_MODE)) { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Not in client source mode\n"); jerry_debugger_close_connection (); return false; } JERRY_DEBUGGER_CHECK_PACKET_SIZE (jerry_debugger_receive_type_t); JERRY_CONTEXT (debugger_flags) = (uint8_t) (JERRY_CONTEXT (debugger_flags) & ~JERRY_DEBUGGER_CLIENT_SOURCE_MODE); JERRY_CONTEXT (debugger_flags) = (uint8_t) (JERRY_CONTEXT (debugger_flags) | JERRY_DEBUGGER_CLIENT_NO_SOURCE); *resume_exec_p = true; return true; } default: { jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Unexpected message."); jerry_debugger_close_connection (); return false; } } } /* jerry_debugger_process_message */ #undef JERRY_DEBUGGER_CHECK_PACKET_SIZE /** * Tell the client that a breakpoint has been hit and wait for further debugger commands. */ void jerry_debugger_breakpoint_hit (uint8_t message_type) /**< message type */ { JERRY_ASSERT (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED); JERRY_DEBUGGER_SEND_BUFFER_AS (jerry_debugger_send_breakpoint_hit_t, breakpoint_hit_p); JERRY_DEBUGGER_INIT_SEND_MESSAGE (breakpoint_hit_p); JERRY_DEBUGGER_SET_SEND_MESSAGE_SIZE_FROM_TYPE (breakpoint_hit_p, jerry_debugger_send_breakpoint_hit_t); breakpoint_hit_p->type = message_type; vm_frame_ctx_t *frame_ctx_p = JERRY_CONTEXT (vm_top_context_p); jmem_cpointer_t byte_code_header_cp; JMEM_CP_SET_NON_NULL_POINTER (byte_code_header_cp, frame_ctx_p->bytecode_header_p); memcpy (breakpoint_hit_p->byte_code_cp, &byte_code_header_cp, sizeof (jmem_cpointer_t)); uint32_t offset = (uint32_t) (frame_ctx_p->byte_code_p - (uint8_t *) frame_ctx_p->bytecode_header_p); memcpy (breakpoint_hit_p->offset, &offset, sizeof (uint32_t)); if (!jerry_debugger_send (sizeof (jerry_debugger_send_breakpoint_hit_t))) { return; } JERRY_CONTEXT (debugger_flags) = (uint8_t) (JERRY_CONTEXT (debugger_flags) | JERRY_DEBUGGER_BREAKPOINT_MODE); jerry_debugger_uint8_data_t *uint8_data = NULL; while (!jerry_debugger_receive (&uint8_data)) { jerry_debugger_sleep (); } if (uint8_data != NULL) { jmem_heap_free_block (uint8_data, uint8_data->uint8_size + sizeof (jerry_debugger_uint8_data_t)); } JERRY_CONTEXT (debugger_flags) = (uint8_t) (JERRY_CONTEXT (debugger_flags) & ~JERRY_DEBUGGER_BREAKPOINT_MODE); JERRY_CONTEXT (debugger_message_delay) = JERRY_DEBUGGER_MESSAGE_FREQUENCY; } /* jerry_debugger_breakpoint_hit */ /** * Send the type signal to the client. */ void jerry_debugger_send_type (jerry_debugger_header_type_t type) /**< message type */ { JERRY_ASSERT (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED); JERRY_DEBUGGER_SEND_BUFFER_AS (jerry_debugger_send_type_t, message_type_p); JERRY_DEBUGGER_INIT_SEND_MESSAGE (message_type_p); JERRY_DEBUGGER_SET_SEND_MESSAGE_SIZE_FROM_TYPE (message_type_p, jerry_debugger_send_type_t); message_type_p->type = (uint8_t) type; jerry_debugger_send (sizeof (jerry_debugger_send_type_t)); } /* jerry_debugger_send_type */ /** * Send the type signal to the client. * * @return true - if the data sent successfully to the debugger client, * false - otherwise */ bool jerry_debugger_send_configuration (uint8_t max_message_size) /**< maximum message size */ { JERRY_DEBUGGER_SEND_BUFFER_AS (jerry_debugger_send_configuration_t, configuration_p); /* Helper structure for endianness check. */ union { uint16_t uint16_value; /**< a 16-bit value */ uint8_t uint8_value[2]; /**< lower and upper byte of a 16-bit value */ } endian_data; endian_data.uint16_value = 1; JERRY_DEBUGGER_INIT_SEND_MESSAGE (configuration_p); JERRY_DEBUGGER_SET_SEND_MESSAGE_SIZE_FROM_TYPE (configuration_p, jerry_debugger_send_configuration_t); configuration_p->type = JERRY_DEBUGGER_CONFIGURATION; configuration_p->max_message_size = max_message_size; configuration_p->cpointer_size = sizeof (jmem_cpointer_t); configuration_p->little_endian = (endian_data.uint8_value[0] == 1); return jerry_debugger_send (sizeof (jerry_debugger_send_configuration_t)); } /* jerry_debugger_send_configuration */ /** * Send raw data to the debugger client. */ void jerry_debugger_send_data (jerry_debugger_header_type_t type, /**< message type */ const void *data, /**< raw data */ size_t size) /**< size of data */ { JERRY_ASSERT (size <= JERRY_DEBUGGER_SEND_MAX (uint8_t)); JERRY_DEBUGGER_SEND_BUFFER_AS (jerry_debugger_send_type_t, message_type_p); JERRY_DEBUGGER_INIT_SEND_MESSAGE (message_type_p); JERRY_DEBUGGER_SET_SEND_MESSAGE_SIZE (message_type_p, 1 + size); message_type_p->type = type; memcpy (message_type_p + 1, data, size); jerry_debugger_send (sizeof (jerry_debugger_send_type_t) + size); } /* jerry_debugger_send_data */ /** * Send string to the debugger client. * * @return true - if the data sent successfully to the debugger client, * false - otherwise */ bool jerry_debugger_send_string (uint8_t message_type, /**< message type */ uint8_t sub_type, /**< subtype of the string */ const uint8_t *string_p, /**< string data */ size_t string_length) /**< length of string */ { JERRY_ASSERT (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED); const size_t max_fragment_len = JERRY_DEBUGGER_SEND_MAX (uint8_t); JERRY_DEBUGGER_SEND_BUFFER_AS (jerry_debugger_send_string_t, message_string_p); JERRY_DEBUGGER_INIT_SEND_MESSAGE (message_string_p); JERRY_DEBUGGER_SET_SEND_MESSAGE_SIZE_FROM_TYPE (message_string_p, jerry_debugger_send_string_t); message_string_p->type = message_type; while (string_length > max_fragment_len) { memcpy (message_string_p->string, string_p, max_fragment_len); if (!jerry_debugger_send (sizeof (jerry_debugger_send_string_t))) { return false; } string_length -= max_fragment_len; string_p += max_fragment_len; } if (sub_type != JERRY_DEBUGGER_NO_SUBTYPE) { string_length += 1; } JERRY_DEBUGGER_SET_SEND_MESSAGE_SIZE (message_string_p, 1 + string_length); message_string_p->type = (uint8_t) (message_type + 1); memcpy (message_string_p->string, string_p, string_length); if (sub_type != JERRY_DEBUGGER_NO_SUBTYPE) { message_string_p->string[string_length - 1] = sub_type; } return jerry_debugger_send (sizeof (jerry_debugger_send_type_t) + string_length); } /* jerry_debugger_send_string */ /** * Send the function compressed pointer to the debugger client. * * @return true - if the data was sent successfully to the debugger client, * false - otherwise */ bool jerry_debugger_send_function_cp (jerry_debugger_header_type_t type, /**< message type */ ecma_compiled_code_t *compiled_code_p) /**< byte code pointer */ { JERRY_ASSERT (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED); JERRY_DEBUGGER_SEND_BUFFER_AS (jerry_debugger_send_byte_code_cp_t, byte_code_cp_p); JERRY_DEBUGGER_INIT_SEND_MESSAGE (byte_code_cp_p); JERRY_DEBUGGER_SET_SEND_MESSAGE_SIZE_FROM_TYPE (byte_code_cp_p, jerry_debugger_send_byte_code_cp_t); byte_code_cp_p->type = (uint8_t) type; jmem_cpointer_t compiled_code_cp; JMEM_CP_SET_NON_NULL_POINTER (compiled_code_cp, compiled_code_p); memcpy (byte_code_cp_p->byte_code_cp, &compiled_code_cp, sizeof (jmem_cpointer_t)); return jerry_debugger_send (sizeof (jerry_debugger_send_byte_code_cp_t)); } /* jerry_debugger_send_function_cp */ /** * Send function data to the debugger client. * * @return true - if the data sent successfully to the debugger client, * false - otherwise */ bool jerry_debugger_send_parse_function (uint32_t line, /**< line */ uint32_t column) /**< column */ { JERRY_ASSERT (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED); JERRY_DEBUGGER_SEND_BUFFER_AS (jerry_debugger_send_parse_function_t, message_parse_function_p); JERRY_DEBUGGER_INIT_SEND_MESSAGE (message_parse_function_p); JERRY_DEBUGGER_SET_SEND_MESSAGE_SIZE_FROM_TYPE (message_parse_function_p, jerry_debugger_send_parse_function_t); message_parse_function_p->type = JERRY_DEBUGGER_PARSE_FUNCTION; memcpy (message_parse_function_p->line, &line, sizeof (uint32_t)); memcpy (message_parse_function_p->column, &column, sizeof (uint32_t)); return jerry_debugger_send (sizeof (jerry_debugger_send_parse_function_t)); } /* jerry_debugger_send_parse_function */ /** * Send memory statistics to the debugger client. */ void jerry_debugger_send_memstats (void) { JERRY_ASSERT (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED); JERRY_DEBUGGER_SEND_BUFFER_AS (jerry_debugger_send_memstats_t, memstats_p); JERRY_DEBUGGER_INIT_SEND_MESSAGE (memstats_p); JERRY_DEBUGGER_SET_SEND_MESSAGE_SIZE_FROM_TYPE (memstats_p, jerry_debugger_send_memstats_t); memstats_p->type = JERRY_DEBUGGER_MEMSTATS_RECEIVE; #ifdef JMEM_STATS /* if jmem_stats are defined */ jmem_heap_stats_t *heap_stats = &JERRY_CONTEXT (jmem_heap_stats); uint32_t allocated_bytes = (uint32_t) heap_stats->allocated_bytes; memcpy (memstats_p->allocated_bytes, &allocated_bytes, sizeof (uint32_t)); uint32_t byte_code_bytes = (uint32_t) heap_stats->byte_code_bytes; memcpy (memstats_p->byte_code_bytes, &byte_code_bytes, sizeof (uint32_t)); uint32_t string_bytes = (uint32_t) heap_stats->string_bytes; memcpy (memstats_p->string_bytes, &string_bytes, sizeof (uint32_t)); uint32_t object_bytes = (uint32_t) heap_stats->object_bytes; memcpy (memstats_p->object_bytes, &object_bytes, sizeof (uint32_t)); uint32_t property_bytes = (uint32_t) heap_stats->property_bytes; memcpy (memstats_p->property_bytes, &property_bytes, sizeof (uint32_t)); #else /* if not, just put zeros */ memset (memstats_p->allocated_bytes, 0, sizeof (uint32_t)); memset (memstats_p->byte_code_bytes, 0, sizeof (uint32_t)); memset (memstats_p->string_bytes, 0, sizeof (uint32_t)); memset (memstats_p->object_bytes, 0, sizeof (uint32_t)); memset (memstats_p->property_bytes, 0, sizeof (uint32_t)); #endif jerry_debugger_send (sizeof (jerry_debugger_send_memstats_t)); } /* jerry_debugger_send_memstats */ /* * Converts an standard error into a string. * * @return standard error string */ static ecma_string_t * jerry_debugger_exception_object_to_string (ecma_value_t exception_obj_value) /**< exception object */ { ecma_object_t *object_p = ecma_get_object_from_value (exception_obj_value); ecma_object_t *prototype_p = ecma_get_object_prototype (object_p); if (prototype_p == NULL || ecma_get_object_type (prototype_p) != ECMA_OBJECT_TYPE_GENERAL || !ecma_get_object_is_builtin (prototype_p)) { return NULL; } lit_magic_string_id_t string_id; switch (((ecma_extended_object_t *) prototype_p)->u.built_in.id) { #ifndef CONFIG_DISABLE_ERROR_BUILTINS case ECMA_BUILTIN_ID_EVAL_ERROR_PROTOTYPE: { string_id = LIT_MAGIC_STRING_EVAL_ERROR_UL; break; } case ECMA_BUILTIN_ID_RANGE_ERROR_PROTOTYPE: { string_id = LIT_MAGIC_STRING_RANGE_ERROR_UL; break; } case ECMA_BUILTIN_ID_REFERENCE_ERROR_PROTOTYPE: { string_id = LIT_MAGIC_STRING_REFERENCE_ERROR_UL; break; } case ECMA_BUILTIN_ID_SYNTAX_ERROR_PROTOTYPE: { string_id = LIT_MAGIC_STRING_SYNTAX_ERROR_UL; break; } case ECMA_BUILTIN_ID_TYPE_ERROR_PROTOTYPE: { string_id = LIT_MAGIC_STRING_TYPE_ERROR_UL; break; } case ECMA_BUILTIN_ID_URI_ERROR_PROTOTYPE: { string_id = LIT_MAGIC_STRING_URI_ERROR_UL; break; } #endif /* !CONFIG_DISABLE_ERROR_BUILTINS */ case ECMA_BUILTIN_ID_ERROR_PROTOTYPE: { string_id = LIT_MAGIC_STRING_ERROR_UL; break; } default: { return NULL; } } lit_utf8_size_t size = lit_get_magic_string_size (string_id); JERRY_ASSERT (size <= 14); lit_utf8_byte_t data[16]; memcpy (data, lit_get_magic_string_utf8 (string_id), size); ecma_string_t message_string; ecma_init_ecma_magic_string (&message_string, LIT_MAGIC_STRING_MESSAGE); ecma_property_t *property_p; property_p = ecma_find_named_property (ecma_get_object_from_value (exception_obj_value), &message_string); if (property_p == NULL || ECMA_PROPERTY_GET_TYPE (*property_p) != ECMA_PROPERTY_TYPE_NAMEDDATA) { return ecma_new_ecma_string_from_utf8 (data, size); } ecma_property_value_t *prop_value_p = ECMA_PROPERTY_VALUE_PTR (property_p); if (!ecma_is_value_string (prop_value_p->value)) { return ecma_new_ecma_string_from_utf8 (data, size); } data[size] = LIT_CHAR_COLON; data[size + 1] = LIT_CHAR_SP; ecma_string_t *type_string_p = ecma_new_ecma_string_from_utf8 (data, size + 2); ecma_string_t *string_p = ecma_concat_ecma_strings (type_string_p, ecma_get_string_from_value (prop_value_p->value)); ecma_deref_ecma_string (type_string_p); return string_p; } /* jerry_debugger_exception_object_to_string */ /** * Send string representation of exception to the client. * * @return true - if the data sent successfully to the debugger client, * false - otherwise */ bool jerry_debugger_send_exception_string (ecma_value_t exception_value) /**< error value */ { ecma_string_t *string_p = NULL; if (ecma_is_value_object (exception_value)) { ecma_value_t object_value = ecma_get_value_from_error_value (exception_value); string_p = jerry_debugger_exception_object_to_string (object_value); if (string_p == NULL) { string_p = ecma_get_string_from_value (ecma_builtin_helper_object_to_string (object_value)); } } else if (ecma_is_value_string (exception_value)) { string_p = ecma_get_string_from_value (exception_value); ecma_ref_ecma_string (string_p); } else { exception_value = ecma_op_to_string (exception_value); string_p = ecma_get_string_from_value (exception_value); } ECMA_STRING_TO_UTF8_STRING (string_p, string_data_p, string_size); bool result = jerry_debugger_send_string (JERRY_DEBUGGER_EXCEPTION_STR, JERRY_DEBUGGER_NO_SUBTYPE, string_data_p, string_size); ECMA_FINALIZE_UTF8_STRING (string_data_p, string_size); ecma_deref_ecma_string (string_p); return result; } /* jerry_debugger_send_exception_string */ #endif /* JERRY_DEBUGGER */
63e291b99fe2eeac8034495b1b301d69aecd5571
a5a99f646e371b45974a6fb6ccc06b0a674818f2
/Validation/HcalHits/test/rootlogon.C
8ffcebea419297a983f712a666e62c3c48464753
[ "Apache-2.0" ]
permissive
cms-sw/cmssw
4ecd2c1105d59c66d385551230542c6615b9ab58
19c178740257eb48367778593da55dcad08b7a4f
refs/heads/master
2023-08-23T21:57:42.491143
2023-08-22T20:22:40
2023-08-22T20:22:40
10,969,551
1,006
3,696
Apache-2.0
2023-09-14T19:14:28
2013-06-26T14:09:07
C++
UTF-8
C
false
false
2,175
c
rootlogon.C
{ cout << "FWlite ..." << endl; gSystem->Load("libFWCoreFWLite.so"); FWLiteEnabler::enable(); cout << "Redefining colors ..." << endl; TColor::InitializeColors(); TColor *color = (TColor*)(gROOT->GetListOfColors()->At(41)); color->SetRGB(1.0, 0.1, 0.5); // deep roze TColor *color = (TColor*)(gROOT->GetListOfColors()->At(42)); color->SetRGB(0.5, 0.8, 0.1); // light green TColor *color = (TColor*)(gROOT->GetListOfColors()->At(43)); color->SetRGB(0.1, 0.5, 0.3); // dark green TColor *color = (TColor*)(gROOT->GetListOfColors()->At(44)); color->SetRGB(0.5, 0.2, 0.8); // blue-violet TColor *color = (TColor*)(gROOT->GetListOfColors()->At(45)); color->SetRGB(0.2, 0.6, 0.9); // grey-blue TColor *color = (TColor*)(gROOT->GetListOfColors()->At(46)); color->SetRGB(1.0, 0.5, 0.0); // orange-brick TColor *color = (TColor*)(gROOT->GetListOfColors()->At(47)); color->SetRGB(0.8, 0.0, 0.0); // brick // TColor *color = (TColor*)(gROOT->GetListOfColors()->At(51)); color->SetRGB(1.0 , 1.0 , 0.8 ); // lightest yellow TColor *color = (TColor*)(gROOT->GetListOfColors()->At(52)); color->SetRGB(0.8 , 1.00, 1.00); // lightest blue-cyan TColor *color = (TColor*)(gROOT->GetListOfColors()->At(53)); color->SetRGB(1.0 , 0.95, 0.95); // lightest rose TColor *color = (TColor*)(gROOT->GetListOfColors()->At(54)); color->SetRGB(0.8 , 1.0 , 0.8 ); // lightest green TColor *color = (TColor*)(gROOT->GetListOfColors()->At(55)); color->SetRGB(1.00, 1.00, 1.00); // white gStyle->SetOptStat(0); gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(52); gStyle->SetTitleSize(0.06, "XYZ"); gStyle->SetTitleXOffset(0.9); gStyle->SetTitleYOffset(1.25); gStyle->SetLabelOffset(0.007, "XYZ"); gStyle->SetLabelSize(0.05, "XYZ"); gStyle->SetTitle(""); gStyle->SetOptTitle(0); gStyle->SetHistLineColor(45); gStyle->SetHistLineStyle(1); gStyle->SetHistLineWidth(2); gStyle->SetPadColor(52); gStyle->SetPadBorderSize(1); gStyle->SetPadBottomMargin(0.15); gStyle->SetPadTopMargin(0.1); gStyle->SetPadLeftMargin(0.15); gStyle->SetPadRightMargin(0.15); gStyle->SetFrameBorderMode(0); gStyle->SetFrameFillColor(55); }
7778f57d00a133fc44bb9e349c02358f41d7d366
cff4428975e403e4ef02d75498b78cd1a610a01a
/src/box/sql/sqlLimit.h
53dbe15059753e48da968a3835a5bca6f9cea1f3
[ "BSD-2-Clause" ]
permissive
tarantool/tarantool
c1f252b642d223af62485dc21165c7f7c3354e7e
f58cc96f2798ddc5f492223897d0b77e4f902128
refs/heads/master
2023-09-03T15:16:29.144171
2023-08-31T11:39:28
2023-09-01T12:39:29
911,980
3,205
490
NOASSERTION
2023-09-14T17:58:17
2010-09-15T07:59:26
Lua
UTF-8
C
false
false
6,090
h
sqlLimit.h
#ifndef TARANTOOL_SQL_sqlLIMIT_H_INCLUDED #define TARANTOOL_SQL_sqlLIMIT_H_INCLUDED /* * Copyright 2010-2017, Tarantool AUTHORS, please see AUTHORS file. * * 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 <COPYRIGHT HOLDER> ``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 * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * * This file defines various limits of what sql can process. */ #include "tt_static.h" enum { /* * The maximum value of a $nnn wildcard that the parser will accept. */ SQL_BIND_PARAMETER_MAX = 65000, }; /* * The maximum length of a TEXT or BLOB in bytes. This also * limits the size of a row in a table or index. * * The hard limit is the ability of a 32-bit signed integer * to count the size: 2^31-1 or 2147483647. */ #ifndef SQL_MAX_LENGTH #define SQL_MAX_LENGTH 1000000000 #endif /* * This is the maximum number of * * * Columns in a table * * Columns in an index * * Columns in a view * * Terms in the SET clause of an UPDATE statement * * Terms in the result set of a SELECT statement * * Terms in the GROUP BY or ORDER BY clauses of a SELECT statement. * * Terms in the VALUES clause of an INSERT statement * * The hard upper limit here is 32676. Most database people will * tell you that in a well-normalized database, you usually should * not have more than a dozen or so columns in any table. And if * that is the case, there is no point in having more than a few * dozen values in any of the other situations described above. */ #ifndef SQL_MAX_COLUMN #define SQL_MAX_COLUMN 2000 #endif /* * tt_static_buf() is used to store bitmask for used columns in a table during * SQL parsing stage. The following statement checks if static buffer is big * enough to store the bitmask. */ #if SQL_MAX_COLUMN > TT_STATIC_BUF_LEN * 8 #error "Bitmask for used table columns cannot fit into static buffer" #endif /* * The maximum length of a single SQL statement in bytes. * * It used to be the case that setting this value to zero would * turn the limit off. That is no longer true. It is not possible * to turn this limit off. */ #ifndef SQL_MAX_SQL_LENGTH #define SQL_MAX_SQL_LENGTH 1000000000 #endif /* * The maximum depth of an expression tree. This is limited to * some extent by sql_MAX_SQL_LENGTH. But sometime you might * want to place more severe limits on the complexity of an * expression. * * A value of 0 used to mean that the limit was not enforced. * But that is no longer true. The limit is now strictly enforced * at all times. */ #ifndef SQL_MAX_EXPR_DEPTH #define SQL_MAX_EXPR_DEPTH 200 #endif /* * The maximum number of terms in a compound SELECT statement. * The code generator for compound SELECT statements does one * level of recursion for each term. A stack overflow can result * if the number of terms is too large. In practice, most SQL * never has more than 3 or 4 terms. Use a value of 0 to disable * any limit on the number of terms in a compount SELECT. */ #ifndef SQL_MAX_COMPOUND_SELECT #define SQL_MAX_COMPOUND_SELECT 50 #endif /* * The maximum number of opcodes in a VDBE program. * Not currently enforced. */ #ifndef SQL_MAX_VDBE_OP #define SQL_MAX_VDBE_OP 25000 #endif /* * The maximum number of arguments to an SQL function. */ #ifndef SQL_MAX_FUNCTION_ARG #define SQL_MAX_FUNCTION_ARG 127 #endif /* * The suggested maximum number of in-memory pages to use for * the main database table and for temporary tables. * * IMPLEMENTATION-OF: R-30185-15359 The default suggested cache size is -2000, * which means the cache size is limited to 2048000 bytes of memory. * IMPLEMENTATION-OF: R-48205-43578 The default suggested cache size can be * altered using the sql_DEFAULT_CACHE_SIZE compile-time options. */ #ifndef SQL_DEFAULT_CACHE_SIZE #define SQL_DEFAULT_CACHE_SIZE -2000 #endif /* * The maximum number of attached databases. This must be between 0 * and 125. The upper bound of 125 is because the attached databases are * counted using a signed 8-bit integer which has a maximum value of 127 * and we have to allow 2 extra counts for the "main" and "temp" databases. */ #ifndef SQL_MAX_ATTACHED #define SQL_MAX_ATTACHED 10 #endif /* * Maximum length (in bytes) of the pattern in a LIKE operator. */ #ifndef SQL_MAX_LIKE_PATTERN_LENGTH #define SQL_MAX_LIKE_PATTERN_LENGTH 50000 #endif /* * Maximum depth of recursion for triggers. * * A value of 1 means that a trigger program will not be able to itself * fire any triggers. A value of 0 means that no trigger programs at all * may be executed. */ #ifndef SQL_MAX_TRIGGER_DEPTH #define SQL_MAX_TRIGGER_DEPTH 1000 #endif /* * Tarantool: gh-2550: Fiber stack is 64KB by default, so maximum * number of entities (in chain of compiling trigger programs) should be less than * 40 or stack guard will be triggered. */ #define SQL_MAX_COMPILING_TRIGGERS 30 #endif /* TARANTOOL_SQL_sqlLIMIT_H_INCLUDED */
ec6bd88aee6c1b47161882666a9534126cd2490f
0853493263443e3493d5d359576f71fc7b1d509c
/binmodules/luasocket/src/except.h
2497c0566b8f835ec55ec46fc8fb5ae2bdcee241
[ "BSD-3-Clause", "MIT" ]
permissive
premake/premake-core
2480471ed07868913533b045b7d7db7d9630e8ba
7b309649ce08cb40f4947d6952fb554c94f8cff6
refs/heads/master
2023-09-01T07:23:53.970594
2023-08-30T19:06:18
2023-08-30T19:06:18
32,634,405
3,160
944
BSD-3-Clause
2023-09-09T23:25:44
2015-03-21T14:08:15
C
UTF-8
C
false
false
1,704
h
except.h
#ifndef EXCEPT_H #define EXCEPT_H /*=========================================================================*\ * Exception control * LuaSocket toolkit (but completely independent from other modules) * * This provides support for simple exceptions in Lua. During the * development of the HTTP/FTP/SMTP support, it became aparent that * error checking was taking a substantial amount of the coding. These * function greatly simplify the task of checking errors. * * The main idea is that functions should return nil as their first return * values when they find an error, and return an error message (or value) * following nil. In case of success, as long as the first value is not nil, * the other values don't matter. * * The idea is to nest function calls with the "try" function. This function * checks the first value, and, if it's falsy, wraps the second value in a * table with metatable and calls "error" on it. Otherwise, it returns all * values it received. Basically, it works like the Lua "assert" function, * but it creates errors targeted specifically at "protect". * * The "newtry" function is a factory for "try" functions that call a * finalizer in protected mode before calling "error". * * The "protect" function returns a new function that behaves exactly like * the function it receives, but the new function catches exceptions thrown * by "try" functions and returns nil followed by the error message instead. * * With these three functions, it's easy to write functions that throw * exceptions on error, but that don't interrupt the user script. \*=========================================================================*/ #include "lua.h" int except_open(lua_State *L); #endif
d7f98581ebcdd63b2e88fb76084a98e54273da67
03666e5f961946fc1a0ac67781ac1425562ef0d7
/src/common/state/HostProfileList.C
3f65b361ba2ea9977265722980339f25e38a171a
[ "BSD-3-Clause", "LicenseRef-scancode-unknown-license-reference" ]
permissive
visit-dav/visit
e9f81b4d4b9b9930a0db9d5282cd1bcabf465e2e
601ae46e0bef2e18425b482a755d03490ade0493
refs/heads/develop
2023-09-06T08:19:38.397058
2023-09-05T21:29:32
2023-09-05T21:29:32
165,565,988
335
120
BSD-3-Clause
2023-09-14T00:53:37
2019-01-13T23:27:26
C
UTF-8
C
false
false
25,063
c
HostProfileList.C
// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt // Project developers. See the top-level LICENSE file for dates and other // details. No copyright assignment is required to contribute to VisIt. #include <HostProfileList.h> #include <DataNode.h> #include <MachineProfile.h> // **************************************************************************** // Method: HostProfileList::HostProfileList // // Purpose: // Init utility for the HostProfileList class. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** void HostProfileList::Init() { HostProfileList::SelectAll(); } // **************************************************************************** // Method: HostProfileList::HostProfileList // // Purpose: // Copy utility for the HostProfileList class. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** void HostProfileList::Copy(const HostProfileList &obj) { AttributeGroupVector::const_iterator pos; // *** Copy the machines field *** // Delete the AttributeGroup objects and clear the vector. for(pos = machines.begin(); pos != machines.end(); ++pos) delete *pos; machines.clear(); if(obj.machines.size() > 0) machines.reserve(obj.machines.size()); // Duplicate the machines from obj. for(pos = obj.machines.begin(); pos != obj.machines.end(); ++pos) { MachineProfile *oldMachineProfile = (MachineProfile *)(*pos); MachineProfile *newMachineProfile = new MachineProfile(*oldMachineProfile); machines.push_back(newMachineProfile); } HostProfileList::SelectAll(); } // Type map format string const char *HostProfileList::TypeMapFormatString = HOSTPROFILELIST_TMFS; const AttributeGroup::private_tmfs_t HostProfileList::TmfsStruct = {HOSTPROFILELIST_TMFS}; // **************************************************************************** // Method: HostProfileList::HostProfileList // // Purpose: // Default constructor for the HostProfileList class. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** HostProfileList::HostProfileList() : AttributeSubject(HostProfileList::TypeMapFormatString) { HostProfileList::Init(); } // **************************************************************************** // Method: HostProfileList::HostProfileList // // Purpose: // Constructor for the derived classes of HostProfileList class. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** HostProfileList::HostProfileList(private_tmfs_t tmfs) : AttributeSubject(tmfs.tmfs) { HostProfileList::Init(); } // **************************************************************************** // Method: HostProfileList::HostProfileList // // Purpose: // Copy constructor for the HostProfileList class. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** HostProfileList::HostProfileList(const HostProfileList &obj) : AttributeSubject(HostProfileList::TypeMapFormatString) { HostProfileList::Copy(obj); } // **************************************************************************** // Method: HostProfileList::HostProfileList // // Purpose: // Copy constructor for derived classes of the HostProfileList class. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** HostProfileList::HostProfileList(const HostProfileList &obj, private_tmfs_t tmfs) : AttributeSubject(tmfs.tmfs) { HostProfileList::Copy(obj); } // **************************************************************************** // Method: HostProfileList::~HostProfileList // // Purpose: // Destructor for the HostProfileList class. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** HostProfileList::~HostProfileList() { AttributeGroupVector::iterator pos; // Destroy the machines field. for(pos = machines.begin(); pos != machines.end(); ++pos) delete *pos; } // **************************************************************************** // Method: HostProfileList::operator = // // Purpose: // Assignment operator for the HostProfileList class. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** HostProfileList& HostProfileList::operator = (const HostProfileList &obj) { if (this == &obj) return *this; HostProfileList::Copy(obj); return *this; } // **************************************************************************** // Method: HostProfileList::operator == // // Purpose: // Comparison operator == for the HostProfileList class. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** bool HostProfileList::operator == (const HostProfileList &obj) const { bool machines_equal = (obj.machines.size() == machines.size()); for(size_t i = 0; (i < machines.size()) && machines_equal; ++i) { // Make references to MachineProfile from AttributeGroup *. const MachineProfile &machines1 = *((const MachineProfile *)(machines[i])); const MachineProfile &machines2 = *((const MachineProfile *)(obj.machines[i])); machines_equal = (machines1 == machines2); } // Create the return value return (machines_equal); } // **************************************************************************** // Method: HostProfileList::operator != // // Purpose: // Comparison operator != for the HostProfileList class. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** bool HostProfileList::operator != (const HostProfileList &obj) const { return !(this->operator == (obj)); } // **************************************************************************** // Method: HostProfileList::TypeName // // Purpose: // Type name method for the HostProfileList class. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** const std::string HostProfileList::TypeName() const { return "HostProfileList"; } // **************************************************************************** // Method: HostProfileList::CopyAttributes // // Purpose: // CopyAttributes method for the HostProfileList class. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** bool HostProfileList::CopyAttributes(const AttributeGroup *atts) { if(TypeName() != atts->TypeName()) return false; // Call assignment operator. const HostProfileList *tmp = (const HostProfileList *)atts; *this = *tmp; return true; } // **************************************************************************** // Method: HostProfileList::CreateCompatible // // Purpose: // CreateCompatible method for the HostProfileList class. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** AttributeSubject * HostProfileList::CreateCompatible(const std::string &tname) const { AttributeSubject *retval = 0; if(TypeName() == tname) retval = new HostProfileList(*this); // Other cases could go here too. return retval; } // **************************************************************************** // Method: HostProfileList::NewInstance // // Purpose: // NewInstance method for the HostProfileList class. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** AttributeSubject * HostProfileList::NewInstance(bool copy) const { AttributeSubject *retval = 0; if(copy) retval = new HostProfileList(*this); else retval = new HostProfileList; return retval; } // **************************************************************************** // Method: HostProfileList::SelectAll // // Purpose: // Selects all attributes. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** void HostProfileList::SelectAll() { Select(ID_machines, (void *)&machines); } // **************************************************************************** // Method: HostProfileList::CreateSubAttributeGroup // // Purpose: // This class contains a list of host profiles. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** AttributeGroup * HostProfileList::CreateSubAttributeGroup(int) { return new MachineProfile; } /////////////////////////////////////////////////////////////////////////////// // Persistence methods /////////////////////////////////////////////////////////////////////////////// // **************************************************************************** // Method: HostProfileList::CreateNode // // Purpose: // This method creates a DataNode representation of the object so it can be saved to a config file. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** bool HostProfileList::CreateNode(DataNode *parentNode, bool completeSave, bool forceAdd) { if(parentNode == 0) return false; HostProfileList defaultObject; bool addToParent = false; // Create a node for HostProfileList. DataNode *node = new DataNode("HostProfileList"); if(completeSave || !FieldsEqual(ID_machines, &defaultObject)) { addToParent = true; for(size_t i = 0; i < machines.size(); ++i) machines[i]->CreateNode(node, completeSave, true); } // Add the node to the parent node. if(addToParent || forceAdd) parentNode->AddNode(node); else delete node; return (addToParent || forceAdd); } // **************************************************************************** // Method: HostProfileList::SetFromNode // // Purpose: // This method sets attributes in this object from values in a DataNode representation of the object. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** void HostProfileList::SetFromNode(DataNode *parentNode) { if(parentNode == 0) return; DataNode *searchNode = parentNode->GetNode("HostProfileList"); if(searchNode == 0) return; DataNode **children; // Clear all the MachineProfiles if we got any. bool clearedMachines = false; // Go through all of the children and construct a new // MachineProfile for each one of them. children = searchNode->GetChildren(); if(children != 0) { for(int i = 0; i < searchNode->GetNumChildren(); ++i) { if(children[i]->GetKey() == std::string("MachineProfile")) { if (!clearedMachines) { ClearMachines(); clearedMachines = true; } MachineProfile temp; temp.SetFromNode(children[i]); AddMachines(temp); } } } } /////////////////////////////////////////////////////////////////////////////// // Set property methods /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// // Get property methods /////////////////////////////////////////////////////////////////////////////// const AttributeGroupVector & HostProfileList::GetMachines() const { return machines; } AttributeGroupVector & HostProfileList::GetMachines() { return machines; } /////////////////////////////////////////////////////////////////////////////// // Select property methods /////////////////////////////////////////////////////////////////////////////// void HostProfileList::SelectMachines() { Select(ID_machines, (void *)&machines); } /////////////////////////////////////////////////////////////////////////////// // AttributeGroupVector convenience methods. /////////////////////////////////////////////////////////////////////////////// // **************************************************************************** // Method: HostProfileList::AddMachines // // Purpose: // This class contains a list of host profiles. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** void HostProfileList::AddMachines(const MachineProfile &obj) { MachineProfile *newMachineProfile = new MachineProfile(obj); machines.push_back(newMachineProfile); // Indicate that things have changed by selecting it. Select(ID_machines, (void *)&machines); } // **************************************************************************** // Method: HostProfileList::ClearMachines // // Purpose: // This class contains a list of host profiles. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** void HostProfileList::ClearMachines() { AttributeGroupVector::iterator pos; for(pos = machines.begin(); pos != machines.end(); ++pos) delete *pos; machines.clear(); // Indicate that things have changed by selecting the list. Select(ID_machines, (void *)&machines); } // **************************************************************************** // Method: HostProfileList::RemoveMachines // // Purpose: // This class contains a list of host profiles. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** void HostProfileList::RemoveMachines(int index) { AttributeGroupVector::iterator pos = machines.begin(); // Iterate through the vector "index" times. for(int i = 0; i < index; ++i) if(pos != machines.end()) ++pos; // If pos is still a valid iterator, remove that element. if(pos != machines.end()) { delete *pos; machines.erase(pos); } // Indicate that things have changed by selecting the list. Select(ID_machines, (void *)&machines); } // **************************************************************************** // Method: HostProfileList::GetNumMachines // // Purpose: // This class contains a list of host profiles. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** int HostProfileList::GetNumMachines() const { return (int)machines.size(); } // **************************************************************************** // Method: HostProfileList::GetMachines // // Purpose: // This class contains a list of host profiles. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** MachineProfile & HostProfileList::GetMachines(int i) { return *((MachineProfile *)machines[i]); } // **************************************************************************** // Method: HostProfileList::GetMachines // // Purpose: // This class contains a list of host profiles. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** const MachineProfile & HostProfileList::GetMachines(int i) const { return *((MachineProfile *)machines[i]); } // **************************************************************************** // Method: HostProfileList::operator [] // // Purpose: // This class contains a list of host profiles. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** MachineProfile & HostProfileList::operator [] (int i) { return *((MachineProfile *)machines[i]); } // **************************************************************************** // Method: HostProfileList::operator [] // // Purpose: // This class contains a list of host profiles. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** const MachineProfile & HostProfileList::operator [] (int i) const { return *((MachineProfile *)machines[i]); } /////////////////////////////////////////////////////////////////////////////// // Keyframing methods /////////////////////////////////////////////////////////////////////////////// // **************************************************************************** // Method: HostProfileList::GetFieldName // // Purpose: // This method returns the name of a field given its index. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** std::string HostProfileList::GetFieldName(int index) const { switch (index) { case ID_machines: return "machines"; default: return "invalid index"; } } // **************************************************************************** // Method: HostProfileList::GetFieldType // // Purpose: // This method returns the type of a field given its index. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** AttributeGroup::FieldType HostProfileList::GetFieldType(int index) const { switch (index) { case ID_machines: return FieldType_attVector; default: return FieldType_unknown; } } // **************************************************************************** // Method: HostProfileList::GetFieldTypeName // // Purpose: // This method returns the name of a field type given its index. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** std::string HostProfileList::GetFieldTypeName(int index) const { switch (index) { case ID_machines: return "attVector"; default: return "invalid index"; } } // **************************************************************************** // Method: HostProfileList::FieldsEqual // // Purpose: // This method compares two fields and return true if they are equal. // // Note: Autogenerated by xml2atts. // // Programmer: xml2atts // Creation: omitted // // Modifications: // // **************************************************************************** bool HostProfileList::FieldsEqual(int index_, const AttributeGroup *rhs) const { const HostProfileList &obj = *((const HostProfileList*)rhs); bool retval = false; switch (index_) { case ID_machines: { // new scope bool machines_equal = (obj.machines.size() == machines.size()); for(size_t i = 0; (i < machines.size()) && machines_equal; ++i) { // Make references to MachineProfile from AttributeGroup *. const MachineProfile &machines1 = *((const MachineProfile *)(machines[i])); const MachineProfile &machines2 = *((const MachineProfile *)(obj.machines[i])); machines_equal = (machines1 == machines2); } retval = machines_equal; } break; default: retval = false; } return retval; } /////////////////////////////////////////////////////////////////////////////// // User-defined methods. /////////////////////////////////////////////////////////////////////////////// // **************************************************************************** // Method: HostProfileList::GetActiveLaunchProfileForHost // // Purpose: // Returns the active launch profile for the machine with a host name // pattern matching the specified host name. // // Arguments: // hostName the host name to match with the profile hostname patterns // // Returns: // A pointer to the host profile, or NULL. // // Programmer: Jeremy Meredith // Creation: February 18, 2010 // // Modifications: // // **************************************************************************** LaunchProfile * HostProfileList::GetActiveLaunchProfileForHost(const std::string &hostName) const { MachineProfile *machine = GetMachineProfileForHost(hostName); return machine ? machine->GetActiveLaunchProfile() : NULL; } // **************************************************************************** // Method: HostProfileList::GetMachineProfileForHost // // Purpose: // Gets the machine profile with a host name pattern // matching the specified host name. // // Arguments: // hostName the host name to match with the profile hostname patterns // // Returns: // A pointer to the machine profile, or NULL. // // Programmer: Jeremy Meredith // Creation: February 18, 2010 // // Modifications: // Brad Whitlock, Tue May 20 11:53:37 PDT 2003 // I moved these include files to here so we can successfully regenerate // the class. // // Jeremy Meredith, Fri Feb 26 09:28:01 EST 2010 // Try matching against the original hostname if matching against the // resolved host name fails. // // David Camp, Fri Feb 26 13:53:28 PST 2010 // Try matching against all of the host's aliases. // **************************************************************************** #if defined(_WIN32) #include <winsock2.h> #else #include <netdb.h> #endif MachineProfile * HostProfileList::GetMachineProfileForHost(const std::string &hostName) const { // Check for the hostname for(size_t i = 0; i < machines.size(); i++) { MachineProfile *m = (MachineProfile *)(machines[i]); if (m->ProfileMatchesHost(hostName)) return m; } struct hostent *hostEnt = gethostbyname(hostName.c_str()); if (hostEnt) { // Check for the official host name std::string fqhostName(hostEnt->h_name); for(size_t i = 0; i < machines.size(); i++) { MachineProfile *m = (MachineProfile *)(machines[i]); if (m->ProfileMatchesHost(fqhostName)) return m; } // Check all of the aliases for(int j=0; hostEnt->h_aliases[j] != NULL; j++) { fqhostName = std::string(hostEnt->h_aliases[j]); for(size_t i = 0; i < machines.size(); i++) { MachineProfile *m = (MachineProfile *)(machines[i]); if (m->ProfileMatchesHost(fqhostName)) return m; } } } return NULL; }
3cd2f11ce3cc090bfa1a20756b793a3de17ced79
e73547787354afd9b717ea57fe8dd0695d161821
/include/mapfs/jan_00_hit.h
69783245410f63fcb0e572e303bd748db91761a1
[]
no_license
pmret/papermario
8b514b19653cef8d6145e47499b3636b8c474a37
9774b26d93f1045dd2a67e502b6efc9599fb6c31
refs/heads/main
2023-08-31T07:09:48.951514
2023-08-21T18:07:08
2023-08-21T18:07:08
287,151,133
904
139
null
2023-09-14T02:44:23
2020-08-13T01:22:57
C
UTF-8
C
false
false
934
h
jan_00_hit.h
#define COLLIDER_Root 0x14 #define COLLIDER_g47 0x13 #define COLLIDER_o90 0x12 #define COLLIDER_o257 0x11 #define COLLIDER_g61 0x10 #define COLLIDER_o293 0xF #define COLLIDER_o286 0xE #define COLLIDER_o282 0xD #define COLLIDER_o281 0xC #define COLLIDER_o280 0xB #define COLLIDER_o279 0xA #define COLLIDER_o278 0x9 #define COLLIDER_g1 0x8 #define COLLIDER_g62 0x7 #define COLLIDER_o96 0x6 #define COLLIDER_deilitne 0x5 #define COLLIDER_deiline 0x4 #define COLLIDER_g12 0x3 #define COLLIDER_o94 0x2 #define COLLIDER_deilitse 0x1 #define COLLIDER_deilise 0x0 #define ZONE_Root 0x3 #define ZONE_g1 0x2 #define ZONE_o95 0x1 #define ZONE_o93 0x0
cdb9fe9decef4ce87f68c381a076d3b0801c5191
ca4c4631f3d47a90b8415bbe70dbc7cae18c071e
/unit_tests/UnitTestFieldUtils.C
1ccd412e6f35c1568749cfa8324ca13c135278f8
[ "BSD-3-Clause", "BSD-2-Clause" ]
permissive
Exawind/nalu-wind
5765078c445d379ea952d2b25a01f5ff490837a6
722cd7757a412c9306645963808047824c312a17
refs/heads/master
2023-08-16T17:44:54.744168
2023-08-15T18:05:23
2023-08-15T18:05:23
132,016,365
111
87
NOASSERTION
2023-09-14T04:02:07
2018-05-03T15:39:32
C
UTF-8
C
false
false
1,517
c
UnitTestFieldUtils.C
// Copyright 2017 National Technology & Engineering Solutions of Sandia, LLC // (NTESS), National Renewable Energy Laboratory, University of Texas Austin, // Northwest Research Associates. Under the terms of Contract DE-NA0003525 // with NTESS, the U.S. Government retains certain rights in this software. // // This software is released under the BSD 3-clause license. See LICENSE file // for more details. // #include "UnitTestFieldUtils.h" namespace unit_test_utils { double field_norm( const ScalarFieldType& field, const stk::mesh::BulkData& bulk, stk::mesh::Selector selector) { stk::ParallelMachine comm = bulk.parallel(); const auto& buckets = bulk.get_buckets(stk::topology::NODE_RANK, selector); size_t N = 0; size_t g_N = 0; double norm = 0.0; double g_norm = 0.0; Kokkos::parallel_for( sierra::nalu::HostTeamPolicy(buckets.size(), Kokkos::AUTO), NONCONST_LAMBDA(const sierra::nalu::TeamHandleType& team) { const stk::mesh::Bucket& bkt = *buckets[team.league_rank()]; Kokkos::parallel_for( Kokkos::TeamThreadRange(team, bkt.size()), NONCONST_LAMBDA(const size_t& j) { double node_value = *stk::mesh::field_data(field, bkt[j]); Kokkos::atomic_add(&N, (size_t)1); Kokkos::atomic_add(&norm, (node_value * node_value)); }); }); stk::all_reduce_sum(comm, &N, &g_N, 1); stk::all_reduce_sum(comm, &norm, &g_norm, 1); g_norm = std::sqrt(g_norm / g_N); return g_norm; } } // namespace unit_test_utils
8ad256bd0e9490bba1eadabcb2f8fa199a14409b
9e0c8c8d8bafa73d133e41f201badc756c92978a
/include/tilck/kernel/arch/generic_x86/debug_utils_x86.h
6ddce0e77c9d6674446fbf04c04a39ff2367a3f3
[ "BSD-2-Clause", "MIT", "CC0-1.0", "BSD-3-Clause", "LicenseRef-scancode-public-domain", "BSD-2-Clause-Views" ]
permissive
vvaltchev/tilck
ccf8d9933be1269b85388e5b21645b831ecf5412
e9c27da4dd15f5f8a927b11f31484aec3f1429f0
refs/heads/master
2023-08-16T00:07:42.593483
2023-07-04T21:00:31
2023-07-19T23:25:42
53,845,595
2,142
115
BSD-2-Clause
2023-09-03T05:36:46
2016-03-14T10:02:41
C
UTF-8
C
false
false
121
h
debug_utils_x86.h
/* SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include <tilck/common/basic_defs.h> void dump_eflags(u32 f);
e577bc129144c31b2c0c812e1135b4c206ce4066
3f55217e912141e04815bc8bcb6fbd5638d0896e
/src/rt/text.c
af935b8d1b2fdba2be38c476858f9c9151ce4533
[ "BSD-2-Clause" ]
permissive
NREL/Radiance
bfbb93c99d86368ad0f27052a2a5504aeced47f8
2fcca99ace2f2435f32a09525ad31f2b3be3c1bc
refs/heads/master
2021-12-26T12:42:04.586614
2021-12-18T00:43:56
2021-12-18T00:43:56
8,210,805
164
68
NOASSERTION
2019-06-06T19:57:11
2013-02-15T00:47:56
C
UTF-8
C
false
false
7,898
c
text.c
#ifndef lint static const char RCSid[] = "$Id: text.c,v 2.28 2021/11/19 22:51:31 greg Exp $"; #endif /* * text.c - functions for text patterns and mixtures. */ #include "copyright.h" #include "ray.h" #include "paths.h" #include "otypes.h" #include "rtotypes.h" #include "font.h" /* * A text pattern is specified as the text (a file or line), * the upper left anchor point, the right motion vector, the down * motion vector, and the foreground and background brightness. * For a file, the description is as follows: * * modifier brighttext id * 2 fontfile textfile * 0 * 11+ * Ax Ay Az * Rx Ry Rz * Dx Dy Dz * foreground background * [spacing] * * For a single line, we use: * * modifier brighttext id * N+2 fontfile . This is a line with N words... * 0 * 11+ * Ax Ay Az * Rx Ry Rz * Dx Dy Dz * foreground background * [spacing] * * Colortext is identical, except colors are given rather than * brightnesses. * * Mixtext has foreground and background modifiers: * * modifier mixtext id * 4+ foremod backmod fontfile text.. * 0 * 9+ * Ax Ay Az * Rx Ry Rz * Dx Dy Dz * [spacing] */ #define fndx(m) ((m)->otype==MIX_TEXT ? 2 : 0) #define tndx(m) ((m)->otype==MIX_TEXT ? 3 : 1) #define sndx(m) ((m)->otype==PAT_BTEXT ? 11 : \ (m)->otype==PAT_CTEXT ? 15 : 9) typedef struct tline { struct tline *next; /* pointer to next line */ short *spc; /* character spacing */ int width; /* total line width */ /* followed by the string */ } TLINE; #define TLSTR(l) ((char *)((l)+1)) typedef struct { FVECT right, down; /* right and down unit vectors */ FONT *f; /* our font */ TLINE tl; /* line list */ } TEXT; static TLINE * tlalloc(char *s); static TEXT * gettext(OBJREC *tm); static int intext(FVECT p, OBJREC *m); static int inglyph(double x, double y, GLYPH *gl); int do_text( OBJREC *m, RAY *r ) { FVECT v; int foreground; /* get transformed position */ if (r->rox != NULL) multp3(v, r->rop, r->rox->b.xfm); else VCOPY(v, r->rop); /* check if we are within a text glyph */ foreground = intext(v, m); /* modify */ if (m->otype == MIX_TEXT) { OBJECT omod; char *modname = m->oargs.sarg[foreground ? 0 : 1]; if (!strcmp(modname, VOIDID)) omod = OVOID; else if ((omod = lastmod(objndx(m), modname)) == OVOID) { sprintf(errmsg, "undefined modifier \"%s\"", modname); objerror(m, USER, errmsg); } if (rayshade(r, omod)) { if (m->omod != OVOID) objerror(m, USER, "inappropriate modifier"); return(1); } } else if (m->otype == PAT_BTEXT) { if (foreground) scalecolor(r->pcol, m->oargs.farg[9]); else scalecolor(r->pcol, m->oargs.farg[10]); } else { /* PAT_CTEXT */ COLOR cval; if (foreground) setcolor(cval, m->oargs.farg[9], m->oargs.farg[10], m->oargs.farg[11]); else setcolor(cval, m->oargs.farg[12], m->oargs.farg[13], m->oargs.farg[14]); multcolor(r->pcol, cval); } return(0); } static TLINE * tlalloc( /* allocate and assign text line */ char *s ) { int siz; TLINE *tl; siz = strlen(s) + 1; if ((tl=(TLINE *)malloc(sizeof(TLINE)+siz)) == NULL || (tl->spc=(short *)malloc(siz*sizeof(short))) == NULL) error(SYSTEM, "out of memory in tlalloc"); tl->next = NULL; strcpy(TLSTR(tl), s); return(tl); } static TEXT * gettext( /* get text structure for material */ OBJREC *tm ) { #define R (tm->oargs.farg+3) #define D (tm->oargs.farg+6) FVECT DxR; double d; FILE *fp; char linbuf[512]; TEXT *t; int i; TLINE *tlp; char *s; if ((t = (TEXT *)tm->os) != NULL) return(t); /* check arguments */ if (tm->oargs.nsargs - tndx(tm) < 1 || tm->oargs.nfargs < sndx(tm)) objerror(tm, USER, "bad # arguments"); if ((t = (TEXT *)malloc(sizeof(TEXT))) == NULL) error(SYSTEM, "out of memory in gettext"); /* compute vectors */ fcross(DxR, D, R); fcross(t->right, DxR, D); d = DOT(t->right,t->right); if (d <= FTINY*FTINY*FTINY*FTINY) objerror(tm, USER, "illegal motion vector"); d = DOT(D,D)/d; for (i = 0; i < 3; i++) t->right[i] *= d; fcross(t->down, R, DxR); d = DOT(R,R)/DOT(t->down,t->down); for (i = 0; i < 3; i++) t->down[i] *= d; /* get text */ tlp = &t->tl; if (tm->oargs.nsargs - tndx(tm) > 1) { /* single line */ s = linbuf; for (i = tndx(tm)+1; i < tm->oargs.nsargs; i++) { strcpy(s, tm->oargs.sarg[i]); s += strlen(s); *s++ = ' '; } *--s = '\0'; tlp->next = tlalloc(linbuf); tlp = tlp->next; } else { /* text file */ if ((s = getpath(tm->oargs.sarg[tndx(tm)], getrlibpath(), R_OK)) == NULL) { sprintf(errmsg, "cannot find text file \"%s\"", tm->oargs.sarg[tndx(tm)]); error(SYSTEM, errmsg); } if ((fp = fopen(s, "r")) == NULL) { sprintf(errmsg, "cannot open text file \"%s\"", s); error(SYSTEM, errmsg); } while (fgets(linbuf, sizeof(linbuf), fp) != NULL) { s = linbuf + strlen(linbuf) - 1; if (*s == '\n') *s = '\0'; tlp->next = tlalloc(linbuf); tlp = tlp->next; } fclose(fp); } tlp->next = NULL; /* get the font */ t->f = getfont(tm->oargs.sarg[fndx(tm)]); if (!t->f) objerror(tm, USER, "font load error"); /* compute character spacing */ i = sndx(tm); d = i < tm->oargs.nfargs ? tm->oargs.farg[i] : 0.0; i = d * 255.0; t->tl.width = 0; for (tlp = t->tl.next; tlp != NULL; tlp = tlp->next) { if (i < 0) tlp->width = squeeztext(tlp->spc, TLSTR(tlp), t->f, -i); else if (i > 0) tlp->width = proptext(tlp->spc, TLSTR(tlp), t->f, i, 3); else tlp->width = uniftext(tlp->spc, TLSTR(tlp), t->f); if (tlp->width > t->tl.width) t->tl.width = tlp->width; } /* we're done */ tm->os = (char *)t; return(t); #undef R #undef D } void freetext( /* free text structures associated with m */ OBJREC *m ) { TEXT *tp; TLINE *tlp; tp = (TEXT *)m->os; if (tp == NULL) return; while ((tlp = tp->tl.next) != NULL) { tp->tl.next = tlp->next; free((void *)tlp->spc); free((void *)tlp); } freefont(tp->f); /* release font reference */ free((void *)tp); m->os = NULL; } static int intext( /* check to see if p is in text glyph */ FVECT p, OBJREC *m ) { TEXT *tp; TLINE *tlp; FVECT v; double y, x; int i, h; /* first, compute position in text */ tp = gettext(m); v[0] = p[0] - m->oargs.farg[0]; v[1] = p[1] - m->oargs.farg[1]; v[2] = p[2] - m->oargs.farg[2]; x = DOT(v, tp->right); i = sndx(m); if (i < m->oargs.nfargs) x *= tp->f->mwidth + 255.*fabs(m->oargs.farg[i]); else x *= 255.; h = x; i = y = DOT(v, tp->down); if (x < 0.0 || y < 0.0) return(0); x -= (double)h; y = ((i+1) - y)*255.; /* find the line position */ for (tlp = tp->tl.next; tlp != NULL; tlp = tlp->next) if (--i < 0) break; if (tlp == NULL || h >= tlp->width) return(0); for (i = 0; (h -= tlp->spc[i]) >= 0; i++) if (h < 255 && inglyph(h+x, y, tp->f->fg[TLSTR(tlp)[i]&0xff])) return(1); return(0); } static int inglyph( /* (x,y) within font glyph gl? */ double x, /* real coordinates in range [0,255) */ double y, GLYPH *gl ) { int n, ncross; int xlb, ylb; int tv; GORD *p0, *p1; if (gl == NULL) return(0); xlb = x; ylb = y; if (gl->left > xlb || gl->right <= xlb || /* check extent */ gl->bottom > ylb || gl->top <= ylb) return(0); xlb = xlb<<1 | 1; /* add 1/2 to test points... */ ylb = ylb<<1 | 1; /* ...so no equal comparisons */ n = gl->nverts; /* get # of vertices */ p0 = gvlist(gl) + 2*(n-1); /* connect last to first */ p1 = gvlist(gl); ncross = 0; /* positive x axis cross test */ while (n--) { if ((p0[1]<<1 > ylb) ^ (p1[1]<<1 > ylb)) { tv = (p0[0]<<1 > xlb) | ((p1[0]<<1 > xlb) << 1); if (tv == 03) ncross++; else if (tv) ncross += (p1[1] > p0[1]) ^ ((p0[1]-y)*(p1[0]-x) > (p0[0]-x)*(p1[1]-y)); } p0 = p1; p1 += 2; } return(ncross & 01); }
f667a11305e5e6f0ff84a20c48d8835ba6628efe
99bdb3251fecee538e0630f15f6574054dfc1468
/bsp/lpc55sxx/Libraries/LPC55S36/LPC55S36/drivers/fsl_itrc.h
877134aa4d9c9647799eb85c4591865400720abb
[ "Apache-2.0", "Zlib", "LicenseRef-scancode-proprietary-license", "MIT", "BSD-3-Clause", "X11", "BSD-4-Clause-UC", "LicenseRef-scancode-unknown-license-reference" ]
permissive
RT-Thread/rt-thread
03a7c52c2aeb1b06a544143b0e803d72f47d1ece
3602f891211904a27dcbd51e5ba72fefce7326b2
refs/heads/master
2023-09-01T04:10:20.295801
2023-08-31T16:20:55
2023-08-31T16:20:55
7,408,108
9,599
5,805
Apache-2.0
2023-09-14T13:37:26
2013-01-02T14:49:21
C
UTF-8
C
false
false
5,950
h
fsl_itrc.h
/* * Copyright 2021 NXP * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ #ifndef _FSL_ITRC_H_ #define _FSL_ITRC_H_ #include "fsl_common.h" /*! * @addtogroup ITRC * @{ */ /*! @file */ /******************************************************************************* * Definitions *******************************************************************************/ /*! @name Driver version */ /*@{*/ /*! @brief Defines ITRC driver version 2.1.0. * * Change log: * - Version 2.1.0 * - Make SYSCON glitch platform dependent * - Version 2.0.0 * - initial version */ #define FSL_ITRC_DRIVER_VERSION (MAKE_VERSION(2, 1, 0)) /*@}*/ typedef enum _itrc_input_signals { kITRC_CssGlitch = 0U, kITRC_RtcTamper = 1U, kITRC_Cdog = 2U, kITRC_BodVbat = 3u, kITRC_BodVdd = 4u, kITRC_Watchdog = 5u, kITRC_FlashEcc = 6u, kITRC_Ahb = 7u, kITRC_CssErr = 8u, #if defined(FSL_FEATURE_ITRC_HAS_SYSCON_GLITCH) && (FSL_FEATURE_ITRC_HAS_SYSCON_GLITCH > 0) kITRC_SysconGlitch = 9u, #endif kITRC_Pkc = 10u, kITRC_SwEvent1 = 14u, kITRC_SwEvent2 = 15u } itrc_input_signals_t; typedef enum _itrc_lock { kITRC_Unlock = 0U, kITRC_Lock = 1U, } itrc_lock_t; typedef enum _itrc_enable { kITRC_Enable = 0U, kITRC_Disable = 1U, } itrc_enable_t; typedef enum _itrc_out_signals { kITRC_Irq = 16U, kITRC_CssReset = 17U, kITRC_PufZeroize = 18U, kITRC_RamZeroize = 19u, kITRC_ChipReset = 20u, kITRC_TamperOut = 21u, } itrc_out_signals_t; #if defined(FSL_FEATURE_ITRC_HAS_SYSCON_GLITCH) && (FSL_FEATURE_ITRC_HAS_SYSCON_GLITCH > 0) #define IN_EVENTS_MASK \ (ITRC_STATUS_IN0_STATUS_MASK | ITRC_STATUS_IN1_STATUS_MASK | ITRC_STATUS_IN2_STATUS_MASK | \ ITRC_STATUS_IN3_STATUS_MASK | ITRC_STATUS_IN4_STATUS_MASK | ITRC_STATUS_IN5_STATUS_MASK | \ ITRC_STATUS_IN6_STATUS_MASK | ITRC_STATUS_IN7_STATUS_MASK | ITRC_STATUS_IN8_STATUS_MASK | \ ITRC_STATUS_IN9_STATUS_MASK | ITRC_STATUS_IN10_STATUS_MASK | ITRC_STATUS_IN14_STATUS_MASK | \ ITRC_STATUS_IN15_STATUS_MASK) #else #define IN_EVENTS_MASK \ (ITRC_STATUS_IN0_STATUS_MASK | ITRC_STATUS_IN1_STATUS_MASK | ITRC_STATUS_IN2_STATUS_MASK | \ ITRC_STATUS_IN3_STATUS_MASK | ITRC_STATUS_IN4_STATUS_MASK | ITRC_STATUS_IN5_STATUS_MASK | \ ITRC_STATUS_IN6_STATUS_MASK | ITRC_STATUS_IN7_STATUS_MASK | ITRC_STATUS_IN8_STATUS_MASK | \ ITRC_STATUS_IN10_STATUS_MASK | ITRC_STATUS_IN14_STATUS_MASK | ITRC_STATUS_IN15_STATUS_MASK) #endif /* FSL_FEATURE_ITRC_HAS_SYSCON_GLITCH */ #define OUT_ACTIONS_MASK \ (ITRC_STATUS_OUT0_STATUS_MASK | ITRC_STATUS_OUT1_STATUS_MASK | ITRC_STATUS_OUT2_STATUS_MASK | \ ITRC_STATUS_OUT3_STATUS_MASK | ITRC_STATUS_OUT4_STATUS_MASK | ITRC_STATUS_OUT5_STATUS_MASK) #ifndef ITRC #define ITRC ITRC0 #endif /******************************************************************************* * API *******************************************************************************/ extern void ITRC0_DriverIRQHandler(void); #if defined(__cplusplus) extern "C" { #endif /* __cplusplus */ /*! * @name ITRC Functional Operation * @{ */ /*! * @brief Set ITRC Action to Event * * This function sets input Event signal to corresponding output Action response signal. * * @param base ITRC peripheral base address * @param out ITRC OUT signal action * @param in ITRC IN signal event * @param lock if set locks INx_SEL configuration. This can be cleared only by PMC Core reset. * @param enable if set input Event will be selected for output Action, otherwise disable (if not already locked). * @return kStatus_Success if success, kStatus_InvalidArgument otherwise */ status_t ITRC_SetActionToEvent( ITRC_Type *base, itrc_out_signals_t out, itrc_input_signals_t in, itrc_lock_t lock, itrc_enable_t enable); /*! * @brief Trigger ITRC SW Event 0 * * This funciton set SW_EVENT0 register with value !=0 which triggers ITRC SW Event 0. * * @param base ITRC peripheral base address */ void ITRC_SetSWEvent0(ITRC_Type *base); /*! * @brief Trigger ITRC SW Event 1 * * This funciton set SW_EVENT1 register with value !=0 which triggers ITRC SW Event 1. * * @param base ITRC peripheral base address */ void ITRC_SetSWEvent1(ITRC_Type *base); /*! * @brief Get ITRC Status * * This function returns ITRC register status. * * @param base ITRC peripheral base address * @return Value of ITRC STATUS register */ status_t ITRC_GetStatus(ITRC_Type *base); /*! * @brief Clear ITRC status * * This function clears corresponding ITRC event or action in STATUS register. * * @param base ITRC peripheral base address * @param word 32bit word represent corresponding event/action in STATUS register to be cleared (see * ITRC_STATUS_INx/OUTx_STATUS) * @return kStatus_Success if success, kStatus_InvalidArgument otherwise */ status_t ITRC_ClearStatus(ITRC_Type *base, uint32_t word); /*! * @brief Clear All ITRC status * * This function clears all event and action status. * * @param base ITRC peripheral base address * @return kStatus_Success if success */ status_t ITRC_ClearAllStatus(ITRC_Type *base); /*! * @brief Initialize ITRC * * This function initializes ITRC by enabling IRQ. * * @param base ITRC peripheral base address * @param conf ITRC configuration structure * @return Status of the init operation */ status_t ITRC_Init(ITRC_Type *base); /*! * @brief Deinitialize ITRC * * This function deinitializes ITRC by disabling IRQ. * * @param base ITRC peripheral base address */ void ITRC_Deinit(ITRC_Type *base); /*! @}*/ #if defined(__cplusplus) } #endif /* __cplusplus */ /*! @}*/ /* end of group itrc */ #endif /* _FSL_ITRC_H_ */
96bb87074a20c3dfdf10d3aa7917e42556d9923e
7df190df28da7e4ff166e55dc8ce780f11236a9f
/src/router/services/sysinit/sysinit-whrag108.c
7338dadb494e5e30cb9e34bf402336fdcf7fa3be
[]
no_license
mirror/dd-wrt
25416946e6132aa54b35809de61834a1825a9a36
8f2934a5a2adfbb59b471375aa3a38de5d036531
refs/heads/master
2023-08-31T14:54:47.496685
2023-08-30T17:40:54
2023-08-30T17:40:54
7,470,282
520
281
null
2023-05-29T20:56:24
2013-01-06T17:21:29
null
UTF-8
C
false
false
5,676
c
sysinit-whrag108.c
/* * sysinit-whrag108.c * * Copyright (C) 2006 Sebastian Gottschall <s.gottschall@dd-wrt.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id: */ #include <stdio.h> #include <stdlib.h> #include <limits.h> #include <time.h> #include <unistd.h> #include <errno.h> #include <syslog.h> #include <signal.h> #include <string.h> #include <termios.h> #include <sys/klog.h> #include <sys/types.h> #include <sys/mount.h> #include <sys/reboot.h> #include <sys/stat.h> #include <sys/sysmacros.h> #include <sys/time.h> #include <sys/utsname.h> #include <sys/wait.h> #include <sys/ioctl.h> #include <bcmnvram.h> #include <shutils.h> #include <utils.h> #define SIOCGMIIREG 0x8948 /* Read MII PHY register. */ #define SIOCSMIIREG 0x8949 /* Write MII PHY register. */ #include <arpa/inet.h> #include <sys/socket.h> #include <linux/if.h> #include <linux/sockios.h> #include <linux/mii.h> #include "devices/wireless.c" // highly experimental void setRegister(int socket, short reg, short value) { // struct mii_ioctl_data data; struct ifreq ifr; unsigned short *data = (unsigned short *)(&ifr.ifr_data); data[0] = 0; data[1] = reg; data[2] = value; (void)strncpy(ifr.ifr_name, "eth0", sizeof("eth0")); // data.reg_num = reg; // data.val_in = value; ioctl(socket, SIOCSMIIREG, &ifr); } void switch_main(int argc, char *argv[]) { int reg = atoi(argv[1]); int val = atoi(argv[2]); int s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) { return; } setRegister(s, reg, val); close(s); } void setupSwitch(void) { int s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) { return; } // setRegister(s,0x02,0xa0); // Enable 8021Q (80) and IGMP snooping (40) // setRegister(s,0x05,0xa0); // vlan1: valid,5,2,1 port fid=1 vid=1 // setRegister(s,0x76,0x21); // setRegister(s,0x77,0x10); // setRegister(s,0x78,0x01); // write (04) and trigger address 0 // setRegister(s,0x6E,0x04); // setRegister(s,0x6F,0x00); // vlan2: valid,5,4,3 port fid=2 vid=2 // setRegister(s,0x76,0x3E); // setRegister(s,0x77,0x20); // setRegister(s,0x78,0x02); // write (04) and trigger address 0 // setRegister(s,0x6E,0x04); // setRegister(s,0x6F,0x01); // config port 1,2 to VLAN id 1 setRegister(s, 0x14, 0x01); // config port 1,2 to filter vid 1 setRegister(s, 0x12, 0x46); // config port 3,4 to VLAN id 2 setRegister(s, 0x24, 0x02); setRegister(s, 0x34, 0x02); setRegister(s, 0x44, 0x02); setRegister(s, 0x54, 0x02); // config port 3,4 to filter vid 2 setRegister(s, 0x22, 0x46); setRegister(s, 0x32, 0x46); setRegister(s, 0x42, 0x46); setRegister(s, 0x52, 0x46); // for IGMP, disenable special tagging // setRegister(s,0x0b,0x01); // enable vlan tag insertion por 5 // setRegister(s,0x50,0x04); // setRegister(s,0x52,0x06); // remove it from all others setRegister(s, 0x10, 0x02); setRegister(s, 0x20, 0x02); setRegister(s, 0x30, 0x02); setRegister(s, 0x40, 0x02); setRegister(s, 0x50, 0x02); // switch enable setRegister(s, 0x01, 0x01); close(s); } void start_sysinit(void) { char buf[PATH_MAX]; struct stat tmp_stat; time_t tm = 0; eval("/bin/tar", "-xzf", "/dev/mtdblock/3", "-C", "/"); FILE *in = fopen("/tmp/nvram/nvram.db", "rb"); if (in != NULL) { fclose(in); eval("/usr/sbin/convertnvram"); eval("/sbin/mtd", "erase", "nvram"); nvram_commit(); } /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, nvram_geti("console_loglevel")); cprintf("sysinit() get router\n"); int brand = getRouterBrand(); insmod("zlib_deflate"); insmod("crc-ccitt"); insmod("crypto"); insmod("crypto_algapi"); insmod("crypto_blkcipher"); insmod("crypto_hash"); insmod("crypto_wq"); insmod("aead"); insmod("arc4"); insmod("ecb"); insmod("pcompress"); insmod("rng"); insmod("sha1_generic"); insmod("chainiv"); insmod("eseqiv"); insmod("cryptomgr"); insmod("slhc"); insmod("ppp_generic"); insmod("ppp_async"); insmod("ppp_synctty"); insmod("ppp_mppe"); insmod("pppox"); insmod("pppoe"); insmod("nf_conntrack_h323"); insmod("nf_nat_h323"); insmod("nf_conntrack_sip"); insmod("nf_nat_sip"); insmod("xt_state"); insmod("xt_recent"); insmod("xt_mac"); insmod("xt_limit"); insmod("xt_connlimit"); insmod("xt_multiport"); /* * network drivers */ #ifdef HAVE_HOTPLUG2 insmod("ar231x"); #else insmod("ar2313"); #endif detect_wireless_devices(RADIO_ALL); writeprocsys("dev/wifi0/ledpin", "2"); writeprocsys("dev/wifi0/softled", "1"); writeprocsys("dev/wifi0/ledpin", "3"); writeprocsys("dev/wifi0/softled", "1"); // eval ("ifconfig", "wifi0", "up"); // eval ("ifconfig", "wifi1", "up"); /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "wlan0"); return; cprintf("done\n"); } int check_cfe_nv(void) { nvram_seti("portprio_support", 0); return 0; } int check_pmon_nv(void) { return 0; } void start_overclocking(void) { } char *enable_dtag_vlan(int enable) { return "eth0"; } char *set_wan_state(int state) { return NULL; } void start_devinit_arch(void) { }
e9b74363dbe7fe10f46b3e222fb353072c36e26a
88ae8695987ada722184307301e221e1ba3cc2fa
/third_party/icu/source/test/cintltst/ulistfmttest.c
b0a1f6bc34965dc2ef44ea45b3dcc07896a51786
[ "BSD-3-Clause", "LicenseRef-scancode-unicode", "ICU", "LicenseRef-scancode-unknown-license-reference", "GPL-3.0-or-later", "NTP", "GPL-2.0-or-later", "LicenseRef-scancode-autoconf-simple-exception", "Autoconf-exception-generic", "LicenseRef-scancode-public-domain", "NAIST-2003", "BSD-2-Clause", "MIT", "Apache-2.0", "LGPL-2.0-or-later", "GPL-1.0-or-later" ]
permissive
iridium-browser/iridium-browser
71d9c5ff76e014e6900b825f67389ab0ccd01329
5ee297f53dc7f8e70183031cff62f37b0f19d25f
refs/heads/master
2023-08-03T16:44:16.844552
2023-07-20T15:17:00
2023-07-23T16:09:30
220,016,632
341
40
BSD-3-Clause
2021-08-13T13:54:45
2019-11-06T14:32:31
null
UTF-8
C
false
false
15,310
c
ulistfmttest.c
// © 2016 and later: Unicode, Inc. and others. // License & terms of use: http://www.unicode.org/copyright.html /******************************************************************** * Copyright (c) 2015, International Business Machines Corporation * and others. All Rights Reserved. ********************************************************************/ /* C API TEST for UListFormatter */ #include "unicode/utypes.h" #if !UCONFIG_NO_FORMATTING #include "unicode/ustring.h" #include "unicode/ulistformatter.h" #include "cintltst.h" #include "cmemory.h" #include "cstring.h" #include "cformtst.h" static void TestUListFmt(void); static void TestUListFmtToValue(void); static void TestUListOpenStyled(void); static void TestUList21871_A(void); static void TestUList21871_B(void); void addUListFmtTest(TestNode** root); #define TESTCASE(x) addTest(root, &x, "tsformat/ulistfmttest/" #x) void addUListFmtTest(TestNode** root) { TESTCASE(TestUListFmt); TESTCASE(TestUListFmtToValue); TESTCASE(TestUListOpenStyled); TESTCASE(TestUList21871_A); TESTCASE(TestUList21871_B); } static const UChar str0[] = { 0x41,0 }; /* "A" */ static const UChar str1[] = { 0x42,0x62,0 }; /* "Bb" */ static const UChar str2[] = { 0x43,0x63,0x63,0 }; /* "Ccc" */ static const UChar str3[] = { 0x44,0x64,0x64,0x64,0 }; /* "Dddd" */ static const UChar str4[] = { 0x45,0x65,0x65,0x65,0x65,0 }; /* "Eeeee" */ static const UChar* strings[] = { str0, str1, str2, str3, str4 }; static const int32_t stringLengths[] = { 1, 2, 3, 4, 5 }; static const int32_t stringLengthsNeg[] = { -1, -1, -1, -1, -1 }; typedef struct { const char * locale; int32_t stringCount; const char *expectedResult; /* invariant chars + escaped Unicode */ } ListFmtTestEntry; static ListFmtTestEntry listFmtTestEntries[] = { /* locale stringCount expectedResult */ { "en" , 5, "A, Bb, Ccc, Dddd, and Eeeee" }, { "en" , 2, "A and Bb" }, { "de" , 5, "A, Bb, Ccc, Dddd und Eeeee" }, { "de" , 2, "A und Bb" }, { "ja" , 5, "A\\u3001Bb\\u3001Ccc\\u3001Dddd\\u3001Eeeee" }, { "ja" , 2, "A\\u3001Bb" }, { "zh" , 5, "A\\u3001Bb\\u3001Ccc\\u3001Dddd\\u548CEeeee" }, { "zh" , 2, "A\\u548CBb" }, { NULL , 0, NULL } /* terminator */ }; enum { kUBufMax = 128, kBBufMax = 256 }; static void TestUListFmt() { const ListFmtTestEntry * lftep; for (lftep = listFmtTestEntries; lftep->locale != NULL ; lftep++ ) { UErrorCode status = U_ZERO_ERROR; UListFormatter *listfmt = ulistfmt_open(lftep->locale, &status); if ( U_FAILURE(status) ) { log_data_err("ERROR: ulistfmt_open fails for locale %s, status %s\n", lftep->locale, u_errorName(status)); } else { UChar ubufActual[kUBufMax]; int32_t ulenActual = ulistfmt_format(listfmt, strings, stringLengths, lftep->stringCount, ubufActual, kUBufMax, &status); if ( U_FAILURE(status) ) { log_err("ERROR: ulistfmt_format fails for locale %s count %d (real lengths), status %s\n", lftep->locale, lftep->stringCount, u_errorName(status)); } else { UChar ubufExpected[kUBufMax]; int32_t ulenExpected = u_unescape(lftep->expectedResult, ubufExpected, kUBufMax); if (ulenActual != ulenExpected || u_strncmp(ubufActual, ubufExpected, ulenExpected) != 0) { log_err("ERROR: ulistfmt_format for locale %s count %d (real lengths), actual \"%s\" != expected \"%s\"\n", lftep->locale, lftep->stringCount, aescstrdup(ubufActual, ulenActual), aescstrdup(ubufExpected, ulenExpected)); } } /* try again with all lengths -1 */ status = U_ZERO_ERROR; ulenActual = ulistfmt_format(listfmt, strings, stringLengthsNeg, lftep->stringCount, ubufActual, kUBufMax, &status); if ( U_FAILURE(status) ) { log_err("ERROR: ulistfmt_format fails for locale %s count %d (-1 lengths), status %s\n", lftep->locale, lftep->stringCount, u_errorName(status)); } else { UChar ubufExpected[kUBufMax]; int32_t ulenExpected = u_unescape(lftep->expectedResult, ubufExpected, kUBufMax); if (ulenActual != ulenExpected || u_strncmp(ubufActual, ubufExpected, ulenExpected) != 0) { log_err("ERROR: ulistfmt_format for locale %s count %d (-1 lengths), actual \"%s\" != expected \"%s\"\n", lftep->locale, lftep->stringCount, aescstrdup(ubufActual, ulenActual), aescstrdup(ubufExpected, ulenExpected)); } } /* try again with NULL lengths */ status = U_ZERO_ERROR; ulenActual = ulistfmt_format(listfmt, strings, NULL, lftep->stringCount, ubufActual, kUBufMax, &status); if ( U_FAILURE(status) ) { log_err("ERROR: ulistfmt_format fails for locale %s count %d (NULL lengths), status %s\n", lftep->locale, lftep->stringCount, u_errorName(status)); } else { UChar ubufExpected[kUBufMax]; int32_t ulenExpected = u_unescape(lftep->expectedResult, ubufExpected, kUBufMax); if (ulenActual != ulenExpected || u_strncmp(ubufActual, ubufExpected, ulenExpected) != 0) { log_err("ERROR: ulistfmt_format for locale %s count %d (NULL lengths), actual \"%s\" != expected \"%s\"\n", lftep->locale, lftep->stringCount, aescstrdup(ubufActual, ulenActual), aescstrdup(ubufExpected, ulenExpected)); } } /* try calls that should return error */ status = U_ZERO_ERROR; ulenActual = ulistfmt_format(listfmt, NULL, NULL, lftep->stringCount, ubufActual, kUBufMax, &status); if (status != U_ILLEGAL_ARGUMENT_ERROR || ulenActual > 0) { log_err("ERROR: ulistfmt_format for locale %s count %d with NULL strings, expected U_ILLEGAL_ARGUMENT_ERROR, got %s, result %d\n", lftep->locale, lftep->stringCount, u_errorName(status), ulenActual); } status = U_ZERO_ERROR; ulenActual = ulistfmt_format(listfmt, strings, NULL, lftep->stringCount, NULL, kUBufMax, &status); if (status != U_ILLEGAL_ARGUMENT_ERROR || ulenActual > 0) { log_err("ERROR: ulistfmt_format for locale %s count %d with NULL result, expected U_ILLEGAL_ARGUMENT_ERROR, got %s, result %d\n", lftep->locale, lftep->stringCount, u_errorName(status), ulenActual); } ulistfmt_close(listfmt); } } } static void TestUListFmtToValue() { UErrorCode ec = U_ZERO_ERROR; UListFormatter* fmt = ulistfmt_open("en", &ec); UFormattedList* fl = ulistfmt_openResult(&ec); assertSuccess("Opening", &ec); { const char* message = "Field position test 1"; const UChar* expectedString = u"hello, wonderful, and world"; const UChar* inputs[] = { u"hello", u"wonderful", u"world" }; ulistfmt_formatStringsToResult(fmt, inputs, NULL, UPRV_LENGTHOF(inputs), fl, &ec); assertSuccess("Formatting", &ec); static const UFieldPositionWithCategory expectedFieldPositions[] = { // field, begin index, end index {UFIELD_CATEGORY_LIST_SPAN, 0, 0, 5}, {UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD, 0, 5}, {UFIELD_CATEGORY_LIST, ULISTFMT_LITERAL_FIELD, 5, 7}, {UFIELD_CATEGORY_LIST_SPAN, 1, 7, 16}, {UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD, 7, 16}, {UFIELD_CATEGORY_LIST, ULISTFMT_LITERAL_FIELD, 16, 22}, {UFIELD_CATEGORY_LIST_SPAN, 2, 22, 27}, {UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD, 22, 27}}; checkMixedFormattedValue( message, ulistfmt_resultAsValue(fl, &ec), expectedString, expectedFieldPositions, UPRV_LENGTHOF(expectedFieldPositions)); } { const char* message = "Field position test 1"; const UChar* expectedString = u"A, B, C, D, E, F, and G"; const UChar* inputs[] = { u"A", u"B", u"C", u"D", u"E", u"F", u"G" }; ulistfmt_formatStringsToResult(fmt, inputs, NULL, UPRV_LENGTHOF(inputs), fl, &ec); assertSuccess("Formatting", &ec); static const UFieldPositionWithCategory expectedFieldPositions[] = { // field, begin index, end index {UFIELD_CATEGORY_LIST_SPAN, 0, 0, 1}, {UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD, 0, 1}, {UFIELD_CATEGORY_LIST, ULISTFMT_LITERAL_FIELD, 1, 3}, {UFIELD_CATEGORY_LIST_SPAN, 1, 3, 4}, {UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD, 3, 4}, {UFIELD_CATEGORY_LIST, ULISTFMT_LITERAL_FIELD, 4, 6}, {UFIELD_CATEGORY_LIST_SPAN, 2, 6, 7}, {UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD, 6, 7}, {UFIELD_CATEGORY_LIST, ULISTFMT_LITERAL_FIELD, 7, 9}, {UFIELD_CATEGORY_LIST_SPAN, 3, 9, 10}, {UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD, 9, 10}, {UFIELD_CATEGORY_LIST, ULISTFMT_LITERAL_FIELD, 10, 12}, {UFIELD_CATEGORY_LIST_SPAN, 4, 12, 13}, {UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD, 12, 13}, {UFIELD_CATEGORY_LIST, ULISTFMT_LITERAL_FIELD, 13, 15}, {UFIELD_CATEGORY_LIST_SPAN, 5, 15, 16}, {UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD, 15, 16}, {UFIELD_CATEGORY_LIST, ULISTFMT_LITERAL_FIELD, 16, 22}, {UFIELD_CATEGORY_LIST_SPAN, 6, 22, 23}, {UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD, 22, 23}}; checkMixedFormattedValue( message, ulistfmt_resultAsValue(fl, &ec), expectedString, expectedFieldPositions, UPRV_LENGTHOF(expectedFieldPositions)); } ulistfmt_close(fmt); ulistfmt_closeResult(fl); } static void TestUListOpenStyled() { UErrorCode ec = U_ZERO_ERROR; UListFormatter* fmt = ulistfmt_openForType("en", ULISTFMT_TYPE_OR, ULISTFMT_WIDTH_SHORT, &ec); UFormattedList* fl = ulistfmt_openResult(&ec); assertSuccess("Opening", &ec); { const char* message = "openStyled test 1"; const UChar* expectedString = u"A, B, or C"; const UChar* inputs[] = { u"A", u"B", u"C", }; ulistfmt_formatStringsToResult(fmt, inputs, NULL, UPRV_LENGTHOF(inputs), fl, &ec); assertSuccess("Formatting", &ec); static const UFieldPositionWithCategory expectedFieldPositions[] = { // field, begin index, end index {UFIELD_CATEGORY_LIST_SPAN, 0, 0, 1}, {UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD, 0, 1}, {UFIELD_CATEGORY_LIST, ULISTFMT_LITERAL_FIELD, 1, 3}, {UFIELD_CATEGORY_LIST_SPAN, 1, 3, 4}, {UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD, 3, 4}, {UFIELD_CATEGORY_LIST, ULISTFMT_LITERAL_FIELD, 4, 9}, {UFIELD_CATEGORY_LIST_SPAN, 2, 9, 10}, {UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD, 9, 10}}; checkMixedFormattedValue( message, ulistfmt_resultAsValue(fl, &ec), expectedString, expectedFieldPositions, UPRV_LENGTHOF(expectedFieldPositions)); } ulistfmt_close(fmt); ulistfmt_closeResult(fl); } #include <stdio.h> static void TestUList21871_A() { UErrorCode status = U_ZERO_ERROR; UListFormatter *fmt = ulistfmt_openForType("en", ULISTFMT_TYPE_AND, ULISTFMT_WIDTH_WIDE, &status); assertSuccess("ulistfmt_openForType", &status); const UChar *strs[] = {u"A", u""}; const int32_t lens[] = {1, 0}; UFormattedList *fl = ulistfmt_openResult(&status); assertSuccess("ulistfmt_openResult", &status); ulistfmt_formatStringsToResult(fmt, strs, lens, 2, fl, &status); assertSuccess("ulistfmt_formatStringsToResult", &status); const UFormattedValue *value = ulistfmt_resultAsValue(fl, &status); assertSuccess("ulistfmt_resultAsValue", &status); { int32_t len; const UChar *str = ufmtval_getString(value, &len, &status); assertUEquals("TEST ufmtval_getString", u"A and ", str); } UConstrainedFieldPosition *fpos = ucfpos_open(&status); assertSuccess("ucfpos_open", &status); ucfpos_constrainField(fpos, UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD, &status); assertSuccess("ucfpos_constrainField", &status); bool hasMore = ufmtval_nextPosition(value, fpos, &status); assertSuccess("ufmtval_nextPosition", &status); assertTrue("hasMore 1", hasMore); int32_t beginIndex, endIndex; ucfpos_getIndexes(fpos, &beginIndex, &endIndex, &status); assertSuccess("ufmtval_nextPosition", &status); assertIntEquals("TEST beginIndex", 0, beginIndex); assertIntEquals("TEST endIndex", 1, endIndex); hasMore = ufmtval_nextPosition(value, fpos, &status); assertSuccess("ufmtval_nextPosition", &status); assertTrue("hasMore 2", !hasMore); ucfpos_close(fpos); ulistfmt_closeResult(fl); ulistfmt_close(fmt); } static void TestUList21871_B() { UErrorCode status = U_ZERO_ERROR; UListFormatter *fmt = ulistfmt_openForType("en", ULISTFMT_TYPE_AND, ULISTFMT_WIDTH_WIDE, &status); assertSuccess("ulistfmt_openForType", &status); const UChar *strs[] = {u"", u"B"}; const int32_t lens[] = {0, 1}; UFormattedList *fl = ulistfmt_openResult(&status); assertSuccess("ulistfmt_openResult", &status); ulistfmt_formatStringsToResult(fmt, strs, lens, 2, fl, &status); assertSuccess("ulistfmt_formatStringsToResult", &status); const UFormattedValue *value = ulistfmt_resultAsValue(fl, &status); assertSuccess("ulistfmt_resultAsValue", &status); { int32_t len; const UChar *str = ufmtval_getString(value, &len, &status); assertUEquals("TEST ufmtval_getString", u" and B", str); } UConstrainedFieldPosition *fpos = ucfpos_open(&status); assertSuccess("ucfpos_open", &status); ucfpos_constrainField(fpos, UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD, &status); assertSuccess("ucfpos_constrainField", &status); bool hasMore = ufmtval_nextPosition(value, fpos, &status); assertSuccess("ufmtval_nextPosition", &status); assertTrue("hasMore 1", hasMore); int32_t beginIndex, endIndex; ucfpos_getIndexes(fpos, &beginIndex, &endIndex, &status); assertSuccess("ucfpos_getIndexes", &status); assertIntEquals("TEST beginIndex", 5, beginIndex); assertIntEquals("TEST endIndex", 6, endIndex); hasMore = ufmtval_nextPosition(value, fpos, &status); assertSuccess("ufmtval_nextPosition", &status); assertTrue("hasMore 2", !hasMore); ucfpos_close(fpos); ulistfmt_closeResult(fl); ulistfmt_close(fmt); } #endif /* #if !UCONFIG_NO_FORMATTING */
cf76c1d12e1fba47f753b03310b71719b1c0a4a8
dfb59af794367d02891de53923aa3b67f7073472
/src/php/classes/php_vector_ce.c
8b7394d7048029b48edc3256351af5d309651420
[ "MIT", "LicenseRef-scancode-unknown-license-reference" ]
permissive
php-ds/ext-ds
b31df34b05ad14af53a0d23ba7a7a15437f4004a
d42750d69beb684ec3ef7b3da48fba769ce57ffc
refs/heads/master
2023-08-26T11:28:53.328205
2023-07-29T04:04:32
2023-07-29T04:04:32
50,824,235
625
40
MIT
2023-07-29T04:04:33
2016-02-01T08:05:07
C
UTF-8
C
false
false
6,478
c
php_vector_ce.c
#include "../../common.h" #include "../parameters.h" #include "../arginfo.h" #include "../objects/php_vector.h" #include "../iterators/php_vector_iterator.h" #include "../handlers/php_vector_handlers.h" #include "php_collection_ce.h" #include "php_sequence_ce.h" #include "php_vector_ce.h" #define METHOD(name) PHP_METHOD(Vector, name) zend_class_entry *php_ds_vector_ce; METHOD(__construct) { PARSE_OPTIONAL_ZVAL(values); if (values) { ds_vector_push_all(THIS_DS_VECTOR(), values); } } METHOD(allocate) { PARSE_LONG(capacity); ds_vector_allocate(THIS_DS_VECTOR(), capacity); } METHOD(apply) { PARSE_CALLABLE(); ds_vector_apply(THIS_DS_VECTOR(), FCI_ARGS); } METHOD(capacity) { PARSE_NONE; RETURN_LONG((THIS_DS_VECTOR())->capacity); } METHOD(clear) { PARSE_NONE; ds_vector_clear(THIS_DS_VECTOR()); } METHOD(contains) { PARSE_VARIADIC_ZVAL(); RETURN_BOOL(ds_vector_contains_va(THIS_DS_VECTOR(), argc, argv)); } METHOD(copy) { PARSE_NONE; RETURN_OBJ(php_ds_vector_create_clone(THIS_DS_VECTOR())); } METHOD(count) { PARSE_NONE; RETURN_LONG(DS_VECTOR_SIZE(THIS_DS_VECTOR())); } METHOD(filter) { if (ZEND_NUM_ARGS()) { PARSE_CALLABLE(); RETURN_DS_VECTOR(ds_vector_filter_callback(THIS_DS_VECTOR(), FCI_ARGS)); } else { RETURN_DS_VECTOR(ds_vector_filter(THIS_DS_VECTOR())); } } METHOD(find) { PARSE_ZVAL(value); ds_vector_find(THIS_DS_VECTOR(), value, return_value); } METHOD(first) { PARSE_NONE; RETURN_ZVAL_COPY(ds_vector_get_first_throw(THIS_DS_VECTOR())); } METHOD(get) { PARSE_LONG(index); RETURN_ZVAL_COPY(ds_vector_get(THIS_DS_VECTOR(), index)); } METHOD(insert) { PARSE_LONG_AND_VARIADIC_ZVAL(index); ds_vector_insert_va(THIS_DS_VECTOR(), index, argc, argv); } METHOD(isEmpty) { PARSE_NONE; RETURN_BOOL(DS_VECTOR_IS_EMPTY(THIS_DS_VECTOR())); } METHOD(join) { if (ZEND_NUM_ARGS()) { PARSE_STRING(); ds_vector_join(THIS_DS_VECTOR(), str, len, return_value); } else { ds_vector_join(THIS_DS_VECTOR(), NULL, 0, return_value); } } METHOD(jsonSerialize) { PARSE_NONE; ds_vector_to_array(THIS_DS_VECTOR(), return_value); } METHOD(last) { PARSE_NONE; RETURN_ZVAL_COPY(ds_vector_get_last_throw(THIS_DS_VECTOR())); } METHOD(map) { PARSE_CALLABLE(); RETURN_DS_VECTOR(ds_vector_map(THIS_DS_VECTOR(), FCI_ARGS)); } METHOD(merge) { PARSE_ZVAL(values); RETURN_DS_VECTOR(ds_vector_merge(THIS_DS_VECTOR(), values)); } METHOD(pop) { PARSE_NONE; ds_vector_pop_throw(THIS_DS_VECTOR(), return_value); } METHOD(push) { PARSE_VARIADIC_ZVAL(); ds_vector_push_va(THIS_DS_VECTOR(), argc, argv); } METHOD(push_one) { PARSE_ZVAL(value); ds_vector_push(THIS_DS_VECTOR(), value); } METHOD(reduce) { PARSE_CALLABLE_AND_OPTIONAL_ZVAL(initial); ds_vector_reduce(THIS_DS_VECTOR(), initial, return_value, FCI_ARGS); } METHOD(remove) { PARSE_LONG(index); ds_vector_remove(THIS_DS_VECTOR(), index, return_value); } METHOD(reverse) { PARSE_NONE; ds_vector_reverse(THIS_DS_VECTOR()); } METHOD(reversed) { PARSE_NONE; RETURN_DS_VECTOR(ds_vector_reversed(THIS_DS_VECTOR())); } METHOD(rotate) { PARSE_LONG(rotations); ds_vector_rotate(THIS_DS_VECTOR(), rotations); } METHOD(set) { PARSE_LONG_AND_ZVAL(index, value); ds_vector_set(THIS_DS_VECTOR(), index, value); } METHOD(shift) { PARSE_NONE; ds_vector_shift_throw(THIS_DS_VECTOR(), return_value); } METHOD(slice) { ds_vector_t *vector = THIS_DS_VECTOR(); PARSE_LONG_AND_OPTIONAL_ZVAL(index, length); if (ZEND_NUM_ARGS() > 1 && Z_TYPE_P(length) != IS_NULL) { if (Z_TYPE_P(length) != IS_LONG) { INTEGER_LENGTH_REQUIRED(length); } else { RETURN_DS_VECTOR(ds_vector_slice(vector, index, Z_LVAL_P(length))); } } else { RETURN_DS_VECTOR(ds_vector_slice(vector, index, vector->size)); } } METHOD(sort) { ds_vector_t *vector = THIS_DS_VECTOR(); if (ZEND_NUM_ARGS()) { PARSE_COMPARE_CALLABLE(); ds_vector_sort_callback(vector); } else { ds_vector_sort(vector); } } METHOD(sorted) { ds_vector_t *vector = ds_vector_clone(THIS_DS_VECTOR()); if (ZEND_NUM_ARGS()) { PARSE_COMPARE_CALLABLE(); ds_vector_sort_callback(vector); } else { ds_vector_sort(vector); } RETURN_DS_VECTOR(vector); } METHOD(sum) { PARSE_NONE; ds_vector_sum(THIS_DS_VECTOR(), return_value); } METHOD(toArray) { PARSE_NONE; ds_vector_to_array(THIS_DS_VECTOR(), return_value); } METHOD(unshift) { PARSE_VARIADIC_ZVAL(); ds_vector_unshift_va(THIS_DS_VECTOR(), argc, argv); } METHOD(getIterator) { PARSE_NONE; ZVAL_COPY(return_value, getThis()); } METHOD(offsetExists) { PARSE_LONG(index); RETURN_BOOL(ds_vector_isset(THIS_DS_VECTOR(), index, false)); } METHOD(offsetGet) { PARSE_LONG(index); RETURN_ZVAL_COPY(ds_vector_get(THIS_DS_VECTOR(), index)); } METHOD(offsetSet) { PARSE_ZVAL_ZVAL(offset, value); if (Z_TYPE_P(offset) == IS_NULL) { ds_vector_push(THIS_DS_VECTOR(), value); } else { if (Z_TYPE_P(offset) != IS_LONG) { INTEGER_INDEX_REQUIRED(offset); } else { ds_vector_set(THIS_DS_VECTOR(), Z_LVAL_P(offset), value); } } } METHOD(offsetUnset) { PARSE_LONG(index); ds_vector_remove(THIS_DS_VECTOR(), index, return_value); } void php_ds_register_vector() { zend_class_entry ce; zend_function_entry methods[] = { PHP_DS_ME(Vector, __construct) PHP_DS_ME(Vector, getIterator) PHP_DS_SEQUENCE_ME_LIST(Vector) PHP_DS_COLLECTION_ME_LIST(Vector) PHP_FE_END }; INIT_CLASS_ENTRY(ce, PHP_DS_NS(Vector), methods); php_ds_vector_ce = zend_register_internal_class(&ce); php_ds_vector_ce->ce_flags |= ZEND_ACC_FINAL; php_ds_vector_ce->create_object = php_ds_vector_create_object; php_ds_vector_ce->get_iterator = php_ds_vector_get_iterator; php_ds_vector_ce->serialize = php_ds_vector_serialize; php_ds_vector_ce->unserialize = php_ds_vector_unserialize; zend_declare_class_constant_long(php_ds_vector_ce, STR_AND_LEN("MIN_CAPACITY"), DS_VECTOR_MIN_CAPACITY); zend_class_implements(php_ds_vector_ce, 1, sequence_ce); php_register_vector_handlers(); }
f733add65b5d7ccd4f0417f9831a5e30cb8cc507
8e56b05b32a978eb170e01409a7aaaa1fc755979
/lib/libc/locale/runetype_file.h
33a58bd98e6416812b88bc7ada81c1628cb3cab6
[]
permissive
cahirwpz/mimiker
d71f37c2c6efc58a0026e8e4cfcd676d85ef7445
5343231aeeeb0d16b2419f84405f52981dc51c07
refs/heads/master
2023-09-01T20:20:07.256932
2023-08-30T18:36:27
2023-08-30T18:36:27
46,346,617
278
67
BSD-3-Clause
2023-09-14T16:57:32
2015-11-17T12:46:47
C
UTF-8
C
false
false
5,303
h
runetype_file.h
/* $NetBSD: runetype_file.h,v 1.3 2010/06/20 02:23:15 tnozaki Exp $ */ /*- * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Paul Borman at Krystal Technologies. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)runetype.h 8.1 (Berkeley) 6/2/93 */ #ifndef _RUNETYPE_FILE_H_ #define _RUNETYPE_FILE_H_ #include <sys/cdefs.h> #include <sys/types.h> #include "ctype_local.h" /* for cross host tools on older systems */ #ifndef UINT32_C /* assumes sizeof(unsigned int)>=4 */ #define UINT32_C(c) ((uint32_t)(c##U)) #endif typedef uint32_t __nbrune_t; typedef uint64_t __runepad_t; #define _DEFAULT_INVALID_RUNE ((__nbrune_t)-3) /* * The lower 8 bits of runetype[] contain the digit value of the rune. */ typedef uint32_t _RuneType; #define _RUNETYPE_A UINT32_C(0x00000100) /* Alpha */ #define _RUNETYPE_C UINT32_C(0x00000200) /* Control */ #define _RUNETYPE_D UINT32_C(0x00000400) /* Digit */ #define _RUNETYPE_G UINT32_C(0x00000800) /* Graph */ #define _RUNETYPE_L UINT32_C(0x00001000) /* Lower */ #define _RUNETYPE_P UINT32_C(0x00002000) /* Punct */ #define _RUNETYPE_S UINT32_C(0x00004000) /* Space */ #define _RUNETYPE_U UINT32_C(0x00008000) /* Upper */ #define _RUNETYPE_X UINT32_C(0x00010000) /* X digit */ #define _RUNETYPE_B UINT32_C(0x00020000) /* Blank */ #define _RUNETYPE_R UINT32_C(0x00040000) /* Print */ #define _RUNETYPE_I UINT32_C(0x00080000) /* Ideogram */ #define _RUNETYPE_T UINT32_C(0x00100000) /* Special */ #define _RUNETYPE_Q UINT32_C(0x00200000) /* Phonogram */ #define _RUNETYPE_SWM UINT32_C(0xc0000000) /* Mask to get screen width data */ #define _RUNETYPE_SWS 30 /* Bits to shift to get width */ #define _RUNETYPE_SW0 UINT32_C(0x20000000) /* 0 width character */ #define _RUNETYPE_SW1 UINT32_C(0x40000000) /* 1 width character */ #define _RUNETYPE_SW2 UINT32_C(0x80000000) /* 2 width character */ #define _RUNETYPE_SW3 UINT32_C(0xc0000000) /* 3 width character */ /* * rune file format. network endian. */ typedef struct { int32_t fre_min; /* First rune of the range */ int32_t fre_max; /* Last rune (inclusive) of the range */ int32_t fre_map; /* What first maps to in maps */ uint32_t fre_pad1; /* backward compatibility */ __runepad_t fre_pad2; /* backward compatibility */ } __packed _FileRuneEntry; typedef struct { uint32_t frr_nranges; /* Number of ranges stored */ uint32_t frr_pad1; /* backward compatibility */ __runepad_t frr_pad2; /* backward compatibility */ } __packed _FileRuneRange; typedef struct { char frl_magic[8]; /* Magic saying what version we are */ char frl_encoding[32]; /* ASCII name of this encoding */ __runepad_t frl_pad1; /* backward compatibility */ __runepad_t frl_pad2; /* backward compatibility */ int32_t frl_invalid_rune; uint32_t frl_pad3; /* backward compatibility */ _RuneType frl_runetype[_CTYPE_CACHE_SIZE]; int32_t frl_maplower[_CTYPE_CACHE_SIZE]; int32_t frl_mapupper[_CTYPE_CACHE_SIZE]; /* * The following are to deal with Runes larger than _CTYPE_CACHE_SIZE - 1. * Their data is actually contiguous with this structure so as to make * it easier to read/write from/to disk. */ _FileRuneRange frl_runetype_ext; _FileRuneRange frl_maplower_ext; _FileRuneRange frl_mapupper_ext; __runepad_t frl_pad4; /* backward compatibility */ int32_t frl_variable_len; /* how long that data is */ uint32_t frl_pad5; /* backward compatibility */ /* variable size data follows */ } __packed _FileRuneLocale; /* magic number for LC_CTYPE (rune)locale declaration */ #define _RUNECT10_MAGIC "RuneCT10" /* Indicates version 0 of RuneLocale */ /* codeset tag */ #define _RUNE_CODESET "CODESET=" #endif /* !_RUNETYPE_FILE_H_ */
b5bd08b014dd412bb5fbb7864fab6e8d52affb36
810237086aae7600b9ef87a610aec4777b1bf156
/Example/Pods/Headers/Private/SJVideoPlayer/SJClipsVideoCountDownView.h
93004d6eecb3302b72633d140bedae9c97fd5ae3
[ "MIT" ]
permissive
changsanjiang/SJVideoPlayer
f63f3156d5ad07ec107b0feb481110222dd45a85
bff75e1f7f033edc05e07c333ce3557cb289c95c
refs/heads/master
2022-12-20T22:47:04.095976
2022-12-10T08:57:46
2022-12-10T08:57:46
100,693,284
2,680
513
MIT
2022-11-02T11:04:42
2017-08-18T08:56:30
Objective-C
UTF-8
C
false
false
100
h
SJClipsVideoCountDownView.h
../../../../../SJVideoPlayer/ControlLayers/SJClipsControlLayer/Core/View/SJClipsVideoCountDownView.h
26cbcba34a0896f0c00344eab065279d06831364
a5a99f646e371b45974a6fb6ccc06b0a674818f2
/Validation/TrackerHits/test/SiTrackerHitsCompareToF.C
cdf46f3ecdb5cc1e32c17bf3994ed238012afe9d
[ "Apache-2.0" ]
permissive
cms-sw/cmssw
4ecd2c1105d59c66d385551230542c6615b9ab58
19c178740257eb48367778593da55dcad08b7a4f
refs/heads/master
2023-08-23T21:57:42.491143
2023-08-22T20:22:40
2023-08-22T20:22:40
10,969,551
1,006
3,696
Apache-2.0
2023-09-14T19:14:28
2013-06-26T14:09:07
C++
UTF-8
C
false
false
4,601
c
SiTrackerHitsCompareToF.C
void SiTrackerHitsCompareToF() { gROOT ->Reset(); gStyle->SetNdivisions(504,"XYZ"); gStyle->SetStatH(0.18); gStyle->SetStatW(0.35); char* cfilename = "TrackerHitHisto.root"; //current char* rfilename = "../TrackerHitHisto.root"; //reference delete gROOT->GetListOfFiles()->FindObject(rfilename); delete gROOT->GetListOfFiles()->FindObject(cfilename); TText* te = new TText(); TFile * rfile = new TFile(rfilename); TDirectory * rdir=gDirectory; TFile * cfile = new TFile(cfilename); TDirectory * cdir=gDirectory; if(rfile->cd("DQMData/Run 1/TrackerHitsV"))rfile->cd("DQMData/Run 1/TrackerHitsV/Run summary/TrackerHit"); else rfile->cd("DQMData/TrackerHitsV/TrackerHit"); rdir=gDirectory; if(cfile->cd("DQMData/Run 1/TrackerHitsV"))cfile->cd("DQMData/Run 1/TrackerHitsV/Run summary/TrackerHit"); else cfile->cd("DQMData/TrackerHitsV/TrackerHit"); cdir=gDirectory; TLegend leg(0.3, 0.83, 0.55, 0.90); //Get list of Keys from the Reference file. TList* ref_list = rfile->GetListOfKeys() ; if (!ref_list) { std::cout<<"=========>> AutoComaprison:: There is no Keys available in the Reference file."<<std::endl; exit(1) ; } //Get list of Keys from the New file. TList* new_list = cfile->GetListOfKeys() ; if (!new_list) { std::cout<<"=========>> AutoComaprison:: There is no Keys available in New file."<<std::endl; exit(1) ; } //Iterate on the List of Keys of the Reference file. TIter refkey_iter( ref_list) ; TKey* ref_key ; TObject* ref_obj ; char rver[50]; char cver[50]; while ( ref_key = (TKey*) refkey_iter() ) { ref_obj = ref_key->ReadObj() ; if (strcmp(ref_obj->IsA()->GetName(),"TObjString")==0) { TObjString * rversion = dynamic_cast< TObjString*> (ref_obj); sprintf(rver, "%s", rversion->GetName()); std::cout<<" Ref. version =" << rver<<std::endl; break; } } //Iterate on the List of Keys of the Reference file. TIter newkey_iter( new_list) ; TKey* new_key ; TObject* new_obj ; while ( new_key = (TKey*) newkey_iter() ) { new_obj = new_key->ReadObj() ; if (strcmp(new_obj->IsA()->GetName(),"TObjString")==0) { TObjString * cversion = dynamic_cast< TObjString*> (new_obj); sprintf(cver, "%s", cversion->GetName()); std::cout<<" Cur version =" << cver<<std::endl; break; } } ofstream outfile("LowKS_energy_list.dat"); string statp = "KS prob"; Double_t ks1e[12],ks2e[12],ks3e[12],ks4e[12],ks5e[12],ks6e[12]; gROOT->ProcessLine(".x HistoCompare.C"); HistoCompare * PV = new HistoCompare(); Char_t histo[200]; Char_t profileo[200]; Char_t profilen[200]; std::strstream buf; std::string value; TCanvas * ToF = new TCanvas("ToF","ToF",600,800); ToF->Divide(2,2); TProfile * ch1e[4]; TProfile * rh1e[4]; cout<<cdir->GetPath()<<endl; cout<<rdir->GetPath()<<endl; sprintf(histo,"tof_eta"); sprintf(profileo,"tof_eta_old"); sprintf(profilen,"tof_eta_new"); rh1e[0] = ((TH2F*)rdir->Get(histo))->ProfileX(profileo); ch1e[0] = ((TH2F*)cdir->Get(histo))->ProfileX(profilen); sprintf(histo,"tof_phi"); sprintf(profileo,"tof_phi_old"); sprintf(profilen,"tof_phi_new"); rh1e[1] = ((TH2F*)rdir->Get(histo))->ProfileX(profileo); ch1e[1] = ((TH2F*)cdir->Get(histo))->ProfileX(profilen); sprintf(histo,"tof_r"); sprintf(profileo,"tof_r_old"); sprintf(profilen,"tof_r_new"); rh1e[2] = ((TH2F*)rdir->Get(histo))->ProfileX(profileo); ch1e[2] = ((TH2F*)cdir->Get(histo))->ProfileX(profilen); sprintf(histo,"tof_z"); sprintf(profileo,"tof_z_old"); sprintf(profilen,"tof_z_new"); rh1e[3] = ((TH2F*)rdir->Get(histo))->ProfileX(profileo); ch1e[3] = ((TH2F*)cdir->Get(histo))->ProfileX(profilen); for (Int_t i=0; i<4; i++) { ToF->cd(i+1); if (PV->KSok(rh1e[i] , ch1e[i])) { ks1e[i] = PV->KSCompute(rh1e[i] , ch1e[i] , te ); PV->KSdraw(rh1e[i] , ch1e[i]); rh1e[i]->Draw("h"); ch1e[i]->Draw("h same"); buf<<"KS="<<ks1e[i]<<std::endl; buf>>value; te->DrawTextNDC(0.5,0.7, value.c_str()); leg.Clear(); leg.AddEntry(rh1e[i],rver , "l"); leg.AddEntry(ch1e[i],cver , "l"); leg.Draw(); } // std::cout << " i =" << i << " KS = " << ks1e[i] << std::endl; if (ks1e[i] < 0.1) outfile << ch1e[i]->GetName() <<" KS probability = "<< ks1e[i] <<" "<<endl; } ToF->Print("Tof.eps"); ToF->Print("Tof.gif"); }
75958a1f9eceb9d69ad002e5ec9c6bf66512f6f9
9ceacf33fd96913cac7ef15492c126d96cae6911
/sys/dev/mii/nsgphyreg.h
145b6475840ee6911436c5cc168821a7c366ebee
[]
no_license
openbsd/src
ab97ef834fd2d5a7f6729814665e9782b586c130
9e79f3a0ebd11a25b4bff61e900cb6de9e7795e9
refs/heads/master
2023-09-02T18:54:56.624627
2023-09-02T15:16:12
2023-09-02T15:16:12
66,966,208
3,394
1,235
null
2023-08-08T02:42:25
2016-08-30T18:18:25
C
UTF-8
C
false
false
3,626
h
nsgphyreg.h
/* $OpenBSD: nsgphyreg.h,v 1.5 2005/05/27 09:24:01 brad Exp $ */ /* * Copyright (c) 2001 Wind River Systems * Copyright (c) 2001 * Bill Paul <wpaul@bsdi.com>. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 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. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Bill Paul. * 4. Neither the name of the author nor the names of any co-contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY Bill Paul 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 Bill Paul OR THE VOICES IN HIS HEAD * 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. * * $FreeBSD: /usr/local/www/cvsroot/FreeBSD/src/sys/dev/mii/nsgphyreg.h,v 1.3 2002/04/29 11:57:28 phk Exp $ */ #ifndef _DEV_MII_NSGPHYREG_H_ #define _DEV_MII_NSGPHYREG_H_ /* * NatSemi DP83891 registers */ #define NSGPHY_MII_STRAPOPT 0x10 /* Strap options */ #define NSGPHY_STRAPOPT_PHYADDR 0xF800 /* PHY address */ #define NSGPHY_STRAPOPT_COMPAT 0x0400 /* Broadcom compat mode */ #define NSGPHY_STRAPOPT_MMSE 0x0200 /* Manual master/slave enable */ #define NSGPHY_STRAPOPT_ANEG 0x0100 /* Autoneg enable */ #define NSGPHY_STRAPOPT_MMSV 0x0080 /* Manual master/slave setting */ #define NSGPHY_STRAPOPT_1000HDX 0x0010 /* Advertise 1000 half-duplex */ #define NSGPHY_STRAPOPT_1000FDX 0x0008 /* Advertise 1000 full-duplex */ #define NSGPHY_STRAPOPT_100_ADV 0x0004 /* Advertise 100 full/half-duplex */ #define NSGPHY_STRAPOPT_SPEED1 0x0002 /* speed selection */ #define NSGPHY_STRAPOPT_SPEED0 0x0001 /* speed selection */ #define NSGPHY_STRAPOPT_SPDSEL (NSGPHY_STRAPOPT_SPEED1|NSGPHY_STRAPOPT_SPEED0) #define NSGPHY_MII_PHYSUP 0x11 /* PHY support/current status */ #define PHY_SUP_SPEED1 0x0010 /* speed bit 1 */ #define PHY_SUP_SPEED0 0x0008 /* speed bit 1 */ #define NSGPHY_PHYSUP_SPEED1 0x0010 /* speed status */ #define NSGPHY_PHYSUP_SPEED0 0x0008 /* speed status */ #define NSGPHY_PHYSUP_SPDSTS (NSGPHY_PHYSUP_SPEED1|NSGPHY_PHYSUP_SPEED0) #define NSGPHY_PHYSUP_LNKSTS 0x0004 /* link status */ #define PHY_SUP_LINK 0x0004 /* link status */ #define PHY_SUP_DUPLEX 0x0002 /* 1 == full-duplex */ #define NSGPHY_PHYSUP_DUPSTS 0x0002 /* duplex status 1 == full */ #define NSGPHY_PHYSUP_10BT 0x0001 /* 10baseT resolved */ #define NSGPHY_SPDSTS_1000 0x0010 #define NSGPHY_SPDSTS_100 0x0008 #define NSGPHY_SPDSTS_10 0x0000 #endif /* _DEV_NSGPHY_MIIREG_H_ */
f4a197d75faf00c5c965f76c569f81793acc4175
9b1a345a2377bbac949856f2aac8947ab2e26205
/tests/gdb-tests/tests/binaries/tls.x86-64.c
54c885f0bf780b70a79febfc6ee812691224e04c
[ "MIT" ]
permissive
pwndbg/pwndbg
4577c02d213fa347891d7e0f5415beb2a497c002
f642efbd92e30c7b892b5e816d353cc5a03e5cb5
refs/heads/dev
2023-08-31T10:48:45.172197
2023-08-27T09:55:46
2023-08-27T10:12:02
31,181,767
5,954
1,080
MIT
2023-09-11T11:03:02
2015-02-22T21:35:19
Python
UTF-8
C
false
false
225
c
tls.x86-64.c
void *tls_address; void break_here(void) {} int main(){ // TODO: This only works for x86-64, we should support arm/aarch64 in the future asm("movq %%fs:0, %0" : "=r" (tls_address)); break_here(); return 0; }
4a763ea8cd1fd9ad0c684c792ebcb2ab759a63ac
06052ccd6db697947c1fcbb6ac96eba79c057fea
/lambdaLayers/SharpLayer/nodejs/node_modules/sharp/vendor/8.10.6/include/orc-0.4/orc/orcinternal.h
b86f698b4a9f94be39b0470fd89a21792e96f78d
[ "MIT", "Apache-2.0" ]
permissive
venveo/serverless-sharp
89e673e8ab727a00a5bb3cf2c8b9b3876caec8db
1f64468784763bbf40c32497c35de69406765335
refs/heads/master
2023-04-15T01:45:01.990626
2022-06-29T12:30:07
2022-06-29T12:30:07
198,690,918
165
39
MIT
2023-03-04T04:28:54
2019-07-24T18:38:47
JavaScript
UTF-8
C
false
false
1,111
h
orcinternal.h
#ifndef _ORC_INTERNAL_H_ #define _ORC_INTERNAL_H_ #include <orc/orcutils.h> #include <orc/orclimits.h> ORC_BEGIN_DECLS #ifdef ORC_ENABLE_UNSTABLE_API /* FIXME: not sure why these are exported, no one needs to call these, that's * already done as part of orc_init() */ void orc_mmx_init (void); void orc_sse_init (void); void orc_arm_init (void); void orc_powerpc_init (void); void orc_c_init (void); void orc_neon_init (void); void orc_c64x_init (void); void orc_c64x_c_init (void); void orc_mips_init (void); typedef struct _OrcCodeChunk OrcCodeChunk; /* This is internal API, nothing in the public headers returns an OrcCodeChunk */ void orc_code_chunk_free (OrcCodeChunk *chunk); extern int _orc_data_cache_size_level1; extern int _orc_data_cache_size_level2; extern int _orc_data_cache_size_level3; extern int _orc_cpu_family; extern int _orc_cpu_model; extern int _orc_cpu_stepping; extern const char *_orc_cpu_name; void orc_compiler_emit_invariants (OrcCompiler *compiler); int orc_program_has_float (OrcCompiler *compiler); char* _orc_getenv (const char *var); #endif ORC_END_DECLS #endif
370cf3c797b1e04c6d109f93b178965a6b225a1b
9907672fcd81ab73ac63b2a83422a82bf31eadde
/tyama_PG110502.c
f00a169d9471c9915c0ecddec776cd5607acb6b7
[ "0BSD" ]
permissive
cielavenir/procon
bbe1974b9bddb51b76d58722a0686a5b477c4456
746e1a91f574f20647e8aaaac0d9e6173f741176
refs/heads/master
2023-06-21T23:11:24.562546
2023-06-11T13:15:15
2023-06-11T13:15:15
7,557,464
137
136
null
2020-10-20T09:35:52
2013-01-11T09:40:26
C++
UTF-8
C
false
false
976
c
tyama_PG110502.c
//tyama070521reverse.c #include <stdio.h> #include <stdlib.h> #include <string.h> #if 0 reverse()の設計ミス。place()もpower()も不必要でした。 int place(unsigned u){ unsigned t=u/10; if(!t)return 0; return (place(t))+1; /*asmが使えれば絶対その方が早い。Cだと++がコンパイルエラーにw __asm{ xor edx,edx mov eax, u div 10 test eax, 0 jz @return push eax call place inc eax ret @return xor eax, eax ret } */ } //マイコンクラブのscheme講習会で作ったものの移植w unsigned power(unsigned u, int i){ if(!i)return 1; return u*power(u,--i); } #endif unsigned reverse(unsigned u){ unsigned ret=0; while(u){ ret=ret*10+u%10; u/=10; } return ret; } void main(){ unsigned u; int i,n,count; scanf("%d", &n); for(i=0;i<n;i++){ count=0; scanf("%u", &u); while(u!=reverse(u)){ u+=reverse(u); count++; } printf("%d %u\n",count,u); } }
955e54f3a527d6fadb9b9fe5eea3ec44bfb9e7f6
88ae8695987ada722184307301e221e1ba3cc2fa
/third_party/ffmpeg/libavcodec/brenderpix.c
e95ab3d4afdf241ad013f597571f5323cf144718
[ "LGPL-2.1-only", "LGPL-3.0-only", "LGPL-2.0-or-later", "GPL-1.0-or-later", "GPL-2.0-only", "LGPL-2.1-or-later", "GPL-3.0-or-later", "LGPL-3.0-or-later", "IJG", "LicenseRef-scancode-other-permissive", "MIT", "GPL-2.0-or-later", "Apache-2.0", "GPL-3.0-only", "BSD-3-Clause" ]
permissive
iridium-browser/iridium-browser
71d9c5ff76e014e6900b825f67389ab0ccd01329
5ee297f53dc7f8e70183031cff62f37b0f19d25f
refs/heads/master
2023-08-03T16:44:16.844552
2023-07-20T15:17:00
2023-07-23T16:09:30
220,016,632
341
40
BSD-3-Clause
2021-08-13T13:54:45
2019-11-06T14:32:31
null
UTF-8
C
false
false
10,772
c
brenderpix.c
/* * BRender PIX (.pix) image decoder * Copyright (c) 2012 Aleksi Nurmi * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /* Tested against samples from I-War / Independence War and Defiance. */ #include "libavutil/imgutils.h" #include "avcodec.h" #include "bytestream.h" #include "codec_internal.h" #include "decode.h" #define HEADER1_CHUNK 0x03 #define HEADER2_CHUNK 0x3D #define IMAGE_DATA_CHUNK 0x21 /* In 8-bit colour mode, 256 colours are available at any time. Which 256 * colours are available is determined by the contents of the hardware palette * (or CLUT). In this case, the palette supplied with BRender (std.pal) has * been loaded into the CLUT. * * The 256 colours in std.pal are divided into seven ranges, or `colour ramps'. * The first 64 colours represent shades of grey ranging from very dark grey * (black) to very light grey (white). The following colours are 32-element * ramps for six colours as shown below. */ static const uint32_t std_pal_table[256] = { // gray 0xFF000000, 0xFF030303, 0xFF060606, 0xFF090909, 0xFF0C0C0C, 0xFF0F0F0F, 0xFF121212, 0xFF151515, 0xFF181818, 0xFF1B1B1B, 0xFF1E1E1E, 0xFF212121, 0xFF242424, 0xFF272727, 0xFF2A2A2A, 0xFF2D2D2D, 0xFF313131, 0xFF343434, 0xFF373737, 0xFF3A3A3A, 0xFF3D3D3D, 0xFF404040, 0xFF434343, 0xFF464646, 0xFF494949, 0xFF4C4C4C, 0xFF4F4F4F, 0xFF525252, 0xFF555555, 0xFF585858, 0xFF5B5B5B, 0xFF5E5E5E, 0xFF626262, 0xFF656565, 0xFF686868, 0xFF6B6B6B, 0xFF6E6E6E, 0xFF717171, 0xFF747474, 0xFF777777, 0xFF7A7A7A, 0xFF7D7D7D, 0xFF808080, 0xFF838383, 0xFF868686, 0xFF898989, 0xFF8C8C8C, 0xFF8F8F8F, 0xFF939393, 0xFF999999, 0xFFA0A0A0, 0xFFA7A7A7, 0xFFAEAEAE, 0xFFB4B4B4, 0xFFBBBBBB, 0xFFC2C2C2, 0xFFC9C9C9, 0xFFCFCFCF, 0xFFD6D6D6, 0xFFDDDDDD, 0xFFE4E4E4, 0xFFEAEAEA, 0xFFF1F1F1, 0xFFF8F8F8, // blue 0xFF000000, 0xFF020209, 0xFF050513, 0xFF07071D, 0xFF0A0A27, 0xFF0C0C31, 0xFF0F0F3B, 0xFF111145, 0xFF14144F, 0xFF161659, 0xFF181863, 0xFF1B1B6D, 0xFF1E1E77, 0xFF202080, 0xFF22228A, 0xFF252594, 0xFF28289E, 0xFF2A2AA8, 0xFF2D2DB2, 0xFF2F2FBC, 0xFF3131C6, 0xFF3434D0, 0xFF3737DA, 0xFF3939E4, 0xFF3C3CEE, 0xFF5454F0, 0xFF6C6CF2, 0xFF8585F4, 0xFF9D9DF6, 0xFFB5B5F8, 0xFFCECEFA, 0xFFE6E6FC, // green 0xFF000000, 0xFF020902, 0xFF051305, 0xFF071D07, 0xFF0A270A, 0xFF0C310C, 0xFF0F3B0F, 0xFF114511, 0xFF144F14, 0xFF165916, 0xFF186318, 0xFF1B6D1B, 0xFF1E771E, 0xFF208020, 0xFF228A22, 0xFF259425, 0xFF289E28, 0xFF2AA82A, 0xFF2DB22D, 0xFF2FBC2F, 0xFF31C631, 0xFF34D034, 0xFF37DA37, 0xFF39E439, 0xFF3CEE3C, 0xFF54F054, 0xFF6CF26C, 0xFF85F485, 0xFF9DF69D, 0xFFB5F8B5, 0xFFCEFACE, 0xFFE6FCE6, // cyan 0xFF000000, 0xFF020909, 0xFF051313, 0xFF071D1D, 0xFF0A2727, 0xFF0C3131, 0xFF0F3B3B, 0xFF114545, 0xFF144F4F, 0xFF165959, 0xFF186363, 0xFF1B6D6D, 0xFF1E7777, 0xFF208080, 0xFF228A8A, 0xFF259494, 0xFF289E9E, 0xFF2AA8A8, 0xFF2DB2B2, 0xFF2FBCBC, 0xFF31C6C6, 0xFF34D0D0, 0xFF37DADA, 0xFF39E4E4, 0xFF3CEEEE, 0xFF54F0F0, 0xFF6CF2F2, 0xFF85F4F4, 0xFF9DF6F6, 0xFFB5F8F8, 0xFFCEFAFA, 0xFFE6FCFC, // red 0xFF000000, 0xFF090202, 0xFF130505, 0xFF1D0707, 0xFF270A0A, 0xFF310C0C, 0xFF3B0F0F, 0xFF451111, 0xFF4F1414, 0xFF591616, 0xFF631818, 0xFF6D1B1B, 0xFF771E1E, 0xFF802020, 0xFF8A2222, 0xFF942525, 0xFF9E2828, 0xFFA82A2A, 0xFFB22D2D, 0xFFBC2F2F, 0xFFC63131, 0xFFD03434, 0xFFDA3737, 0xFFE43939, 0xFFEE3C3C, 0xFFF05454, 0xFFF26C6C, 0xFFF48585, 0xFFF69D9D, 0xFFF8B5B5, 0xFFFACECE, 0xFFFCE6E6, // magenta 0xFF000000, 0xFF090209, 0xFF130513, 0xFF1D071D, 0xFF270A27, 0xFF310C31, 0xFF3B0F3B, 0xFF451145, 0xFF4F144F, 0xFF591659, 0xFF631863, 0xFF6D1B6D, 0xFF771E77, 0xFF802080, 0xFF8A228A, 0xFF942594, 0xFF9E289E, 0xFFA82AA8, 0xFFB22DB2, 0xFFBC2FBC, 0xFFC631C6, 0xFFD034D0, 0xFFDA37DA, 0xFFE439E4, 0xFFEE3CEE, 0xFFF054F0, 0xFFF26CF2, 0xFFF485F4, 0xFFF69DF6, 0xFFF8B5F8, 0xFFFACEFA, 0xFFFCE6FC, // yellow 0xFF000000, 0xFF090902, 0xFF131305, 0xFF1D1D07, 0xFF27270A, 0xFF31310C, 0xFF3B3B0F, 0xFF454511, 0xFF4F4F14, 0xFF595916, 0xFF636318, 0xFF6D6D1B, 0xFF77771E, 0xFF808020, 0xFF8A8A22, 0xFF949425, 0xFF9E9E28, 0xFFA8A82A, 0xFFB2B22D, 0xFFBCBC2F, 0xFFC6C631, 0xFFD0D034, 0xFFDADA37, 0xFFE4E439, 0xFFEEEE3C, 0xFFF0F054, 0xFFF2F26C, 0xFFF4F485, 0xFFF6F69D, 0xFFF8F8B5, 0xFFFAFACE, 0xFFFCFCE6, }; typedef struct PixHeader { int width; int height; int format; } PixHeader; static int pix_decode_header(PixHeader *out, GetByteContext *pgb) { unsigned int header_len = bytestream2_get_be32(pgb); out->format = bytestream2_get_byte(pgb); bytestream2_skip(pgb, 2); out->width = bytestream2_get_be16(pgb); out->height = bytestream2_get_be16(pgb); // the header is at least 11 bytes long; we read the first 7 if (header_len < 11) return AVERROR_INVALIDDATA; // skip the rest of the header bytestream2_skip(pgb, header_len - 7); return 0; } static int pix_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt) { int ret, i; GetByteContext gb; unsigned int bytes_pp; unsigned int magic[4]; unsigned int chunk_type; unsigned int data_len; unsigned int bytes_per_scanline; unsigned int bytes_left; PixHeader hdr; bytestream2_init(&gb, avpkt->data, avpkt->size); magic[0] = bytestream2_get_be32(&gb); magic[1] = bytestream2_get_be32(&gb); magic[2] = bytestream2_get_be32(&gb); magic[3] = bytestream2_get_be32(&gb); if (magic[0] != 0x12 || magic[1] != 0x08 || magic[2] != 0x02 || magic[3] != 0x02) { av_log(avctx, AV_LOG_ERROR, "Not a BRender PIX file.\n"); return AVERROR_INVALIDDATA; } chunk_type = bytestream2_get_be32(&gb); if (chunk_type != HEADER1_CHUNK && chunk_type != HEADER2_CHUNK) { av_log(avctx, AV_LOG_ERROR, "Invalid chunk type %d.\n", chunk_type); return AVERROR_INVALIDDATA; } ret = pix_decode_header(&hdr, &gb); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Invalid header length.\n"); return ret; } switch (hdr.format) { case 3: avctx->pix_fmt = AV_PIX_FMT_PAL8; bytes_pp = 1; break; case 4: avctx->pix_fmt = AV_PIX_FMT_RGB555BE; bytes_pp = 2; break; case 5: avctx->pix_fmt = AV_PIX_FMT_RGB565BE; bytes_pp = 2; break; case 6: avctx->pix_fmt = AV_PIX_FMT_RGB24; bytes_pp = 3; break; case 7: avctx->pix_fmt = AV_PIX_FMT_0RGB; bytes_pp = 4; break; case 8: // ARGB avctx->pix_fmt = AV_PIX_FMT_ARGB; bytes_pp = 4; break; case 18: avctx->pix_fmt = AV_PIX_FMT_YA8; bytes_pp = 2; break; default: avpriv_request_sample(avctx, "Format %d", hdr.format); return AVERROR_PATCHWELCOME; } bytes_per_scanline = bytes_pp * hdr.width; if (bytestream2_get_bytes_left(&gb) < hdr.height * bytes_per_scanline) return AVERROR_INVALIDDATA; if ((ret = ff_set_dimensions(avctx, hdr.width, hdr.height)) < 0) return ret; if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) return ret; chunk_type = bytestream2_get_be32(&gb); if (avctx->pix_fmt == AV_PIX_FMT_PAL8 && (chunk_type == HEADER1_CHUNK || chunk_type == HEADER2_CHUNK)) { /* read palette data from data[1] */ PixHeader palhdr; uint32_t *pal_out = (uint32_t *)frame->data[1]; ret = pix_decode_header(&palhdr, &gb); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Invalid palette header length.\n"); return ret; } if (palhdr.format != 7) avpriv_request_sample(avctx, "Palette not in RGB format"); chunk_type = bytestream2_get_be32(&gb); data_len = bytestream2_get_be32(&gb); bytestream2_skip(&gb, 8); if (chunk_type != IMAGE_DATA_CHUNK || data_len != 1032 || bytestream2_get_bytes_left(&gb) < 1032) { av_log(avctx, AV_LOG_ERROR, "Invalid palette data.\n"); return AVERROR_INVALIDDATA; } // palette data is surrounded by 8 null bytes (both top and bottom) // convert 0RGB to machine endian format (ARGB32) for (i = 0; i < 256; ++i) *pal_out++ = (0xFFU << 24) | bytestream2_get_be32u(&gb); bytestream2_skip(&gb, 8); frame->palette_has_changed = 1; chunk_type = bytestream2_get_be32(&gb); } else if (avctx->pix_fmt == AV_PIX_FMT_PAL8) { /* no palette supplied, use the default one */ uint32_t *pal_out = (uint32_t *)frame->data[1]; // TODO: add an AVOption to load custom palette files av_log(avctx, AV_LOG_WARNING, "Using default palette, colors might be off.\n"); memcpy(pal_out, std_pal_table, sizeof(uint32_t) * 256); frame->palette_has_changed = 1; } data_len = bytestream2_get_be32(&gb); bytestream2_skip(&gb, 8); // read the image data to the buffer bytes_left = bytestream2_get_bytes_left(&gb); if (chunk_type != IMAGE_DATA_CHUNK || data_len != bytes_left || bytes_left / bytes_per_scanline < hdr.height) { av_log(avctx, AV_LOG_ERROR, "Invalid image data.\n"); return AVERROR_INVALIDDATA; } av_image_copy_plane(frame->data[0], frame->linesize[0], avpkt->data + bytestream2_tell(&gb), bytes_per_scanline, bytes_per_scanline, hdr.height); frame->pict_type = AV_PICTURE_TYPE_I; frame->key_frame = 1; *got_frame = 1; return avpkt->size; } const FFCodec ff_brender_pix_decoder = { .p.name = "brender_pix", CODEC_LONG_NAME("BRender PIX image"), .p.type = AVMEDIA_TYPE_VIDEO, .p.id = AV_CODEC_ID_BRENDER_PIX, .p.capabilities = AV_CODEC_CAP_DR1, FF_CODEC_DECODE_CB(pix_decode_frame), };
3c9668d41bde1884ed683c43f1a70f38612c8539
6601ed1b6c24e8b7e78312aeaadf816262c4bee3
/c/apps/aion/timestamp_compare.c
c8c7f20173d4874c8dfd82d378f9cd67221c99c2
[ "BSD-2-Clause" ]
permissive
t-crest/patmos
bb9764c5897ee8bbac2a336cb09d7bb77d54916a
c63dadffa3db2ad241c31ae6e952d6fe2298986a
refs/heads/master
2023-04-11T12:18:37.795018
2023-03-25T17:57:33
2023-03-25T17:57:33
1,500,522
108
90
BSD-2-Clause
2023-03-25T17:57:35
2011-03-19T17:01:39
VHDL
UTF-8
C
false
false
5,884
c
timestamp_compare.c
/* Comparing hardware vs software timestamping capabilities Experiments with ping request/reply implemented in Patmos (80MHz) showed: Max ping request processing rate: ~900 us Demo cycle takes: 207.7625 us Checking for packet takes: ~157.4875 us Processing ping takes: ~70 us Author: Eleftherios Kyriakakis Copyright: DTU, BSD License */ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <machine/patmos.h> #include <machine/exceptions.h> #include <machine/spm.h> #include "ethlib/icmp.h" #include "ethlib/arp.h" #include "ethlib/mac.h" #include "ethlib/udp.h" #include "ethlib/ipv4.h" #include "ethlib/eth_mac_driver.h" #include "ethlib/ptp1588.h" #define NO_RX_PACKETS 100 const char* eth_protocol_names[] = {"UFF", "IP", "ICMP", "UDP", "TCP", "PTP", "ARP", "LLDP", "MDNS", "TTE_PCF"}; unsigned int rx_addr = 0x000; unsigned int tx_addr = 0x800; const unsigned char multicastip[4] = {224, 0, 0, 255}; volatile _SPM int *uart_ptr = (volatile _SPM int *) PATMOS_IO_UART; volatile _SPM int *led_ptr = (volatile _SPM int *) PATMOS_IO_LED; volatile _SPM int *key_ptr = (volatile _SPM int *) PATMOS_IO_KEYS; volatile _SPM unsigned *disp_ptr = (volatile _SPM unsigned *) PATMOS_IO_SEGDISP; //Variables unsigned int initNanoseconds; unsigned int initSeconds; PTPPortInfo thisPtpPortInfo; PTPv2Time softTimestamp; PTPv2Time hardTimestamp; float avgJitterNs = 0.0; int maxJitterNs = 0.0; int jitterNsLog[NO_RX_PACKETS]; unsigned short rxPacketLog[NO_RX_PACKETS]; unsigned short rxSizeLog[NO_RX_PACKETS]; unsigned int ethPeriodLog[NO_RX_PACKETS]; int rxPacketCount; void print_general_info(){ printf("\nGeneral info:\n"); printf("\tMAC: %llx", get_mac_address()); printf("\n\tIP: "); ipv4_print_my_ip(); printf("\n"); arp_table_print(); printf("\n"); return; } void printSegmentInt(unsigned number) { *(disp_ptr+0) = number & 0xF; *(disp_ptr+1) = (number >> 4) & 0xF; *(disp_ptr+2) = (number >> 8) & 0xF; *(disp_ptr+3) = (number >> 12) & 0xF; *(disp_ptr+4) = (number >> 16) & 0xF; *(disp_ptr+5) = (number >> 20) & 0xF; *(disp_ptr+6) = (number >> 24) & 0xF; *(disp_ptr+7) = (number >> 28) & 0xF; } void testRTCAdjustment(){ initNanoseconds = RTC_TIME_NS(thisPtpPortInfo.eth_base); initSeconds = RTC_TIME_SEC(thisPtpPortInfo.eth_base); RTC_ADJUST_OFFSET(thisPtpPortInfo.eth_base) = 0x1000; while((*led_ptr=RTC_ADJUST_OFFSET(thisPtpPortInfo.eth_base)) != 0){printSegmentInt(*led_ptr);} RTC_TIME_NS(thisPtpPortInfo.eth_base) = initNanoseconds; RTC_TIME_SEC(thisPtpPortInfo.eth_base) = initSeconds; } int receiveAndHandleFrame(const unsigned int timeout){ unsigned short dest_port; if(eth_mac_receive(rx_addr, timeout)){ softTimestamp.nanoseconds = (unsigned) RTC_TIME_NS(thisPtpPortInfo.eth_base); softTimestamp.seconds = (unsigned) RTC_TIME_SEC(thisPtpPortInfo.eth_base); switch (mac_packet_type(rx_addr)) { case ICMP: return (icmp_process_received(rx_addr, tx_addr)==0) ? -ICMP : ICMP; case UDP: dest_port = udp_get_destination_port(rx_addr); if((dest_port==PTP_EVENT_PORT) || (dest_port==PTP_GENERAL_PORT)){ return (ptpv2_process_received(thisPtpPortInfo, tx_addr, rx_addr)!=PTP_DLYRPLY_MSGTYPE) ? -PTP : PTP; } else if (dest_port==5353){ return MDNS; } else { return UDP; } case TCP: return TCP; case ARP: return (arp_process_received(rx_addr, tx_addr)==0) ? -ARP : ARP; case TTE_PCF: return TTE_PCF; default: return UNSUPPORTED; } } else { return -1; } } int demoLoop(){ int packetType = receiveAndHandleFrame(1000000); *led_ptr = packetType; if(packetType != -1){ if(abs(packetType) == PTP){ //then use the already consumed hardware timestamp hardTimestamp.nanoseconds = ptpTimeRecord.t4Nanoseconds; hardTimestamp.seconds = ptpTimeRecord.t4Seconds; } else { hardTimestamp.nanoseconds = (unsigned) PTP_RXCHAN_TIMESTAMP_NS(thisPtpPortInfo.eth_base); hardTimestamp.seconds = (unsigned) PTP_RXCHAN_TIMESTAMP_SEC(thisPtpPortInfo.eth_base); PTP_RXCHAN_STATUS(thisPtpPortInfo.eth_base) = 0x1; //Clear PTP timestampAvail flag } int jitterNs = (hardTimestamp.nanoseconds-softTimestamp.nanoseconds); avgJitterNs = abs(avgJitterNs + jitterNs); if(jitterNs > maxJitterNs) maxJitterNs = jitterNs; jitterNsLog[rxPacketCount] = jitterNs; rxPacketLog[rxPacketCount] = packetType; rxSizeLog[rxPacketCount] = ipv4_get_length(rx_addr); ethPeriodLog[rxPacketCount] = abs(initNanoseconds-hardTimestamp.nanoseconds); initNanoseconds = hardTimestamp.nanoseconds; return jitterNs; } else { return 0; } } int main(int argc, char **argv){ *led_ptr = 0x1FF; puts("\nEthernet Timestamping Demo Started"); //MAC controller settings set_mac_address(0x1D000400, 0x00000289); //MODER: PAD|HUGEN|CRCEN|DLYCRCEN|-|FULLD|EXDFREN|NOBCKOF|LOOPBCK|IFG|PRO|IAM|BRO|NOPRE|TXEN|RXEN eth_iowr(0x00, 0x0000A423); ipv4_set_my_ip((unsigned char[4]) {192, 168, 2, 69}); arp_table_init(); print_general_info(); thisPtpPortInfo = ptpv2_intialize_local_port(PATMOS_IO_ETH, PTP_SLAVE, my_mac, my_ip, 1, 0); //Test offset testRTCAdjustment(); initNanoseconds = 0; initSeconds = 0; *led_ptr = 0x100; //Demo for(rxPacketCount=0; rxPacketCount < NO_RX_PACKETS; rxPacketCount++){ demoLoop(); printSegmentInt(get_ptp_secs(thisPtpPortInfo.eth_base)); if(*key_ptr == 0xE) break; } //Report printf("Received No. Packets = %d\n", rxPacketCount); printf("Avg. timestamping jitter = %.3f (ns)\n", avgJitterNs / rxPacketCount); printf("Max. timestamping jitter = %d.000 (ns)\n", maxJitterNs); puts("Jitter log:"); puts("------------------------------------------"); puts("Eth Type;\tLength;\tJitter(ns);\tPeriod(ns);"); for(int i=0;i<NO_RX_PACKETS;i++){ printf("%s;\t%d;\t%d;\t%d\n", eth_protocol_names[rxPacketLog[i]], rxSizeLog[i], jitterNsLog[i], ethPeriodLog[i]); } puts("\nExiting!"); return 0; }
f607e2b9f0b44e88aa92e8cf35dec6a7ce433056
85b4bbde9e0ec36b0db29463281c36b24e1f161d
/interfaces/simulink/hpipm_sfun.c
442bad3997c13205a571dffcc5d76a7bfb0650f5
[ "BSD-2-Clause" ]
permissive
giaf/hpipm
9617000b88c3a65842154e86209a09a067fe34ac
b5239f756181918f97deca39884d12dc6286dc73
refs/heads/master
2023-08-17T01:13:25.056738
2023-08-15T15:02:11
2023-08-15T15:02:11
91,068,419
398
120
NOASSERTION
2023-08-15T20:51:27
2017-05-12T08:20:10
C
UTF-8
C
false
false
8,969
c
hpipm_sfun.c
#define S_FUNCTION_NAME hpipm_solver_sfunction #define S_FUNCTION_LEVEL 2 #define MDL_START // HPIPM #include <blasfeo_d_aux_ext_dep.h> #include "hpipm_d_ocp_qp_ipm.h" #include "hpipm_d_ocp_qp_dim.h" #include "hpipm_d_ocp_qp.h" #include "hpipm_d_ocp_qp_sol.h" #include "hpipm_timing.h" #include "simstruc.h" #define SAMPLINGTIME -1 // memory as global data void *dim_mem; void *qp_mem; void *qp_sol_mem; void *ipm_arg_mem; void *ipm_mem; // hpipm structs as global data struct d_ocp_qp *qp; struct d_ocp_qp_sol *qp_sol; struct d_ocp_qp_dim *dim; struct d_ocp_qp_ipm_arg *arg; struct d_ocp_qp_ipm_ws *workspace; // timing structures struct timeval tv0, tv1; // auxiliary dimensions int nx_total; int nu_total; // qp data as global data // qp data as global data extern int N; extern int *nx; extern int *nu; extern int *nbu; extern int *nbx; extern int *ng; extern int *nsbx; extern int *nsbu; extern int *nsg; extern double **hA; extern double **hB; extern double **hb; extern double **hQ; extern double **hR; extern double **hS; extern double **hq; extern double **hr; extern int **hidxbx; extern double **hlbx; extern double **hubx; extern int **hidxbu; extern double **hlbu; extern double **hubu; extern double **hC; extern double **hD; extern double **hlg; extern double **hug; extern double **hZl; extern double **hZu; extern double **hzl; extern double **hzu; extern int **hidxs; extern double **hlls; extern double **hlus; // arg extern int mode; extern int iter_max; extern double alpha_min; extern double mu0; extern double tol_stat; extern double tol_eq; extern double tol_ineq; extern double tol_comp; extern double reg_prim; extern int warm_start; extern int pred_corr; extern int ric_alg; static void mdlInitializeSizes (SimStruct *S) { // specify the number of continuous and discrete states ssSetNumContStates(S, 0); ssSetNumDiscStates(S, 0); // specify the number of input ports if ( !ssSetNumInputPorts(S, 1) ) return; // specify the number of output ports if ( !ssSetNumOutputPorts(S, 4) ) return; // specify dimension information for the input ports ssSetInputPortVectorDimension(S, 0, nx[0]); // specify dimension information for the output ports // compute sum of dimensions nx_total = 0; nu_total = 0; for(int i = 0; i <= N; i++) nu_total += nu[i]; for(int i = 0; i <= N; i++) nx_total += nx[i]; ssSetOutputPortVectorDimension(S, 0, nu_total); // optimal input trajectory ssSetOutputPortVectorDimension(S, 1, nx_total); // optimal state trajectory ssSetOutputPortVectorDimension(S, 2, 1 ); // solver status ssSetOutputPortVectorDimension(S, 3, 1); // computation times // specify the direct feedthrough status ssSetInputPortDirectFeedThrough(S, 0, 1); // current state x0 // one sample time ssSetNumSampleTimes(S, 1); } #if defined(MATLAB_MEX_FILE) #define MDL_SET_INPUT_PORT_DIMENSION_INFO #define MDL_SET_OUTPUT_PORT_DIMENSION_INFO static void mdlSetInputPortDimensionInfo(SimStruct *S, int_T port, const DimsInfo_T *dimsInfo) { if ( !ssSetInputPortDimensionInfo(S, port, dimsInfo) ) return; } static void mdlSetOutputPortDimensionInfo(SimStruct *S, int_T port, const DimsInfo_T *dimsInfo) { if ( !ssSetOutputPortDimensionInfo(S, port, dimsInfo) ) return; } #endif /* MATLAB_MEX_FILE */ static void mdlInitializeSampleTimes(SimStruct *S) { ssSetSampleTime(S, 0, SAMPLINGTIME); ssSetOffsetTime(S, 0, 0.0); } static void mdlStart(SimStruct *S) { int ii; int rep, nrep=10; /************************************************ * ocp qp dim ************************************************/ hpipm_size_t dim_size = d_ocp_qp_dim_memsize(N); dim_mem = malloc(dim_size); if(dim_mem == NULL) printf("Error allocating memory for dim_mem. Exiting.\n\n"); dim = malloc(sizeof(struct d_ocp_qp_dim)); if(dim == NULL) printf("Error allocating memory for dim. Exiting.\n\n"); d_ocp_qp_dim_create(N, dim, dim_mem); d_ocp_qp_dim_set_all(nx, nu, nbx, nbu, ng, nsbx, nsbu, nsg, dim); /************************************************ * ocp qp ************************************************/ hpipm_size_t qp_size = d_ocp_qp_memsize(dim); qp_mem = malloc(qp_size); if(qp_mem == NULL) printf("Error allocating memory for qp_mem. Exiting.\n\n"); qp = malloc(sizeof(struct d_ocp_qp)); if(qp == NULL) printf("Error allocating memory for qp. Exiting.\n\n"); d_ocp_qp_create(dim, qp, qp_mem); d_ocp_qp_set_all(hA, hB, hb, hQ, hS, hR, hq, hr, hidxbx, hlbx, hubx, hidxbu, hlbu, hubu, hC, hD, hlg, hug, hZl, hZu, hzl, hzu, hidxs, hlls, hlus, qp); /************************************************ * ocp qp sol ************************************************/ hpipm_size_t qp_sol_size = d_ocp_qp_sol_memsize(dim); qp_sol_mem = malloc(qp_sol_size); if(qp_sol_mem == NULL) printf("Error allocating memory for qp_sol_mem. Exiting.\n\n"); qp_sol = malloc(sizeof(struct d_ocp_qp_sol)); if(qp_sol == NULL) printf("Error allocating memory for qp_sol. Exiting.\n\n"); d_ocp_qp_sol_create(dim, qp_sol, qp_sol_mem); /************************************************ * ipm arg ************************************************/ hpipm_size_t ipm_arg_size = d_ocp_qp_ipm_arg_memsize(dim); ipm_arg_mem = malloc(ipm_arg_size); if(ipm_arg_mem == NULL) printf("Error allocating memory for ipm_arg_mem. Exiting.\n\n"); arg = malloc(sizeof(struct d_ocp_qp_ipm_arg)); if(arg == NULL) printf("Error allocating memory for arg. Exiting.\n\n"); d_ocp_qp_ipm_arg_create(dim, arg, ipm_arg_mem); d_ocp_qp_ipm_arg_set_default(mode, arg); d_ocp_qp_ipm_arg_set_mu0(&mu0, arg); d_ocp_qp_ipm_arg_set_iter_max(&iter_max, arg); d_ocp_qp_ipm_arg_set_tol_stat(&tol_stat, arg); d_ocp_qp_ipm_arg_set_tol_eq(&tol_eq, arg); d_ocp_qp_ipm_arg_set_tol_ineq(&tol_ineq, arg); d_ocp_qp_ipm_arg_set_tol_comp(&tol_comp, arg); d_ocp_qp_ipm_arg_set_reg_prim(&reg_prim, arg); d_ocp_qp_ipm_arg_set_warm_start(&warm_start, arg); // d_ocp_qp_ipm_arg_set_ric_alg(&ric_alg, arg); /************************************************ * ipm workspace ************************************************/ hpipm_size_t ipm_size = d_ocp_qp_ipm_ws_memsize(dim, arg); ipm_mem = malloc(ipm_size); workspace = malloc(sizeof(struct d_ocp_qp_ipm_ws)); if(workspace == NULL) printf("Error allocating memory for workspace. Exiting.\n\n"); d_ocp_qp_ipm_ws_create(dim, arg, workspace, ipm_mem); } static void mdlOutputs(SimStruct *S, int_T tid) { int hpipm_status; int ii; // get input signals InputRealPtrsType in_x0_sign; // InputRealPtrsType in_y_ref_sign; // InputRealPtrsType in_y_ref_e_sign; // local buffers double in_x0[nx[0]]; // double in_y_ref[{{ ocp.dims.ny }}]; // double in_y_ref_e[{{ ocp.dims.ny_e }}]; in_x0_sign = ssGetInputPortRealSignalPtrs(S, 0); // in_y_ref_sign = ssGetInputPortRealSignalPtrs(S, 1); // in_y_ref_e_sign = ssGetInputPortRealSignalPtrs(S, 2); // copy signals into local buffers for (int i = 0; i < nx[0]; i++) in_x0[i] = (double)(*in_x0_sign[i]); // for (int i = 0; i < {{ ocp.dims.ny }}; i++) in_y_ref[i] = (double)(*in_y_ref_sign[i]); // for (int i = 0; i < {{ ocp.dims.ny_e }}; i++) in_y_ref_e[i] = (double)(*in_y_ref_e_sign[i]); // for (int i = 0; i < 4; i++) ssPrintf("x0[%d] = %f\n", i, in_x0[i]); // ssPrintf("\n"); // set initial condition d_ocp_qp_set_lbx(0, in_x0, qp); d_ocp_qp_set_ubx(0, in_x0, qp); // update reference // for (int ii = 0; ii < {{ocp.dims.N}}; ii++) // ocp_nlp_cost_model_set(nlp_config, nlp_dims, nlp_in, ii, "yref", (void *) in_y_ref); // assign pointers to output signals double *out_u, *out_x, *out_status, *out_time; out_u = ssGetOutputPortRealSignal(S, 0); out_x = ssGetOutputPortRealSignal(S, 1); out_status = ssGetOutputPortRealSignal(S, 2); out_time = ssGetOutputPortRealSignal(S, 3); hpipm_timer timer; hpipm_tic(&timer); // call solver d_ocp_qp_ipm_solve(qp, qp_sol, arg, workspace); d_ocp_qp_ipm_get_status(workspace, &hpipm_status); *out_time = hpipm_toc(&timer); printf("time = %f\n", out_time); *out_status = (double) hpipm_status; // get solution // u int offset = 0; for(ii=0; ii<=N; ii++) { d_ocp_qp_sol_get_u(ii, qp_sol, out_u+offset); // d_print_mat(1, nu[ii], out_u+offset, 1); offset+=nu[ii]; } // x offset = 0; for(ii=0; ii<=N; ii++) { d_ocp_qp_sol_get_x(ii, qp_sol, out_x+offset); // d_print_mat(1, nx[ii], out_x+offset, 1); offset+=nx[ii]; } } static void mdlTerminate(SimStruct *S) { free(dim_mem); free(qp_mem); free(qp_sol_mem); free(ipm_arg_mem); free(ipm_mem); free(qp); free(qp_sol); free(dim); free(arg); free(workspace); } #ifdef MATLAB_MEX_FILE #include "simulink.c" #else #include "cg_sfun.h" #endif
8a783c122c231c555cf0845c75c28e640f254a5f
99bdb3251fecee538e0630f15f6574054dfc1468
/bsp/stm32/stm32l475-atk-pandora/board/ports/lcd/drv_lcd.c
5fc1417a5c9fa66fdabc29723d54f16d1d51393a
[ "Zlib", "LicenseRef-scancode-proprietary-license", "MIT", "BSD-3-Clause", "X11", "BSD-4-Clause-UC", "LicenseRef-scancode-unknown-license-reference", "Apache-2.0" ]
permissive
RT-Thread/rt-thread
03a7c52c2aeb1b06a544143b0e803d72f47d1ece
3602f891211904a27dcbd51e5ba72fefce7326b2
refs/heads/master
2023-09-01T04:10:20.295801
2023-08-31T16:20:55
2023-08-31T16:20:55
7,408,108
9,599
5,805
Apache-2.0
2023-09-14T13:37:26
2013-01-02T14:49:21
C
UTF-8
C
false
false
22,210
c
drv_lcd.c
/* * Copyright (c) 2006-2023, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2018-08-14 flybreak the first version * 2018-09-18 balanceTWK add sleep mode function * 2018-09-27 ZYLX optimized display speed * 2021-10-17 Meco Man add lcd_fill_array() * 2021-10-17 Meco Man fix the bug of lcd_fill_array() */ #include <rtdevice.h> #include <drv_gpio.h> #include <drv_spi.h> #include "drv_lcd.h" #ifndef BSP_USING_LVGL #include "drv_lcd_font.h" #endif /* BSP_USING_LVGL */ #define DBG_TAG "drv.lcd" #define DBG_LVL DBG_INFO #include <rtdbg.h> #define LCD_DC_PIN GET_PIN(B, 4) #define LCD_RES_PIN GET_PIN(B, 6) #ifndef BSP_USING_LVGL #define LCD_CLEAR_SEND_NUMBER 5760 /* 240*240/10 */ rt_uint16_t BACK_COLOR = WHITE, FORE_COLOR = BLACK; #endif /* BSP_USING_LVGL */ static struct rt_spi_device *spi_dev_lcd; static int rt_hw_lcd_config(void) { spi_dev_lcd = (struct rt_spi_device *)rt_device_find("spi30"); /* config spi */ { struct rt_spi_configuration cfg = {0}; cfg.data_width = 8; cfg.mode = RT_SPI_MASTER | RT_SPI_MODE_0 | RT_SPI_MSB; cfg.max_hz = 42 * 1000 * 1000; /* 42M,SPI max 42MHz,lcd 4-wire spi */ rt_spi_configure(spi_dev_lcd, &cfg); } return RT_EOK; } static rt_err_t lcd_write_cmd(const rt_uint8_t cmd) { rt_size_t len; rt_pin_write(LCD_DC_PIN, PIN_LOW); len = rt_spi_send(spi_dev_lcd, &cmd, 1); if (len != 1) { LOG_I("lcd_write_cmd error. %d", len); return -RT_ERROR; } else { return RT_EOK; } } static rt_err_t lcd_write_data(const rt_uint8_t data) { rt_size_t len; rt_pin_write(LCD_DC_PIN, PIN_HIGH); len = rt_spi_send(spi_dev_lcd, &data, 1); if (len != 1) { LOG_I("lcd_write_data error. %d", len); return -RT_ERROR; } else { return RT_EOK; } } #ifndef BSP_USING_LVGL static rt_err_t lcd_write_half_word(const rt_uint16_t da) { rt_size_t len; char data[2] = {0}; data[0] = da >> 8; data[1] = da; rt_pin_write(LCD_DC_PIN, PIN_HIGH); len = rt_spi_send(spi_dev_lcd, data, 2); if (len != 2) { LOG_I("lcd_write_half_word error. %d", len); return -RT_ERROR; } else { return RT_EOK; } } #endif /* BSP_USING_LVGL */ static void lcd_gpio_init(void) { rt_hw_lcd_config(); rt_pin_mode(LCD_DC_PIN, PIN_MODE_OUTPUT); rt_pin_mode(LCD_RES_PIN, PIN_MODE_OUTPUT); rt_pin_write(LCD_RES_PIN, PIN_LOW); rt_thread_delay(RT_TICK_PER_SECOND / 10); /* wait at least 100ms for reset */ rt_pin_write(LCD_RES_PIN, PIN_HIGH); } static int rt_hw_lcd_init(void) { __HAL_RCC_GPIOD_CLK_ENABLE(); rt_hw_spi_device_attach("spi3", "spi30", GET_PIN(D, 7)); lcd_gpio_init(); /* Memory Data Access Control */ lcd_write_cmd(0x36); lcd_write_data(0x00); /* RGB 5-6-5-bit */ lcd_write_cmd(0x3A); lcd_write_data(0x65); /* Porch Setting */ lcd_write_cmd(0xB2); lcd_write_data(0x0C); lcd_write_data(0x0C); lcd_write_data(0x00); lcd_write_data(0x33); lcd_write_data(0x33); /* Gate Control */ lcd_write_cmd(0xB7); lcd_write_data(0x35); /* VCOM Setting */ lcd_write_cmd(0xBB); lcd_write_data(0x19); /* LCM Control */ lcd_write_cmd(0xC0); lcd_write_data(0x2C); /* VDV and VRH Command Enable */ lcd_write_cmd(0xC2); lcd_write_data(0x01); /* VRH Set */ lcd_write_cmd(0xC3); lcd_write_data(0x12); /* VDV Set */ lcd_write_cmd(0xC4); lcd_write_data(0x20); /* Frame Rate Control in Normal Mode */ lcd_write_cmd(0xC6); lcd_write_data(0x0F); /* Power Control 1 */ lcd_write_cmd(0xD0); lcd_write_data(0xA4); lcd_write_data(0xA1); /* Positive Voltage Gamma Control */ lcd_write_cmd(0xE0); lcd_write_data(0xD0); lcd_write_data(0x04); lcd_write_data(0x0D); lcd_write_data(0x11); lcd_write_data(0x13); lcd_write_data(0x2B); lcd_write_data(0x3F); lcd_write_data(0x54); lcd_write_data(0x4C); lcd_write_data(0x18); lcd_write_data(0x0D); lcd_write_data(0x0B); lcd_write_data(0x1F); lcd_write_data(0x23); /* Negative Voltage Gamma Control */ lcd_write_cmd(0xE1); lcd_write_data(0xD0); lcd_write_data(0x04); lcd_write_data(0x0C); lcd_write_data(0x11); lcd_write_data(0x13); lcd_write_data(0x2C); lcd_write_data(0x3F); lcd_write_data(0x44); lcd_write_data(0x51); lcd_write_data(0x2F); lcd_write_data(0x1F); lcd_write_data(0x1F); lcd_write_data(0x20); lcd_write_data(0x23); /* Display Inversion On */ lcd_write_cmd(0x21); /* Sleep Out */ lcd_write_cmd(0x11); /* wait for power stability */ rt_thread_mdelay(100); /* display on */ lcd_display_on(); lcd_write_cmd(0x29); return RT_EOK; } INIT_COMPONENT_EXPORT(rt_hw_lcd_init); #ifndef BSP_USING_LVGL /** * Set background color and foreground color * * @param back background color * @param fore fore color * * @return void */ void lcd_set_color(rt_uint16_t back, rt_uint16_t fore) { BACK_COLOR = back; FORE_COLOR = fore; } #endif /* BSP_USING_LVGL */ void lcd_display_brightness(rt_uint8_t percent) { struct rt_device_pwm *pwm_dev; if(percent > 100) { percent = 100; } pwm_dev = (struct rt_device_pwm*)rt_device_find("pwm4"); if(pwm_dev != RT_NULL) { rt_pwm_set(pwm_dev, 2, 1000000, percent*10000); /* PB7, PWM4 CH2 with 1000Hz */ rt_pwm_enable(pwm_dev, 2); } } void lcd_display_on(void) { lcd_display_brightness(100); } void lcd_display_off(void) { lcd_display_brightness(0); } /* lcd enter the minimum power consumption mode and backlight off. */ void lcd_enter_sleep(void) { lcd_display_off(); rt_thread_mdelay(5); lcd_write_cmd(0x10); } /* lcd turn off sleep mode and backlight on. */ void lcd_exit_sleep(void) { lcd_display_on(); rt_thread_mdelay(5); lcd_write_cmd(0x11); rt_thread_mdelay(120); } /** * Set drawing area * * @param x1 start of x position * @param y1 start of y position * @param x2 end of x position * @param y2 end of y position * * @return void */ void lcd_address_set(rt_uint16_t x1, rt_uint16_t y1, rt_uint16_t x2, rt_uint16_t y2) { lcd_write_cmd(0x2a); lcd_write_data(x1 >> 8); lcd_write_data(x1); lcd_write_data(x2 >> 8); lcd_write_data(x2); lcd_write_cmd(0x2b); lcd_write_data(y1 >> 8); lcd_write_data(y1); lcd_write_data(y2 >> 8); lcd_write_data(y2); lcd_write_cmd(0x2C); } #ifndef BSP_USING_LVGL /** * clear the lcd. * * @param color Fill color * * @return void */ void lcd_clear(rt_uint16_t color) { rt_uint16_t i, j; rt_uint8_t data[2] = {0}; rt_uint8_t *buf = RT_NULL; data[0] = color >> 8; data[1] = color; lcd_address_set(0, 0, LCD_W - 1, LCD_H - 1); buf = rt_malloc(LCD_CLEAR_SEND_NUMBER); if (buf) { /* 2880 = 5760/2 color is 16 bit */ for (j = 0; j < LCD_CLEAR_SEND_NUMBER / 2; j++) { buf[j * 2] = data[0]; buf[j * 2 + 1] = data[1]; } rt_pin_write(LCD_DC_PIN, PIN_HIGH); for (i = 0; i < 20; i++) { rt_spi_send(spi_dev_lcd, buf, LCD_CLEAR_SEND_NUMBER); } rt_free(buf); } else { rt_pin_write(LCD_DC_PIN, PIN_HIGH); for (i = 0; i < LCD_W; i++) { for (j = 0; j < LCD_H; j++) { rt_spi_send(spi_dev_lcd, data, 2); } } } } /** * display a point on the lcd. * * @param x x position * @param y y position * * @return void */ void lcd_draw_point(rt_uint16_t x, rt_uint16_t y) { lcd_address_set(x, y, x, y); lcd_write_half_word(FORE_COLOR); } /** * display a point on the lcd using the given colour. * * @param x x position * @param y y position * @param color color of point * * @return void */ void lcd_draw_point_color(rt_uint16_t x, rt_uint16_t y, rt_uint16_t color) { lcd_address_set(x, y, x, y); lcd_write_half_word(color); } /** * full color on the lcd. * * @param x_start start of x position * @param y_start start of y position * @param x_end end of x position * @param y_end end of y position * @param color Fill color * * @return void */ void lcd_fill(rt_uint16_t x_start, rt_uint16_t y_start, rt_uint16_t x_end, rt_uint16_t y_end, rt_uint16_t color) { rt_uint16_t i = 0, j = 0; rt_uint32_t size = 0, size_remain = 0; rt_uint8_t *fill_buf = RT_NULL; size = (x_end - x_start + 1) * (y_end - y_start + 1) * 2; if (size > LCD_CLEAR_SEND_NUMBER) { /* the number of remaining to be filled */ size_remain = size - LCD_CLEAR_SEND_NUMBER; size = LCD_CLEAR_SEND_NUMBER; } lcd_address_set(x_start, y_start, x_end, y_end); fill_buf = (rt_uint8_t *)rt_malloc(size); if (fill_buf) { /* fast fill */ while (1) { for (i = 0; i < size / 2; i++) { fill_buf[2 * i] = color >> 8; fill_buf[2 * i + 1] = color; } rt_pin_write(LCD_DC_PIN, PIN_HIGH); rt_spi_send(spi_dev_lcd, fill_buf, size); /* Fill completed */ if (size_remain == 0) break; /* calculate the number of fill next time */ if (size_remain > LCD_CLEAR_SEND_NUMBER) { size_remain = size_remain - LCD_CLEAR_SEND_NUMBER; } else { size = size_remain; size_remain = 0; } } rt_free(fill_buf); } else { for (i = y_start; i <= y_end; i++) { for (j = x_start; j <= x_end; j++)lcd_write_half_word(color); } } } #endif /* BSP_USING_LVGL */ /** * full color array on the lcd. * * @param x_start start of x position * @param y_start start of y position * @param x_end end of x position * @param y_end end of y position * @param color Fill color array's pointer * * @return void */ void lcd_fill_array(rt_uint16_t x_start, rt_uint16_t y_start, rt_uint16_t x_end, rt_uint16_t y_end, void *pcolor) { rt_uint32_t size = 0; size = (x_end - x_start + 1) * (y_end - y_start + 1) * 2/*16bit*/; lcd_address_set(x_start, y_start, x_end, y_end); rt_pin_write(LCD_DC_PIN, PIN_HIGH); rt_spi_send(spi_dev_lcd, pcolor, size); } #ifndef BSP_USING_LVGL /** * display a line on the lcd. * * @param x1 x1 position * @param y1 y1 position * @param x2 x2 position * @param y2 y2 position * * @return void */ void lcd_draw_line(rt_uint16_t x1, rt_uint16_t y1, rt_uint16_t x2, rt_uint16_t y2) { rt_uint16_t t; rt_uint32_t i = 0; int xerr = 0, yerr = 0, delta_x, delta_y, distance; int incx, incy, row, col; if (y1 == y2) { /* fast draw transverse line */ rt_uint32_t x_offset = 0; if (x1 < x2) { x_offset = x2 - x1; lcd_address_set(x1, y1, x2, y2); } else if (x1 > x2) { x_offset = x1 - x2; lcd_address_set(x2, y2, x1, y1); } else { lcd_draw_point(x1, y1); return; } rt_uint8_t line_buf[480] = {0}; for (i = 0; i < x_offset; i++) { line_buf[2 * i] = FORE_COLOR >> 8; line_buf[2 * i + 1] = FORE_COLOR; } rt_pin_write(LCD_DC_PIN, PIN_HIGH); rt_spi_send(spi_dev_lcd, line_buf, x_offset * 2); return ; } delta_x = x2 - x1; delta_y = y2 - y1; row = x1; col = y1; if (delta_x > 0)incx = 1; else if (delta_x == 0)incx = 0; else { incx = -1; delta_x = -delta_x; } if (delta_y > 0)incy = 1; else if (delta_y == 0)incy = 0; else { incy = -1; delta_y = -delta_y; } if (delta_x > delta_y)distance = delta_x; else distance = delta_y; for (t = 0; t <= distance + 1; t++) { lcd_draw_point(row, col); xerr += delta_x ; yerr += delta_y ; if (xerr > distance) { xerr -= distance; row += incx; } if (yerr > distance) { yerr -= distance; col += incy; } } } /** * display a rectangle on the lcd. * * @param x1 x1 position * @param y1 y1 position * @param x2 x2 position * @param y2 y2 position * * @return void */ void lcd_draw_rectangle(rt_uint16_t x1, rt_uint16_t y1, rt_uint16_t x2, rt_uint16_t y2) { lcd_draw_line(x1, y1, x2, y1); lcd_draw_line(x1, y1, x1, y2); lcd_draw_line(x1, y2, x2, y2); lcd_draw_line(x2, y1, x2, y2); } /** * display a circle on the lcd. * * @param x x position of Center * @param y y position of Center * @param r radius * * @return void */ void lcd_draw_circle(rt_uint16_t x0, rt_uint16_t y0, rt_uint8_t r) { int a, b; int di; a = 0; b = r; di = 3 - (r << 1); while (a <= b) { lcd_draw_point(x0 - b, y0 - a); lcd_draw_point(x0 + b, y0 - a); lcd_draw_point(x0 - a, y0 + b); lcd_draw_point(x0 - b, y0 - a); lcd_draw_point(x0 - a, y0 - b); lcd_draw_point(x0 + b, y0 + a); lcd_draw_point(x0 + a, y0 - b); lcd_draw_point(x0 + a, y0 + b); lcd_draw_point(x0 - b, y0 + a); a++; //Bresenham if (di < 0)di += 4 * a + 6; else { di += 10 + 4 * (a - b); b--; } lcd_draw_point(x0 + a, y0 + b); } } static void lcd_show_char(rt_uint16_t x, rt_uint16_t y, rt_uint8_t data, rt_uint32_t size) { rt_uint8_t temp; rt_uint8_t num = 0;; rt_uint8_t pos, t; rt_uint16_t colortemp = FORE_COLOR; rt_uint8_t *font_buf = RT_NULL; if (x > LCD_W - size / 2 || y > LCD_H - size)return; data = data - ' '; #ifdef ASC2_1608 if (size == 16) { lcd_address_set(x, y, x + size / 2 - 1, y + size - 1);//(x,y,x+8-1,y+16-1) font_buf = (rt_uint8_t *)rt_malloc(size * size); if (!font_buf) { /* fast show char */ for (pos = 0; pos < size * (size / 2) / 8; pos++) { temp = asc2_1608[(rt_uint16_t)data * size * (size / 2) / 8 + pos]; for (t = 0; t < 8; t++) { if (temp & 0x80)colortemp = FORE_COLOR; else colortemp = BACK_COLOR; lcd_write_half_word(colortemp); temp <<= 1; } } } else { for (pos = 0; pos < size * (size / 2) / 8; pos++) { temp = asc2_1608[(rt_uint16_t)data * size * (size / 2) / 8 + pos]; for (t = 0; t < 8; t++) { if (temp & 0x80)colortemp = FORE_COLOR; else colortemp = BACK_COLOR; font_buf[2 * (8 * pos + t)] = colortemp >> 8; font_buf[2 * (8 * pos + t) + 1] = colortemp; temp <<= 1; } } rt_pin_write(LCD_DC_PIN, PIN_HIGH); rt_spi_send(spi_dev_lcd, font_buf, size * size); rt_free(font_buf); } } else #endif #ifdef ASC2_2412 if (size == 24) { lcd_address_set(x, y, x + size / 2 - 1, y + size - 1); font_buf = (rt_uint8_t *)rt_malloc(size * size); if (!font_buf) { /* fast show char */ for (pos = 0; pos < (size * 16) / 8; pos++) { temp = asc2_2412[(rt_uint16_t)data * (size * 16) / 8 + pos]; if (pos % 2 == 0) { num = 8; } else { num = 4; } for (t = 0; t < num; t++) { if (temp & 0x80)colortemp = FORE_COLOR; else colortemp = BACK_COLOR; lcd_write_half_word(colortemp); temp <<= 1; } } } else { for (pos = 0; pos < (size * 16) / 8; pos++) { temp = asc2_2412[(rt_uint16_t)data * (size * 16) / 8 + pos]; if (pos % 2 == 0) { num = 8; } else { num = 4; } for (t = 0; t < num; t++) { if (temp & 0x80)colortemp = FORE_COLOR; else colortemp = BACK_COLOR; if (num == 8) { font_buf[2 * (12 * (pos / 2) + t)] = colortemp >> 8; font_buf[2 * (12 * (pos / 2) + t) + 1] = colortemp; } else { font_buf[2 * (8 + 12 * (pos / 2) + t)] = colortemp >> 8; font_buf[2 * (8 + 12 * (pos / 2) + t) + 1] = colortemp; } temp <<= 1; } } rt_pin_write(LCD_DC_PIN, PIN_HIGH); rt_spi_send(spi_dev_lcd, font_buf, size * size); rt_free(font_buf); } } else #endif #ifdef ASC2_3216 if (size == 32) { lcd_address_set(x, y, x + size / 2 - 1, y + size - 1); font_buf = (rt_uint8_t *)rt_malloc(size * size); if (!font_buf) { /* fast show char */ for (pos = 0; pos < size * (size / 2) / 8; pos++) { temp = asc2_3216[(rt_uint16_t)data * size * (size / 2) / 8 + pos]; for (t = 0; t < 8; t++) { if (temp & 0x80)colortemp = FORE_COLOR; else colortemp = BACK_COLOR; lcd_write_half_word(colortemp); temp <<= 1; } } } else { for (pos = 0; pos < size * (size / 2) / 8; pos++) { temp = asc2_3216[(rt_uint16_t)data * size * (size / 2) / 8 + pos]; for (t = 0; t < 8; t++) { if (temp & 0x80)colortemp = FORE_COLOR; else colortemp = BACK_COLOR; font_buf[2 * (8 * pos + t)] = colortemp >> 8; font_buf[2 * (8 * pos + t) + 1] = colortemp; temp <<= 1; } } rt_pin_write(LCD_DC_PIN, PIN_HIGH); rt_spi_send(spi_dev_lcd, font_buf, size * size); rt_free(font_buf); } } else #endif { LOG_E("There is no any define ASC2_1208 && ASC2_2412 && ASC2_2416 && ASC2_3216 !"); } } /** * display the number on the lcd. * * @param x x position * @param y y position * @param num number * @param len length of number * @param size size of font * * @return void */ void lcd_show_num(rt_uint16_t x, rt_uint16_t y, rt_uint32_t num, rt_uint8_t len, rt_uint32_t size) { lcd_show_string(x, y, size, "%d", num); } /** * display the string on the lcd. * * @param x x position * @param y y position * @param size size of font * @param p the string to be display * * @return 0: display success * -1: size of font is not support */ rt_err_t lcd_show_string(rt_uint16_t x, rt_uint16_t y, rt_uint32_t size, const char *fmt, ...) { #define LCD_STRING_BUF_LEN 128 va_list args; rt_uint8_t buf[LCD_STRING_BUF_LEN] = {0}; rt_uint8_t *p = RT_NULL; if (size != 16 && size != 24 && size != 32) { LOG_E("font size(%d) is not support!", size); return -RT_ERROR; } va_start(args, fmt); rt_vsnprintf((char *)buf, 100, (const char *)fmt, args); va_end(args); p = buf; while (*p != '\0') { if (x > LCD_W - size / 2) { x = 0; y += size; } if (y > LCD_H - size) { y = x = 0; lcd_clear(RED); } lcd_show_char(x, y, *p, size); x += size / 2; p++; } return RT_EOK; } /** * display the image on the lcd. * * @param x x position * @param y y position * @param length length of image * @param wide wide of image * @param p image * * @return 0: display success * -1: the image is too large */ rt_err_t lcd_show_image(rt_uint16_t x, rt_uint16_t y, rt_uint16_t length, rt_uint16_t wide, const rt_uint8_t *p) { RT_ASSERT(p); if (x + length > LCD_W || y + wide > LCD_H) { return -RT_ERROR; } lcd_address_set(x, y, x + length - 1, y + wide - 1); rt_pin_write(LCD_DC_PIN, PIN_HIGH); rt_spi_send(spi_dev_lcd, p, length * wide * 2); return RT_EOK; } #endif /* BSP_USING_LVGL */
e5eea5e481c4803104c3d87d1aa4797b91d5da6f
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
/sys/dev/ofisa/ofisavar.h
b2b6f05de06f8d0fc836d0909d1dffeb82e4466b
[]
no_license
NetBSD/src
1a9cbc22ed778be638b37869ed4fb5c8dd616166
23ee83f7c0aea0777bd89d8ebd7f0cde9880d13c
refs/heads/trunk
2023-08-31T13:24:58.105962
2023-08-27T15:50:47
2023-08-27T15:50:47
88,439,547
656
348
null
2023-07-20T20:07:24
2017-04-16T20:03:43
null
UTF-8
C
false
false
3,810
h
ofisavar.h
/* $NetBSD: ofisavar.h,v 1.8 2021/04/30 02:13:15 thorpej Exp $ */ /* * Copyright 1998 * Digital Equipment Corporation. All rights reserved. * * This software is furnished under license and may be used and * copied only in accordance with the following terms and conditions. * Subject to these conditions, you may download, copy, install, * use, modify and distribute this software in source and/or binary * form. No title or ownership is transferred hereby. * * 1) Any source code used, modified or distributed must reproduce * and retain this copyright notice and list of conditions as * they appear in the source file. * * 2) No right is granted to use any trade name, trademark, or logo of * Digital Equipment Corporation. Neither the "Digital Equipment * Corporation" name nor any trademark or logo of Digital Equipment * Corporation may be used to endorse or promote products derived * from this software without the prior written permission of * Digital Equipment Corporation. * * 3) This software is provided "AS-IS" and any express or implied * warranties, including but not limited to, any implied warranties * of merchantability, fitness for a particular purpose, or * non-infringement are disclaimed. In no event shall DIGITAL be * liable for any damages whatsoever, and in particular, DIGITAL * shall not be liable for special, indirect, consequential, or * incidental damages or damages for lost profits, loss of * revenue or loss of use, whether such damages arise in contract, * negligence, tort, under statute, in equity, at law or otherwise, * even if advised of the possibility of such damage. */ #ifndef _DEV_OFISA_OFISAVAR_H_ #define _DEV_OFISA_OFISAVAR_H_ #include <dev/ofw/openfirm.h> #include <dev/isa/isavar.h> struct ofisa_attach_args { struct ofbus_attach_args oba; /* common */ bus_space_tag_t iot; /* i/o space tag */ bus_space_tag_t memt; /* mem space tag */ bus_dma_tag_t dmat; /* DMA tag */ isa_chipset_tag_t ic; /* chipset tag (for intr, etc.) */ }; struct ofisa_reg_desc { int type; /* type. XXX aliasing modifiers? */ bus_addr_t addr; /* base address. */ bus_size_t len; /* length. */ }; #define OFISA_REG_TYPE_MEM 0 /* memory space */ #define OFISA_REG_TYPE_IO 1 /* I/O space */ struct ofisa_intr_desc { int share; /* sharing type: IST_*. */ int irq; /* IRQ. */ }; struct ofisa_dma_desc { int drq; /* DMA request */ int mode; /* DMA mode */ int width; /* DMA width */ int countwidth; /* DMA count width */ int busmaster; /* boolean; is a busmaster */ }; #define OFISA_DMA_MODE_COMPAT 0 /* compatibility mode */ #define OFISA_DMA_MODE_A 1 /* DMA A mode */ #define OFISA_DMA_MODE_B 2 /* DMA B mode */ #define OFISA_DMA_MODE_F 3 /* DMA F mode */ #define OFISA_DMA_MODE_C 4 /* DMA C mode */ /* * Machine-dependent function/macro definitions. * * Machine-dependent code must implement at least: * * int ofisa_get_isabus_data(int phandle, * struct isabus_attach_args *iba); * * int ofisa_ignore_child(int pphandle, int cphandle); * * Individual ofisa attachments may want addition functions or * macros from this (or other) headers. See those attachments' * files for more details. */ #include <machine/ofisa_machdep.h> int ofisa_reg_count(int); int ofisa_reg_get(int, struct ofisa_reg_desc *, int); void ofisa_reg_print(struct ofisa_reg_desc *, int); int ofisa_intr_count(int); int ofisa_intr_get(int, struct ofisa_intr_desc *, int); void ofisa_intr_print(struct ofisa_intr_desc *, int); int ofisa_dma_count(int); int ofisa_dma_get(int, struct ofisa_dma_desc *, int); void ofisa_dma_print(struct ofisa_dma_desc *, int); void ofisa_print_model(device_t, int); int ofisaprint(void *, const char *); #endif /* _DEV_OFISA_OFISAVAR_H_ */
4b08a1829124250db21f28e16ac0a355eafac604
909095842af0bbf2e769aff361b5af344abc7433
/engine/source/2d/sceneobject/Path_ScriptBinding.h
cdec4e7e5e7be6d35c58c2070d4d1099848b45c3
[ "MIT" ]
permissive
TorqueGameEngines/Torque2D
316105e8b91cebf8660ff43871440e1c4d0b1c5e
2c555d6dd0172a05ddb6a14f014d22f335b4ccad
refs/heads/master
2023-09-01T02:22:53.663431
2023-05-02T20:45:37
2023-05-02T20:45:37
268,352,960
1,001
117
MIT
2023-05-02T20:19:19
2020-05-31T19:51:55
C
UTF-8
C
false
false
4,636
h
Path_ScriptBinding.h
//----------------------------------------------------------------------------- // Copyright (c) 2013 GarageGames, LLC // // 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. //----------------------------------------------------------------------------- /*! Attaches a sceneObject to the path. @param SceneObject The object that will be attached to the path. @param speed The rate that the sceneObject will follow the path. @param orient If true, the object will automatically rate to face the direction that it is moving. @param angOff The offset that will be applied to the rotation if orient is true. @param snapToNode If true, the object will have to get close to a node instead of reaching it exactly. The distance is based on the distance given a node when it is created. @param startNode A zero-based integer that represents the node that the object should start at. @param loop If true, the object will start the path again when it reaches the last node. The object will travel from the last node to the first. @param maxLoop An integer value describing the number of times the object will travel the path if looping is turned on. @return No return value. */ ConsoleMethodWithDocs(Path, attachObject, ConsoleVoid, 4, 11, (sceneObject, float speed,[float force], [bool orient], [float angOff], [bool snapToNode],[integer startNode],[bool loop],[integer maxLoop])) { // Set Group. SceneObject* pSceneObject = dynamic_cast<SceneObject*>(Sim::findObject(argv[2])); // Did we find the object? if (!pSceneObject) { // No, so warn. Con::warnf("Path::attachObject() - Could not find the specified object '%s'.", argv[2]); return; } F32 speed = dAtof(argv[3]); F32 force = 3.0f; if (argc > 4) { force = dAtof(argv[4]); } bool orient = false; if (argc > 5) { orient = dAtob(argv[5]); } F32 angleOff = 0.0f; if (argc > 6) { angleOff = dAtof(argv[6]); } bool snapToNode = false; if (argc > 7) { snapToNode = dAtob(argv[7]); } S32 startNode = 0; if (argc > 8) { startNode = dAtoi(argv[8]); } bool loop = true; if (argc > 9) { loop = dAtob(argv[9]); } S32 maxLoop = 0; if (argc > 10) { maxLoop = dAtoi(argv[10]); } object->attachObject(pSceneObject, speed, force, orient, angleOff, snapToNode, startNode, loop, maxLoop); } /*! Removes a sceneObject from a path. @param SceneObject The object that will be detached from the path. @return No return value. */ ConsoleMethodWithDocs(Path, detachObject, ConsoleVoid, 3, 3, (sceneObject)) { // Set Group. SceneObject* pSceneObject = dynamic_cast<SceneObject*>(Sim::findObject(argv[2])); if (pSceneObject) object->detachObject(pSceneObject); else Con::warnf("Path::detachObject() - Could not find the specified object '%s'.", argv[2]); } /*! Adds a node to a path. @param x The horizontal position of the node in world units. @param y The vertical position of the node in world units. @param distance The distance a from a node that it object must reach before it is considered to have reached the node, if snapToNode is set true for the object. @return No return value. */ ConsoleMethodWithDocs(Path, addNode, ConsoleVoid, 3, 6, (float x, float y, [float distance], [float weight])) { Vector2 position; position.Set(dAtof(argv[2]), dAtof(argv[3])); F32 distance = 0.0f; if (argc > 4) { distance = dAtof(argv[4]); } F32 weight = 0.0f; if(argc > 5) { weight = dAtof(argv[5]); } object->addNode(position, distance, weight); }
938e4e303c8d70236ab1a157d6fa0815a4625dfe
376e1818d427b5e4d32fa6dd6c7b71e9fd88afdb
/emulators/wine/patches/patch-dlls_ws2__32_socket.c
b9629eb621887babac736a346e07c80f690d0540
[]
no_license
NetBSD/pkgsrc
a0732c023519650ef821ab89c23ab6ab59e25bdb
d042034ec4896cc5b47ed6f2e5b8802d9bc5c556
refs/heads/trunk
2023-09-01T07:40:12.138283
2023-09-01T05:25:19
2023-09-01T05:25:19
88,439,572
321
138
null
2023-07-12T22:34:14
2017-04-16T20:04:15
null
UTF-8
C
false
false
1,517
c
patch-dlls_ws2__32_socket.c
$NetBSD: patch-dlls_ws2__32_socket.c,v 1.1 2020/05/26 15:20:23 adam Exp $ Conditionally use RFC3678 socket options. --- dlls/ws2_32/socket.c.orig 2020-05-25 20:28:31.195748937 +0000 +++ dlls/ws2_32/socket.c @@ -692,10 +692,12 @@ static const int ws_ip_map[][2] = MAP_OPTION( IP_MULTICAST_LOOP ), MAP_OPTION( IP_ADD_MEMBERSHIP ), MAP_OPTION( IP_DROP_MEMBERSHIP ), +#ifdef IP_UNBLOCK_SOURCE MAP_OPTION( IP_ADD_SOURCE_MEMBERSHIP ), MAP_OPTION( IP_DROP_SOURCE_MEMBERSHIP ), MAP_OPTION( IP_BLOCK_SOURCE ), MAP_OPTION( IP_UNBLOCK_SOURCE ), +#endif MAP_OPTION( IP_OPTIONS ), #ifdef IP_HDRINCL MAP_OPTION( IP_HDRINCL ), @@ -5776,7 +5778,9 @@ int WINAPI WS_setsockopt(SOCKET s, int l int woptval; struct linger linger; struct timeval tval; +#ifdef IP_BLOCK_SOURCE struct ip_mreq_source mreq_source; +#endif TRACE("(socket %04lx, %s, optval %s, optlen %d)\n", s, debugstr_sockopt(level, optname), debugstr_optval(optval, optlen), @@ -5987,6 +5991,7 @@ int WINAPI WS_setsockopt(SOCKET s, int l case WS_IPPROTO_IP: switch(optname) { +#ifdef IP_BLOCK_SOURCE case WS_IP_ADD_SOURCE_MEMBERSHIP: case WS_IP_DROP_SOURCE_MEMBERSHIP: case WS_IP_BLOCK_SOURCE: @@ -6003,6 +6008,7 @@ int WINAPI WS_setsockopt(SOCKET s, int l convert_sockopt(&level, &optname); break; } +#endif case WS_IP_ADD_MEMBERSHIP: case WS_IP_DROP_MEMBERSHIP: #ifdef IP_HDRINCL
3665b812b85d873ef0936ceaa75648c090addb86
14e762a695b82858a12cb168ba961e2fa38c69b9
/src/flow.c
799a84ae272ea214d725a522876010eb48c76dcc
[ "MIT" ]
permissive
picolisp/picolisp
f94ba31d066720269ce79084489d2cc8559be349
12fa8370ef14975edbcfc134c6f0b70859c73faf
refs/heads/dev
2022-08-22T11:17:48.624427
2020-11-05T02:56:34
2020-11-05T02:56:34
88,331,638
234
27
NOASSERTION
2020-09-22T15:00:42
2017-04-15T07:30:01
PicoLisp
UTF-8
C
false
false
40,441
c
flow.c
/* 16mar16abu * (c) Software Lab. Alexander Burger */ #include "pico.h" static void redefMsg(any x, any y) { outFile *oSave = OutFile; void (*putSave)(int) = Env.put; OutFile = OutFiles[STDERR_FILENO], Env.put = putStdout; outString("# "); print(x); if (y) space(), print(y); outString(" redefined\n"); Env.put = putSave, OutFile = oSave; } static void putSrc(any s, any k) { if (!isNil(val(Dbg)) && !isExt(s) && InFile && InFile->name) { any x, y; cell c1; Push(c1, boxCnt(InFile->src)); data(c1) = cons(data(c1), mkStr(InFile->name)); x = get(s, Dbg); if (!k) { if (isNil(x)) put(s, Dbg, cons(data(c1), Nil)); else car(x) = data(c1); } else if (isNil(x)) put(s, Dbg, cons(Nil, cons(data(c1), Nil))); else { for (y = cdr(x); isCell(y); y = cdr(y)) if (caar(y) == k) { cdar(y) = data(c1); drop(c1); return; } cdr(x) = cons(cons(k, data(c1)), cdr(x)); } drop(c1); } } static void redefine(any ex, any s, any x) { NeedSym(ex,s); CheckVar(ex,s); if (!isNil(val(s)) && s != val(s) && !equal(x,val(s))) redefMsg(s, NULL); val(s) = x; putSrc(s, NULL); } // (quote . any) -> any any doQuote(any x) {return cdr(x);} // (as 'any1 . any2) -> any2 | NIL any doAs(any x) { x = cdr(x); if (isNil(EVAL(car(x)))) return Nil; return cdr(x); } // (lit 'any) -> any any doLit(any x) { x = cadr(x); if (isNum(x = EVAL(x)) || isNil(x) || x == T || isCell(x) && isNum(car(x))) return x; return cons(Quote, x); } // (eval 'any ['cnt ['lst]]) -> any any doEval(any x) { any y; cell c1; bindFrame *p; x = cdr(x), Push(c1, EVAL(car(x))), x = cdr(x); if (!isNum(y = EVAL(car(x))) || !(p = Env.bind)) data(c1) = EVAL(data(c1)); else { int cnt, n, i, j; struct { // bindFrame struct bindFrame *link; int i, cnt; struct {any sym; any val;} bnd[length(x)]; } f; x = cdr(x), x = EVAL(car(x)); j = cnt = (int)unBox(y); n = f.i = f.cnt = 0; do { ++n; if ((i = p->i) <= 0 && (p->i -= cnt, i == 0)) { for (i = 0; i < p->cnt; ++i) { y = val(p->bnd[i].sym); val(p->bnd[i].sym) = p->bnd[i].val; p->bnd[i].val = y; } if (p->cnt && p->bnd[0].sym == At && !--j) break; } } while (p = p->link); while (isCell(x)) { for (p = Env.bind, j = n; ; p = p->link) { if (p->i < 0) for (i = 0; i < p->cnt; ++i) { if (p->bnd[i].sym == car(x)) { f.bnd[f.cnt].val = val(f.bnd[f.cnt].sym = car(x)); val(car(x)) = p->bnd[i].val; ++f.cnt; goto next; } } if (!--j) break; } next: x = cdr(x); } f.link = Env.bind, Env.bind = (bindFrame*)&f; data(c1) = EVAL(data(c1)); while (--f.cnt >= 0) val(f.bnd[f.cnt].sym) = f.bnd[f.cnt].val; Env.bind = f.link; do { for (p = Env.bind, i = n; --i; p = p->link); if (p->i < 0 && (p->i += cnt) == 0) for (i = p->cnt; --i >= 0;) { y = val(p->bnd[i].sym); val(p->bnd[i].sym) = p->bnd[i].val; p->bnd[i].val = y; } } while (--n); } return Pop(c1); } // (run 'any ['cnt ['lst]]) -> any any doRun(any x) { any y; cell c1; bindFrame *p; x = cdr(x), data(c1) = EVAL(car(x)), x = cdr(x); if (!isNum(data(c1))) { Save(c1); if (!isNum(y = EVAL(car(x))) || !(p = Env.bind)) data(c1) = isSym(data(c1))? val(data(c1)) : run(data(c1)); else { int cnt, n, i, j; struct { // bindFrame struct bindFrame *link; int i, cnt; struct {any sym; any val;} bnd[length(x)]; } f; x = cdr(x), x = EVAL(car(x)); j = cnt = (int)unBox(y); n = f.i = f.cnt = 0; do { ++n; if ((i = p->i) <= 0 && (p->i -= cnt, i == 0)) { for (i = 0; i < p->cnt; ++i) { y = val(p->bnd[i].sym); val(p->bnd[i].sym) = p->bnd[i].val; p->bnd[i].val = y; } if (p->cnt && p->bnd[0].sym == At && !--j) break; } } while (p = p->link); while (isCell(x)) { for (p = Env.bind, j = n; ; p = p->link) { if (p->i < 0) for (i = 0; i < p->cnt; ++i) { if (p->bnd[i].sym == car(x)) { f.bnd[f.cnt].val = val(f.bnd[f.cnt].sym = car(x)); val(car(x)) = p->bnd[i].val; ++f.cnt; goto next; } } if (!--j) break; } next: x = cdr(x); } f.link = Env.bind, Env.bind = (bindFrame*)&f; data(c1) = isSym(data(c1))? val(data(c1)) : prog(data(c1)); while (--f.cnt >= 0) val(f.bnd[f.cnt].sym) = f.bnd[f.cnt].val; Env.bind = f.link; do { for (p = Env.bind, i = n; --i; p = p->link); if (p->i < 0 && (p->i += cnt) == 0) for (i = p->cnt; --i >= 0;) { y = val(p->bnd[i].sym); val(p->bnd[i].sym) = p->bnd[i].val; p->bnd[i].val = y; } } while (--n); } drop(c1); } return data(c1); } // (def 'sym 'any) -> sym // (def 'sym 'sym 'any) -> sym any doDef(any ex) { any x, y; cell c1, c2, c3; x = cdr(ex), Push(c1, EVAL(car(x))); NeedSym(ex,data(c1)); x = cdr(x), Push(c2, EVAL(car(x))); if (!isCell(cdr(x))) { CheckVar(ex,data(c1)); Touch(ex,data(c1)); if (!isNil(y = val(data(c1))) && y != data(c1) && !equal(data(c2), y)) redefMsg(data(c1), NULL); val(data(c1)) = data(c2); putSrc(data(c1), NULL); } else { x = cdr(x), Push(c3, EVAL(car(x))); if (isExt(data(c1))) db(ex, data(c1), !isNil(data(c2))? 2 : 1); if (!isNil(y = get(data(c1), data(c2))) && !equal(data(c3), y)) redefMsg(data(c1), data(c2)); put(data(c1), data(c2), data(c3)); putSrc(data(c1), data(c2)); } return Pop(c1); } // (de sym . any) -> sym any doDe(any ex) { redefine(ex, cadr(ex), cddr(ex)); return cadr(ex); } // (dm sym . fun|cls2) -> sym // (dm (sym . cls) . fun|cls2) -> sym // (dm (sym sym2 [. cls]) . fun|cls2) -> sym any doDm(any ex) { any x, y, msg, cls; x = cdr(ex); if (!isCell(car(x))) msg = car(x), cls = val(Class); else { msg = caar(x); cls = !isCell(cdar(x))? cdar(x) : get(isNil(cddar(x))? val(Class) : cddar(x), cadar(x)); } if (msg != T) redefine(ex, msg, val(Meth)); if (isSym(cdr(x))) { y = val(cdr(x)); for (;;) { if (!isCell(y) || !isCell(car(y))) err(ex, msg, "Bad message"); if (caar(y) == msg) { x = car(y); break; } y = cdr(y); } } for (y = val(cls); isCell(y) && isCell(car(y)); y = cdr(y)) if (caar(y) == msg) { if (!equal(cdr(x), cdar(y))) redefMsg(msg, cls); cdar(y) = cdr(x); putSrc(cls, msg); return msg; } if (!isCell(car(x))) val(cls) = cons(x, val(cls)); else val(cls) = cons(cons(msg, cdr(x)), val(cls)); putSrc(cls, msg); return msg; } /* Evaluate method invocation */ static any evMethod(any o, any expr, any x) { any y = car(expr); any cls = TheCls, key = TheKey; struct { // bindFrame struct bindFrame *link; int i, cnt; struct {any sym; any val;} bnd[length(y)+3]; } f; f.link = Env.bind, Env.bind = (bindFrame*)&f; f.i = sizeof(f.bnd) / (2*sizeof(any)) - 2; f.cnt = 1, f.bnd[0].sym = At, f.bnd[0].val = val(At); while (isCell(y)) { f.bnd[f.cnt].sym = car(y); f.bnd[f.cnt].val = EVAL(car(x)); ++f.cnt, x = cdr(x), y = cdr(y); } if (isNil(y)) { do { x = val(f.bnd[--f.i].sym); val(f.bnd[f.i].sym) = f.bnd[f.i].val; f.bnd[f.i].val = x; } while (f.i); f.bnd[f.cnt].sym = This, f.bnd[f.cnt++].val = val(This), val(This) = o; y = cls, cls = Env.cls; Env.cls = y; y = key, key = Env.key; Env.key = y; x = prog(cdr(expr)); } else if (y != At) { f.bnd[f.cnt].sym = y, f.bnd[f.cnt++].val = val(y), val(y) = x; do { x = val(f.bnd[--f.i].sym); val(f.bnd[f.i].sym) = f.bnd[f.i].val; f.bnd[f.i].val = x; } while (f.i); f.bnd[f.cnt].sym = This, f.bnd[f.cnt++].val = val(This), val(This) = o; y = cls, cls = Env.cls; Env.cls = y; y = key, key = Env.key; Env.key = y; x = prog(cdr(expr)); } else { int n, cnt; cell *arg; cell c[n = cnt = length(x)]; while (--n >= 0) Push(c[n], EVAL(car(x))), x = cdr(x); do { x = val(f.bnd[--f.i].sym); val(f.bnd[f.i].sym) = f.bnd[f.i].val; f.bnd[f.i].val = x; } while (f.i); n = Env.next, Env.next = cnt; arg = Env.arg, Env.arg = c; f.bnd[f.cnt].sym = This, f.bnd[f.cnt++].val = val(This), val(This) = o; y = cls, cls = Env.cls; Env.cls = y; y = key, key = Env.key; Env.key = y; x = prog(cdr(expr)); if (cnt) drop(c[cnt-1]); Env.arg = arg, Env.next = n; } while (--f.cnt >= 0) val(f.bnd[f.cnt].sym) = f.bnd[f.cnt].val; Env.bind = f.link; Env.cls = cls, Env.key = key; return x; } any method(any x) { any y, z; if (isCell(y = val(x))) { while (isCell(z = car(y))) { if (car(z) == TheKey) return cdr(z); if (!isCell(y = cdr(y))) return NULL; } do if (x = method(car(TheCls = y))) return x; while (isCell(y = cdr(y))); } return NULL; } // (box 'any) -> sym any doBox(any x) { x = cdr(x); return consSym(EVAL(car(x)), Nil); } // (new ['flg|num] ['typ ['any ..]]) -> obj any doNew(any ex) { any x, y, *h; cell c1, c2; x = cdr(ex); if (isCell(y = EVAL(car(x)))) Push(c1, consSym(y,Nil)); else { if (isNil(y)) data(c1) = consSym(Nil,Nil); else { y = newId(ex, isNum(y)? (int)unDig(y)/2 : 1); if (data(c1) = findHash(y, h = Extern + ehash(y))) tail(data(c1)) = y; else *h = cons(data(c1) = consSym(Nil,y), *h); mkExt(data(c1)); } Save(c1); x = cdr(x), val(data(c1)) = EVAL(car(x)); } TheKey = T, TheCls = NULL; if (y = method(data(c1))) evMethod(data(c1), y, cdr(x)); else { Push(c2, Nil); while (isCell(x = cdr(x))) { data(c2) = EVAL(car(x)), x = cdr(x); put(data(c1), data(c2), EVAL(car(x))); } } return Pop(c1); } // (type 'any) -> lst any doType(any ex) { any x, y, z; x = cdr(ex), x = EVAL(car(x)); if (isSym(x)) { Fetch(ex,x); z = x = val(x); while (isCell(x)) { if (!isCell(car(x))) { y = x; while (isSym(car(x))) { if (!isCell(x = cdr(x))) return isNil(x)? y : Nil; if (z == x) return Nil; } return Nil; } if (z == (x = cdr(x))) return Nil; } } return Nil; } static bool isa(any cls, any x) { any z; z = x = val(x); while (isCell(x)) { if (!isCell(car(x))) { while (isSym(car(x))) { if (isExt(car(x))) return NO; if (cls == car(x) || isa(cls, car(x))) return YES; if (!isCell(x = cdr(x)) || z == x) return NO; } return NO; } if (z == (x = cdr(x))) return NO; } return NO; } // (isa 'cls|typ 'any) -> obj | NIL any doIsa(any ex) { any x; cell c1; x = cdr(ex), Push(c1, EVAL(car(x))); x = cdr(x), x = EVAL(car(x)); if (isSym(x)) { Fetch(ex,x); drop(c1); if (isSym(data(c1))) return isa(data(c1), x)? x : Nil; while (isCell(data(c1))) { if (!isa(car(data(c1)), x)) return Nil; data(c1) = cdr(data(c1)); } return x; } drop(c1); return Nil; } // (method 'msg 'obj) -> fun any doMethod(any ex) { any x; cell c1; x = cdr(ex), Push(c1, EVAL(car(x))); NeedSym(ex,data(c1)); x = cdr(x), x = EVAL(car(x)); NeedSym(ex,x); Fetch(ex,x); TheKey = Pop(c1); return method(x)? : Nil; } // (meth 'obj ['any ..]) -> any any doMeth(any ex) { any x, y; cell c1; x = cdr(ex), Push(c1, EVAL(car(x))); NeedSym(ex,data(c1)); Fetch(ex,data(c1)); for (TheKey = car(ex); ; TheKey = val(TheKey)) { if (!isSym(TheKey)) err(ex, TheKey, "Bad message"); if (isNum(val(TheKey))) { TheCls = NULL; if (y = method(data(c1))) { x = evMethod(data(c1), y, cdr(x)); drop(c1); return x; } err(ex, TheKey, "Bad message"); } } } // (send 'msg 'obj ['any ..]) -> any any doSend(any ex) { any x, y; cell c1, c2; x = cdr(ex), Push(c1, EVAL(car(x))); NeedSym(ex,data(c1)); x = cdr(x), Push(c2, EVAL(car(x))); NeedSym(ex,data(c2)); Fetch(ex,data(c2)); TheKey = data(c1), TheCls = NULL; if (y = method(data(c2))) { x = evMethod(data(c2), y, cdr(x)); drop(c1); return x; } err(ex, TheKey, "Bad message"); } // (try 'msg 'obj ['any ..]) -> any any doTry(any ex) { any x, y; cell c1, c2; x = cdr(ex), Push(c1, EVAL(car(x))); NeedSym(ex,data(c1)); x = cdr(x), Push(c2, EVAL(car(x))); if (isSym(data(c2))) { if (isExt(data(c2))) { if (!isLife(data(c2))) return Nil; db(ex,data(c2),1); } TheKey = data(c1), TheCls = NULL; if (y = method(data(c2))) { x = evMethod(data(c2), y, cdr(x)); drop(c1); return x; } } drop(c1); return Nil; } // (super ['any ..]) -> any any doSuper(any ex) { any x, y, cls, key; TheKey = Env.key; x = val(Env.cls? car(Env.cls) : val(This)); while (isCell(car(x))) x = cdr(x); while (isCell(x)) { if (y = method(car(TheCls = x))) { cls = Env.cls, Env.cls = TheCls; key = Env.key, Env.key = TheKey; x = evExpr(y, cdr(ex)); Env.key = key, Env.cls = cls; return x; } x = cdr(x); } err(ex, TheKey, "Bad super"); } static any extra(any x) { any y; for (x = val(x); isCell(car(x)); x = cdr(x)); while (isCell(x)) { if (x == Env.cls || !(y = extra(car(x)))) { while (isCell(x = cdr(x))) if (y = method(car(TheCls = x))) return y; return NULL; } if (y && num(y) != 1) return y; x = cdr(x); } return (any)1; } // (extra ['any ..]) -> any any doExtra(any ex) { any x, y, cls, key; TheKey = Env.key; if ((y = extra(val(This))) && num(y) != 1) { cls = Env.cls, Env.cls = TheCls; key = Env.key, Env.key = TheKey; x = evExpr(y, cdr(ex)); Env.key = key, Env.cls = cls; return x; } err(ex, TheKey, "Bad extra"); } // (with 'sym . prg) -> any any doWith(any ex) { any x; bindFrame f; x = cdr(ex); if (isNil(x = EVAL(car(x)))) return Nil; NeedSym(ex,x); Bind(This,f), val(This) = x; x = prog(cddr(ex)); Unbind(f); return x; } // (bind 'sym|lst . prg) -> any any doBind(any ex) { any x, y; x = cdr(ex); if (isNum(y = EVAL(car(x)))) argError(ex, y); if (isNil(y)) return prog(cdr(x)); if (isSym(y)) { bindFrame f; Bind(y,f); x = prog(cdr(x)); Unbind(f); return x; } { struct { // bindFrame struct bindFrame *link; int i, cnt; struct {any sym; any val;} bnd[length(y)]; } f; f.link = Env.bind, Env.bind = (bindFrame*)&f; f.i = f.cnt = 0; do { if (isNum(car(y))) argError(ex, car(y)); if (isSym(car(y))) { f.bnd[f.cnt].sym = car(y); f.bnd[f.cnt].val = val(car(y)); } else { f.bnd[f.cnt].sym = caar(y); f.bnd[f.cnt].val = val(caar(y)); val(caar(y)) = cdar(y); } ++f.cnt; } while (isCell(y = cdr(y))); x = prog(cdr(x)); while (--f.cnt >= 0) val(f.bnd[f.cnt].sym) = f.bnd[f.cnt].val; Env.bind = f.link; return x; } } // (job 'lst . prg) -> any any doJob(any ex) { any x = cdr(ex); any y = EVAL(car(x)); cell c1; struct { // bindFrame struct bindFrame *link; int i, cnt; struct {any sym; any val;} bnd[length(y)]; } f; Push(c1,y); f.link = Env.bind, Env.bind = (bindFrame*)&f; f.i = f.cnt = 0; while (isCell(y)) { f.bnd[f.cnt].sym = caar(y); f.bnd[f.cnt].val = val(caar(y)); val(caar(y)) = cdar(y); ++f.cnt, y = cdr(y); } x = prog(cdr(x)); for (f.cnt = 0, y = Pop(c1); isCell(y); ++f.cnt, y = cdr(y)) { cdar(y) = val(caar(y)); val(caar(y)) = f.bnd[f.cnt].val; } Env.bind = f.link; return x; } // (let sym 'any . prg) -> any // (let (sym 'any ..) . prg) -> any any doLet(any x) { any y; x = cdr(x); if (isSym(y = car(x))) { bindFrame f; x = cdr(x), Bind(y,f), val(y) = EVAL(car(x)); x = prog(cdr(x)); Unbind(f); } else { struct { // bindFrame struct bindFrame *link; int i, cnt; struct {any sym; any val;} bnd[(length(y)+1)/2]; } f; f.link = Env.bind, Env.bind = (bindFrame*)&f; f.i = f.cnt = 0; do { f.bnd[f.cnt].sym = car(y); f.bnd[f.cnt].val = val(car(y)); ++f.cnt; val(car(y)) = EVAL(cadr(y)); } while (isCell(y = cddr(y))); x = prog(cdr(x)); while (--f.cnt >= 0) val(f.bnd[f.cnt].sym) = f.bnd[f.cnt].val; Env.bind = f.link; } return x; } // (let? sym 'any . prg) -> any any doLetQ(any x) { any y, z; bindFrame f; x = cdr(x), y = car(x), x = cdr(x); if (isNil(z = EVAL(car(x)))) return Nil; Bind(y,f), val(y) = z; x = prog(cdr(x)); Unbind(f); return x; } // (use sym . prg) -> any // (use (sym ..) . prg) -> any any doUse(any x) { any y; x = cdr(x); if (isSym(y = car(x))) { bindFrame f; Bind(y,f); x = prog(cdr(x)); Unbind(f); } else { struct { // bindFrame struct bindFrame *link; int i, cnt; struct {any sym; any val;} bnd[length(y)]; } f; f.link = Env.bind, Env.bind = (bindFrame*)&f; f.i = f.cnt = 0; do { f.bnd[f.cnt].sym = car(y); f.bnd[f.cnt].val = val(car(y)); ++f.cnt; } while (isCell(y = cdr(y))); x = prog(cdr(x)); while (--f.cnt >= 0) val(f.bnd[f.cnt].sym) = f.bnd[f.cnt].val; Env.bind = f.link; } return x; } // (and 'any ..) -> any any doAnd(any x) { any a; x = cdr(x); do { if (isNil(a = EVAL(car(x)))) return Nil; val(At) = a; } while (isCell(x = cdr(x))); return a; } // (or 'any ..) -> any any doOr(any x) { any a; x = cdr(x); do if (!isNil(a = EVAL(car(x)))) return val(At) = a; while (isCell(x = cdr(x))); return Nil; } // (nand 'any ..) -> flg any doNand(any x) { any a; x = cdr(x); do { if (isNil(a = EVAL(car(x)))) return T; val(At) = a; } while (isCell(x = cdr(x))); return Nil; } // (nor 'any ..) -> flg any doNor(any x) { any a; x = cdr(x); do if (!isNil(a = EVAL(car(x)))) { val(At) = a; return Nil; } while (isCell(x = cdr(x))); return T; } // (xor 'any 'any) -> flg any doXor(any x) { bool f; x = cdr(x), f = isNil(EVAL(car(x))), x = cdr(x); return f ^ isNil(EVAL(car(x)))? T : Nil; } // (bool 'any) -> flg any doBool(any x) {return isNil(EVAL(cadr(x)))? Nil : T;} // (not 'any) -> flg any doNot(any x) { any a; if (isNil(a = EVAL(cadr(x)))) return T; val(At) = a; return Nil; } // (nil . prg) -> NIL any doNil(any x) { while (isCell(x = cdr(x))) if (isCell(car(x))) evList(car(x)); return Nil; } // (t . prg) -> T any doT(any x) { while (isCell(x = cdr(x))) if (isCell(car(x))) evList(car(x)); return T; } // (prog . prg) -> any any doProg(any x) {return prog(cdr(x));} // (prog1 'any1 . prg) -> any1 any doProg1(any x) { cell c1; x = cdr(x), Push(c1, val(At) = EVAL(car(x))); while (isCell(x = cdr(x))) if (isCell(car(x))) evList(car(x)); return Pop(c1); } // (prog2 'any1 'any2 . prg) -> any2 any doProg2(any x) { cell c1; x = cdr(x), EVAL(car(x)); x = cdr(x), Push(c1, val(At) = EVAL(car(x))); while (isCell(x = cdr(x))) if (isCell(car(x))) evList(car(x)); return Pop(c1); } // (if 'any1 any2 . prg) -> any any doIf(any x) { any a; x = cdr(x); if (isNil(a = EVAL(car(x)))) return prog(cddr(x)); val(At) = a; x = cdr(x); return EVAL(car(x)); } // (if2 'any1 'any2 any3 any4 any5 . prg) -> any any doIf2(any x) { any a; x = cdr(x); if (isNil(a = EVAL(car(x)))) { x = cdr(x); if (isNil(a = EVAL(car(x)))) return prog(cddddr(x)); val(At) = a; x = cdddr(x); return EVAL(car(x)); } val(At) = a; x = cdr(x); if (isNil(a = EVAL(car(x)))) { x = cddr(x); return EVAL(car(x)); } val(At) = a; x = cdr(x); return EVAL(car(x)); } // (ifn 'any1 any2 . prg) -> any any doIfn(any x) { any a; x = cdr(x); if (!isNil(a = EVAL(car(x)))) { val(At) = a; return prog(cddr(x)); } x = cdr(x); return EVAL(car(x)); } // (when 'any . prg) -> any any doWhen(any x) { any a; x = cdr(x); if (isNil(a = EVAL(car(x)))) return Nil; val(At) = a; return prog(cdr(x)); } // (unless 'any . prg) -> any any doUnless(any x) { any a; x = cdr(x); if (!isNil(a = EVAL(car(x)))) { val(At) = a; return Nil; } return prog(cdr(x)); } // (cond ('any1 . prg1) ('any2 . prg2) ..) -> any any doCond(any x) { any a; while (isCell(x = cdr(x))) { if (!isNil(a = EVAL(caar(x)))) { val(At) = a; return prog(cdar(x)); } } return Nil; } // (nond ('any1 . prg1) ('any2 . prg2) ..) -> any any doNond(any x) { any a; while (isCell(x = cdr(x))) { if (isNil(a = EVAL(caar(x)))) return prog(cdar(x)); val(At) = a; } return Nil; } // (case 'any (any1 . prg1) (any2 . prg2) ..) -> any any doCase(any x) { any y, z; x = cdr(x), val(At) = EVAL(car(x)); while (isCell(x = cdr(x))) { y = car(x), z = car(y); if (z == T || equal(val(At), z)) return prog(cdr(y)); if (isCell(z)) { do if (equal(val(At), car(z))) return prog(cdr(y)); while (isCell(z = cdr(z))); } } return Nil; } // (casq 'any (any1 . prg1) (any2 . prg2) ..) -> any any doCasq(any x) { any y, z; x = cdr(x), val(At) = EVAL(car(x)); while (isCell(x = cdr(x))) { y = car(x), z = car(y); if (z == T || z == val(At)) return prog(cdr(y)); if (isCell(z)) { do if (car(z) == val(At)) return prog(cdr(y)); while (isCell(z = cdr(z))); } } return Nil; } // (state 'var (sym|lst exe [. prg]) ..) -> any any doState(any ex) { any x, y, a; cell c1; x = cdr(ex); Push(c1, EVAL(car(x))); NeedVar(ex,data(c1)); CheckVar(ex,data(c1)); while (isCell(x = cdr(x))) { y = car(x); if (car(y) == T || memq(val(data(c1)), car(y))) { y = cdr(y); if (!isNil(a = EVAL(car(y)))) { val(At) = val(data(c1)) = a; drop(c1); return prog(cdr(y)); } } } drop(c1); return Nil; } // (while 'any . prg) -> any any doWhile(any x) { any cond, a; cell c1; cond = car(x = cdr(x)), x = cdr(x); Push(c1, Nil); while (!isNil(a = EVAL(cond))) { val(At) = a; data(c1) = prog(x); } return Pop(c1); } // (until 'any . prg) -> any any doUntil(any x) { any cond, a; cell c1; cond = car(x = cdr(x)), x = cdr(x); Push(c1, Nil); while (isNil(a = EVAL(cond))) data(c1) = prog(x); val(At) = a; return Pop(c1); } // (loop ['any | (NIL 'any . prg) | (T 'any . prg) ..]) -> any any doLoop(any ex) { any x, y, a; for (;;) { x = cdr(ex); do { if (isCell(y = car(x))) { if (isNil(car(y))) { y = cdr(y); if (isNil(a = EVAL(car(y)))) return prog(cdr(y)); val(At) = a; } else if (car(y) == T) { y = cdr(y); if (!isNil(a = EVAL(car(y)))) { val(At) = a; return prog(cdr(y)); } } else evList(y); } } while (isCell(x = cdr(x))); } } // (do 'flg|num ['any | (NIL 'any . prg) | (T 'any . prg) ..]) -> any any doDo(any x) { any y, z, a; cell c1; x = cdr(x); if (isNil(data(c1) = EVAL(car(x)))) return Nil; Save(c1); if (isNum(data(c1))) { if (isNeg(data(c1))) { drop(c1); return Nil; } data(c1) = bigCopy(data(c1)); } x = cdr(x), z = Nil; for (;;) { if (isNum(data(c1))) { if (IsZero(data(c1))) { drop(c1); return z; } digSub1(data(c1)); } y = x; do { if (!isNum(z = car(y))) { if (isSym(z)) z = val(z); else if (isNil(car(z))) { z = cdr(z); if (isNil(a = EVAL(car(z)))) { drop(c1); return prog(cdr(z)); } val(At) = a; z = Nil; } else if (car(z) == T) { z = cdr(z); if (!isNil(a = EVAL(car(z)))) { val(At) = a; drop(c1); return prog(cdr(z)); } z = Nil; } else z = evList(z); } } while (isCell(y = cdr(y))); } } // (at '(cnt1 . cnt2|NIL) . prg) -> any any doAt(any ex) { any x; x = cdr(ex), x = EVAL(car(x)); NeedPair(ex,x); if (isNil(cdr(x))) return Nil; NeedCnt(ex,car(x)); NeedCnt(ex,cdr(x)); if (num(setDig(car(x), unDig(car(x))+2)) < unDig(cdr(x))) return Nil; setDig(car(x), 0); return prog(cddr(ex)); } // (for sym 'num ['any | (NIL 'any . prg) | (T 'any . prg) ..]) -> any // (for sym|(sym2 . sym) 'lst ['any | (NIL 'any . prg) | (T 'any . prg) ..]) -> any // (for (sym|(sym2 . sym) 'any1 'any2 [. prg]) ['any | (NIL 'any . prg) | (T 'any . prg) ..]) -> any any doFor(any x) { any y, body, cond, a; cell c1; struct { // bindFrame struct bindFrame *link; int i, cnt; struct {any sym; any val;} bnd[2]; } f; f.link = Env.bind, Env.bind = (bindFrame*)&f; f.i = 0; if (!isCell(y = car(x = cdr(x))) || !isCell(cdr(y))) { if (!isCell(y)) { f.cnt = 1; f.bnd[0].sym = y; f.bnd[0].val = val(y); } else { f.cnt = 2; f.bnd[0].sym = cdr(y); f.bnd[0].val = val(cdr(y)); f.bnd[1].sym = car(y); f.bnd[1].val = val(car(y)); val(f.bnd[1].sym) = Zero; } y = Nil; x = cdr(x), Push(c1, EVAL(car(x))); if (isNum(data(c1))) val(f.bnd[0].sym) = Zero; body = x = cdr(x); for (;;) { if (isNum(data(c1))) { val(f.bnd[0].sym) = bigCopy(val(f.bnd[0].sym)); digAdd(val(f.bnd[0].sym), 2); if (bigCompare(val(f.bnd[0].sym), data(c1)) > 0) break; } else { if (!isCell(data(c1))) break; val(f.bnd[0].sym) = car(data(c1)); if (!isCell(data(c1) = cdr(data(c1)))) data(c1) = Nil; } if (f.cnt == 2) { val(f.bnd[1].sym) = bigCopy(val(f.bnd[1].sym)); digAdd(val(f.bnd[1].sym), 2); } do { if (!isNum(y = car(x))) { if (isSym(y)) y = val(y); else if (isNil(car(y))) { y = cdr(y); if (isNil(a = EVAL(car(y)))) { y = prog(cdr(y)); goto for1; } val(At) = a; y = Nil; } else if (car(y) == T) { y = cdr(y); if (!isNil(a = EVAL(car(y)))) { val(At) = a; y = prog(cdr(y)); goto for1; } y = Nil; } else y = evList(y); } } while (isCell(x = cdr(x))); x = body; } for1: drop(c1); if (f.cnt == 2) val(f.bnd[1].sym) = f.bnd[1].val; val(f.bnd[0].sym) = f.bnd[0].val; Env.bind = f.link; return y; } if (!isCell(car(y))) { f.cnt = 1; f.bnd[0].sym = car(y); f.bnd[0].val = val(car(y)); } else { f.cnt = 2; f.bnd[0].sym = cdar(y); f.bnd[0].val = val(cdar(y)); f.bnd[1].sym = caar(y); f.bnd[1].val = val(caar(y)); val(f.bnd[1].sym) = Zero; } y = cdr(y); val(f.bnd[0].sym) = EVAL(car(y)); y = cdr(y), cond = car(y), y = cdr(y); Push(c1,Nil); body = x = cdr(x); for (;;) { if (f.cnt == 2) { val(f.bnd[1].sym) = bigCopy(val(f.bnd[1].sym)); digAdd(val(f.bnd[1].sym), 2); } if (isNil(a = EVAL(cond))) break; val(At) = a; do { if (!isNum(data(c1) = car(x))) { if (isSym(data(c1))) data(c1) = val(data(c1)); else if (isNil(car(data(c1)))) { data(c1) = cdr(data(c1)); if (isNil(a = EVAL(car(data(c1))))) { data(c1) = prog(cdr(data(c1))); goto for2; } val(At) = a; data(c1) = Nil; } else if (car(data(c1)) == T) { data(c1) = cdr(data(c1)); if (!isNil(a = EVAL(car(data(c1))))) { val(At) = a; data(c1) = prog(cdr(data(c1))); goto for2; } data(c1) = Nil; } else data(c1) = evList(data(c1)); } } while (isCell(x = cdr(x))); if (isCell(y)) val(f.bnd[0].sym) = prog(y); x = body; } for2: if (f.cnt == 2) val(f.bnd[1].sym) = f.bnd[1].val; val(f.bnd[0].sym) = f.bnd[0].val; Env.bind = f.link; return Pop(c1); } // (catch 'any . prg) -> any any doCatch(any x) { any y; catchFrame f; x = cdr(x), f.tag = EVAL(car(x)), f.fin = Zero; f.link = CatchPtr, CatchPtr = &f; f.env = Env; y = setjmp(f.rst)? Thrown : prog(cdr(x)); CatchPtr = f.link; return y; } // (throw 'sym 'any) any doThrow(any ex) { any x, tag; catchFrame *p; x = cdr(ex), tag = EVAL(car(x)); x = cdr(x), Thrown = EVAL(car(x)); for (p = CatchPtr; p; p = p->link) if (p->tag == T || tag == p->tag) { unwind(p); longjmp(p->rst, 1); } err(ex, tag, "Tag not found"); } // (finally exe . prg) -> any any doFinally(any x) { catchFrame f; cell c1; x = cdr(x), f.tag = NULL, f.fin = car(x); f.link = CatchPtr, CatchPtr = &f; f.env = Env; Push(c1, prog(cdr(x))); EVAL(f.fin); CatchPtr = f.link; return Pop(c1); } static outFrame Out; static struct { // bindFrame struct bindFrame *link; int i, cnt; struct {any sym; any val;} bnd[3]; // for 'Up', 'Run' and 'At' } Brk; any brkLoad(any x) { if (!Break && isatty(STDIN_FILENO) && isatty(STDOUT_FILENO)) { Break = YES; Brk.cnt = 3; Brk.bnd[0].sym = Up, Brk.bnd[0].val = val(Up), val(Up) = x; Brk.bnd[1].sym = Run, Brk.bnd[1].val = val(Run), val(Run) = Nil; Brk.bnd[2].sym = At, Brk.bnd[2].val = val(At); Brk.link = Env.bind, Env.bind = (bindFrame*)&Brk; Out.pid = 0, Out.fd = STDOUT_FILENO, pushOutFiles(&Out); print(x), newline(); load(NULL, '!', Nil); popOutFiles(); val(At) = Brk.bnd[2].val; val(Run) = Brk.bnd[1].val; x = val(Up), val(Up) = Brk.bnd[0].val; Env.bind = Brk.link; Break = NO; } return x; } // (! . exe) -> any any doBreak(any x) { x = cdr(x); if (!isNil(val(Dbg))) x = brkLoad(x); return EVAL(x); } // (e . prg) -> any any doE(any ex) { any x; inFrame *in; cell c1, at, key; if (!Break) err(ex, NULL, "No Break"); Push(c1,val(Dbg)), val(Dbg) = Nil; Push(at, val(At)), val(At) = Brk.bnd[2].val; Push(key, val(Run)), val(Run) = Brk.bnd[1].val; in = Env.inFrames, popInFiles(); popOutFiles(); x = isCell(cdr(ex))? prog(cdr(ex)) : EVAL(val(Up)); pushOutFiles(&Out); pushInFiles(in); val(Run) = data(key); val(At) = data(at); val(Dbg) = Pop(c1); return x; } static void traceIndent(int i, any x, char *s) { if (i > 64) i = 64; while (--i >= 0) Env.put(' '); if (isSym(x)) print(x); else print(car(x)), space(), print(cdr(x)), space(), print(val(This)); outString(s); } // ($ sym|lst lst . prg) -> any any doTrace(any x) { any foo, body; outFile *oSave; void (*putSave)(int); cell c1; x = cdr(x); if (isNil(val(Dbg))) return prog(cddr(x)); oSave = OutFile, putSave = Env.put; OutFile = OutFiles[STDERR_FILENO], Env.put = putStdout; foo = car(x); x = cdr(x), body = cdr(x); traceIndent(++Env.trace, foo, " :"); for (x = car(x); isCell(x); x = cdr(x)) space(), print(val(car(x))); if (!isNil(x)) { if (x != At) space(), print(val(x)); else { int i = Env.next; while (--i >= 0) space(), print(data(Env.arg[i])); } } newline(); Env.put = putSave, OutFile = oSave; Push(c1, prog(body)); OutFile = OutFiles[STDERR_FILENO], Env.put = putStdout; traceIndent(Env.trace--, foo, " = "), print(data(c1)); newline(); Env.put = putSave, OutFile = oSave; return Pop(c1); } // (exec 'any ..) any doExec(any x) { any y; int i, ac = length(x = cdr(x)); char *av[ac+1]; if (ac) { av[0] = alloc(NULL, pathSize(y = evSym(x))), pathString(y, av[0]); for (i = 1; isCell(x = cdr(x)); ++i) av[i] = alloc(NULL, bufSize(y = evSym(x))), bufString(y, av[i]); av[ac] = NULL; flushAll(); execvp(av[0], av); execError(av[0]); } return Nil; } // (call 'any ..) -> flg any doCall(any ex) { pid_t pid; any x, y; int res, i, ac = length(x = cdr(ex)); char *av[ac+1]; if (ac == 0) return Nil; av[0] = alloc(NULL, pathSize(y = evSym(x))), pathString(y, av[0]); for (i = 1; isCell(x = cdr(x)); ++i) av[i] = alloc(NULL, bufSize(y = evSym(x))), bufString(y, av[i]); av[ac] = NULL; flushAll(); if ((pid = fork()) == 0) { setpgid(0,0); execvp(av[0], av); execError(av[0]); } i = 0; do free(av[i]); while (++i < ac); if (pid < 0) err(ex, NULL, "fork"); setpgid(pid,0); if (Termio) tcsetpgrp(0,pid); for (;;) { while (waitpid(pid, &res, WUNTRACED) < 0) { if (errno != EINTR) err(ex, NULL, "wait pid"); if (*Signal) sighandler(ex); } if (Termio) tcsetpgrp(0,getpgrp()); if (!WIFSTOPPED(res)) { val(At2) = box(res+res); return res == 0? T : Nil; } load(NULL, '+', Nil); if (Termio) tcsetpgrp(0,pid); kill(pid, SIGCONT); } } // (tick (cnt1 . cnt2) . prg) -> any any doTick(any ex) { any x; clock_t n1, n2, save1, save2; struct tms tim; static clock_t ticks1, ticks2; save1 = ticks1, save2 = ticks2; times(&tim), n1 = tim.tms_utime, n2 = tim.tms_stime; x = prog(cddr(ex)); times(&tim); n1 = (tim.tms_utime - n1) - (ticks1 - save1); n2 = (tim.tms_stime - n2) - (ticks2 - save2); setDig(caadr(ex), unDig(caadr(ex)) + 2*n1); setDig(cdadr(ex), unDig(cdadr(ex)) + 2*n2); ticks1 += n1, ticks2 += n2; return x; } // (ipid) -> pid | NIL any doIpid(any ex __attribute__((unused))) { if (Env.inFrames && Env.inFrames->pid > 1) return boxCnt((long)Env.inFrames->pid); return Nil; } // (opid) -> pid | NIL any doOpid(any ex __attribute__((unused))) { if (Env.outFrames && Env.outFrames->pid > 1) return boxCnt((long)Env.outFrames->pid); return Nil; } // (kill 'pid ['cnt]) -> flg any doKill(any ex) { pid_t pid; pid = (pid_t)evCnt(ex,cdr(ex)); return kill(pid, isCell(cddr(ex))? (int)evCnt(ex,cddr(ex)) : SIGTERM)? Nil : T; } static void allocChildren(void) { int i; Child = alloc(Child, (Children + 8) * sizeof(child)); for (i = 0; i < 8; ++i) Child[Children++].pid = 0; } pid_t forkLisp(any ex) { pid_t n; int i, hear[2], tell[2]; static int mic[2]; flushAll(); if (!Spkr) { if (pipe(mic) < 0) pipeError(ex, "open"); closeOnExec(ex, mic[0]), closeOnExec(ex, mic[1]); Spkr = mic[0]; } if (pipe(hear) < 0 || pipe(tell) < 0) pipeError(ex, "open"); closeOnExec(ex, hear[0]), closeOnExec(ex, hear[1]); closeOnExec(ex, tell[0]), closeOnExec(ex, tell[1]); for (i = 0; i < Children; ++i) if (!Child[i].pid) break; if ((n = fork()) < 0) err(ex, NULL, "fork"); if (n == 0) { void *p; Slot = i; Spkr = 0; Mic = mic[1]; close(hear[1]), close(tell[0]), close(mic[0]); if (Hear) close(Hear), closeInFile(Hear), closeOutFile(Hear); initInFile(Hear = hear[0], NULL); if (Tell) close(Tell); Tell = tell[1]; for (i = 0; i < Children; ++i) if (Child[i].pid) close(Child[i].hear), close(Child[i].tell), free(Child[i].buf); Children = 0, free(Child), Child = NULL; for (p = Env.inFrames; p; p = ((inFrame*)p)->link) ((inFrame*)p)->pid = 0; for (p = Env.outFrames; p; p = ((outFrame*)p)->link) ((outFrame*)p)->pid = 0; for (p = CatchPtr; p; p = ((catchFrame*)p)->link) ((catchFrame*)p)->fin = Zero; free(Termio), Termio = NULL; if (Repl) ++Repl; val(PPid) = val(Pid); val(Pid) = boxCnt(getpid()); run(val(Fork)); val(Fork) = Nil; return 0; } if (i == Children) allocChildren(); close(hear[0]), close(tell[1]); Child[i].pid = n; Child[i].hear = tell[0]; nonblocking(Child[i].tell = hear[1]); Child[i].ofs = Child[i].cnt = 0; Child[i].buf = NULL; return n; } // (fork) -> pid | NIL any doFork(any ex) { int n; return (n = forkLisp(ex))? boxCnt(n) : Nil; } // (detach) -> pid | NIL any doDetach(any x) { if (!isNil(x = val(PPid))) { val(PPid) = Nil; close(Tell), Tell = 0; close(Hear), closeInFile(Hear), closeOutFile(Hear), Hear = 0; close(Mic), Mic = 0; Slot = 0; setsid(); } return x; } // (bye ['cnt]) any doBye(any ex) { any x = EVAL(cadr(ex)); bye(isNil(x)? 0 : xCnt(ex,x)); }
0e5b98584b2362b9b5062e6a75364f3b76882240
25b7cd3e4b750803565c374e59f8179c8aab276d
/h3m/h3mlib/h3m_parsing/parse_ai_teams.c
47279edd59a5b1e0c0e9822bd03b3e936619d95b
[ "MIT" ]
permissive
potmdehex/homm3tools
320ce70e0d22dc597df440ec7c63fde9844f7dbe
6b36d1f92ea67f5ad6d4847aeaf2dfb1766d3cc5
refs/heads/master
2023-08-06T02:56:53.534443
2022-09-19T12:42:50
2022-09-19T12:42:50
40,399,205
141
29
MIT
2019-12-06T12:11:43
2015-08-08T10:15:08
C
UTF-8
C
false
false
733
c
parse_ai_teams.c
// Created by John Åkerblom 2014-11-21 #include "../h3mlib.h" #include "parse_ai.h" #include "../utils/format_select.h" #include "../utils/safe_read.h" #include <stdlib.h> #include <string.h> int parse_ai_teams(struct H3MLIB_CTX *ctx) { struct H3M *p = &ctx->h3m; struct H3MLIB_META *meta = &ctx->meta; struct H3MLIB_PARSING *parsing = &ctx->parsing; //int orig_off = ctx->parsing.offset; //int ret = 0; const uint32_t fm = p->format; uint8_t count = 0; SAFE_READ_SIZEOF(&count, parsing) if (0 != count) { FS_ANY_ASSIGN(p->ai, teams_count, count, fm) FS_ANY_READ_SIZEOF(p->ai, teams, parsing, fm) meta->ai_teams_size = sizeof(p->ai.any.teams); } return 0; }
088f8e66f99b2b5b5936c102a9f9c23fee07c9d4
7f6c235b0598353549959c18f69eefd20b766907
/src/ticks/profiler.h
a6070c163383189f1a95c8335b6eb34e7c662832
[ "ClArtistic" ]
permissive
z88dk/z88dk
46dfd4905f36d99333173cadd0a660839befc9f0
8b07f37cc43c5d9ffe69b563c80763491d8faff7
refs/heads/master
2023-09-04T19:29:49.254958
2023-09-03T20:51:24
2023-09-03T20:51:24
54,035,569
820
263
NOASSERTION
2023-09-05T11:09:04
2016-03-16T13:48:16
Assembly
UTF-8
C
false
false
241
h
profiler.h
#ifndef PROFILER_H #define PROFILER_H #include <stdint.h> extern int profiler_enabled; extern void profiler_start(const char* function, int iterations_limit); extern uint8_t profiler_check(uint16_t pc); extern void profiler_stop(); #endif
9c75a4bcd43a8ca455894e5a30c13d55f575846e
c18e3cba4f445613b2ed7503061cdfe088d46da5
/docs/parallel/concrt/codesnippet/CPP/walkthrough-creating-a-custom-message-block_8.h
36d1fc5c640e48528f200567cb6248f1d9a5d374
[ "CC-BY-4.0", "MIT" ]
permissive
MicrosoftDocs/cpp-docs
dad03e548e13ca6a6e978df3ba84c4858c77d4bd
87bacc85d5a1e9118a69122d84c43d70f6893f72
refs/heads/main
2023-09-01T00:19:22.423787
2023-08-28T17:27:40
2023-08-28T17:27:40
73,740,405
1,354
1,213
CC-BY-4.0
2023-09-08T21:27:46
2016-11-14T19:38:32
PowerShell
UTF-8
C
false
false
298
h
walkthrough-creating-a-custom-message-block_8.h
// Sends an item to the message block. bool enqueue(Type const& item) { return concurrency::asend<Type>(this, item); } // Receives an item from the message block. Type dequeue() { return receive<Type>(this); }
b80903c5425536cfce06ae384b62376d9c10c5b6
cb9ab2e6b33f0befa99543c9501108641501500e
/IsoLib/libisomediafile/src/MP4IPMPToolDescriptor.c
26f6d8514ff6ad39f7878977ec3d03b3af57fc88
[]
no_license
MPEGGroup/isobmff
3401d5022d9bf0bfe3fc860c8fe53e83b66021d2
2a0e1a3690efb4553defca31caf347013f1eb9e1
refs/heads/master
2023-08-10T19:09:28.069852
2022-11-08T15:18:52
2022-11-08T15:18:52
118,715,054
101
37
null
2023-08-30T18:48:42
2018-01-24T05:07:44
C
UTF-8
C
false
false
6,963
c
MP4IPMPToolDescriptor.c
/* This software module was originally developed by Apple Computer, Inc. in the course of development of MPEG-4. This software module is an implementation of a part of one or more MPEG-4 tools as specified by MPEG-4. ISO/IEC gives users of MPEG-4 free license to this software module or modifications thereof for use in hardware or software products claiming conformance to MPEG-4. Those intending to use this software module in hardware or software products are advised that its use may infringe existing patents. The original developer of this software module and his/her company, the subsequent editors and their companies, and ISO/IEC have no liability for use of this software module or modifications thereof in an implementation. Copyright is not released for non MPEG-4 conforming products. Apple Computer, Inc. retains full right to use the code for its own purpose, assign or donate the code to a third party and to inhibit third parties from using the code for non MPEG-4 conforming products. This copyright notice must be included in all copies or derivative works. Copyright (c) 1999. */ #include "MP4Descriptors.h" #include "MP4Movies.h" #include <stdlib.h> #include <string.h> static MP4Err addIPMPXData(struct MP4DescriptorRecord *s, MP4IPMPXDataPtr data) { MP4Err err; MP4IPMPToolDescriptorPtr self = (MP4IPMPToolDescriptorPtr)s; err = MP4NoErr; err = MP4AddListEntry(data, self->ipmpxData); if(err) goto bail; bail: TEST_RETURN(err); return err; } static MP4Err calculateSize(struct MP4DescriptorRecord *s) { MP4Err err; u32 i; u32 ipmpxDataCount; MP4IPMPToolDescriptorPtr self = (MP4IPMPToolDescriptorPtr)s; err = MP4NoErr; if(s == NULL) BAILWITHERROR(MP4BadParamErr); self->size = DESCRIPTOR_TAG_LEN_SIZE; /* tag + length word */ self->size += 18; /* ipmpToolDescId + ipmpToolId */ if(self->ipmpToolId->upperPart == 0 && self->ipmpToolId->lowerPart == 0) { self->size += 4; /* size of ByteArray */ self->size += self->url->size; } else { self->size += 1; /* initialize tag */ if(self->initData != NULL) { self->initData->calculateSize(self->initData); self->size += self->initData->size; } self->size += 1; /* ipmpxDataCount */ err = MP4GetListEntryCount(self->ipmpxData, &ipmpxDataCount); if(err) goto bail; for(i = 0; i < ipmpxDataCount; i++) { MP4IPMPXDataPtr entry; err = MP4GetListEntry(self->ipmpxData, i, (char **)&entry); if(err) goto bail; entry->calculateSize(entry); self->size += entry->size; } } bail: TEST_RETURN(err); return err; } static MP4Err serialize(struct MP4DescriptorRecord *s, char *buffer) { MP4Err err; u32 ipmpxDataCount; u32 i; MP4IPMPToolDescriptorPtr self = (MP4IPMPToolDescriptorPtr)s; err = MP4NoErr; if(s == NULL) BAILWITHERROR(MP4BadParamErr); err = MP4EncodeBaseDescriptor(s, buffer); if(err) goto bail; buffer += DESCRIPTOR_TAG_LEN_SIZE; PUT16(ipmpToolDescriptorId); PUT64(ipmpToolId->upperPart); PUT64(ipmpToolId->lowerPart); if(self->ipmpToolId->upperPart == 0 && self->ipmpToolId->lowerPart == 0) { if(self->url == NULL) BAILWITHERROR(MP4BadDataErr); PUT32_V(self->url->size); PUTBYTES(self->url->data, self->url->size); } else { PUT8_V((self->initData != NULL) ? 0x80 : 0X00); /* isInitialize flag */ if(self->initData != NULL) { err = self->initData->serialize(self->initData, buffer); if(err) goto bail; buffer += self->initData->bytesWritten; self->bytesWritten += self->initData->bytesWritten; } err = MP4GetListEntryCount(self->ipmpxData, &ipmpxDataCount); if(err) goto bail; PUT8_V(ipmpxDataCount); for(i = 0; i < ipmpxDataCount; i++) { MP4IPMPXDataPtr entry; err = MP4GetListEntry(self->ipmpxData, i, (char **)&entry); if(err) goto bail; entry->serialize(entry, buffer); self->bytesWritten += entry->bytesWritten; buffer += entry->bytesWritten; } } if(self->bytesWritten != self->size) BAILWITHERROR(MP4BadDataErr); bail: TEST_RETURN(err); return err; } static MP4Err createFromInputStream(struct MP4DescriptorRecord *s, MP4InputStreamPtr inputStream) { MP4Err err; u32 i; u32 ipmpxDataCount; u8 initFlag; MP4IPMPToolDescriptorPtr self = (MP4IPMPToolDescriptorPtr)s; err = MP4NoErr; if(s == NULL) BAILWITHERROR(MP4BadParamErr); GET16(ipmpToolDescriptorId); GET64(ipmpToolId->upperPart); GET64(ipmpToolId->lowerPart); if(self->ipmpToolId->upperPart == 0 && self->ipmpToolId->lowerPart == 0) { self->url = (MP4IPMPByteArrayPtr)calloc(1, sizeof(MP4IPMPByteArray)); TESTMALLOC(self->url); GET32(url->size); self->url->data = (char *)calloc(1, self->url->size); TESTMALLOC(self->url->data); GETBYTES(self->url->size, url->data); } else { GET8_V(initFlag); if(initFlag & 0x80) { err = MP4CreateIPMPInitialize(&self->initData); if(err) goto bail; err = self->initData->createFromInputStream(self->initData, inputStream); if(err) goto bail; self->bytesRead += self->initData->bytesRead; } GET8_V(ipmpxDataCount); for(i = 0; i < ipmpxDataCount; i++) { MP4IPMPXDataPtr data; err = MP4ParseIPMPXData(inputStream, &data); if(err) goto bail; self->bytesRead += data->size; err = addIPMPXData(s, data); if(err) goto bail; } } if(self->bytesRead != self->size) BAILWITHERROR(MP4BadDataErr); bail: TEST_RETURN(err); return err; } static void destroy(struct MP4DescriptorRecord *s) { MP4Err err; u32 i; u32 ipmpxDataCount; MP4IPMPToolDescriptorPtr self = (MP4IPMPToolDescriptorPtr)s; err = MP4NoErr; if(s == NULL) BAILWITHERROR(MP4BadParamErr); if(self->ipmpToolId) free(self->ipmpToolId); if(self->url) { if(self->url->data) free(self->url->data); free(self->url); } if(self->initData) { self->initData->destroy(self->initData); free(self->initData); } err = MP4GetListEntryCount(self->ipmpxData, &ipmpxDataCount); if(err) goto bail; for(i = 0; i < ipmpxDataCount; i++) { MP4IPMPXDataPtr entry; err = MP4GetListEntry(self->ipmpxData, i, (char **)&entry); if(err) goto bail; if(entry) entry->destroy(entry); } err = MP4DeleteLinkedList(self->ipmpxData); free(s); bail: return; } MP4Err MP4CreateIPMPToolDescriptor(u32 tag, u32 size, u32 bytesRead, MP4DescriptorPtr *outDesc) { SETUP_BASE_DESCRIPTOR(MP4IPMPToolDescriptor); err = MP4MakeLinkedList(&self->ipmpxData); if(err) goto bail; self->ipmpToolId = (MP4IPMPToolIdPtr)calloc(1, sizeof(MP4IPMPToolId)); TESTMALLOC(self->ipmpToolId); self->addIPMPXData = addIPMPXData; *outDesc = (MP4DescriptorPtr)self; bail: TEST_RETURN(err); return err; }
214d446d657ba256f6be363d485ce459f82b8a24
e65a4dbfbfb0e54e59787ba7741efee12f7687f3
/games/libretro-beetle_saturn/files/patch-libretro-common_rthreads_rthreads.c
09e7cfd6ee7c23409ea8436f8334e197c3e97970
[ "BSD-2-Clause" ]
permissive
freebsd/freebsd-ports
86f2e89d43913412c4f6b2be3e255bc0945eac12
605a2983f245ac63f5420e023e7dce56898ad801
refs/heads/main
2023-08-30T21:46:28.720924
2023-08-30T19:33:44
2023-08-30T19:33:44
1,803,961
916
918
NOASSERTION
2023-09-08T04:06:26
2011-05-26T11:15:35
null
UTF-8
C
false
false
234
c
patch-libretro-common_rthreads_rthreads.c
--- libretro-common/rthreads/rthreads.c.orig 2021-06-22 13:57:12 UTC +++ libretro-common/rthreads/rthreads.c @@ -64,6 +64,8 @@ #include <mach/mach.h> #endif +#include <sys/time.h> + struct thread_data { void (*func)(void*);
762da3925d7ad755b3da126c2a590e20632930dc
cdc6c85f66ff27e566aaf8c39b868bda3e80e192
/libsrc/math/sin.c
af4234dd089dd672395fb117f897619fcff67d0e
[]
no_license
tyfkda/xcc
e2deafc3b4f1d163956619742f617b1b1eb81a3b
9614ac50d6e813e5b3c2ab76bb3eabad10875f64
refs/heads/main
2023-08-23T23:48:16.443583
2023-08-21T02:58:14
2023-08-22T00:41:17
166,307,267
128
9
null
2023-07-20T01:09:36
2019-01-17T22:38:21
C
UTF-8
C
false
false
887
c
sin.c
#include "math.h" #ifndef __NO_FLONUM extern double normalize_radian(double x); double sin(double x) { static const double TABLE[] = { 1 / 1.0, -1 / (3.0 * 2 * 1), 1 / (5.0 * 4 * 3 * 2 * 1), -1 / (7.0 * 6 * 5 * 4 * 3 * 2 * 1), 1 / (9.0 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1), -1 / (11.0 * 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1), 1 / (13.0 * 12 * 11 * 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1), -1 / (15.0 * 14 * 13 * 12 * 11 * 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1), 1 / (17.0 * 16 * 15 * 14 * 13 * 12 * 11 * 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1), -1 / (19.0 * 18 * 17 * 16 * 15 * 14 * 13 * 12 * 11 * 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1), }; x = normalize_radian(x); double v = 0; double xx = x * x; for (int i = 0; i < (int)(sizeof(TABLE) / sizeof(*TABLE)); ++i) { v += x * TABLE[i]; x *= xx; } return v; } #endif
c3804dfcca25b47ca879985b9b406946f46c7b58
89db60818afeb3dc7c3b7abe9ceae155f074f7f2
/src/cmd/astro/nutate.c
bc7daa31ab02b26a839ad05018ff16c8fdc088c4
[ "bzip2-1.0.6", "LPL-1.02", "MIT" ]
permissive
9fans/plan9port
63c3d01928c6f8a8617d3ea6ecc05bac72391132
65c090346a38a8c30cb242d345aa71060116340c
refs/heads/master
2023-08-25T17:14:26.233105
2023-08-23T13:21:37
2023-08-23T18:47:08
26,095,474
1,645
468
NOASSERTION
2023-09-05T16:55:41
2014-11-02T22:40:13
C
UTF-8
C
false
false
1,754
c
nutate.c
#include "astro.h" void nutate(void) { /* * uses radian, radsec * sets phi, eps, dphi, deps, obliq, gst, tobliq */ double msun, mnom, noded, dmoon; /* * nutation of the equinoxes is a wobble of the pole * of the earths rotation whose magnitude is about * 9 seconds of arc and whose period is about 18.6 years. * * it depends upon the pull of the sun and moon on the * equatorial bulge of the earth. * * phi and eps are the two angles which specify the * true pole with respect to the mean pole. * * all coeffieients are from Exp. Supp. pp.44-45 */ mnom = 296.104608 + 13.0649924465*eday + 9.192e-3*capt2 + 14.38e-6*capt3; mnom *= radian; msun = 358.475833 + .9856002669*eday - .150e-3*capt2 - 3.33e-6*capt3; msun *= radian; noded = 11.250889 + 13.2293504490*eday - 3.211e-3*capt2 - 0.33e-6*capt3; noded *= radian; dmoon = 350.737486 + 12.1907491914*eday - 1.436e-3*capt2 + 1.89e-6*capt3; dmoon *= radian; node = 259.183275 - .0529539222*eday + 2.078e-3*capt2 + 2.22e-6*capt3; node *= radian; /* * long period terms */ phi = 0.; eps = 0.; dphi = 0.; deps = 0.; icosadd(nutfp, nutcp); phi = -(17.2327+.01737*capt)*sin(node); phi += sinadd(4, node, noded, dmoon, msun); eps = cosadd(4, node, noded, dmoon, msun); /* * short period terms */ dphi = sinadd(4, node, noded, mnom, dmoon); deps = cosadd(3, node, noded, mnom); phi = (phi+dphi)*radsec; eps = (eps+deps)*radsec; dphi *= radsec; deps *= radsec; obliq = 23.452294 - .0130125*capt - 1.64e-6*capt2 + 0.503e-6*capt3; obliq *= radian; tobliq = obliq + eps; gst = 99.690983 + 360.9856473354*eday + .000387*capt2; gst -= 180.; gst = fmod(gst, 360.); if(gst < 0.) gst += 360.; gst *= radian; gst += phi*cos(obliq); }
995cf5ec34b0119e37f88a07ee73cb7aaefdf442
aa5c1a530f95d629e686ac9124caf1a49a9f23e9
/runtime/src/iree/modules/hal/utils/buffer_diagnostics.c
cd2852576124f5159b57be8c535d79aec66a1e78
[ "Apache-2.0", "LLVM-exception", "LicenseRef-scancode-unknown-license-reference" ]
permissive
openxla/iree
eacf5b239559e1d3b40c38039ac4c26315b523f7
13ef677e556d0a1d154e45b052fe016256057f65
refs/heads/main
2023-09-06T01:19:49.598662
2023-09-04T07:01:30
2023-09-04T07:01:30
208,145,128
387
110
Apache-2.0
2023-09-14T20:48:00
2019-09-12T20:57:39
C++
UTF-8
C
false
false
13,522
c
buffer_diagnostics.c
// Copyright 2022 The IREE Authors // // Licensed under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception #include "iree/modules/hal/utils/buffer_diagnostics.h" #include <stdio.h> #include <string.h> //===----------------------------------------------------------------------===// // iree_hal_buffer_t //===----------------------------------------------------------------------===// iree_status_t iree_hal_modules_buffer_assert( iree_vm_ref_t buffer_ref, iree_vm_ref_t message_ref, iree_device_size_t minimum_length, iree_hal_memory_type_t required_memory_types, iree_hal_buffer_usage_t required_buffer_usage) { iree_hal_buffer_t* buffer = NULL; IREE_RETURN_IF_ERROR(iree_hal_buffer_check_deref(buffer_ref, &buffer)); iree_vm_buffer_t* message = NULL; IREE_RETURN_IF_ERROR(iree_vm_buffer_check_deref(message_ref, &message)); iree_string_view_t message_str = iree_vm_buffer_as_string(message); (void)message_str; // Ensure we have enough bytes in the buffer for the encoding we have. // Note that having more bytes is fine: // assert(expected_length <= actual_length); iree_device_size_t actual_length = iree_hal_buffer_byte_length(buffer); if (actual_length < minimum_length) { return iree_make_status(IREE_STATUS_INVALID_ARGUMENT, "%.*s buffer byte length %" PRIdsz " less than expected minimum %" PRIdsz, (int)message_str.size, message_str.data, actual_length, minimum_length); } // All memory type bits expected (indicating where the program intends to use // the buffer data) must be set in the buffer while the buffer is allowed to // have more bits. iree_hal_memory_type_t actual_memory_type = iree_hal_buffer_memory_type(buffer); if (!iree_all_bits_set(actual_memory_type, required_memory_types)) { #if ((IREE_STATUS_FEATURES & IREE_STATUS_FEATURE_ANNOTATIONS) != 0) && \ IREE_HAL_MODULE_STRING_UTIL_ENABLE iree_bitfield_string_temp_t temp0, temp1; iree_string_view_t actual_memory_type_str = iree_hal_memory_type_format(actual_memory_type, &temp0); iree_string_view_t expected_memory_type_str = iree_hal_memory_type_format(required_memory_types, &temp1); return iree_make_status( IREE_STATUS_PERMISSION_DENIED, "%.*s buffer memory type is not compatible; buffer has %.*s, operation " "requires %.*s", (int)message_str.size, message_str.data, (int)actual_memory_type_str.size, actual_memory_type_str.data, (int)expected_memory_type_str.size, expected_memory_type_str.data); #else return iree_make_status( IREE_STATUS_PERMISSION_DENIED, "%.*s buffer memory type is not compatible; buffer has %08X, operation " "requires %08X", (int)message_str.size, message_str.data, actual_memory_type, expected_memory_type); #endif // IREE_HAL_MODULE_STRING_UTIL_ENABLE } // All usage bits expected (indicating what the program intends to use the // buffer for) must be set in the buffer while the buffer is allowed to have // more bits. iree_hal_buffer_usage_t actual_buffer_usage = iree_hal_buffer_allowed_usage(buffer); if (!iree_all_bits_set(actual_buffer_usage, required_buffer_usage)) { #if ((IREE_STATUS_FEATURES & IREE_STATUS_FEATURE_ANNOTATIONS) != 0) && \ IREE_HAL_MODULE_STRING_UTIL_ENABLE iree_bitfield_string_temp_t temp0, temp1; iree_string_view_t allowed_usage_str = iree_hal_buffer_usage_format(actual_buffer_usage, &temp0); iree_string_view_t required_usage_str = iree_hal_buffer_usage_format(required_buffer_usage, &temp1); return iree_make_status( IREE_STATUS_PERMISSION_DENIED, "%.*s requested usage was not specified when the buffer was allocated; " "buffer allows %.*s, operation requires %.*s", (int)message_str.size, message_str.data, (int)allowed_usage_str.size, allowed_usage_str.data, (int)required_usage_str.size, required_usage_str.data); #else return iree_make_status( IREE_STATUS_PERMISSION_DENIED, "%.*s requested usage was not specified when the buffer was allocated; " "buffer allows %08X, operation requires %08X", (int)message_str.size, message_str.data, allowed_buffer_usage, required_buffer_usage); #endif // IREE_HAL_MODULE_STRING_UTIL_ENABLE } return iree_ok_status(); } //===----------------------------------------------------------------------===// // iree_hal_buffer_view_t //===----------------------------------------------------------------------===// // Returns true if the |expected_type| can be satisfied with |actual_type|. // This allows for basic type widening and bypassing instead of requiring an // exact match in all cases. static bool iree_hal_element_types_are_compatible( iree_hal_element_type_t actual_type, iree_hal_element_type_t expected_type) { if (iree_hal_element_numerical_type_is_opaque(actual_type)) { // If the provided type is opaque it can map to anything. This allows // applications to bypass the checks when they are treating all the data as // opaque, such as when carrying around buffer data in binary blobs. return true; } if (iree_hal_element_numerical_type_is_integer(actual_type) && iree_hal_element_numerical_type_is_integer(expected_type) && iree_hal_element_bit_count(actual_type) == iree_hal_element_bit_count(expected_type)) { // Integer types of the same bit width are allowed to be cast. // This allows users or the compiler to treat data as signless while still // allowing signedness. For example, tensor<1xi32> can successfully match // a tensor<1xui32> expectation. return true; } // Otherwise we require an exact match. This may be overly conservative but // in most cases is a useful error message. Users can pass in OPAQUE types if // hitting this to bypass. return actual_type == expected_type; } iree_status_t iree_hal_modules_buffer_view_assert( iree_vm_ref_t buffer_view_ref, iree_vm_ref_t message_ref, iree_hal_element_type_t expected_element_type, iree_hal_encoding_type_t expected_encoding_type, iree_host_size_t expected_shape_rank, const iree_hal_dim_t* expected_shape_dims) { iree_hal_buffer_view_t* buffer_view = NULL; IREE_RETURN_IF_ERROR( iree_hal_buffer_view_check_deref(buffer_view_ref, &buffer_view)); iree_vm_buffer_t* message = NULL; IREE_RETURN_IF_ERROR(iree_vm_buffer_check_deref(message_ref, &message)); iree_string_view_t message_str = iree_vm_buffer_as_string(message); (void)message_str; // Check encoding first; getting the encoding wrong is worse than the shape. // If the actual encoding is opaque we allow it to pass through - this lets // users override the assertion in the case where they are just passing data // around and don't care about the contents. iree_hal_encoding_type_t actual_encoding_type = iree_hal_buffer_view_encoding_type(buffer_view); if (actual_encoding_type != IREE_HAL_ENCODING_TYPE_OPAQUE && actual_encoding_type != expected_encoding_type) { // TODO(benvanik): string formatting of encodings. return iree_make_status( IREE_STATUS_INVALID_ARGUMENT, "%.*s encoding mismatch; expected %08X but have %08X", (int)message_str.size, message_str.data, expected_encoding_type, actual_encoding_type); } // Element types determine the storage requirements. // If the actual element type is opaque we allow it to pass through. iree_hal_element_type_t actual_element_type = iree_hal_buffer_view_element_type(buffer_view); if (!iree_hal_element_types_are_compatible(actual_element_type, expected_element_type)) { #if ((IREE_STATUS_FEATURES & IREE_STATUS_FEATURE_ANNOTATIONS) != 0) && \ IREE_HAL_MODULE_STRING_UTIL_ENABLE char actual_element_type_str[32]; iree_host_size_t actual_element_type_str_length = 0; char expected_element_type_str[32]; iree_host_size_t expected_element_type_str_length = 0; IREE_RETURN_IF_ERROR(iree_hal_format_element_type( actual_element_type, sizeof(actual_element_type_str), actual_element_type_str, &actual_element_type_str_length)); IREE_RETURN_IF_ERROR(iree_hal_format_element_type( expected_element_type, sizeof(expected_element_type_str), expected_element_type_str, &expected_element_type_str_length)); return iree_make_status( IREE_STATUS_INVALID_ARGUMENT, "%.*s element type mismatch; expected %.*s (%08X) but have %.*s (%08X)", (int)message_str.size, message_str.data, (int)expected_element_type_str_length, expected_element_type_str, expected_element_type, (int)actual_element_type_str_length, actual_element_type_str, actual_element_type); #else return iree_make_status( IREE_STATUS_INVALID_ARGUMENT, "%.*s element type mismatch; expected %08X but have %08X", (int)message_str.size, message_str.data, expected_element_type, actual_element_type); #endif // IREE_HAL_MODULE_STRING_UTIL_ENABLE } // Rank check before the individual shape dimensions. iree_host_size_t actual_shape_rank = iree_hal_buffer_view_shape_rank(buffer_view); const iree_hal_dim_t* actual_shape_dims = iree_hal_buffer_view_shape_dims(buffer_view); iree_status_t shape_status = iree_ok_status(); if (actual_shape_rank != expected_shape_rank) { shape_status = iree_make_status( IREE_STATUS_INVALID_ARGUMENT, "%.*s shape rank mismatch; expected %" PRIhsz "%s but have %" PRIhsz "%s", (int)message_str.size, message_str.data, expected_shape_rank, expected_shape_rank == 0 ? " (scalar)" : "", actual_shape_rank, actual_shape_rank == 0 ? " (scalar)" : ""); } if (iree_status_is_ok(shape_status)) { for (iree_host_size_t i = 0; i < actual_shape_rank; ++i) { if (actual_shape_dims[i] == expected_shape_dims[i]) continue; // Dimension mismatch. shape_status = iree_make_status(IREE_STATUS_INVALID_ARGUMENT, "%.*s shape dimension %" PRIhsz " mismatch; expected %" PRIdim " but have %" PRIdim, (int)message_str.size, message_str.data, i, expected_shape_dims[i], actual_shape_dims[i]); break; } } #if ((IREE_STATUS_FEATURES & IREE_STATUS_FEATURE_ANNOTATIONS) != 0) && \ IREE_HAL_MODULE_STRING_UTIL_ENABLE if (!iree_status_is_ok(shape_status)) { char actual_shape_str[32]; iree_host_size_t actual_shape_str_length = 0; char expected_shape_str[32]; iree_host_size_t expected_shape_str_length = 0; IREE_RETURN_IF_ERROR(iree_hal_format_shape( actual_shape_rank, actual_shape_dims, sizeof(actual_shape_str), actual_shape_str, &actual_shape_str_length)); IREE_RETURN_IF_ERROR(iree_hal_format_shape( expected_shape_rank, expected_shape_dims, sizeof(expected_shape_str), expected_shape_str, &expected_shape_str_length)); shape_status = iree_status_annotate_f( shape_status, "expected shape `%.*s`, actual shape `%.*s`", (int)expected_shape_str_length, expected_shape_str, (int)actual_shape_str_length, actual_shape_str); } #endif // IREE_HAL_MODULE_STRING_UTIL_ENABLE return shape_status; } iree_status_t iree_hal_modules_buffer_view_trace( iree_vm_ref_t key_ref, iree_vm_size_t buffer_view_count, iree_vm_abi_r_t* buffer_view_refs, iree_allocator_t host_allocator) { #if IREE_HAL_MODULE_STRING_UTIL_ENABLE iree_vm_buffer_t* key = NULL; IREE_RETURN_IF_ERROR(iree_vm_buffer_check_deref(key_ref, &key)); iree_string_view_t key_str = iree_vm_buffer_as_string(key); fprintf(stderr, "=== %.*s ===\n", (int)key_str.size, key_str.data); for (iree_host_size_t i = 0; i < buffer_view_count; ++i) { iree_hal_buffer_view_t* buffer_view = NULL; IREE_RETURN_IF_ERROR( iree_hal_buffer_view_check_deref(buffer_view_refs[i].r0, &buffer_view)); // NOTE: this export is for debugging only and a no-op in min-size builds. // We heap-alloc here because at the point this export is used performance // is not a concern. // Query total length (excluding NUL terminator). iree_host_size_t result_length = 0; iree_status_t status = iree_hal_buffer_view_format( buffer_view, IREE_HOST_SIZE_MAX, 0, NULL, &result_length); if (!iree_status_is_out_of_range(status)) { return status; } ++result_length; // include NUL // Allocate scratch heap memory to contain the result and format into it. char* result_str = NULL; IREE_RETURN_IF_ERROR(iree_allocator_malloc(host_allocator, result_length, (void**)&result_str)); status = iree_hal_buffer_view_format(buffer_view, IREE_HOST_SIZE_MAX, result_length, result_str, &result_length); if (iree_status_is_ok(status)) { fprintf(stderr, "%.*s\n", (int)result_length, result_str); } iree_allocator_free(host_allocator, result_str); IREE_RETURN_IF_ERROR(status); } fprintf(stderr, "\n"); #endif // IREE_HAL_MODULE_STRING_UTIL_ENABLE return iree_ok_status(); }
09176317dbf95ee4c6aa3412909cf9c587ef00bf
08db5520055df5865d09c7e2bc888e7219666d3c
/src/mysocket.c
083fc45d25f055f158f100966c7b81b834e28eb0
[ "Artistic-1.0" ]
permissive
pennmush/pennmush
9ab3f8d368bd01c4c1b919a936c4ffc3d222ad38
6c6173eca6865f88a97e0b5cd1fadbab49f1afad
refs/heads/master
2023-09-02T03:52:35.455020
2023-08-19T20:16:55
2023-08-19T20:16:55
32,365,792
121
83
null
2023-08-19T20:16:56
2015-03-17T02:13:05
C
UTF-8
C
false
false
19,218
c
mysocket.c
/** * \file mysocket.c * * \brief Socket routines for PennMUSH. * * */ #define _GNU_SOURCE #include "copyrite.h" #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #ifdef WIN32 #include <winsock2.h> #include <ws2tcpip.h> #endif #ifdef HAVE_SYS_TYPES_H #include <sys/types.h> #endif #ifdef HAVE_NETINET_IN_H #ifdef WIN32 #undef EINTR #endif #include <netinet/in.h> #endif #ifdef HAVE_SYS_UN_H #include <sys/un.h> #endif #ifdef HAVE_NETINET_TCP_H #include <netinet/tcp.h> #endif #ifdef HAVE_ARPA_INET_H #include <arpa/inet.h> #endif #ifdef HAVE_UNISTD_H #include <unistd.h> #endif #ifndef HAVE_GETADDRINFO #ifndef WIN32 #ifdef __APPLE__ #ifdef __APPLE_CC__ #include <nameser.h> #endif #endif #ifndef __CYGWIN__ #include <resolv.h> #endif #endif #endif #ifdef HAVE_NETDB_H #include <netdb.h> #endif #include <errno.h> #include <fcntl.h> #ifdef HAVE_SYS_TIME_H #include <sys/time.h> #ifdef TIME_WITH_SYS_TIME #include <time.h> #endif #else #include <time.h> #endif #ifdef HAVE_POLL_H #include <poll.h> #endif #ifdef HAVE_SYS_PARAM_H #include <sys/param.h> #endif #ifdef HAVE_SYS_UCRED_H #include <sys/ucred.h> #endif #include "mysocket.h" #include "conf.h" #include "log.h" #include "mymalloc.h" #include "wait.h" /* TODO: Hack until we move mush_panic() somewhere more reasonable. */ void mush_panic(const char *); static int connect_nonb(int sockfd, const struct sockaddr *saptr, socklen_t salen, bool nonb); static const char * time_string(void) { static char buffer[100]; time_t now; struct tm *ltm; now = time(NULL); ltm = localtime(&now); strftime(buffer, 100, "[%Y-%m-%d %H:%M:%S]", ltm); return buffer; } bool is_blocking_err(int code) { #ifdef WIN32 return code == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK; #else if (code == EWOULDBLOCK) return 1; if (code == EINTR) return 1; #ifdef EAGAIN if (code == EAGAIN) return 1; #endif return 0; #endif } #ifndef SLAVE /** Given a sockaddr structure, try to look up and return hostname info. * If we can't get a hostname from DNS (or if we're not using DNS), * we settle for the IP address. * \param host pointer to a sockaddr structure. * \param len length of host structure. * \return static hostname_info structure with hostname and port. */ struct hostname_info * hostname_convert(struct sockaddr *host, int len) { static struct hostname_info hi; static char hostname[NI_MAXHOST]; static char port[NI_MAXSERV]; if (getnameinfo(host, len, hostname, sizeof hostname, port, sizeof port, (USE_DNS ? 0 : NI_NUMERICHOST) | NI_NUMERICSERV) != 0) { return NULL; } hi.hostname = hostname; hi.port = port; return &hi; } #endif /** Given a sockaddr structure, try to look up and return ip address info. * \param host pointer to a sockaddr structure. * \param len length of host structure. * \return static hostname_info structure with ip address and port. */ struct hostname_info * ip_convert(struct sockaddr *host, int len) { static struct hostname_info hi; static char hostname[NI_MAXHOST]; static char port[NI_MAXSERV]; if (getnameinfo(host, len, hostname, sizeof hostname, port, sizeof port, NI_NUMERICHOST | NI_NUMERICSERV) != 0) { return NULL; } hi.hostname = hostname; hi.port = port; return &hi; } /** Open a connection to a given host and port. Basically * tcp_connect from UNPv1 * \param host hostname or ip address to connect to, as a string. * \param socktype The type of socket - SOCK_STREAM or SOCK_DGRAM * \param myiterface pointer to sockaddr structure for specific interface. * \param myilen length of myiterface * \param port port to connect to. * \param nonb true to do a nonblocking connect in the background. * \return file descriptor for connected socket, or -1 for failure. */ int make_socket_conn(const char *host, int socktype, struct sockaddr *myiterface, socklen_t myilen, Port_t port, bool nonb) { struct addrinfo hints, *server, *save; char cport[NI_MAXSERV]; int s; int res; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; /* Try to use IPv6 if available */ hints.ai_socktype = socktype; snprintf(cport, sizeof cport, "%hu", port); if ((res = getaddrinfo(host, cport, &hints, &server)) != 0) { lock_file(stderr); fprintf(stderr, "%s In getaddrinfo: %s (Host %s Port %hu)\n", time_string(), gai_strerror(res), host, port); fflush(stderr); unlock_file(stderr); return -1; } if (!server) { lock_file(stderr); fprintf(stderr, "%s Couldn't get address for host %s port %hu\n", time_string(), host, port); fflush(stderr); unlock_file(stderr); return -1; } save = server; do { s = socket(server->ai_family, server->ai_socktype, server->ai_protocol); if (s < 0) continue; if (myiterface && myilen > 0 && myiterface->sa_family == server->ai_family) { /* Bind to a specific interface. Don't even try for the case of * an IPv4 socket and an IPv6 interface. Happens with ident, which * seems to work okay without the bind(). */ if (bind(s, myiterface, myilen) < 0) penn_perror("bind failed (Possibly harmless)"); } if (connect_nonb(s, server->ai_addr, server->ai_addrlen, nonb) == 0) break; #ifdef DEBUG penn_perror("connect failed (Probably harmless)"); #endif closesocket(s); } while ((server = server->ai_next) != NULL); freeaddrinfo(save); if (server == NULL) { lock_file(stderr); fprintf(stderr, "%s Couldn't connect to %s on port %hu\n", time_string(), host, port); fflush(stderr); unlock_file(stderr); return -1; } return s; } /** Start listening on a given port. Basically tcp_listen * from UNPv1 * \param port port to listen on. * \param socktype the type of socket - SOCK_STREAM or SOCK_DGRAM * \param addr pointer to sockaddr to copy address data to. * \param len length of addr. * \param host hostname or address to listen on, as a string. * \return file descriptor of listening socket, or -1 for failure. */ int make_socket(Port_t port, int socktype, union sockaddr_u *addr, socklen_t *len, const char *host) { int s, opt, ipv = 4; /* Use getaddrinfo() to fill in the sockaddr fields. This * effectively makes us IPv6 capable if the host is. Much of this is * lifted from listing 11.9 (tcp_listen()) in W. Richard Steven's * Unix Network Programming, vol 1. If getaddrinfo() isn't * present on the system, we'll use our own version, also from UNPv1. */ struct addrinfo *server, *save, hints; char portbuf[NI_MAXSERV], *cport; int res; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_flags = AI_PASSIVE; #ifdef FORCE_IPV4 hints.ai_family = AF_INET; /* OpenBSD apparently doesn't properly map IPv4 connections to IPv6 servers. */ #else hints.ai_family = AF_UNSPEC; /* Try to use IPv6 if available */ #endif hints.ai_socktype = socktype; if (port > 0) { snprintf(portbuf, sizeof portbuf, "%hu", port); cport = portbuf; } else cport = NULL; if (strlen(host) == 0) host = NULL; if ((res = getaddrinfo(host, cport, &hints, &server)) != 0) { lock_file(stderr); fprintf(stderr, "%s In getaddrinfo: %s (Host: %s Port %hu)\n", time_string(), gai_strerror(res), host, port); unlock_file(stderr); exit(3); } save = server; if (!server) { lock_file(stderr); fprintf(stderr, "%s Couldn't get address for host %s port %hu\n", time_string(), host, port); unlock_file(stderr); exit(3); } do { s = socket(server->ai_family, server->ai_socktype, server->ai_protocol); if (s < 0) continue; opt = 1; if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *) &opt, sizeof(opt)) < 0) { penn_perror("setsockopt (Possibly ignorable)"); } #ifdef IPV6_V6ONLY if (server->ai_family == AF_INET6 && host == NULL) { opt = 0; if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &opt, sizeof opt) < 0) { penn_perror("setsockopt (Possibly ignorable)"); } } #endif if (bind(s, server->ai_addr, server->ai_addrlen) == 0) break; /* Success */ #ifdef WIN32 if (WSAGetLastError() == WSAEADDRINUSE) { #else if (errno == EADDRINUSE) { #endif lock_file(stderr); fprintf(stderr, "%s Another process (Possibly another copy of this mush?) " "appears to be using port %hu. Aborting.\n", time_string(), port); unlock_file(stderr); exit(1); } penn_perror("binding stream socket (Possibly ignorable)"); closesocket(s); } while ((server = server->ai_next) != NULL); if (server == NULL) { lock_file(stderr); fprintf(stderr, "%s Couldn't bind to port %d\n", time_string(), port); unlock_file(stderr); exit(4); } ipv = (server->ai_family == AF_INET) ? 4 : 6; if (addr) { memcpy(addr->data, server->ai_addr, server->ai_addrlen); if (len) *len = server->ai_addrlen; } freeaddrinfo(save); lock_file(stderr); fprintf(stderr, "%s Listening on port %d using IPv%d.\n", time_string(), port, ipv); fflush(stderr); unlock_file(stderr); listen(s, 5); return s; } #ifndef WIN32 /** Create a unix-domain socket . * \param filename The name of the socket file. * \param socktype The type of socket. * \return a fd for the socket, or -1 on error. */ int make_unix_socket(const char *filename, int socktype) { int s; struct sockaddr_un addr; memset(&addr, 0, sizeof addr); addr.sun_family = AF_LOCAL; strncpy(addr.sun_path, filename, sizeof(addr.sun_path) - 1); unlink(filename); if ((s = socket(AF_LOCAL, socktype, 0)) < 0) { penn_perror("socket"); return -1; } if (bind(s, (const struct sockaddr *) &addr, sizeof addr) < 0) { penn_perror("bind"); close(s); return -1; } if (listen(s, 5) < 0) { penn_perror("listen"); close(s); return -1; } lock_file(stderr); fprintf(stderr, "%s Listening on socket file %s (fd %d)\n", time_string(), filename, s); unlock_file(stderr); return s; } /** Connect to a unix-domain socket * \param filename The name of the socket file. * \param socktype the type of socket * \return a fd for the socket or -1 on error. */ int connect_unix_socket(const char *filename, int socktype) { int s; struct sockaddr_un addr; memset(&addr, 0, sizeof addr); addr.sun_family = AF_LOCAL; strncpy(addr.sun_path, filename, sizeof(addr.sun_path) - 1); if ((s = socket(AF_LOCAL, socktype, 0)) < 0) { penn_perror("socket"); return -1; } if (connect_nonb(s, (const struct sockaddr *) &addr, sizeof addr, 1) == 0) { return s; } else { int savederrno = errno; close(s); errno = savederrno; return -1; } } #endif /* Send data to a unix socket, including sending credentials (uid, * pid, etc.) if they must be explicently sent. Used by ssl_slave. * You can't lie about credentials unless you're root, so we don't * even take them as parameters. * * \param s the socket descriptor * \param buf the buffer to write * \param len size of the buffer * \return number of bytes written or -1 on failure. */ ssize_t send_with_creds(int s, void *buf, size_t len) { ssize_t slen; /* Linux and OS X can get credentials on the receiving end via a getsockopt() call. Use it instead of sendmsg() because it's a lot simpler. */ #if 0 /* Sample sendmsg() credential passing using linux structs. */ { struct msghdr msg; struct cmsghdr *cmsg; struct ucred *creds; uint8_t credbuf[CMSG_SPACE(sizeof *creds)] = { 0 }; struct iovec iov; int sockopt = 1; memset(&msg, 0, sizeof msg); iov.iov_base = buf; iov.iov_len = len; msg.msg_iov = &iov; msg.msg_iovlen = 1; msg.msg_control = credbuf; msg.msg_controllen = sizeof credbuf; cmsg = CMSG_FIRSTHDR(&msg); cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_type = SCM_CREDENTIALS; cmsg->cmsg_len = CMSG_LEN(sizeof *creds); creds = (struct ucred *) CMSG_DATA(cmsg); creds->pid = getpid(); creds->uid = geteuid(); creds->gid = getegid(); if (setsockopt(s, SOL_SOCKET, SO_PASSCRED, &sockopt, sizeof sockopt) < 0) penn_perror("setsockopt SO_PASSCRED"); slen = sendmsg(s, &msg, 0); } #else slen = send(s, buf, len, 0); #endif return slen; } #if defined(__CYGWIN__) || defined(WIN32) /* There is probably a better way to actually fix (instead of ignore) the * lack of MSG_DONTWAIT on cygwin, but since I doubt anyone is actually * using the SSL_SLAVE code on cygwin, I'm not bothering. Can be looked into * if this assumption is proved wrong. */ #ifndef MSG_DONTWAIT #define MSG_DONTWAIT 0 #endif #endif /* Read from a unix socket, getting unix credentials from the other end. Use for * authentication when acceping local connections from ssl_slave or the like. * \param s the socket descriptor * \param buf The buffer to read into * \param len the length of the buffer * \param remote_pid Non-null pointer that returns the remote side's pid or -1 * if unable to read credentials. * \param remote_uid Non-null pointer that returns the remote side's uid or -1 * if unable to read credentials. * \return the number of bytes read, or -1 on read failure */ ssize_t recv_with_creds(int s, void *buf, size_t len, int *remote_pid, int *remote_uid) { /* Only implemented on linux and OS X so far because different OSes support slightly different fields and ways of doing this. Argh. We'll prefer getsockopt() approaches over recvmsg() when supported. */ *remote_pid = -1; *remote_uid = -1; #if defined(linux) { struct ucred creds; socklen_t credlen = sizeof creds; if (getsockopt(s, SOL_SOCKET, SO_PEERCRED, &creds, &credlen) < 0) { penn_perror("getsockopt SO_PEERCRED"); } else { *remote_pid = creds.pid; *remote_uid = creds.uid; } } #elif defined(__NetBSD__) { struct unpcbid creds; socklen_t credlen = sizeof creds; if (getsockopt(s, 0, LOCAL_PEEREID, &creds, &credlen) < 0) { penn_perror("getsockopt LOCAL_PEEREID"); } else { *remote_pid = creds.unp_pid; *remote_uid = creds.unp_euid; } } #elif defined(__OpenBSD__) { struct sockpeercred creds; socklen_t credlen = sizeof creds; if (getsockopt(s, SOL_SOCKET, SO_PEERCRED, &creds, &credlen) < 0) { penn_perror("getsockopt SO_PEERCRED"); } else { *remote_pid = creds.pid; *remote_uid = creds.uid; } } #elif defined(HAVE_STRUCT_XUCRED) { /* FreeBSD and OS X */ struct xucred creds; socklen_t credlen = sizeof creds; if (getsockopt(s, 0, LOCAL_PEERCRED, &creds, &credlen) < 0) { penn_perror("getsockopt LOCAL_PEERCRED"); } else { /* OS X doesn't pass the pid of the process on the other end of the socket. */ *remote_uid = creds.cr_uid; } } #endif return recv(s, buf, len, MSG_DONTWAIT); } /** Make a socket do nonblocking i/o. * \param s file descriptor of socket. */ void make_nonblocking(int s) { #ifdef WIN32 unsigned long arg = 1; if (ioctlsocket(s, FIONBIO, &arg) == -1) { penn_perror("make_nonblocking: ioctlsocket"); #ifndef SLAVE mush_panic("Fatal network error!"); #else exit(1); #endif } #else int flags; if ((flags = fcntl(s, F_GETFL, 0)) == -1) { penn_perror("make_nonblocking: fcntl"); #ifndef SLAVE mush_panic("Fatal network error!"); #else exit(1); #endif } flags |= O_NONBLOCK; if (fcntl(s, F_SETFL, flags) == -1) { penn_perror("make_nonblocking: fcntl"); #ifndef SLAVE mush_panic("Fatal network error!"); #else exit(1); #endif } #endif } /** Make a socket do blocking i/o. * \param s file descriptor of socket. */ void make_blocking(int s) { #ifdef WIN32 unsigned long arg = 0; if (ioctlsocket(s, FIONBIO, &arg) == -1) { penn_perror("make_blocking: ioctlsocket"); #ifndef SLAVE mush_panic("Fatal network error"); #else exit(1); #endif } #else int flags; if ((flags = fcntl(s, F_GETFL, 0)) == -1) { penn_perror("make_blocking: fcntl"); #ifndef SLAVE mush_panic("Fatal network error!"); #else exit(1); #endif } flags &= ~O_NDELAY; if (fcntl(s, F_SETFL, flags) == -1) { penn_perror("make_nonblocking: fcntl"); #ifndef SLAVE mush_panic("Fatal network error!"); #else exit(1); #endif } #endif } /** Enable TCP keepalive on the given socket if we can. * \param s socket. * \param keepidle how often to send keepalive */ /* ARGSUSED */ void set_keepalive(int s __attribute__((__unused__)), int keepidle __attribute__((__unused__))) { #ifdef SO_KEEPALIVE int keepalive = 1; /* enable TCP keepalive */ if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (void *) &keepalive, sizeof(keepalive)) == -1) { lock_file(stderr); fprintf(stderr, "%s [%d] could not set SO_KEEPALIVE: %s\n", time_string(), s, strerror(errno)); unlock_file(stderr); } /* And set the ping time to something reasonable instead of the default 2 hours. Linux and possibly others use TCP_KEEPIDLE to do this. OS X and possibly others use TCP_KEEPALIVE. */ #if defined(TCP_KEEPIDLE) if (setsockopt(s, IPPROTO_TCP, TCP_KEEPIDLE, (void *) &keepidle, sizeof(keepidle)) == -1) { lock_file(stderr); fprintf(stderr, "%s [%d] could not set TCP_KEEPIDLE: %s\n", time_string(), s, strerror(errno)); unlock_file(stderr); } #elif defined(TCP_KEEPALIVE) if (setsockopt(s, IPPROTO_TCP, TCP_KEEPALIVE, (void *) &keepidle, sizeof(keepidle)) == -1) { lock_file(stderr); fprintf(stderr, "%s [%d] could not set TCP_KEEPALIVE: %s\n", time_string(), s, strerror(errno)); unlock_file(stderr); } #endif #endif return; } /** Set the CLOEXEC bit on a descriptor * * \param fd the file descriptor to set */ void set_close_exec(int fd) { #ifdef HAVE_FCNTL int flags = fcntl(fd, F_GETFD); if (flags < 0) { return; } flags |= FD_CLOEXEC; fcntl(fd, F_SETFD, flags); #endif } /** Connect a socket, possibly making it nonblocking first. * From UNP, with changes. If nsec > 0, we set the socket * nonblocking and connect with timeout. The socket is STILL * nonblocking after it returns. If nsec == 0, a normal blocking * connect is done. * \param sockfd file descriptor of socket. * \param saptr pointer to sockaddr structure with connection data. * \param salen length of saptr. * \param nonb true for a nonblocking connect in the background * \retval 0 success. * \retval -1 failure. */ int connect_nonb(int sockfd, const struct sockaddr *saptr, socklen_t salen, bool nonb) { int n; if (nonb) make_nonblocking(sockfd); if ((n = connect(sockfd, (const struct sockaddr *) saptr, salen)) < 0) #ifdef WIN32 if (n == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK) #else if (errno != EINPROGRESS) #endif return -1; return 0; }
c49f5c5e05e6250e6942d03253a8fd97a5b94ebc
376e1818d427b5e4d32fa6dd6c7b71e9fd88afdb
/www/clearsilver/patches/patch-python_neo__cgi.c
b2617adb7f3786327c40d52ca70c4e58a3902b90
[]
no_license
NetBSD/pkgsrc
a0732c023519650ef821ab89c23ab6ab59e25bdb
d042034ec4896cc5b47ed6f2e5b8802d9bc5c556
refs/heads/trunk
2023-09-01T07:40:12.138283
2023-09-01T05:25:19
2023-09-01T05:25:19
88,439,572
321
138
null
2023-07-12T22:34:14
2017-04-16T20:04:15
null
UTF-8
C
false
false
474
c
patch-python_neo__cgi.c
$NetBSD: patch-python_neo__cgi.c,v 1.1 2011/12/01 20:50:49 gls Exp $ Fix for 2011-4357 Taken from: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=649322 --- python/neo_cgi.c.orig 2007-07-12 03:07:43.000000000 +0000 +++ python/neo_cgi.c @@ -178,7 +178,7 @@ static PyObject * p_cgi_error (PyObject if (!PyArg_ParseTuple(args, "s:error(str)", &s)) return NULL; - cgi_error (cgi, s); + cgi_error (cgi, "%s", s); rv = Py_None; Py_INCREF(rv); return rv;
f92209aa1ee35b85bd2f843a6b4861841fd3f387
9984cf39a4ca67c35f3fbdb6ce96c1d5630663e2
/3rdparty/memcached/vbucket.h
c6c4d8ca95d0117e33ec9d198f335de83b59a79a
[ "BSD-3-Clause" ]
permissive
Qihoo360/evpp
89e7f24793a65e183edee6965fc71e3930073585
477033f938fd47dfecde43c82257cd286d9fa38e
refs/heads/master
2023-08-25T04:46:21.628781
2022-11-06T10:33:10
2022-11-06T10:33:10
83,792,790
3,665
1,074
BSD-3-Clause
2023-08-02T07:15:36
2017-03-03T11:46:03
C++
UTF-8
C
false
false
700
h
vbucket.h
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ #ifndef MEMCACHED_VBUCKET_H #define MEMCACHED_VBUCKET_H 1 #ifdef __cplusplus extern "C" { #endif typedef enum { vbucket_state_active = 1, /**< Actively servicing a vbucket. */ vbucket_state_replica, /**< Servicing a vbucket as a replica only. */ vbucket_state_pending, /**< Pending active. */ vbucket_state_dead /**< Not in use, pending deletion. */ } vbucket_state_t; #define is_valid_vbucket_state_t(state) \ (state == vbucket_state_active || \ state == vbucket_state_replica || \ state == vbucket_state_pending || \ state == vbucket_state_dead) #ifdef __cplusplus } #endif #endif
e35e21134524fc31ca05556e41508b46e3adef60
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
/tests/usr.bin/xlint/lint1/msg_000_c90.c
fa01699d043eb4a9033b3f5def2ba5eba6a8bc57
[]
no_license
NetBSD/src
1a9cbc22ed778be638b37869ed4fb5c8dd616166
23ee83f7c0aea0777bd89d8ebd7f0cde9880d13c
refs/heads/trunk
2023-08-31T13:24:58.105962
2023-08-27T15:50:47
2023-08-27T15:50:47
88,439,547
656
348
null
2023-07-20T20:07:24
2017-04-16T20:03:43
null
UTF-8
C
false
false
292
c
msg_000_c90.c
/* $NetBSD: msg_000_c90.c,v 1.1 2021/07/08 05:18:49 rillig Exp $ */ # 3 "msg_000_c90.c" /* * Test for message: empty declaration [0] * * In strict C90 mode, an empty declaration is an error, not merely a warning. */ /* lint1-flags: -s */ /* expect+1: error: empty declaration [0] */ ;
e3488c109a44aa80a19c82aa877cc9db757c70a2
cfb9808611fc50f09dca006e25ef32f988cc146c
/ext/posix/fcntl.c
e8f9520c24a95252e873a22ad798e2be473b575d
[ "MIT", "LicenseRef-scancode-warranty-disclaimer" ]
permissive
luaposix/luaposix
6d719704b458ad3291c41eed17572da4a0470dc7
f12f957224d12257c882f43fde5cc442bdf44002
refs/heads/master
2023-08-30T23:31:03.556885
2023-08-25T05:16:21
2023-08-28T17:40:39
1,523,340
421
108
MIT
2023-08-28T17:40:40
2011-03-24T23:02:16
C
UTF-8
C
false
false
8,910
c
fcntl.c
/* * POSIX library for Lua 5.1, 5.2, 5.3 & 5.4. * Copyright (C) 2013-2023 Gary V. Vaughan * Copyright (C) 2010-2013 Reuben Thomas <rrt@sc3d.org> * Copyright (C) 2008-2010 Natanael Copa <natanael.copa@gmail.com> * Clean up and bug fixes by Leo Razoumov <slonik.az@gmail.com> 2006-10-11 * Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> 07 Apr 2006 23:17:49 * Based on original by Claudio Terra for Lua 3.x. * With contributions by Roberto Ierusalimschy. * With documentation from Steve Donovan 2012 */ /*** File Control. Low-level control over file descriptors, including creating new file descriptors with `open`. @module posix.fcntl */ #include "_helpers.c" #include <fcntl.h> /* Darwin fails to define O_RSYNC. */ #ifndef O_RSYNC #define O_RSYNC 0 #endif /* FreeBSD 10 fails to define O_DSYNC. */ #ifndef O_DSYNC #define O_DSYNC 0 #endif /* POSIX.2001 uses FD_CLOEXEC instead. */ #ifndef O_CLOEXEC #define O_CLOEXEC 0 #endif /*** Advisory file locks. Passed as *arg* to @{fcntl} when *cmd* is `F_GETLK`, `F_SETLK` or `F_SETLKW`. @table flock @int l_start starting offset @int l_len len = 0 means until end of file @int l_pid lock owner @int l_type lock type @int l_whence one of `SEEK_SET`, `SEEK_CUR` or `SEEK_END` */ /*** Manipulate file descriptor. @function fcntl @int fd file descriptor to act on @int cmd operation to perform @tparam[opt=0] int|flock arg when *cmd* is `F_GETLK`, `F_SETLK` or `F_SETLKW`, then *arg* is a @{flock} table, otherwise an integer with meaning dependent upon the value of *cmd*. @return[1] integer return value depending on *cmd*, if successful @return[2] nil @treturn[2] string error message @treturn[2] int errnum @see fcntl(2) @see lock.lua @usage local flag = posix.fcntl (fd, posix.F_GETFL) */ static int Pfcntl(lua_State *L) { int fd = checkint(L, 1); int cmd = checkint(L, 2); int arg; struct flock lockinfo; int r; checknargs(L, 3); switch (cmd) { case F_SETLK: case F_SETLKW: case F_GETLK: luaL_checktype(L, 3, LUA_TTABLE); /* Copy fields to flock struct */ lua_getfield(L, 3, "l_type"); lockinfo.l_type = (short)lua_tointeger(L, -1); lua_getfield(L, 3, "l_whence"); lockinfo.l_whence = (short)lua_tointeger(L, -1); lua_getfield(L, 3, "l_start"); lockinfo.l_start = (off_t)lua_tointeger(L, -1); lua_getfield(L, 3, "l_len"); lockinfo.l_len = (off_t)lua_tointeger(L, -1); /* Lock */ r = fcntl(fd, cmd, &lockinfo); /* Copy fields from flock struct */ lua_pushinteger(L, lockinfo.l_type); lua_setfield(L, 3, "l_type"); lua_pushinteger(L, lockinfo.l_whence); lua_setfield(L, 3, "l_whence"); lua_pushinteger(L, lockinfo.l_start); lua_setfield(L, 3, "l_start"); lua_pushinteger(L, lockinfo.l_len); lua_setfield(L, 3, "l_len"); lua_pushinteger(L, lockinfo.l_pid); lua_setfield(L, 3, "l_pid"); break; default: arg = optint(L, 3, 0); r = fcntl(fd, cmd, arg); break; } return pushresult(L, r, "fcntl"); } /*** Open a file. @function open @string path @int oflags bitwise OR of zero or more of `O_RDONLY`, `O_WRONLY`, `O_RDWR`, `O_APPEND`, `O_CREAT`, `O_DSYNC`, `O_EXCL`, `O_NOCTTY`, `O_NONBLOCK`, `O_RSYNC`, `O_SYNC` and `O_TRUNC` (and `O_CLOEXEC`, where supported) @int[opt=511] mode access modes used by `O_CREAT` @treturn[1] int file descriptor for *path*, if successful @return[2] nil @treturn[2] string error message @treturn[2] int errnum @see open(2) @usage local P = require "posix.fcntl" fd = P.open ("data", bit.bor (P.O_CREAT, P.O_RDWR), bit.bor (P.S_IRWXU, P.S_IRGRP)) */ static int Popen(lua_State *L) { const char *path = luaL_checkstring(L, 1); int oflags = checkint(L, 2); checknargs(L, 3); return pushresult(L, open(path, oflags, (mode_t)optinteger(L, 3, 511)), path); } #if HAVE_POSIX_FADVISE /*** Instruct kernel on appropriate cache behaviour for a file or file segment. @function posix_fadvise @int fd open file descriptor @int offset start of region @int len number of bytes in region @int advice one of `POSIX_FADV_NORMAL`, `POSIX_FADV_SEQUENTIAL`, `POSIX_FADV_RANDOM`, `POSIX_FADV_NOREUSE`, `POSIX_FADV_WILLNEED` or `POSIX_FADV_DONTNEED` @treturn[1] int `0`, if successful @return[2] nil @treturn[2] string error message @treturn[2] int errnum @see posix_fadvise(2) */ static int Pposix_fadvise(lua_State *L) { int fd = checkint(L, 1); off_t offset = (off_t)checkinteger(L, 2); off_t len = (off_t)checkinteger(L, 3); int advice = checkint(L, 4); int r; checknargs(L, 4); r = posix_fadvise(fd, offset, len, advice); return pushresult(L, r == 0 ? 0 : -1, "posix_fadvise"); } #endif static const luaL_Reg posix_fcntl_fns[] = { LPOSIX_FUNC( Pfcntl ), LPOSIX_FUNC( Popen ), #if HAVE_POSIX_FADVISE LPOSIX_FUNC( Pposix_fadvise ), #endif {NULL, NULL} }; /*** Constants. @section constants */ /*** Fcntl constants. Any constants not available in the underlying system will be `0` valued, if they are usually bitwise ORed with other values, otherwise `nil`. @table posix.fcntl @int AT_EACCESS test access permitted for effective IDs, not real IDs @int AT_FDCWD indicate *at functions to use current directory @int AT_REMOVEDIR remove directory instead of unlinking file @int AT_SYMLINK_FOLLOW follow symbolic links @int AT_SYMLINK_NOFOLLOW do not follow symbolic links @int FD_CLOEXEC close file descriptor on exec flag @int F_DUPFD duplicate file descriptor @int F_GETFD get file descriptor flags @int F_SETFD set file descriptor flags @int F_GETFL get file status flags @int F_SETFL set file status flags @int F_GETLK get record locking information @int F_SETLK set record locking information @int F_SETLKW set lock, and wait if blocked @int F_GETOWN get SIGIO/SIGURG process owner @int F_SETOWN set SIGIO/SIGURG process owner @int F_RDLCK shared or read lock @int F_WRLCK exclusive or write lock @int F_UNLCK unlock @int O_RDONLY open for reading only @int O_WRONLY open for writing only @int O_RDWR open for reading and writing @int O_APPEND set append mode @int O_CLOEXEC set FD_CLOEXEC atomically @int O_CREAT create if nonexistent @int O_DSYNC synchronise io data integrity @int O_EXCL error if file already exists @int O_NOCTTY don't assign controlling terminal @int O_NONBLOCK no delay @int O_RSYNC synchronise file read integrity @int O_SYNC synchronise file write integrity @int O_TRUNC truncate to zero length @int POSIX_FADV_NORMAL no advice @int POSIX_FADV_SEQUENTIAL expecting to access data sequentially @int POSIX_FADV_RANDOM expecting to access data randomly @int POSIX_FADV_NOREUSE expecting to access data once only @int POSIX_FADV_WILLNEED expecting to access data in the near future @int POSIX_FADV_DONTNEED not expecting to access the data in the near future @usage -- Print fcntl constants supported on this host. for name, value in pairs (require "posix.fcntl") do if type (value) == "number" then print (name, value) end end */ LUALIB_API int luaopen_posix_fcntl(lua_State *L) { luaL_newlib(L, posix_fcntl_fns); lua_pushstring(L, LPOSIX_VERSION_STRING("fcntl")); lua_setfield(L, -2, "version"); /* posix *at flags */ #ifdef AT_EACCESS LPOSIX_CONST( AT_EACCESS ); #endif #ifdef AT_FDCWD LPOSIX_CONST( AT_FDCWD ); #endif #ifdef AT_REMOVEDIR LPOSIX_CONST( AT_REMOVEDIR ); #endif #ifdef AT_SYMLINK_FOLLOW LPOSIX_CONST( AT_SYMLINK_FOLLOW ); #endif #ifdef AT_SYMLINK_NOFOLLOW LPOSIX_CONST( AT_SYMLINK_NOFOLLOW ); #endif /* Linux-specific *at flags */ #ifdef AT_EMPTY_PATH LPOSIX_CONST( AT_EMPTY_PATH ); #endif #ifdef AT_NO_AUTOMOUNT LPOSIX_CONST( AT_NO_AUTOMOUNT ); #endif /* fcntl flags */ LPOSIX_CONST( FD_CLOEXEC ); LPOSIX_CONST( F_DUPFD ); LPOSIX_CONST( F_GETFD ); LPOSIX_CONST( F_SETFD ); LPOSIX_CONST( F_GETFL ); LPOSIX_CONST( F_SETFL ); LPOSIX_CONST( F_GETLK ); LPOSIX_CONST( F_SETLK ); LPOSIX_CONST( F_SETLKW ); LPOSIX_CONST( F_GETOWN ); LPOSIX_CONST( F_SETOWN ); LPOSIX_CONST( F_RDLCK ); LPOSIX_CONST( F_WRLCK ); LPOSIX_CONST( F_UNLCK ); /* file creation & status flags */ LPOSIX_CONST( O_RDONLY ); LPOSIX_CONST( O_WRONLY ); LPOSIX_CONST( O_RDWR ); LPOSIX_CONST( O_APPEND ); LPOSIX_CONST( O_CREAT ); LPOSIX_CONST( O_DSYNC ); LPOSIX_CONST( O_EXCL ); LPOSIX_CONST( O_NOCTTY ); LPOSIX_CONST( O_NONBLOCK ); LPOSIX_CONST( O_RSYNC ); LPOSIX_CONST( O_SYNC ); LPOSIX_CONST( O_TRUNC ); LPOSIX_CONST( O_CLOEXEC ); /* Linux 3.11 and above */ #ifdef O_TMPFILE LPOSIX_CONST( O_TMPFILE ); #endif /* posix_fadvise flags */ #ifdef POSIX_FADV_NORMAL LPOSIX_CONST( POSIX_FADV_NORMAL ); #endif #ifdef POSIX_FADV_SEQUENTIAL LPOSIX_CONST( POSIX_FADV_SEQUENTIAL ); #endif #ifdef POSIX_FADV_RANDOM LPOSIX_CONST( POSIX_FADV_RANDOM ); #endif #ifdef POSIX_FADV_NOREUSE LPOSIX_CONST( POSIX_FADV_NOREUSE ); #endif #ifdef POSIX_FADV_WILLNEED LPOSIX_CONST( POSIX_FADV_WILLNEED ); #endif #ifdef POSIX_FADV_DONTNEED LPOSIX_CONST( POSIX_FADV_DONTNEED ); #endif return 1; }
35d06158c8dc6d9bb88eba4b87b1db771179285e
5f0088a88d2a19da1905123507ea66f2e4f7d1ae
/src/khash/c_src/hash.h
0c75ed00f46b679e620692176da2277fa9578c42
[ "Kazlib", "MIT", "LicenseRef-scancode-unknown", "ErlPL-1.1", "WTFPL", "LicenseRef-scancode-public-domain-disclaimer", "OFL-1.1", "BSD-3-Clause", "ISC", "Apache-2.0", "BSD-2-Clause", "LicenseRef-scancode-public-domain" ]
permissive
apache/couchdb
994a26ba1f888c228c545f98264b384cda9d28dc
e60e27554708f46a9e6528fa6049d025c1aba859
refs/heads/main
2023-08-24T02:55:27.557609
2023-08-15T22:49:01
2023-08-15T22:49:01
206,417
5,048
844
Apache-2.0
2023-09-14T20:17:05
2009-05-21T02:03:38
Erlang
UTF-8
C
false
false
9,330
h
hash.h
/* * Hash Table Data Type * Copyright (C) 1997 Kaz Kylheku <kaz@ashi.footprints.net> * * Free Software License: * * All rights are reserved by the author, with the following exceptions: * Permission is granted to freely reproduce and distribute this software, * possibly in exchange for a fee, provided that this copyright notice appears * intact. Permission is also granted to adapt this software to produce * derivative works, as long as the modified versions carry this copyright * notice and additional notices stating that the work has been modified. * This source code may be translated into executable form and incorporated * into proprietary software; there is no requirement for such software to * contain a copyright notice related to this source. * * $Id: hash.h,v 1.22.2.7 2000/11/13 01:36:45 kaz Exp $ * $Name: kazlib_1_20 $ */ #ifndef HASH_H #define HASH_H #include <limits.h> #ifdef KAZLIB_SIDEEFFECT_DEBUG #include "sfx.h" #endif /* * Blurb for inclusion into C++ translation units */ #ifdef __cplusplus extern "C" { #endif typedef unsigned long hashcount_t; #define HASHCOUNT_T_MAX ULONG_MAX typedef unsigned long hash_val_t; #define HASH_VAL_T_MAX ULONG_MAX extern int hash_val_t_bit; #ifndef HASH_VAL_T_BIT #define HASH_VAL_T_BIT ((int) hash_val_t_bit) #endif /* * Hash chain node structure. * Notes: * 1. This preprocessing directive is for debugging purposes. The effect is * that if the preprocessor symbol KAZLIB_OPAQUE_DEBUG is defined prior to the * inclusion of this header, then the structure shall be declared as having * the single member int __OPAQUE__. This way, any attempts by the * client code to violate the principles of information hiding (by accessing * the structure directly) can be diagnosed at translation time. However, * note the resulting compiled unit is not suitable for linking. * 2. This is a pointer to the next node in the chain. In the last node of a * chain, this pointer is null. * 3. The key is a pointer to some user supplied data that contains a unique * identifier for each hash node in a given table. The interpretation of * the data is up to the user. When creating or initializing a hash table, * the user must supply a pointer to a function for comparing two keys, * and a pointer to a function for hashing a key into a numeric value. * 4. The value is a user-supplied pointer to void which may refer to * any data object. It is not interpreted in any way by the hashing * module. * 5. The hashed key is stored in each node so that we don't have to rehash * each key when the table must grow or shrink. */ typedef struct hnode_t { #if defined(HASH_IMPLEMENTATION) || !defined(KAZLIB_OPAQUE_DEBUG) /* 1 */ struct hnode_t *hash_next; /* 2 */ const void *hash_key; /* 3 */ void *hash_data; /* 4 */ hash_val_t hash_hkey; /* 5 */ #else int hash_dummy; #endif } hnode_t; /* * The comparison function pointer type. A comparison function takes two keys * and produces a value of -1 if the left key is less than the right key, a * value of 0 if the keys are equal, and a value of 1 if the left key is * greater than the right key. */ typedef int (*hash_comp_t)(const void *, const void *); /* * The hashing function performs some computation on a key and produces an * integral value of type hash_val_t based on that key. For best results, the * function should have a good randomness properties in *all* significant bits * over the set of keys that are being inserted into a given hash table. In * particular, the most significant bits of hash_val_t are most significant to * the hash module. Only as the hash table expands are less significant bits * examined. Thus a function that has good distribution in its upper bits but * not lower is preferrable to one that has poor distribution in the upper bits * but not the lower ones. */ typedef hash_val_t (*hash_fun_t)(const void *); /* * allocator functions */ typedef hnode_t *(*hnode_alloc_t)(void *); typedef void (*hnode_free_t)(hnode_t *, void *); /* * This is the hash table control structure. It keeps track of information * about a hash table, as well as the hash table itself. * Notes: * 1. Pointer to the hash table proper. The table is an array of pointers to * hash nodes (of type hnode_t). If the table is empty, every element of * this table is a null pointer. A non-null entry points to the first * element of a chain of nodes. * 2. This member keeps track of the size of the hash table---that is, the * number of chain pointers. * 3. The count member maintains the number of elements that are presently * in the hash table. * 4. The maximum count is the greatest number of nodes that can populate this * table. If the table contains this many nodes, no more can be inserted, * and the hash_isfull() function returns true. * 5. The high mark is a population threshold, measured as a number of nodes, * which, if exceeded, will trigger a table expansion. Only dynamic hash * tables are subject to this expansion. * 6. The low mark is a minimum population threshold, measured as a number of * nodes. If the table population drops below this value, a table shrinkage * will occur. Only dynamic tables are subject to this reduction. No table * will shrink beneath a certain absolute minimum number of nodes. * 7. This is the a pointer to the hash table's comparison function. The * function is set once at initialization or creation time. * 8. Pointer to the table's hashing function, set once at creation or * initialization time. * 9. The current hash table mask. If the size of the hash table is 2^N, * this value has its low N bits set to 1, and the others clear. It is used * to select bits from the result of the hashing function to compute an * index into the table. * 10. A flag which indicates whether the table is to be dynamically resized. It * is set to 1 in dynamically allocated tables, 0 in tables that are * statically allocated. */ typedef struct hash_t { #if defined(HASH_IMPLEMENTATION) || !defined(KAZLIB_OPAQUE_DEBUG) struct hnode_t **hash_table; /* 1 */ hashcount_t hash_nchains; /* 2 */ hashcount_t hash_nodecount; /* 3 */ hashcount_t hash_maxcount; /* 4 */ hashcount_t hash_highmark; /* 5 */ hashcount_t hash_lowmark; /* 6 */ hash_comp_t hash_compare; /* 7 */ hash_fun_t hash_function; /* 8 */ hnode_alloc_t hash_allocnode; hnode_free_t hash_freenode; void *hash_context; hash_val_t hash_mask; /* 9 */ int hash_dynamic; /* 10 */ #else int hash_dummy; #endif } hash_t; /* * Hash scanner structure, used for traversals of the data structure. * Notes: * 1. Pointer to the hash table that is being traversed. * 2. Reference to the current chain in the table being traversed (the chain * that contains the next node that shall be retrieved). * 3. Pointer to the node that will be retrieved by the subsequent call to * hash_scan_next(). */ typedef struct hscan_t { #if defined(HASH_IMPLEMENTATION) || !defined(KAZLIB_OPAQUE_DEBUG) hash_t *hash_table; /* 1 */ hash_val_t hash_chain; /* 2 */ hnode_t *hash_next; /* 3 */ #else int hash_dummy; #endif } hscan_t; extern hash_t *kl_hash_create(hashcount_t, hash_comp_t, hash_fun_t); extern void kl_hash_set_allocator(hash_t *, hnode_alloc_t, hnode_free_t, void *); extern void kl_hash_destroy(hash_t *); extern void kl_hash_free_nodes(hash_t *); extern void kl_hash_free(hash_t *); extern hash_t *kl_hash_init(hash_t *, hashcount_t, hash_comp_t, hash_fun_t, hnode_t **, hashcount_t); extern void kl_hash_insert(hash_t *, hnode_t *, const void *); extern hnode_t *kl_hash_lookup(hash_t *, const void *); extern hnode_t *kl_hash_delete(hash_t *, hnode_t *); extern int kl_hash_alloc_insert(hash_t *, const void *, void *); extern void kl_hash_delete_free(hash_t *, hnode_t *); extern void kl_hnode_put(hnode_t *, void *); extern void *kl_hnode_get(hnode_t *); extern const void *kl_hnode_getkey(hnode_t *); extern hashcount_t kl_hash_count(hash_t *); extern hashcount_t kl_hash_size(hash_t *); extern int kl_hash_isfull(hash_t *); extern int kl_hash_isempty(hash_t *); extern void kl_hash_scan_begin(hscan_t *, hash_t *); extern hnode_t *kl_hash_scan_next(hscan_t *); extern hnode_t *kl_hash_scan_delete(hash_t *, hnode_t *); extern void kl_hash_scan_delfree(hash_t *, hnode_t *); extern int kl_hash_verify(hash_t *); extern hnode_t *kl_hnode_create(void *); extern hnode_t *kl_hnode_init(hnode_t *, void *); extern void kl_hnode_destroy(hnode_t *); #if defined(HASH_IMPLEMENTATION) || !defined(KAZLIB_OPAQUE_DEBUG) #ifdef KAZLIB_SIDEEFFECT_DEBUG #define kl_hash_isfull(H) (SFX_CHECK(H)->hash_nodecount == (H)->hash_maxcount) #else #define kl_hash_isfull(H) ((H)->hash_nodecount == (H)->hash_maxcount) #endif #define kl_hash_isempty(H) ((H)->hash_nodecount == 0) #define kl_hash_count(H) ((H)->hash_nodecount) #define kl_hash_size(H) ((H)->hash_nchains) #define kl_hnode_get(N) ((N)->hash_data) #define kl_hnode_getkey(N) ((N)->hash_key) #define kl_hnode_put(N, V) ((N)->hash_data = (V)) #endif #ifdef __cplusplus } #endif #endif
8cc5323dbafbed9ff52c59004d674d091c71c98d
a935ec8dab61675b6a3e348511fb9f8c5d490026
/src/mir/_pitch_stft.h
0a9ed29a6987eb9ac4fe671530c1a1f7ae92cb8c
[ "MIT" ]
permissive
libAudioFlux/audioFlux
d604c54941c17d90e1ef42f04ba353ef6e244926
3ae59434e2c1cacb6da43562677ed4899d7047c7
refs/heads/master
2023-04-28T05:17:22.649299
2023-04-25T09:45:59
2023-04-25T09:45:59
589,514,195
1,701
85
MIT
2023-04-25T09:00:05
2023-01-16T09:53:04
C
UTF-8
C
false
false
916
h
_pitch_stft.h
#ifndef _PITCH_STFT_H #define _PITCH_STFT_H #ifdef __cplusplus extern "C" { #endif #include <stdio.h> #include <stdlib.h> #include "../flux_base.h" typedef struct OpaquePitchSTFT *PitchSTFTObj; /*** samplate 32000 radix2Exp 12 WindowType hamm slideLength (1<<radix2Exp)/4 isContinue 0 ****/ int pitchSTFTObj_new(PitchSTFTObj *pitchSTFTObj, int *samplate,float *lowFre,float *highFre, int *radix2Exp,int *slideLength,WindowType *windowType, int *isContinue); int pitchSTFTObj_calTimeLength(PitchSTFTObj pitchSTFTObj,int dataLength); void pitchSTFTObj_pitch(PitchSTFTObj pitchSTFTObj,float *dataArr,int dataLength, float *freArr,float *dbArr); int pitchSTFTObj_getCorrData(PitchSTFTObj pitchSTFTObj,float **mCorr,int **lenArr); void pitchSTFTObj_enableDebug(PitchSTFTObj pitchSTFTObj,int isDebug); void pitchSTFTObj_free(PitchSTFTObj pitchSTFTObj); #ifdef __cplusplus } #endif #endif
d818f13ee115082fd922f0b947d72e7d7fc072ff
a474d7e6c0dd5f8f3a0919db050ebf773780865f
/lib/bsp/include/syscalls.h
7ff73bc127d548c5427933c0e6d6879ae2fdfe88
[ "Apache-2.0" ]
permissive
kendryte/kendryte-standalone-sdk
7b8b1887eab040da76b4ad9063d11b8ca5e5e5b9
02576ba67e8797444f3ee3f34c625b5ed048e707
refs/heads/develop
2023-09-03T11:18:18.009662
2021-09-24T02:56:10
2021-09-24T02:56:10
147,705,154
416
158
Apache-2.0
2021-07-18T10:25:52
2018-09-06T16:53:21
C
UTF-8
C
false
false
2,229
h
syscalls.h
/* Copyright 2018 Canaan Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _BSP_SYSCALLS_H #define _BSP_SYSCALLS_H #include <machine/syscall.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> #include <string.h> #ifdef __cplusplus extern "C" { #endif /** * @brief Definitions for syscall putchar function * * @param[in] c The char to put * * @return result * - Byte On success, returns the written character. * - EOF On failure, returns EOF and sets the error indicator (see ferror()) on stdout. */ typedef int (*sys_putchar_t)(char c); /** * @brief Definitions for syscall getchar function * * @return byte as int type to get * - Byte The character read as an unsigned char cast to an int * - EOF EOF on end of file or error, no enough byte to read */ typedef int (*sys_getchar_t)(void); extern sys_putchar_t sys_putchar; extern sys_getchar_t sys_getchar; /** * @brief Register putchar function when perform write syscall * * @param[in] putchar The user-defined putchar function * * @return None */ void sys_register_putchar(sys_putchar_t putchar); /** * @brief Register getchar function when perform read syscall * * @param[in] getchar The user-defined getchar function * * @return None */ void sys_register_getchar(sys_getchar_t getchar); /** * @brief Flush stdin buffer * * @return None */ void sys_stdin_flush(void); void __attribute__((noreturn)) sys_exit(int code); /** * @brief Get free memory * * @return The size of free memory */ size_t get_free_heap_size(void); #ifdef __cplusplus } #endif #endif /* _BSP_SYSCALLS_H */
fb25da213d2cbafcce54117de2b377674727c25c
30b736259b38c916e96f8e1517f92231070f5464
/nimble/host/src/ble_l2cap_sig_cmd.c
48b35249ec0563572a6f0a217435757e168fe5a6
[ "Apache-2.0", "LicenseRef-scancode-gary-s-brown", "BSD-3-Clause" ]
permissive
apache/mynewt-nimble
5bcc87df4482705c5a6542467bab028c8fd4e5fe
b5e107e9c55f32d18b16e5afc0a7e1720b901b68
refs/heads/master
2023-09-01T19:28:57.874159
2023-08-31T09:07:59
2023-08-31T14:46:07
113,086,218
606
354
Apache-2.0
2023-09-14T12:14:19
2017-12-04T19:34:47
C
UTF-8
C
false
false
3,233
c
ble_l2cap_sig_cmd.c
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ #include <string.h> #include "ble_hs_priv.h" #if NIMBLE_BLE_CONNECT /* this function consumes tx os_mbuf */ int ble_l2cap_sig_tx(uint16_t conn_handle, struct os_mbuf *txom) { struct ble_l2cap_chan *chan; struct ble_hs_conn *conn; int rc; ble_hs_lock(); rc = ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_SIG, &conn, &chan); if (rc == 0) { rc = ble_l2cap_tx(conn, chan, txom); } else { os_mbuf_free_chain(txom); } ble_hs_unlock(); return rc; } void ble_l2cap_sig_hdr_parse(void *payload, uint16_t len, struct ble_l2cap_sig_hdr *dst) { struct ble_l2cap_sig_hdr *src = payload; BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_HDR_SZ); dst->op = src->op; dst->identifier = src->identifier; dst->length = le16toh(src->length); } int ble_l2cap_sig_reject_tx(uint16_t conn_handle, uint8_t id, uint16_t reason, void *data, int data_len) { struct ble_l2cap_sig_reject *cmd; struct os_mbuf *txom; cmd = ble_l2cap_sig_cmd_get(BLE_L2CAP_SIG_OP_REJECT, id, sizeof(*cmd) + data_len, &txom); if (!cmd) { return BLE_HS_ENOMEM; } cmd->reason = htole16(reason); memcpy(cmd->data, data, data_len); STATS_INC(ble_l2cap_stats, sig_rx); return ble_l2cap_sig_tx(conn_handle, txom); } int ble_l2cap_sig_reject_invalid_cid_tx(uint16_t conn_handle, uint8_t id, uint16_t src_cid, uint16_t dst_cid) { struct { uint16_t local_cid; uint16_t remote_cid; } data = { .local_cid = dst_cid, .remote_cid = src_cid, }; return ble_l2cap_sig_reject_tx(conn_handle, id, BLE_L2CAP_SIG_ERR_INVALID_CID, &data, sizeof data); } void * ble_l2cap_sig_cmd_get(uint8_t opcode, uint8_t id, uint16_t len, struct os_mbuf **txom) { struct ble_l2cap_sig_hdr *hdr; *txom = ble_hs_mbuf_l2cap_pkt(); if (*txom == NULL) { return NULL; } if (os_mbuf_extend(*txom, sizeof(*hdr) + len) == NULL) { os_mbuf_free_chain(*txom); return NULL; } hdr = (struct ble_l2cap_sig_hdr *)(*txom)->om_data; hdr->op = opcode; hdr->identifier = id; hdr->length = htole16(len); return hdr->data; } #endif
a880af3a70fc41d09fcfcaf582451321208c7135
376e1818d427b5e4d32fa6dd6c7b71e9fd88afdb
/audio/gramofile/patches/patch-clrscr.c
fc1366480f6ddb3f720e928888ff1c89766dfe85
[]
no_license
NetBSD/pkgsrc
a0732c023519650ef821ab89c23ab6ab59e25bdb
d042034ec4896cc5b47ed6f2e5b8802d9bc5c556
refs/heads/trunk
2023-09-01T07:40:12.138283
2023-09-01T05:25:19
2023-09-01T05:25:19
88,439,572
321
138
null
2023-07-12T22:34:14
2017-04-16T20:04:15
null
UTF-8
C
false
false
276
c
patch-clrscr.c
$NetBSD: patch-clrscr.c,v 1.1 2021/05/20 19:24:15 nia Exp $ Include missing header for strlen. --- clrscr.c.orig 2000-03-28 21:07:25.000000000 +0000 +++ clrscr.c @@ -13,7 +13,7 @@ #else #include <curses.h> #endif - +#include <string.h> void header (char *headertext)
11b8af463df2e69c0822a35876d45d045c7cd9be
fdbb74a95924e2677466614f6ab6e2bb13b2a95a
/third_party/xed/x86isa.h
3b03b3c6d86692ec9e0ff14884f9d89a44eaffca
[ "ISC" ]
permissive
jart/cosmopolitan
fb11b5658939023977060a7c6c71a74093d9cb44
0d748ad58e1063dd1f8560f18a0c75293b9415b7
refs/heads/master
2023-09-06T09:17:29.303607
2023-09-02T03:49:13
2023-09-02T03:50:18
272,457,606
11,887
435
ISC
2023-09-14T17:47:58
2020-06-15T14:16:13
C
UTF-8
C
false
false
10,815
h
x86isa.h
#ifndef COSMOPOLITAN_THIRD_PARTY_XED_X86ISA_H_ #define COSMOPOLITAN_THIRD_PARTY_XED_X86ISA_H_ #include "third_party/xed/x86.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ #define XED_CHIP_INVALID 1 #define XED_CHIP_I86 2 #define XED_CHIP_I86FP 3 #define XED_CHIP_I186 4 #define XED_CHIP_I186FP 5 #define XED_CHIP_I286REAL 6 #define XED_CHIP_I286 7 #define XED_CHIP_I2186FP 8 #define XED_CHIP_I386REAL 9 #define XED_CHIP_I386 10 #define XED_CHIP_I386FP 11 #define XED_CHIP_I486REAL 12 #define XED_CHIP_I486 13 #define XED_CHIP_PENTIUMREAL 14 #define XED_CHIP_PENTIUM 15 #define XED_CHIP_QUARK 16 #define XED_CHIP_PENTIUMMMXREAL 17 #define XED_CHIP_PENTIUMMMX 18 #define XED_CHIP_ALLREAL 19 #define XED_CHIP_PENTIUMPRO 20 #define XED_CHIP_PENTIUM2 21 #define XED_CHIP_PENTIUM3 22 #define XED_CHIP_PENTIUM4 23 #define XED_CHIP_P4PRESCOTT 24 #define XED_CHIP_P4PRESCOTT_NOLAHF 25 #define XED_CHIP_P4PRESCOTT_VTX 26 #define XED_CHIP_CORE2 27 #define XED_CHIP_PENRYN 28 #define XED_CHIP_PENRYN_E 29 #define XED_CHIP_NEHALEM 30 #define XED_CHIP_WESTMERE 31 #define XED_CHIP_BONNELL 32 #define XED_CHIP_SALTWELL 33 #define XED_CHIP_SILVERMONT 34 #define XED_CHIP_AMD 35 #define XED_CHIP_GOLDMONT 36 #define XED_CHIP_GOLDMONT_PLUS 37 #define XED_CHIP_TREMONT 38 #define XED_CHIP_SANDYBRIDGE 39 #define XED_CHIP_IVYBRIDGE 40 #define XED_CHIP_HASWELL 41 #define XED_CHIP_BROADWELL 42 #define XED_CHIP_SKYLAKE 43 #define XED_CHIP_SKYLAKE_SERVER 44 #define XED_CHIP_CASCADE_LAKE 45 #define XED_CHIP_KNL 46 #define XED_CHIP_KNM 47 #define XED_CHIP_CANNONLAKE 48 #define XED_CHIP_ICELAKE 49 #define XED_CHIP_ICELAKE_SERVER 50 #define XED_CHIP_FUTURE 51 #define XED_CHIP_ALL 52 #define XED_CHIP_LAST 53 #define XED_ISA_SET_INVALID 0 #define XED_ISA_SET_3DNOW 1 #define XED_ISA_SET_ADOX_ADCX 2 #define XED_ISA_SET_AES 3 #define XED_ISA_SET_AMD 4 #define XED_ISA_SET_AVX 5 #define XED_ISA_SET_AVX2 6 #define XED_ISA_SET_AVX2GATHER 7 #define XED_ISA_SET_AVX512BW_128 8 #define XED_ISA_SET_AVX512BW_128N 9 #define XED_ISA_SET_AVX512BW_256 10 #define XED_ISA_SET_AVX512BW_512 11 #define XED_ISA_SET_AVX512BW_KOP 12 #define XED_ISA_SET_AVX512CD_128 13 #define XED_ISA_SET_AVX512CD_256 14 #define XED_ISA_SET_AVX512CD_512 15 #define XED_ISA_SET_AVX512DQ_128 16 #define XED_ISA_SET_AVX512DQ_128N 17 #define XED_ISA_SET_AVX512DQ_256 18 #define XED_ISA_SET_AVX512DQ_512 19 #define XED_ISA_SET_AVX512DQ_KOP 20 #define XED_ISA_SET_AVX512DQ_SCALAR 21 #define XED_ISA_SET_AVX512ER_512 22 #define XED_ISA_SET_AVX512ER_SCALAR 23 #define XED_ISA_SET_AVX512F_128 24 #define XED_ISA_SET_AVX512F_128N 25 #define XED_ISA_SET_AVX512F_256 26 #define XED_ISA_SET_AVX512F_512 27 #define XED_ISA_SET_AVX512F_KOP 28 #define XED_ISA_SET_AVX512F_SCALAR 29 #define XED_ISA_SET_AVX512PF_512 30 #define XED_ISA_SET_AVX512_4FMAPS_512 31 #define XED_ISA_SET_AVX512_4FMAPS_SCALAR 32 #define XED_ISA_SET_AVX512_4VNNIW_512 33 #define XED_ISA_SET_AVX512_BITALG_128 34 #define XED_ISA_SET_AVX512_BITALG_256 35 #define XED_ISA_SET_AVX512_BITALG_512 36 #define XED_ISA_SET_AVX512_GFNI_128 37 #define XED_ISA_SET_AVX512_GFNI_256 38 #define XED_ISA_SET_AVX512_GFNI_512 39 #define XED_ISA_SET_AVX512_IFMA_128 40 #define XED_ISA_SET_AVX512_IFMA_256 41 #define XED_ISA_SET_AVX512_IFMA_512 42 #define XED_ISA_SET_AVX512_VAES_128 43 #define XED_ISA_SET_AVX512_VAES_256 44 #define XED_ISA_SET_AVX512_VAES_512 45 #define XED_ISA_SET_AVX512_VBMI2_128 46 #define XED_ISA_SET_AVX512_VBMI2_256 47 #define XED_ISA_SET_AVX512_VBMI2_512 48 #define XED_ISA_SET_AVX512_VBMI_128 49 #define XED_ISA_SET_AVX512_VBMI_256 50 #define XED_ISA_SET_AVX512_VBMI_512 51 #define XED_ISA_SET_AVX512_VNNI_128 52 #define XED_ISA_SET_AVX512_VNNI_256 53 #define XED_ISA_SET_AVX512_VNNI_512 54 #define XED_ISA_SET_AVX512_VPCLMULQDQ_128 55 #define XED_ISA_SET_AVX512_VPCLMULQDQ_256 56 #define XED_ISA_SET_AVX512_VPCLMULQDQ_512 57 #define XED_ISA_SET_AVX512_VPOPCNTDQ_128 58 #define XED_ISA_SET_AVX512_VPOPCNTDQ_256 59 #define XED_ISA_SET_AVX512_VPOPCNTDQ_512 60 #define XED_ISA_SET_AVXAES 61 #define XED_ISA_SET_AVX_GFNI 62 #define XED_ISA_SET_BMI1 63 #define XED_ISA_SET_BMI2 64 #define XED_ISA_SET_CET 65 #define XED_ISA_SET_CLDEMOTE 66 #define XED_ISA_SET_CLFLUSHOPT 67 #define XED_ISA_SET_CLFSH 68 #define XED_ISA_SET_CLWB 69 #define XED_ISA_SET_CLZERO 70 #define XED_ISA_SET_CMOV 71 #define XED_ISA_SET_CMPXCHG16B 72 #define XED_ISA_SET_F16C 73 #define XED_ISA_SET_FAT_NOP 74 #define XED_ISA_SET_FCMOV 75 #define XED_ISA_SET_FMA 76 #define XED_ISA_SET_FMA4 77 #define XED_ISA_SET_FXSAVE 78 #define XED_ISA_SET_FXSAVE64 79 #define XED_ISA_SET_GFNI 80 #define XED_ISA_SET_I186 81 #define XED_ISA_SET_I286PROTECTED 82 #define XED_ISA_SET_I286REAL 83 #define XED_ISA_SET_I386 84 #define XED_ISA_SET_I486 85 #define XED_ISA_SET_I486REAL 86 #define XED_ISA_SET_I86 87 #define XED_ISA_SET_INVPCID 88 #define XED_ISA_SET_LAHF 89 #define XED_ISA_SET_LONGMODE 90 #define XED_ISA_SET_LZCNT 91 #define XED_ISA_SET_MONITOR 92 #define XED_ISA_SET_MONITORX 93 #define XED_ISA_SET_MOVBE 94 #define XED_ISA_SET_MOVDIR 95 #define XED_ISA_SET_MPX 96 #define XED_ISA_SET_PAUSE 97 #define XED_ISA_SET_PCLMULQDQ 98 #define XED_ISA_SET_PCONFIG 99 #define XED_ISA_SET_PENTIUMMMX 100 #define XED_ISA_SET_PENTIUMREAL 101 #define XED_ISA_SET_PKU 102 #define XED_ISA_SET_POPCNT 103 #define XED_ISA_SET_PPRO 104 #define XED_ISA_SET_PREFETCHW 105 #define XED_ISA_SET_PREFETCHWT1 106 #define XED_ISA_SET_PREFETCH_NOP 107 #define XED_ISA_SET_PT 108 #define XED_ISA_SET_RDPID 109 #define XED_ISA_SET_RDPMC 110 #define XED_ISA_SET_RDRAND 111 #define XED_ISA_SET_RDSEED 112 #define XED_ISA_SET_RDTSCP 113 #define XED_ISA_SET_RDWRFSGS 114 #define XED_ISA_SET_RTM 115 #define XED_ISA_SET_SGX 116 #define XED_ISA_SET_SGX_ENCLV 117 #define XED_ISA_SET_SHA 118 #define XED_ISA_SET_SMAP 119 #define XED_ISA_SET_SMX 120 #define XED_ISA_SET_SSE 121 #define XED_ISA_SET_SSE2 122 #define XED_ISA_SET_SSE2MMX 123 #define XED_ISA_SET_SSE3 124 #define XED_ISA_SET_SSE3X87 125 #define XED_ISA_SET_SSE4 126 #define XED_ISA_SET_SSE42 127 #define XED_ISA_SET_SSE4A 128 #define XED_ISA_SET_SSEMXCSR 129 #define XED_ISA_SET_SSE_PREFETCH 130 #define XED_ISA_SET_SSSE3 131 #define XED_ISA_SET_SSSE3MMX 132 #define XED_ISA_SET_SVM 133 #define XED_ISA_SET_TBM 134 #define XED_ISA_SET_VAES 135 #define XED_ISA_SET_VMFUNC 136 #define XED_ISA_SET_VPCLMULQDQ 137 #define XED_ISA_SET_VTX 138 #define XED_ISA_SET_WAITPKG 139 #define XED_ISA_SET_WBNOINVD 140 #define XED_ISA_SET_X87 141 #define XED_ISA_SET_XOP 142 #define XED_ISA_SET_XSAVE 143 #define XED_ISA_SET_XSAVEC 144 #define XED_ISA_SET_XSAVEOPT 145 #define XED_ISA_SET_XSAVES 146 #define XED_ISA_SET_LAST 147 struct XedChipFeatures { uint64_t f[3]; }; #define xed_set_chip_modes(d, chip) \ do { \ struct XedDecodedInst *__d = d; \ switch (chip) { \ case XED_CHIP_INVALID: \ break; \ case XED_CHIP_I86: \ case XED_CHIP_I86FP: \ case XED_CHIP_I186: \ case XED_CHIP_I186FP: \ case XED_CHIP_I286REAL: \ case XED_CHIP_I286: \ case XED_CHIP_I2186FP: \ case XED_CHIP_I386REAL: \ case XED_CHIP_I386: \ case XED_CHIP_I386FP: \ case XED_CHIP_I486REAL: \ case XED_CHIP_I486: \ case XED_CHIP_QUARK: \ case XED_CHIP_PENTIUM: \ case XED_CHIP_PENTIUMREAL: \ case XED_CHIP_PENTIUMMMX: \ case XED_CHIP_PENTIUMMMXREAL: \ __d->op.mode_first_prefix = 1; \ break; \ default: \ break; \ } \ switch (chip) { \ case XED_CHIP_INVALID: \ case XED_CHIP_ALL: \ case XED_CHIP_AMD: \ break; \ default: \ __d->op.is_intel_specific = 1; \ break; \ } \ } while (0) extern const uint64_t kXedChipFeatures[XED_CHIP_LAST][3]; bool xed_test_chip_features(struct XedChipFeatures *, int); void xed_get_chip_features(struct XedChipFeatures *, int); bool xed_isa_set_is_valid_for_chip(int, int); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_THIRD_PARTY_XED_X86ISA_H_ */
10e65be4cfa500360cc6ebc2953e1dc6bceb2b99
e63ba8150f2596aaf573a8a09f048c6d4478bd3d
/src/util.c
99e73a23274a2717f43ba59aec599ff5adbb32cf
[ "LicenseRef-scancode-unknown-license-reference", "Apache-2.0" ]
permissive
grisha/mod_python
44ec5d1557be4416fb4ecfbc7afefdcc751840e3
9db86bca5106b5cf7ceca7645ec0208446c71e25
refs/heads/master
2023-08-30T10:54:09.295971
2023-08-18T17:28:08
2023-08-18T17:28:08
7,504,434
199
81
Apache-2.0
2023-04-21T00:58:56
2013-01-08T16:00:35
C
UTF-8
C
false
false
11,378
c
util.c
/* * Copyright (C) 2000, 2001, 2013 Gregory Trubetskoy * Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Apache Software Foundation * * 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. * * Originally developed by Gregory Trubetskoy. * * * util.c * * * See accompanying documentation and source code comments * for details. * */ #include "mod_python.h" /** ** tuple_from_array_header ** * Given an array header return a tuple. The array elements * assumed to be strings. */ PyObject * tuple_from_array_header(const apr_array_header_t *ah) { PyObject *t; int i; char **s; if (ah == NULL) t = PyTuple_New(0); else { t = PyTuple_New(ah->nelts); s = (char **) ah->elts; for (i = 0; i < ah->nelts; i++) PyTuple_SetItem(t, i, MpBytesOrUnicode_FromString(s[i])); } return t; } /** ** tuple_from_method_list ** * Given an apr_method_list_t return a tuple. */ PyObject * tuple_from_method_list(const ap_method_list_t *l) { PyObject *t; int i; char **methods; if ((l->method_list == NULL) || (l->method_list->nelts == 0)) t = PyTuple_New(0); else { t = PyTuple_New(l->method_list->nelts); methods = (char **)l->method_list->elts; for (i = 0; i < l->method_list->nelts; ++i) PyTuple_SetItem(t, i, MpBytesOrUnicode_FromString(methods[i])); } return t; } /** ** tuple_from_finfo ** * makes a tuple similar to return of os.stat() from apr_finfo_t * */ PyObject *tuple_from_finfo(apr_finfo_t *f) { PyObject *t; if (f->filetype == APR_NOFILE) { Py_INCREF(Py_None); return Py_None; } t = PyTuple_New(13); /* this should have been first, but was added later */ PyTuple_SET_ITEM(t, 12, PyLong_FromLong(f->filetype)); if (f->valid & APR_FINFO_PROT) { PyTuple_SET_ITEM(t, 0, PyLong_FromLong(f->protection)); } else { Py_INCREF(Py_None); PyTuple_SET_ITEM(t, 0, Py_None); } if (f->valid & APR_FINFO_INODE) { PyTuple_SET_ITEM(t, 1, PyLong_FromLong(f->inode)); } else { Py_INCREF(Py_None); PyTuple_SET_ITEM(t, 1, Py_None); } if (f->valid & APR_FINFO_DEV) { PyTuple_SET_ITEM(t, 2, PyLong_FromLong(f->device)); } else { Py_INCREF(Py_None); PyTuple_SET_ITEM(t, 2, Py_None); } if (f->valid & APR_FINFO_NLINK) { PyTuple_SET_ITEM(t, 3, PyLong_FromLong(f->nlink)); } else { Py_INCREF(Py_None); PyTuple_SET_ITEM(t, 3, Py_None); } if (f->valid & APR_FINFO_USER) { PyTuple_SET_ITEM(t, 4, PyLong_FromLong(f->user)); } else { Py_INCREF(Py_None); PyTuple_SET_ITEM(t, 4, Py_None); } if (f->valid & APR_FINFO_GROUP) { PyTuple_SET_ITEM(t, 5, PyLong_FromLong(f->group)); } else { Py_INCREF(Py_None); PyTuple_SET_ITEM(t, 5, Py_None); } if (f->valid & APR_FINFO_SIZE) { PyTuple_SET_ITEM(t, 6, PyLong_FromLong(f->size)); } else { Py_INCREF(Py_None); PyTuple_SET_ITEM(t, 6, Py_None); } if (f->valid & APR_FINFO_ATIME) { PyTuple_SET_ITEM(t, 7, PyLong_FromLong(f->atime*0.000001)); } else { Py_INCREF(Py_None); PyTuple_SET_ITEM(t, 7, Py_None); } if (f->valid & APR_FINFO_MTIME) { PyTuple_SET_ITEM(t, 8, PyLong_FromLong(f->mtime*0.000001)); } else { Py_INCREF(Py_None); PyTuple_SET_ITEM(t, 8, Py_None); } if (f->valid & APR_FINFO_CTIME) { PyTuple_SET_ITEM(t, 9, PyLong_FromLong(f->ctime*0.000001)); } else { Py_INCREF(Py_None); PyTuple_SET_ITEM(t, 9, Py_None); } if (f->fname) { PyTuple_SET_ITEM(t, 10, MpBytesOrUnicode_FromString(f->fname)); } else { Py_INCREF(Py_None); PyTuple_SET_ITEM(t, 10, Py_None); } if (f->valid & APR_FINFO_NAME) { PyTuple_SET_ITEM(t, 11, MpBytesOrUnicode_FromString(f->name)); } else { Py_INCREF(Py_None); PyTuple_SET_ITEM(t, 11, Py_None); } /* it'd be nice to also return the file dscriptor, f->filehand->filedes, but it's platform dependent, so may be later... */ return t; } /** ** tuple_from_apr_uri ** * makes a tuple from uri_components * */ PyObject *tuple_from_apr_uri(apr_uri_t *u) { PyObject *t; t = PyTuple_New(9); if (u->scheme) { PyTuple_SET_ITEM(t, 0, MpBytesOrUnicode_FromString(u->scheme)); } else { Py_INCREF(Py_None); PyTuple_SET_ITEM(t, 0, Py_None); } if (u->hostinfo) { PyTuple_SET_ITEM(t, 1, MpBytesOrUnicode_FromString(u->hostinfo)); } else { Py_INCREF(Py_None); PyTuple_SET_ITEM(t, 1, Py_None); } if (u->user) { PyTuple_SET_ITEM(t, 2, MpBytesOrUnicode_FromString(u->user)); } else { Py_INCREF(Py_None); PyTuple_SET_ITEM(t, 2, Py_None); } if (u->password) { PyTuple_SET_ITEM(t, 3, MpBytesOrUnicode_FromString(u->password)); } else { Py_INCREF(Py_None); PyTuple_SET_ITEM(t, 3, Py_None); } if (u->hostname) { PyTuple_SET_ITEM(t, 4, MpBytesOrUnicode_FromString(u->hostname)); } else { Py_INCREF(Py_None); PyTuple_SET_ITEM(t, 4, Py_None); } if (u->port_str) { PyTuple_SET_ITEM(t, 5, PyLong_FromLong(u->port)); } else { Py_INCREF(Py_None); PyTuple_SET_ITEM(t, 5, Py_None); } if (u->path) { PyTuple_SET_ITEM(t, 6, MpBytesOrUnicode_FromString(u->path)); } else { Py_INCREF(Py_None); PyTuple_SET_ITEM(t, 6, Py_None); } if (u->query) { PyTuple_SET_ITEM(t, 7, MpBytesOrUnicode_FromString(u->query)); } else { Py_INCREF(Py_None); PyTuple_SET_ITEM(t, 7, Py_None); } if (u->fragment) { PyTuple_SET_ITEM(t, 8, MpBytesOrUnicode_FromString(u->fragment)); } else { Py_INCREF(Py_None); PyTuple_SET_ITEM(t, 8, Py_None); } /* XXX hostent, is_initialized, dns_* */ return t; } /** ** python_decref ** * This helper function is used with apr_pool_cleanup_register to destroy * python objects when a certain pool is destroyed. */ apr_status_t python_decref(void *object) { Py_XDECREF((PyObject *) object); return 0; } /** ** find_module ** * Find an Apache module by name, used by get_addhandler_extensions */ static module *find_module(char *name) { int n; for (n = 0; ap_loaded_modules[n]; ++n) { if (strcmp(name, ap_loaded_modules[n]->name) == 0) return ap_loaded_modules[n]; } return NULL; } /** ** get_addhandler_extensions ** * Get extensions specified for AddHandler, if any. To do this we * retrieve mod_mime's config. This is used by the publisher to strip * file extentions from modules in the most meaningful way. * * XXX This function is a hack and will stop working if mod_mime people * decide to change their code. A better way to implement this would * be via the config tree, but it doesn't seem to be quite there just * yet, because it doesn't have .htaccess directives. */ char * get_addhandler_extensions(request_rec *req) { /* these typedefs are copied from mod_mime.c */ typedef struct { apr_hash_t *extension_mappings; apr_array_header_t *remove_mappings; char *default_language; int multimatch; } mime_dir_config; typedef struct extension_info { char *forced_type; /* Additional AddTyped stuff */ char *encoding_type; /* Added with AddEncoding... */ char *language_type; /* Added with AddLanguage... */ char *handler; /* Added with AddHandler... */ char *charset_type; /* Added with AddCharset... */ char *input_filters; /* Added with AddInputFilter... */ char *output_filters; /* Added with AddOutputFilter... */ } extension_info; mime_dir_config *mconf; apr_hash_index_t *hi; void *val; void *key; extension_info *ei; char *result = NULL; module *mod_mime = find_module("mod_mime.c"); mconf = (mime_dir_config *) ap_get_module_config(req->per_dir_config, mod_mime); if (mconf->extension_mappings) { for (hi = apr_hash_first(req->pool, mconf->extension_mappings); hi; hi = apr_hash_next(hi)) { apr_hash_this(hi, (const void **)&key, NULL, &val); ei = (extension_info *)val; if (ei->handler) if (strcmp("mod_python", ei->handler) == 0 || strcmp("python-program", ei->handler) == 0) result = apr_pstrcat(req->pool, (char *)key, " ", result, NULL); } } return result; } /** ** find_memberdef ** * Find a memberdef in a PyMemberDef array */ PyMemberDef *find_memberdef(const PyMemberDef *mlist, const char *name) { const PyMemberDef *md; for (md = mlist; md->name != NULL; md++) if (name[0] == md->name[0] && strcmp(md->name+1, name+1) == 0) return (PyMemberDef *)md; /* this should never happen or the mlist is screwed up */ return NULL; } /** ** cfgtree_walk ** * walks ap_directive_t tree returning a list of * tuples and lists */ PyObject *cfgtree_walk(ap_directive_t *dir) { PyObject *list = PyList_New(0); if (!list) return PyErr_NoMemory(); while (dir) { PyObject *t = Py_BuildValue("(s, s)", dir->directive, dir->args); if (!t) return PyErr_NoMemory(); PyList_Append(list, t); Py_DECREF(t); if (dir->first_child) { PyObject *child = cfgtree_walk(dir->first_child); if (!child) return PyErr_NoMemory(); PyList_Append(list, child); Py_DECREF(child); } dir = dir->next; } return list; } /** ** makeipaddr ** * utility func to make an ip address */ static PyObject *makeipaddr(struct apr_sockaddr_t *addr) { char *str = NULL; apr_status_t rc; PyObject *ret = NULL; rc = apr_sockaddr_ip_get(&str, addr); if (rc==APR_SUCCESS) { ret = MpBytesOrUnicode_FromString(str); } else { PyErr_SetString(PyExc_SystemError,"apr_sockaddr_ip_get failure"); } return ret; } /** ** makesockaddr ** * utility func to make a socket address */ PyObject *makesockaddr(struct apr_sockaddr_t *addr) { PyObject *addrobj = makeipaddr(addr); PyObject *ret = NULL; if (addrobj) { apr_port_t port; port = addr->port; ret = Py_BuildValue("Oi", addrobj, port ); Py_DECREF(addrobj); } return ret; }
4d6f63f706a600530d7a0209f12caca57e5c2818
549270020f6c8724e2ef1b12e38d11b025579f8d
/recipes/libtiff/all/test_package/test_package.c
0b73b99d432d5e214fe4b05e05bedd405916e8ba
[ "MIT" ]
permissive
conan-io/conan-center-index
1bcec065ccd65aa38b1fed93fbd94d9d5fe6bc43
3b17e69bb4e5601a850b6e006e44775e690bac33
refs/heads/master
2023-08-31T11:34:45.403978
2023-08-31T11:13:23
2023-08-31T11:13:23
204,671,232
844
1,820
MIT
2023-09-14T21:22:42
2019-08-27T09:43:58
Python
UTF-8
C
false
false
112
c
test_package.c
#include <tiffio.h> int main() { TIFF* tif = TIFFOpen("foo.tif", "w"); TIFFClose(tif); return 0; }
db70eb45e8c87d79d93011fc4f46017136415e46
99bdb3251fecee538e0630f15f6574054dfc1468
/bsp/hc32/libraries/hc32f4a0_ddl/drivers/hc32_ll_driver/src/hc32_ll_tmr0.c
0cb858b1fe69da30c281709d9ad24da3ad99bf00
[ "Apache-2.0", "Zlib", "LicenseRef-scancode-proprietary-license", "MIT", "BSD-3-Clause", "X11", "BSD-4-Clause-UC", "LicenseRef-scancode-unknown-license-reference" ]
permissive
RT-Thread/rt-thread
03a7c52c2aeb1b06a544143b0e803d72f47d1ece
3602f891211904a27dcbd51e5ba72fefce7326b2
refs/heads/master
2023-09-01T04:10:20.295801
2023-08-31T16:20:55
2023-08-31T16:20:55
7,408,108
9,599
5,805
Apache-2.0
2023-09-14T13:37:26
2013-01-02T14:49:21
C
UTF-8
C
false
false
23,213
c
hc32_ll_tmr0.c
/** ******************************************************************************* * @file hc32_ll_tmr0.c * @brief This file provides firmware functions to manage the TMR0 * (TMR0). @verbatim Change Logs: Date Author Notes 2022-03-31 CDT First version @endverbatim ******************************************************************************* * Copyright (C) 2022, Xiaohua Semiconductor Co., Ltd. All rights reserved. * * This software component is licensed by XHSC under BSD 3-Clause license * (the "License"); You may not use this file except in compliance with the * License. You may obtain a copy of the License at: * opensource.org/licenses/BSD-3-Clause * ******************************************************************************* */ /******************************************************************************* * Include files ******************************************************************************/ #include "hc32_ll_tmr0.h" #include "hc32_ll_utility.h" /** * @addtogroup LL_Driver * @{ */ /** * @defgroup LL_TMR0 TMR0 * @brief TMR0 Driver Library * @{ */ #if (LL_TMR0_ENABLE == DDL_ON) /******************************************************************************* * Local type definitions ('typedef') ******************************************************************************/ /******************************************************************************* * Local pre-processor symbols/macros ('#define') ******************************************************************************/ /** * @defgroup TMR0_Local_Macros TMR0 Local Macros * @{ */ /* Max channel number */ #define TMR0_CH_MAX (2UL) #define TMR0_CLK_SRC_MASK (TMR0_BCONR_SYNSA | TMR0_BCONR_SYNCLKA | TMR0_BCONR_ASYNCLKA) #define TMR0_BCONR_CLR_MASK (TMR0_BCONR_CAPMDA | TMR0_BCONR_CKDIVA | TMR0_BCONR_HICPA | TMR0_CLK_SRC_MASK) /** * @defgroup TMR0_Register_Address TMR0 Register Address * @{ */ #define TMR0_CNTR_ADDR(__UNIT__, __CH__) (__IO uint32_t*)((uint32_t)(&((__UNIT__)->CNTAR)) + ((__CH__) << 2UL)) #define TMR0_CMPR_ADDR(__UNIT__, __CH__) (__IO uint32_t*)((uint32_t)(&((__UNIT__)->CMPAR)) + ((__CH__) << 2UL)) /** * @} */ #define TMR0_CH_OFFSET(__CH__) ((__CH__) << 4U) /** * @defgroup TMR0_Check_Parameters_Validity TMR0 Check Parameters Validity * @{ */ #define IS_TMR0_UNIT(x) \ ( ((x) == CM_TMR0_1) || \ ((x) == CM_TMR0_2)) #define IS_TMR0_CH(x) \ ( ((x) == TMR0_CH_A) || \ ((x) == TMR0_CH_B)) #define IS_TMR0_CLK_SRC(x) \ ( ((x) == TMR0_CLK_SRC_INTERN_CLK) || \ ((x) == TMR0_CLK_SRC_SPEC_EVT) || \ ((x) == TMR0_CLK_SRC_LRC) || \ ((x) == TMR0_CLK_SRC_XTAL32)) #define IS_TMR0_CLK_DIV(x) \ ( ((x) == TMR0_CLK_DIV1) || \ ((x) == TMR0_CLK_DIV2) || \ ((x) == TMR0_CLK_DIV4) || \ ((x) == TMR0_CLK_DIV8) || \ ((x) == TMR0_CLK_DIV16) || \ ((x) == TMR0_CLK_DIV32) || \ ((x) == TMR0_CLK_DIV64) || \ ((x) == TMR0_CLK_DIV128) || \ ((x) == TMR0_CLK_DIV256) || \ ((x) == TMR0_CLK_DIV512) || \ ((x) == TMR0_CLK_DIV1024)) #define IS_TMR0_FUNC(x) \ ( ((x) == TMR0_FUNC_CMP) || \ ((x) == TMR0_FUNC_CAPT)) #define IS_TMR0_INT(x) \ ( ((x) != 0U) && \ (((x) | TMR0_INT_ALL) == TMR0_INT_ALL)) #define IS_TMR0_FLAG(x) \ ( ((x) != 0U) && \ (((x) | TMR0_FLAG_ALL) == TMR0_FLAG_ALL)) /** * @} */ /** * @} */ /******************************************************************************* * Global variable definitions (declared in header file with 'extern') ******************************************************************************/ /******************************************************************************* * Local function prototypes ('static') ******************************************************************************/ /******************************************************************************* * Local variable definitions ('static') ******************************************************************************/ /******************************************************************************* * Function implementation - global ('extern') and local ('static') ******************************************************************************/ /** * @defgroup TMR0_Global_Functions TMR0 Global Functions * @{ */ /** * @brief De-Initialize TMR0 function * @param [in] TMR0x Pointer to TMR0 unit instance * This parameter can be one of the following values: * @arg CM_TMR0 or CM_TMR0_x: TMR0 unit instance * @retval None */ void TMR0_DeInit(CM_TMR0_TypeDef *TMR0x) { uint32_t u32Ch; __IO uint32_t *CNTR; __IO uint32_t *CMPR; /* Check parameters */ DDL_ASSERT(IS_TMR0_UNIT(TMR0x)); WRITE_REG32(TMR0x->BCONR, 0UL); WRITE_REG32(TMR0x->STFLR, 0UL); for (u32Ch = 0UL; u32Ch < TMR0_CH_MAX; u32Ch++) { CNTR = TMR0_CNTR_ADDR(TMR0x, u32Ch); WRITE_REG32(*CNTR, 0UL); CMPR = TMR0_CMPR_ADDR(TMR0x, u32Ch); WRITE_REG32(*CMPR, 0x0000FFFFUL); } } /** * @brief Initialize TMR0 function. * @param [in] TMR0x Pointer to TMR0 unit instance * This parameter can be one of the following values: * @arg CM_TMR0 or CM_TMR0_x: TMR0 unit instance * @param [in] u32Ch TMR0 channel * This parameter can be one of the following values: * @arg @ref TMR0_Channel * @param [in] pstcTmr0Init Pointer to a @ref stc_tmr0_init_t. * @retval int32_t: * - LL_OK: Initialize success * - LL_ERR_INVD_PARAM: pstcTmr0Init is NULL */ int32_t TMR0_Init(CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch, const stc_tmr0_init_t *pstcTmr0Init) { __IO uint32_t *CNTR; __IO uint32_t *CMPR; int32_t i32Ret = LL_OK; if (NULL == pstcTmr0Init) { i32Ret = LL_ERR_INVD_PARAM; } else { /* Check parameters */ DDL_ASSERT(IS_TMR0_UNIT(TMR0x)); DDL_ASSERT(IS_TMR0_CH(u32Ch)); DDL_ASSERT(IS_TMR0_CLK_SRC(pstcTmr0Init->u32ClockSrc)); DDL_ASSERT(IS_TMR0_CLK_DIV(pstcTmr0Init->u32ClockDiv)); DDL_ASSERT(IS_TMR0_FUNC(pstcTmr0Init->u32Func)); CNTR = TMR0_CNTR_ADDR(TMR0x, u32Ch); WRITE_REG32(*CNTR, 0UL); CMPR = TMR0_CMPR_ADDR(TMR0x, u32Ch); WRITE_REG32(*CMPR, pstcTmr0Init->u16CompareValue); MODIFY_REG32(TMR0x->BCONR, (TMR0_BCONR_CLR_MASK << TMR0_CH_OFFSET(u32Ch)), ((pstcTmr0Init->u32ClockSrc | pstcTmr0Init->u32ClockDiv | pstcTmr0Init->u32Func) << TMR0_CH_OFFSET(u32Ch))); } return i32Ret; } /** * @brief Set the fields of structure stc_tmr0_init_t to default values. * @param [out] pstcTmr0Init Pointer to a @ref stc_tmr0_init_t structure. * @retval int32_t: * - LL_OK: Initialize success * - LL_ERR_INVD_PARAM: pstcTmr0Init is NULL */ int32_t TMR0_StructInit(stc_tmr0_init_t *pstcTmr0Init) { int32_t i32Ret = LL_OK; if (NULL == pstcTmr0Init) { i32Ret = LL_ERR_INVD_PARAM; } else { pstcTmr0Init->u32ClockSrc = TMR0_CLK_SRC_INTERN_CLK; pstcTmr0Init->u32ClockDiv = TMR0_CLK_DIV1; pstcTmr0Init->u32Func = TMR0_FUNC_CMP; pstcTmr0Init->u16CompareValue = 0xFFFFU; } return i32Ret; } /** * @brief Start TMR0. * @param [in] TMR0x Pointer to TMR0 unit instance * This parameter can be one of the following values: * @arg CM_TMR0 or CM_TMR0_x: TMR0 unit instance * @param [in] u32Ch TMR0 channel * This parameter can be one of the following values: * @arg @ref TMR0_Channel * @retval None */ void TMR0_Start(CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch) { /* Check parameters */ DDL_ASSERT(IS_TMR0_UNIT(TMR0x)); DDL_ASSERT(IS_TMR0_CH(u32Ch)); SET_REG32_BIT(TMR0x->BCONR, (TMR0_BCONR_CSTA << TMR0_CH_OFFSET(u32Ch))); } /** * @brief Stop TMR0. * @param [in] TMR0x Pointer to TMR0 unit instance * This parameter can be one of the following values: * @arg CM_TMR0 or CM_TMR0_x: TMR0 unit instance * @param [in] u32Ch TMR0 channel * This parameter can be one of the following values: * @arg @ref TMR0_Channel * @retval None */ void TMR0_Stop(CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch) { /* Check parameters */ DDL_ASSERT(IS_TMR0_UNIT(TMR0x)); DDL_ASSERT(IS_TMR0_CH(u32Ch)); CLR_REG32_BIT(TMR0x->BCONR, (TMR0_BCONR_CSTA << TMR0_CH_OFFSET(u32Ch))); } /** * @brief Set Tmr0 counter value. * @note Setting the count requires stop tmr0. * @param [in] TMR0x Pointer to TMR0 unit instance * This parameter can be one of the following values: * @arg CM_TMR0 or CM_TMR0_x: TMR0 unit instance * @param [in] u32Ch TMR0 channel * This parameter can be one of the following values: * @arg @ref TMR0_Channel * @param [in] u16Value The data to write to the counter register * @retval None */ void TMR0_SetCountValue(CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch, uint16_t u16Value) { __IO uint32_t *CNTR; /* Check parameters */ DDL_ASSERT(IS_TMR0_UNIT(TMR0x)); DDL_ASSERT(IS_TMR0_CH(u32Ch)); CNTR = TMR0_CNTR_ADDR(TMR0x, u32Ch); WRITE_REG32(*CNTR, u16Value); } /** * @brief Get Tmr0 counter value. * @param [in] TMR0x Pointer to TMR0 unit instance * This parameter can be one of the following values: * @arg CM_TMR0 or CM_TMR0_x: TMR0 unit instance * @param [in] u32Ch TMR0 channel * This parameter can be one of the following values: * @arg @ref TMR0_Channel * @retval uint16_t The counter register data */ uint16_t TMR0_GetCountValue(const CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch) { __IO uint32_t *CNTR; /* Check parameters */ DDL_ASSERT(IS_TMR0_UNIT(TMR0x)); DDL_ASSERT(IS_TMR0_CH(u32Ch)); CNTR = TMR0_CNTR_ADDR(TMR0x, u32Ch); return (uint16_t)READ_REG32(*CNTR); } /** * @brief Set Tmr0 compare value. * @param [in] TMR0x Pointer to TMR0 unit instance * This parameter can be one of the following values: * @arg CM_TMR0 or CM_TMR0_x: TMR0 unit instance * @param [in] u32Ch TMR0 channel * This parameter can be one of the following values: * @arg @ref TMR0_Channel * @param [in] u16Value The data to write to the compare register * @retval None */ void TMR0_SetCompareValue(CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch, uint16_t u16Value) { __IO uint32_t *CMPR; /* Check parameters */ DDL_ASSERT(IS_TMR0_UNIT(TMR0x)); DDL_ASSERT(IS_TMR0_CH(u32Ch)); CMPR = TMR0_CMPR_ADDR(TMR0x, u32Ch); WRITE_REG32(*CMPR, u16Value); } /** * @brief Get Tmr0 compare value. * @param [in] TMR0x Pointer to TMR0 unit instance * This parameter can be one of the following values: * @arg CM_TMR0 or CM_TMR0_x: TMR0 unit instance * @param [in] u32Ch TMR0 channel * This parameter can be one of the following values: * @arg @ref TMR0_Channel * @retval The compare register data */ uint16_t TMR0_GetCompareValue(const CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch) { __IO uint32_t *CMPR; /* Check parameters */ DDL_ASSERT(IS_TMR0_UNIT(TMR0x)); DDL_ASSERT(IS_TMR0_CH(u32Ch)); CMPR = TMR0_CMPR_ADDR(TMR0x, u32Ch); return (uint16_t)READ_REG32(*CMPR); } /** * @brief Set clock source. * @param [in] TMR0x Pointer to TMR0 unit instance * This parameter can be one of the following values: * @arg CM_TMR0 or CM_TMR0_x: TMR0 unit instance * @param [in] u32Ch TMR0 channel * This parameter can be one of the following values: * @arg @ref TMR0_Channel * @param [in] u32Src Specifies the clock source * This parameter can be a value of the following: * @arg @ref TMR0_Clock_Source * @retval None */ void TMR0_SetClockSrc(CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch, uint32_t u32Src) { /* Check parameters */ DDL_ASSERT(IS_TMR0_UNIT(TMR0x)); DDL_ASSERT(IS_TMR0_CH(u32Ch)); DDL_ASSERT(IS_TMR0_CLK_SRC(u32Src)); MODIFY_REG32(TMR0x->BCONR, (TMR0_CLK_SRC_MASK << TMR0_CH_OFFSET(u32Ch)), (u32Src << TMR0_CH_OFFSET(u32Ch))); } /** * @brief Set the division of clock. * @param [in] TMR0x Pointer to TMR0 unit instance * This parameter can be one of the following values: * @arg CM_TMR0 or CM_TMR0_x: TMR0 unit instance * @param [in] u32Ch TMR0 channel * This parameter can be one of the following values: * @arg @ref TMR0_Channel * @param [in] u32Div Specifies the clock source division * This parameter can be a value of the following: * @arg TMR0_CLK_DIV1: Clock source / 1 * @arg TMR0_CLK_DIV2: Clock source / 2 * @arg TMR0_CLK_DIV4: Clock source / 4 * @arg TMR0_CLK_DIV8: Clock source / 8 * @arg TMR0_CLK_DIV16: Clock source / 16 * @arg TMR0_CLK_DIV32: Clock source / 32 * @arg TMR0_CLK_DIV64: Clock source / 64 * @arg TMR0_CLK_DIV128: Clock source / 128 * @arg TMR0_CLK_DIV256: Clock source / 256 * @arg TMR0_CLK_DIV512: Clock source / 512 * @arg TMR0_CLK_DIV1024: Clock source / 1024 * @retval None. */ void TMR0_SetClockDiv(CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch, uint32_t u32Div) { /* Check parameters */ DDL_ASSERT(IS_TMR0_UNIT(TMR0x)); DDL_ASSERT(IS_TMR0_CH(u32Ch)); DDL_ASSERT(IS_TMR0_CLK_DIV(u32Div)); MODIFY_REG32(TMR0x->BCONR, (TMR0_BCONR_CKDIVA << TMR0_CH_OFFSET(u32Ch)), (u32Div << TMR0_CH_OFFSET(u32Ch))); } /** * @brief Set Tmr0 Function. * @param [in] TMR0x Pointer to TMR0 unit instance * This parameter can be one of the following values: * @arg CM_TMR0 or CM_TMR0_x: TMR0 unit instance * @param [in] u32Ch TMR0 channel * This parameter can be one of the following values: * @arg @ref TMR0_Channel * @param [in] u32Func Select TMR0 function * This parameter can be a value of the following: * @arg TMR0_FUNC_CMP: Select the Compare function for TMR0 * @arg TMR0_FUNC_CAPT: Select the Capture function for TMR0 * @retval None */ void TMR0_SetFunc(CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch, uint32_t u32Func) { /* Check parameters */ DDL_ASSERT(IS_TMR0_UNIT(TMR0x)); DDL_ASSERT(IS_TMR0_CH(u32Ch)); DDL_ASSERT(IS_TMR0_FUNC(u32Func)); MODIFY_REG32(TMR0x->BCONR, ((TMR0_BCONR_CAPMDA | TMR0_BCONR_HICPA) << TMR0_CH_OFFSET(u32Ch)), (u32Func << TMR0_CH_OFFSET(u32Ch))); } /** * @brief Enable or disable HardWare trigger capture function. * @param [in] TMR0x Pointer to TMR0 unit instance * This parameter can be one of the following values: * @arg CM_TMR0 or CM_TMR0_x: TMR0 unit instance * @param [in] u32Ch TMR0 channel * This parameter can be one of the following values: * @arg @ref TMR0_Channel * @param [in] enNewState An @ref en_functional_state_t enumeration value. * @retval None */ void TMR0_HWCaptureCondCmd(CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch, en_functional_state_t enNewState) { /* Check parameters */ DDL_ASSERT(IS_TMR0_UNIT(TMR0x)); DDL_ASSERT(IS_TMR0_CH(u32Ch)); DDL_ASSERT(IS_FUNCTIONAL_STATE(enNewState)); if (ENABLE == enNewState) { SET_REG32_BIT(TMR0x->BCONR, (TMR0_BCONR_HICPA << TMR0_CH_OFFSET(u32Ch))); } else { CLR_REG32_BIT(TMR0x->BCONR, (TMR0_BCONR_HICPA << TMR0_CH_OFFSET(u32Ch))); } } /** * @brief Enable or disable HardWare trigger start function. * @param [in] TMR0x Pointer to TMR0 unit instance * This parameter can be one of the following values: * @arg CM_TMR0 or CM_TMR0_x: TMR0 unit instance * @param [in] u32Ch TMR0 channel * This parameter can be one of the following values: * @arg @ref TMR0_Channel * @param [in] enNewState An @ref en_functional_state_t enumeration value. * @retval None */ void TMR0_HWStartCondCmd(CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch, en_functional_state_t enNewState) { /* Check parameters */ DDL_ASSERT(IS_TMR0_UNIT(TMR0x)); DDL_ASSERT(IS_TMR0_CH(u32Ch)); DDL_ASSERT(IS_FUNCTIONAL_STATE(enNewState)); if (ENABLE == enNewState) { SET_REG32_BIT(TMR0x->BCONR, (TMR0_BCONR_HSTAA << TMR0_CH_OFFSET(u32Ch))); } else { CLR_REG32_BIT(TMR0x->BCONR, (TMR0_BCONR_HSTAA << TMR0_CH_OFFSET(u32Ch))); } } /** * @brief Enable or disable HardWare trigger stop function. * @param [in] TMR0x Pointer to TMR0 unit instance * This parameter can be one of the following values: * @arg CM_TMR0 or CM_TMR0_x: TMR0 unit instance * @param [in] u32Ch TMR0 channel * This parameter can be one of the following values: * @arg @ref TMR0_Channel * @param [in] enNewState An @ref en_functional_state_t enumeration value. * @retval None */ void TMR0_HWStopCondCmd(CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch, en_functional_state_t enNewState) { /* Check parameters */ DDL_ASSERT(IS_TMR0_UNIT(TMR0x)); DDL_ASSERT(IS_TMR0_CH(u32Ch)); DDL_ASSERT(IS_FUNCTIONAL_STATE(enNewState)); if (ENABLE == enNewState) { SET_REG32_BIT(TMR0x->BCONR, (TMR0_BCONR_HSTPA << TMR0_CH_OFFSET(u32Ch))); } else { CLR_REG32_BIT(TMR0x->BCONR, (TMR0_BCONR_HSTPA << TMR0_CH_OFFSET(u32Ch))); } } /** * @brief Enable or disable HardWare trigger clear function. * @param [in] TMR0x Pointer to TMR0 unit instance * This parameter can be one of the following values: * @arg CM_TMR0 or CM_TMR0_x: TMR0 unit instance * @param [in] u32Ch TMR0 channel * This parameter can be one of the following values: * @arg @ref TMR0_Channel * @param [in] enNewState An @ref en_functional_state_t enumeration value. * @retval None */ void TMR0_HWClearCondCmd(CM_TMR0_TypeDef *TMR0x, uint32_t u32Ch, en_functional_state_t enNewState) { /* Check parameters */ DDL_ASSERT(IS_TMR0_UNIT(TMR0x)); DDL_ASSERT(IS_TMR0_CH(u32Ch)); DDL_ASSERT(IS_FUNCTIONAL_STATE(enNewState)); if (ENABLE == enNewState) { SET_REG32_BIT(TMR0x->BCONR, (TMR0_BCONR_HCLEA << TMR0_CH_OFFSET(u32Ch))); } else { CLR_REG32_BIT(TMR0x->BCONR, (TMR0_BCONR_HCLEA << TMR0_CH_OFFSET(u32Ch))); } } /** * @brief Enable or disable specified Tmr0 interrupt. * @note The comparison matching interrupt of channel 'TMR0_INT_CMP_A' in unit 'CM_TMR0_1' of 'HC32F460,HC32F451,HC32F452'. * is only available in asynchronous counting mode. * @param [in] TMR0x Pointer to TMR0 unit instance * This parameter can be one of the following values: * @arg CM_TMR0 or CM_TMR0_x: TMR0 unit instance * @param [in] u32IntType TMR0 interrupt type * This parameter can be any combination value of the following values: * @arg @ref TMR0_Interrupt. * @param [in] enNewState An @ref en_functional_state_t enumeration value. * @retval None */ void TMR0_IntCmd(CM_TMR0_TypeDef *TMR0x, uint32_t u32IntType, en_functional_state_t enNewState) { /* Check parameters */ DDL_ASSERT(IS_TMR0_UNIT(TMR0x)); DDL_ASSERT(IS_TMR0_INT(u32IntType)); DDL_ASSERT(IS_FUNCTIONAL_STATE(enNewState)); if (DISABLE != enNewState) { SET_REG32_BIT(TMR0x->BCONR, u32IntType); } else { CLR_REG32_BIT(TMR0x->BCONR, u32IntType); } } /** * @brief Get Tmr0 status. * @param [in] TMR0x Pointer to TMR0 unit instance * This parameter can be one of the following values: * @arg CM_TMR0 or CM_TMR0_x: TMR0 unit instance * @param [in] u32Flag TMR0 flag type * This parameter can be any combination value of the following values: * @arg @ref TMR0_FLAG * @retval An @ref en_flag_status_t enumeration type value. */ en_flag_status_t TMR0_GetStatus(const CM_TMR0_TypeDef *TMR0x, uint32_t u32Flag) { en_flag_status_t enFlagSta = RESET; /* Check parameters */ DDL_ASSERT(IS_TMR0_UNIT(TMR0x)); DDL_ASSERT(IS_TMR0_FLAG(u32Flag)); if (0UL != (READ_REG32_BIT(TMR0x->STFLR, u32Flag))) { enFlagSta = SET; } return enFlagSta; } /** * @brief Clear Tmr0 status. * @param [in] TMR0x Pointer to TMR0 unit instance * This parameter can be one of the following values: * @arg CM_TMR0 or CM_TMR0_x: TMR0 unit instance * @param [in] u32Flag TMR0 flag type * This parameter can be any combination value of the following values: * @arg @ref TMR0_FLAG * @retval None */ void TMR0_ClearStatus(CM_TMR0_TypeDef *TMR0x, uint32_t u32Flag) { /* Check parameters */ DDL_ASSERT(IS_TMR0_UNIT(TMR0x)); DDL_ASSERT(IS_TMR0_FLAG(u32Flag)); CLR_REG32_BIT(TMR0x->STFLR, u32Flag); } /** * @} */ #endif /* LL_TMR0_ENABLE */ /** * @} */ /** * @} */ /****************************************************************************** * EOF (not truncated) *****************************************************************************/
7177cf51495091880f4ef29265c9666b7e0f5316
3092a58c12d3f7a887e072c4b98c93c6474ae233
/src/libsm64.h
c6785870e911378e00810d0324c3b02fa7c8133f
[ "CC0-1.0" ]
permissive
libsm64/libsm64
92bb6d90b42250dd54a7e01d77a3ae717e3c949b
9726929fc6ac75abaedbd168f41b16b7d289e544
refs/heads/master
2023-08-16T11:01:34.534480
2023-08-12T19:11:02
2023-08-12T19:11:02
302,426,793
491
35
CC0-1.0
2023-08-12T19:11:03
2020-10-08T18:20:09
C
UTF-8
C
false
false
7,356
h
libsm64.h
#ifndef LIB_SM64_H #define LIB_SM64_H #include <stddef.h> #include <stdint.h> #include <stdbool.h> #if defined(_WIN32) #ifdef SM64_LIB_EXPORT #define SM64_LIB_FN __declspec(dllexport) #else #define SM64_LIB_FN __declspec(dllimport) #endif #elif defined(__GNUC__) && __GNUC__ >= 4 #define SM64_LIB_FN __attribute__ ((visibility("default"))) #else #define SM64_LIB_FN #endif #ifdef __cplusplus extern "C" { #endif struct SM64Surface { int16_t type; int16_t force; uint16_t terrain; int32_t vertices[3][3]; }; struct SM64MarioInputs { float camLookX, camLookZ; float stickX, stickY; uint8_t buttonA, buttonB, buttonZ; }; struct SM64ObjectTransform { float position[3]; float eulerRotation[3]; }; struct SM64SurfaceObject { struct SM64ObjectTransform transform; uint32_t surfaceCount; struct SM64Surface *surfaces; }; struct SM64MarioState { float position[3]; float velocity[3]; float faceAngle; int16_t health; uint32_t action; uint32_t flags; uint32_t particleFlags; int16_t invincTimer; }; struct SM64MarioGeometryBuffers { float *position; float *normal; float *color; float *uv; uint16_t numTrianglesUsed; }; struct SM64WallCollisionData { /*0x00*/ float x, y, z; /*0x0C*/ float offsetY; /*0x10*/ float radius; /*0x14*/ int16_t unk14; /*0x16*/ int16_t numWalls; /*0x18*/ struct SM64SurfaceCollisionData *walls[4]; }; struct SM64FloorCollisionData { float unused[4]; // possibly position data? float normalX; float normalY; float normalZ; float originOffset; }; struct SM64SurfaceObjectTransform { float aPosX, aPosY, aPosZ; float aVelX, aVelY, aVelZ; int16_t aFaceAnglePitch; int16_t aFaceAngleYaw; int16_t aFaceAngleRoll; int16_t aAngleVelPitch; int16_t aAngleVelYaw; int16_t aAngleVelRoll; }; struct SM64SurfaceCollisionData { int16_t type; int16_t force; int8_t flags; int8_t room; int32_t lowerY; // libsm64: 32 bit int32_t upperY; // libsm64: 32 bit int32_t vertex1[3]; // libsm64: 32 bit int32_t vertex2[3]; // libsm64: 32 bit int32_t vertex3[3]; // libsm64: 32 bit struct { float x; float y; float z; } normal; float originOffset; uint8_t isValid; // libsm64: added field struct SM64SurfaceObjectTransform *transform; // libsm64: added field uint16_t terrain; // libsm64: added field }; enum { SM64_TEXTURE_WIDTH = 64 * 11, SM64_TEXTURE_HEIGHT = 64, SM64_GEO_MAX_TRIANGLES = 1024, }; typedef void (*SM64DebugPrintFunctionPtr)( const char * ); extern SM64_LIB_FN void sm64_register_debug_print_function( SM64DebugPrintFunctionPtr debugPrintFunction ); typedef void (*SM64PlaySoundFunctionPtr)( uint32_t soundBits, float *pos ); extern SM64_LIB_FN void sm64_register_play_sound_function( SM64PlaySoundFunctionPtr playSoundFunction ); extern SM64_LIB_FN void sm64_global_init( const uint8_t *rom, uint8_t *outTexture ); extern SM64_LIB_FN void sm64_global_terminate( void ); extern SM64_LIB_FN void sm64_audio_init( const uint8_t *rom ); extern SM64_LIB_FN uint32_t sm64_audio_tick( uint32_t numQueuedSamples, uint32_t numDesiredSamples, int16_t *audio_buffer ); extern SM64_LIB_FN void sm64_static_surfaces_load( const struct SM64Surface *surfaceArray, uint32_t numSurfaces ); extern SM64_LIB_FN int32_t sm64_mario_create( float x, float y, float z ); extern SM64_LIB_FN void sm64_mario_tick( int32_t marioId, const struct SM64MarioInputs *inputs, struct SM64MarioState *outState, struct SM64MarioGeometryBuffers *outBuffers ); extern SM64_LIB_FN void sm64_mario_delete( int32_t marioId ); extern SM64_LIB_FN void sm64_set_mario_action(int32_t marioId, uint32_t action); extern SM64_LIB_FN void sm64_set_mario_action_arg(int32_t marioId, uint32_t action, uint32_t actionArg); extern SM64_LIB_FN void sm64_set_mario_animation(int32_t marioId, int32_t animID); extern SM64_LIB_FN void sm64_set_mario_anim_frame(int32_t marioId, int16_t animFrame); extern SM64_LIB_FN void sm64_set_mario_state(int32_t marioId, uint32_t flags); extern SM64_LIB_FN void sm64_set_mario_position(int32_t marioId, float x, float y, float z); extern SM64_LIB_FN void sm64_set_mario_angle(int32_t marioId, float x, float y, float z); extern SM64_LIB_FN void sm64_set_mario_faceangle(int32_t marioId, float y); extern SM64_LIB_FN void sm64_set_mario_velocity(int32_t marioId, float x, float y, float z); extern SM64_LIB_FN void sm64_set_mario_forward_velocity(int32_t marioId, float vel); extern SM64_LIB_FN void sm64_set_mario_invincibility(int32_t marioId, int16_t timer); extern SM64_LIB_FN void sm64_set_mario_water_level(int32_t marioId, signed int level); extern SM64_LIB_FN void sm64_set_mario_gas_level(int32_t marioId, signed int level); extern SM64_LIB_FN void sm64_set_mario_health(int32_t marioId, uint16_t health); extern SM64_LIB_FN void sm64_mario_take_damage(int32_t marioId, uint32_t damage, uint32_t subtype, float x, float y, float z); extern SM64_LIB_FN void sm64_mario_heal(int32_t marioId, uint8_t healCounter); extern SM64_LIB_FN void sm64_mario_kill(int32_t marioId); extern SM64_LIB_FN void sm64_mario_interact_cap(int32_t marioId, uint32_t capFlag, uint16_t capTime, uint8_t playMusic); extern SM64_LIB_FN void sm64_mario_extend_cap(int32_t marioId, uint16_t capTime); extern SM64_LIB_FN bool sm64_mario_attack(int32_t marioId, float x, float y, float z, float hitboxHeight); extern SM64_LIB_FN uint32_t sm64_surface_object_create( const struct SM64SurfaceObject *surfaceObject ); extern SM64_LIB_FN void sm64_surface_object_move( uint32_t objectId, const struct SM64ObjectTransform *transform ); extern SM64_LIB_FN void sm64_surface_object_delete( uint32_t objectId ); extern SM64_LIB_FN int32_t sm64_surface_find_wall_collision( float *xPtr, float *yPtr, float *zPtr, float offsetY, float radius ); extern SM64_LIB_FN int32_t sm64_surface_find_wall_collisions( struct SM64WallCollisionData *colData ); extern SM64_LIB_FN float sm64_surface_find_ceil( float posX, float posY, float posZ, struct SM64SurfaceCollisionData **pceil ); extern SM64_LIB_FN float sm64_surface_find_floor_height_and_data( float xPos, float yPos, float zPos, struct SM64FloorCollisionData **floorGeo ); extern SM64_LIB_FN float sm64_surface_find_floor_height( float x, float y, float z ); extern SM64_LIB_FN float sm64_surface_find_floor( float xPos, float yPos, float zPos, struct SM64SurfaceCollisionData **pfloor ); extern SM64_LIB_FN float sm64_surface_find_water_level( float x, float z ); extern SM64_LIB_FN float sm64_surface_find_poison_gas_level( float x, float z ); extern SM64_LIB_FN void sm64_seq_player_play_sequence(uint8_t player, uint8_t seqId, uint16_t arg2); extern SM64_LIB_FN void sm64_play_music(uint8_t player, uint16_t seqArgs, uint16_t fadeTimer); extern SM64_LIB_FN void sm64_stop_background_music(uint16_t seqId); extern SM64_LIB_FN void sm64_fadeout_background_music(uint16_t arg0, uint16_t fadeOut); extern SM64_LIB_FN uint16_t sm64_get_current_background_music(); extern SM64_LIB_FN void sm64_play_sound(int32_t soundBits, float *pos); extern SM64_LIB_FN void sm64_play_sound_global(int32_t soundBits); extern SM64_LIB_FN void sm64_set_sound_volume(float vol); #ifdef __cplusplus } #endif #endif//LIB_SM64_H
48489d0db00a42b3bb90ac6035930ce86b135c62
70ffcb065027032a399f44b9ec91e7b61d73583d
/channeld/channeld.c
a2ee13dec5613f202e10f7828bfeca4bbc47c7eb
[ "MIT" ]
permissive
ElementsProject/lightning
4e260841b2ebad8c772a5ff91ef1ebbc3fe1ad71
990096f904e26386527a4eddd8d3262464bacabd
refs/heads/master
2023-09-01T07:11:34.794039
2023-08-31T09:55:14
2023-08-31T22:02:14
37,350,472
2,812
961
NOASSERTION
2023-09-14T19:33:22
2015-06-13T00:04:22
C
UTF-8
C
false
false
196,114
c
channeld.c
/* Main channel operation daemon: runs from channel_ready to shutdown_complete. * * We're fairly synchronous: our main loop looks for master or * peer requests and services them synchronously. * * The exceptions are: * 1. When we've asked the master something: in that case, we queue * non-response packets for later processing while we await the reply. * 2. We queue and send non-blocking responses to peers: if both peers were * reading and writing synchronously we could deadlock if we hit buffer * limits, unlikely as that is. */ #include "config.h" #include <bitcoin/script.h> #include <ccan/asort/asort.h> #include <ccan/cast/cast.h> #include <ccan/mem/mem.h> #include <ccan/tal/str/str.h> #include <channeld/channeld.h> #include <channeld/channeld_wiregen.h> #include <channeld/full_channel.h> #include <channeld/inflight.h> #include <channeld/splice.h> #include <channeld/watchtower.h> #include <common/billboard.h> #include <common/ecdh_hsmd.h> #include <common/gossip_store.h> #include <common/interactivetx.h> #include <common/key_derive.h> #include <common/memleak.h> #include <common/msg_queue.h> #include <common/onionreply.h> #include <common/peer_billboard.h> #include <common/peer_failed.h> #include <common/peer_io.h> #include <common/per_peer_state.h> #include <common/private_channel_announcement.h> #include <common/psbt_internal.h> #include <common/psbt_open.h> #include <common/read_peer_msg.h> #include <common/status.h> #include <common/subdaemon.h> #include <common/timeout.h> #include <common/type_to_string.h> #include <common/wire_error.h> #include <errno.h> #include <fcntl.h> #include <gossipd/gossip_store_wiregen.h> #include <gossipd/gossipd_peerd_wiregen.h> #include <hsmd/hsmd_wiregen.h> #include <stdio.h> #include <wally_bip32.h> #include <wire/peer_wire.h> #include <wire/wire_sync.h> /* stdin == requests, 3 == peer, 4 = HSM */ #define MASTER_FD STDIN_FILENO #define HSM_FD 4 #define VALID_STFU_MESSAGE(msg) \ ((msg) == WIRE_SPLICE || \ (msg) == WIRE_SPLICE_ACK) struct peer { struct per_peer_state *pps; bool channel_ready[NUM_SIDES]; u64 next_index[NUM_SIDES]; /* Features peer supports. */ u8 *their_features; /* Features we support. */ struct feature_set *our_features; /* Tolerable amounts for feerate (only relevant for fundee). */ u32 feerate_min, feerate_max; /* Feerate to be used when creating penalty transactions. */ u32 feerate_penalty; /* Local next per-commit point. */ struct pubkey next_local_per_commit; /* Remote's current per-commit point. */ struct pubkey remote_per_commit; /* Remotes's last per-commitment point: we keep this to check * revoke_and_ack's `per_commitment_secret` is correct. */ struct pubkey old_remote_per_commit; /* Their sig for current commit. */ struct bitcoin_signature their_commit_sig; /* BOLT #2: * * A sending node: *... * - for the first HTLC it offers: * - MUST set `id` to 0. */ u64 htlc_id; struct channel_id channel_id; struct channel *channel; /* Messages from master: we queue them since we might be * waiting for a specific reply. */ struct msg_queue *from_master; struct timers timers; struct oneshot *commit_timer; u32 commit_msec; /* The feerate we want. */ u32 desired_feerate; /* Current blockheight */ u32 our_blockheight; /* Announcement related information */ struct node_id node_ids[NUM_SIDES]; struct short_channel_id short_channel_ids[NUM_SIDES]; secp256k1_ecdsa_signature announcement_node_sigs[NUM_SIDES]; secp256k1_ecdsa_signature announcement_bitcoin_sigs[NUM_SIDES]; bool have_sigs[NUM_SIDES]; bool send_duplicate_announce_sigs; /* Which direction of the channel do we control? */ u16 channel_direction; /* CLTV delta to announce to peers */ u16 cltv_delta; /* We only really know these because we're the ones who create * the channel_updates. */ u32 fee_base; u32 fee_per_satoshi; /* Note: the real min constraint is channel->config[REMOTE].htlc_minimum: * they could kill the channel if we violate that! */ struct amount_msat htlc_minimum_msat, htlc_maximum_msat; /* The scriptpubkey to use for shutting down. */ u32 *final_index; struct ext_key *final_ext_key; u8 *final_scriptpubkey; /* If master told us to shut down */ bool send_shutdown; /* Has shutdown been sent by each side? */ bool shutdown_sent[NUM_SIDES]; /* If master told us to send wrong_funding */ struct bitcoin_outpoint *shutdown_wrong_funding; /* Do we want quiescence? * Note: This flag is needed seperately from `stfu_sent` so we can * detect the entering "stfu" mode. */ bool want_stfu; /* Which side is considered the initiator? */ enum side stfu_initiator; /* Has stfu been sent by each side? */ bool stfu_sent[NUM_SIDES]; /* After STFU mode is enabled, wait for a signle message flag */ bool stfu_wait_single_msg; /* Updates master asked, which we've deferred while quiescing */ struct msg_queue *update_queue; /* Callback for when when stfu is negotiated successfully */ void (*on_stfu_success)(struct peer*); struct splice_state *splice_state; struct splicing *splicing; #if DEVELOPER /* If set, don't fire commit counter when this hits 0 */ u32 *dev_disable_commit; /* If set, send channel_announcement after 1 second, not 30 */ bool dev_fast_gossip; #endif /* Information used for reestablishment. */ bool last_was_revoke; struct changed_htlc *last_sent_commit; u64 revocations_received; u8 channel_flags; bool announce_depth_reached; bool channel_local_active; /* Make sure timestamps move forward. */ u32 last_update_timestamp; /* Additional confirmations need for local lockin. */ u32 depth_togo; /* Non-empty if they specified a fixed shutdown script */ u8 *remote_upfront_shutdown_script; /* Empty commitments. Spec violation, but a minor one. */ u64 last_empty_commitment; /* Penalty bases for this channel / peer. */ struct penalty_base **pbases; /* We allow a 'tx-sigs' message between reconnect + channel_ready */ bool tx_sigs_allowed; /* Have we announced the real scid with a * local_channel_announcement? This can be different from the * `channel_local_active` flag in case we are using zeroconf, * in which case we'll have announced the channels with the * two aliases (LOCAL and REMOTE) but not with the real scid * just yet. If we get a funding depth change, with a scid, * and the two flags not equal we know we have to announce the * channel with the real scid. */ bool gossip_scid_announced; /* Most recent channel_update message. */ u8 *channel_update; /* --experimental-upgrade-protocol */ bool experimental_upgrade; }; static u8 *create_channel_announcement(const tal_t *ctx, struct peer *peer); static void start_commit_timer(struct peer *peer); static void billboard_update(const struct peer *peer) { const char *update = billboard_message(tmpctx, peer->channel_ready, peer->have_sigs, peer->shutdown_sent, peer->depth_togo, num_channel_htlcs(peer->channel)); peer_billboard(false, update); } const u8 *hsm_req(const tal_t *ctx, const u8 *req TAKES) { u8 *msg; /* hsmd goes away at shutdown. That's OK. */ if (!wire_sync_write(HSM_FD, req)) exit(0); msg = wire_sync_read(ctx, HSM_FD); if (!msg) exit(0); return msg; } static bool is_stfu_active(const struct peer *peer) { return peer->stfu_sent[LOCAL] && peer->stfu_sent[REMOTE]; } static void end_stfu_mode(struct peer *peer) { peer->want_stfu = false; peer->stfu_sent[LOCAL] = peer->stfu_sent[REMOTE] = false; peer->stfu_wait_single_msg = false; peer->on_stfu_success = NULL; status_debug("Left STFU mode."); } static void maybe_send_stfu(struct peer *peer) { if (!peer->want_stfu) return; if (pending_updates(peer->channel, LOCAL, false)) { status_info("Pending updates prevent us from STFU mode at this" " time."); } else if (!peer->stfu_sent[LOCAL]) { status_debug("Sending peer that we want to STFU."); u8 *msg = towire_stfu(NULL, &peer->channel_id, peer->stfu_initiator == LOCAL); peer_write(peer->pps, take(msg)); peer->stfu_sent[LOCAL] = true; } if (peer->stfu_sent[LOCAL] && peer->stfu_sent[REMOTE]) { /* Prevent STFU mode being inadvertantly activated twice during * splice. This occurs because the commit -> revoke_and_ack * cycle calls into `maybe_send_stfu`. The `want_stfu` flag is * to prevent triggering the entering of stfu events twice. */ peer->want_stfu = false; status_unusual("STFU complete: we are quiescent"); wire_sync_write(MASTER_FD, towire_channeld_dev_quiesce_reply(tmpctx)); peer->stfu_wait_single_msg = true; status_unusual("STFU complete: setting stfu_wait_single_msg = true"); if (peer->on_stfu_success) { peer->on_stfu_success(peer); peer->on_stfu_success = NULL; } } } static void handle_stfu(struct peer *peer, const u8 *stfu) { struct channel_id channel_id; u8 remote_initiated; if (!feature_negotiated(peer->our_features, peer->their_features, OPT_QUIESCE)) peer_failed_warn(peer->pps, &peer->channel_id, "stfu not supported"); if (!fromwire_stfu(stfu, &channel_id, &remote_initiated)) peer_failed_warn(peer->pps, &peer->channel_id, "Bad stfu %s", tal_hex(peer, stfu)); if (!channel_id_eq(&channel_id, &peer->channel_id)) { peer_failed_err(peer->pps, &channel_id, "Wrong stfu channel_id: expected %s, got %s", type_to_string(tmpctx, struct channel_id, &peer->channel_id), type_to_string(tmpctx, struct channel_id, &channel_id)); } /* Sanity check */ if (pending_updates(peer->channel, REMOTE, false)) peer_failed_warn(peer->pps, &peer->channel_id, "STFU but you still have updates pending?"); if (!peer->want_stfu) { peer->want_stfu = true; if (!remote_initiated) peer_failed_warn(peer->pps, &peer->channel_id, "Unsolicited STFU but you said" " you didn't initiate?"); peer->stfu_initiator = REMOTE; status_debug("STFU initiator was remote."); } else { /* BOLT-quiescent #2: * * If both sides send `stfu` simultaneously, they will both * set `initiator` to `1`, in which case the "initiator" is * arbitrarily considered to be the channel funder (the sender * of `open_channel`). */ if (remote_initiated) { status_debug("Dual STFU intiation tiebreaker. Setting initiator to %s", peer->channel->opener == LOCAL ? "LOCAL" : "REMOTE"); peer->stfu_initiator = peer->channel->opener; } else { status_debug("STFU initiator local."); } } /* BOLT-quiescent #2: * The receiver of `stfu`: * - if it has sent `stfu` then: * - MUST now consider the channel to be quiescent * - otherwise: * - SHOULD NOT send any more update messages. * - MUST reply with `stfu` once it can do so. */ peer->stfu_sent[REMOTE] = true; maybe_send_stfu(peer); } /* Returns true if we queued this for later handling (steals if true) */ static bool handle_master_request_later(struct peer *peer, const u8 *msg) { if (is_stfu_active(peer)) { msg_enqueue(peer->update_queue, take(msg)); return true; } return false; } /* Compare, with false if either is NULL */ static bool match_type(const u8 *t1, const u8 *t2) { /* Missing fields are possible. */ if (!t1 || !t2) return false; return featurebits_eq(t1, t2); } static void set_channel_type(struct channel *channel, const u8 *type) { const struct channel_type *cur = channel->type; if (featurebits_eq(cur->features, type)) return; /* We only allow one upgrade at the moment, so that's it. */ assert(!channel_has(channel, OPT_STATIC_REMOTEKEY)); assert(feature_offered(type, OPT_STATIC_REMOTEKEY)); /* Do upgrade, tell master. */ tal_free(channel->type); channel->type = channel_type_from(channel, type); status_unusual("Upgraded channel to [%s]", fmt_featurebits(tmpctx, type)); wire_sync_write(MASTER_FD, take(towire_channeld_upgraded(NULL, channel->type))); } /* Tell gossipd to create channel_update (then it goes into * gossip_store, then streams out to peers, or sends it directly if * it's a private channel) */ static void send_channel_update(struct peer *peer, int disable_flag) { status_debug("send_channel_update %d", disable_flag); u8 *msg; assert(disable_flag == 0 || disable_flag == ROUTING_FLAGS_DISABLED); /* Only send an update if we told gossipd */ if (!peer->channel_local_active) return; assert(peer->short_channel_ids[LOCAL].u64); msg = towire_channeld_local_channel_update(NULL, &peer->short_channel_ids[LOCAL], disable_flag == ROUTING_FLAGS_DISABLED, peer->cltv_delta, peer->htlc_minimum_msat, peer->fee_base, peer->fee_per_satoshi, peer->htlc_maximum_msat, peer->channel_flags & CHANNEL_FLAGS_ANNOUNCE_CHANNEL); wire_sync_write(MASTER_FD, take(msg)); } /* Tell gossipd and the other side what parameters we expect should * they route through us */ static void send_channel_initial_update(struct peer *peer) { /* If `stfu` is already active then the channel is being mutated quickly * after creation. These mutations (ie. splice) must announce the * channel when they finish anyway, so it is safe to skip it here */ if (!is_stfu_active(peer) && !peer->want_stfu) send_channel_update(peer, 0); } /** * Add a channel locally and send a channel update to the peer * * Send a local_add_channel message to gossipd in order to make the channel * usable locally, and also tell our peer about our parameters via a * channel_update message. The peer may accept the update and use the contained * information to route incoming payments through the channel. The * channel_update is not preceeded by a channel_announcement and won't make much * sense to other nodes, so we don't tell gossipd about it. */ static void make_channel_local_active(struct peer *peer) { u8 *msg; const u8 *annfeatures = get_agreed_channelfeatures(tmpctx, peer->our_features, peer->their_features); /* Tell lightningd to tell gossipd about local channel. */ msg = towire_channeld_local_private_channel(NULL, peer->channel->funding_sats, annfeatures); wire_sync_write(MASTER_FD, take(msg)); /* Under CI, because blocks come so fast, we often find that the * peer sends its first channel_update before the above message has * reached it. */ notleak(new_reltimer(&peer->timers, peer, time_from_sec(5), send_channel_initial_update, peer)); } static void send_announcement_signatures(struct peer *peer) { /* First 2 + 256 byte are the signatures and msg type, skip them */ size_t offset = 258; struct sha256_double hash; const u8 *msg, *ca, *req; struct pubkey mykey; status_debug("Exchanging announcement signatures."); ca = create_channel_announcement(tmpctx, peer); req = towire_hsmd_cannouncement_sig_req(tmpctx, ca); msg = hsm_req(tmpctx, req); if (!fromwire_hsmd_cannouncement_sig_reply(msg, &peer->announcement_node_sigs[LOCAL], &peer->announcement_bitcoin_sigs[LOCAL])) status_failed(STATUS_FAIL_HSM_IO, "Reading cannouncement_sig_resp: %s", strerror(errno)); /* Double-check that HSM gave valid signatures. */ sha256_double(&hash, ca + offset, tal_count(ca) - offset); if (!pubkey_from_node_id(&mykey, &peer->node_ids[LOCAL])) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Could not convert my id '%s' to pubkey", type_to_string(tmpctx, struct node_id, &peer->node_ids[LOCAL])); if (!check_signed_hash(&hash, &peer->announcement_node_sigs[LOCAL], &mykey)) { /* It's ok to fail here, the channel announcement is * unique, unlike the channel update which may have * been replaced in the meantime. */ status_failed(STATUS_FAIL_HSM_IO, "HSM returned an invalid node signature"); } if (!check_signed_hash(&hash, &peer->announcement_bitcoin_sigs[LOCAL], &peer->channel->funding_pubkey[LOCAL])) { /* It's ok to fail here, the channel announcement is * unique, unlike the channel update which may have * been replaced in the meantime. */ status_failed(STATUS_FAIL_HSM_IO, "HSM returned an invalid bitcoin signature"); } msg = towire_announcement_signatures( NULL, &peer->channel_id, &peer->short_channel_ids[LOCAL], &peer->announcement_node_sigs[LOCAL], &peer->announcement_bitcoin_sigs[LOCAL]); peer_write(peer->pps, take(msg)); } /* Tentatively create a channel_announcement, possibly with invalid * signatures. The signatures need to be collected first, by asking * the HSM and by exchanging announcement_signature messages. */ static u8 *create_channel_announcement(const tal_t *ctx, struct peer *peer) { int first, second; u8 *cannounce, *features = get_agreed_channelfeatures(tmpctx, peer->our_features, peer->their_features); if (peer->channel_direction == 0) { first = LOCAL; second = REMOTE; } else { first = REMOTE; second = LOCAL; } cannounce = towire_channel_announcement( ctx, &peer->announcement_node_sigs[first], &peer->announcement_node_sigs[second], &peer->announcement_bitcoin_sigs[first], &peer->announcement_bitcoin_sigs[second], features, &chainparams->genesis_blockhash, &peer->short_channel_ids[LOCAL], &peer->node_ids[first], &peer->node_ids[second], &peer->channel->funding_pubkey[first], &peer->channel->funding_pubkey[second]); return cannounce; } /* Once we have both, we'd better make sure we agree what they are! */ static void check_short_ids_match(struct peer *peer) { assert(peer->have_sigs[LOCAL]); assert(peer->have_sigs[REMOTE]); if (!short_channel_id_eq(&peer->short_channel_ids[LOCAL], &peer->short_channel_ids[REMOTE])) peer_failed_warn(peer->pps, &peer->channel_id, "We disagree on short_channel_ids:" " I have %s, you say %s", type_to_string(peer, struct short_channel_id, &peer->short_channel_ids[LOCAL]), type_to_string(peer, struct short_channel_id, &peer->short_channel_ids[REMOTE])); } static void announce_channel(struct peer *peer) { u8 *cannounce; cannounce = create_channel_announcement(tmpctx, peer); wire_sync_write(MASTER_FD, take(towire_channeld_local_channel_announcement(NULL, cannounce))); send_channel_update(peer, 0); } static void announce_channel_if_not_stfu(struct peer *peer) { if (!is_stfu_active(peer) && !peer->want_stfu) announce_channel(peer); } /* Returns true if an announcement was sent */ static bool channel_announcement_negotiate(struct peer *peer) { bool sent_announcement = false; /* Don't do any announcement work if we're shutting down */ if (peer->shutdown_sent[LOCAL]) return false; /* Can't do anything until funding is locked. */ if (!peer->channel_ready[LOCAL] || !peer->channel_ready[REMOTE]) return false; /* Don't announce channel if we're in stfu mode */ if (peer->want_stfu || is_stfu_active(peer)) return false; if (!peer->channel_local_active) { peer->channel_local_active = true; make_channel_local_active(peer); } else if(!peer->gossip_scid_announced) { /* So we know a short_channel_id, i.e., a point on * chain, but haven't added it to our local view of * the gossip yet. We need to add it now (and once * only), so our `channel_update` we'll send a couple * of lines down has something to attach to. */ peer->gossip_scid_announced = true; make_channel_local_active(peer); } /* BOLT #7: * * A node: * - if the `open_channel` message has the `announce_channel` bit set AND a `shutdown` message has not been sent: * - MUST send the `announcement_signatures` message. * - MUST NOT send `announcement_signatures` messages until `channel_ready` * has been sent and received AND the funding transaction has at least six confirmations. * - otherwise: * - MUST NOT send the `announcement_signatures` message. */ if (!(peer->channel_flags & CHANNEL_FLAGS_ANNOUNCE_CHANNEL)) return false; /* BOLT #7: * * - MUST NOT send `announcement_signatures` messages until `channel_ready` * has been sent and received AND the funding transaction has at least six confirmations. */ if (peer->announce_depth_reached && !peer->have_sigs[LOCAL]) { /* When we reenable the channel, we will also send the announcement to remote peer, and * receive the remote announcement reply. But we will rebuild the channel with announcement * from the DB directly, other than waiting for the remote announcement reply. */ send_announcement_signatures(peer); peer->have_sigs[LOCAL] = true; billboard_update(peer); sent_announcement = true; } /* If we've completed the signature exchange, we can send a real * announcement, otherwise we send a temporary one */ if (peer->have_sigs[LOCAL] && peer->have_sigs[REMOTE]) { check_short_ids_match(peer); /* After making sure short_channel_ids match, we can send remote * announcement to MASTER. */ wire_sync_write(MASTER_FD, take(towire_channeld_got_announcement(NULL, &peer->announcement_node_sigs[REMOTE], &peer->announcement_bitcoin_sigs[REMOTE]))); /* Give other nodes time to notice new block. */ notleak(new_reltimer(&peer->timers, peer, time_from_sec(GOSSIP_ANNOUNCE_DELAY(peer->dev_fast_gossip)), announce_channel_if_not_stfu, peer)); } return sent_announcement; } /* Call this method when splice_locked status are changed. If both sides have * splice_locked'ed than this function consumes the `splice_locked_ready` values * and considers the channel funding to be switched to the splice tx. */ static void check_mutual_splice_locked(struct peer *peer) { u8 *msg; const char *error; struct inflight *inflight; /* If both sides haven't `splice_locked` we're not ready */ if (!peer->splice_state->locked_ready[LOCAL] || !peer->splice_state->locked_ready[REMOTE]) return; if (short_channel_id_eq(&peer->short_channel_ids[LOCAL], &peer->splice_state->short_channel_id)) peer_failed_warn(peer->pps, &peer->channel_id, "Duplicate splice_locked events detected"); peer->splice_state->await_commitment_succcess = true; /* This splice_locked event is used, so reset the flags to false */ peer->splice_state->locked_ready[LOCAL] = false; peer->splice_state->locked_ready[REMOTE] = false; peer->have_sigs[LOCAL] = false; peer->have_sigs[REMOTE] = false; peer->send_duplicate_announce_sigs = true; peer->splice_state->last_short_channel_id = peer->short_channel_ids[LOCAL]; peer->short_channel_ids[LOCAL] = peer->splice_state->short_channel_id; peer->short_channel_ids[REMOTE] = peer->splice_state->short_channel_id; peer->channel->view[LOCAL].lowest_splice_amnt[LOCAL] = 0; peer->channel->view[LOCAL].lowest_splice_amnt[REMOTE] = 0; peer->channel->view[REMOTE].lowest_splice_amnt[LOCAL] = 0; peer->channel->view[REMOTE].lowest_splice_amnt[REMOTE] = 0; status_debug("mutual splice_locked, scid LOCAL & REMOTE updated to: %s", type_to_string(tmpctx, struct short_channel_id, &peer->splice_state->short_channel_id)); inflight = NULL; for (size_t i = 0; i < tal_count(peer->splice_state->inflights); i++) if (bitcoin_txid_eq(&peer->splice_state->inflights[i]->outpoint.txid, &peer->splice_state->locked_txid)) inflight = peer->splice_state->inflights[i]; if (!inflight) peer_failed_warn(peer->pps, &peer->channel_id, "Unable to find inflight txid amoung %zu" " inflights. new funding txid: %s", tal_count(peer->splice_state->inflights), type_to_string(tmpctx, struct bitcoin_txid, &peer->splice_state->locked_txid)); status_debug("mutual splice_locked, updating change from: %s", type_to_string(tmpctx, struct channel, peer->channel)); error = channel_update_funding(peer->channel, &inflight->outpoint, inflight->amnt, inflight->splice_amnt); if (error) peer_failed_warn(peer->pps, &peer->channel_id, "Splice lock unable to update funding. %s", error); status_debug("mutual splice_locked, channel updated to: %s", type_to_string(tmpctx, struct channel, peer->channel)); msg = towire_channeld_got_splice_locked(NULL, inflight->amnt, inflight->splice_amnt, &inflight->outpoint.txid); wire_sync_write(MASTER_FD, take(msg)); channel_announcement_negotiate(peer); billboard_update(peer); send_channel_update(peer, 0); /* valgrind complains last_tx is leaked so we explicitly free it * DTODO: investigate this more. */ for (size_t i = 0; i < tal_count(peer->splice_state->inflights); i++) { inflight = peer->splice_state->inflights[i]; tal_free(inflight->last_tx); tal_free(inflight); } peer->splice_state->inflights = tal_free(peer->splice_state->inflights); peer->splice_state->count = 0; peer->splice_state->revoked_count = 0; peer->splice_state->committed_count = 0; } /* Our peer told us they saw our splice confirm on chain with `splice_locked`. * If we see it to we jump into tansitioning to post-splice, otherwise we mark * a flag and wait until we see it on chain too. */ static void handle_peer_splice_locked(struct peer *peer, const u8 *msg) { struct channel_id chanid; if (!fromwire_splice_locked(msg, &chanid)) peer_failed_warn(peer->pps, &peer->channel_id, "Bad splice_locked %s", tal_hex(msg, msg)); if (!channel_id_eq(&chanid, &peer->channel_id)) peer_failed_err(peer->pps, &chanid, "Wrong splice lock channel id in %s " "(expected %s)", tal_hex(tmpctx, msg), type_to_string(msg, struct channel_id, &peer->channel_id)); peer->splice_state->locked_ready[REMOTE] = true; check_mutual_splice_locked(peer); } static void handle_peer_channel_ready(struct peer *peer, const u8 *msg) { struct channel_id chanid; struct tlv_channel_ready_tlvs *tlvs; /* BOLT #2: * * A node: *... * - upon reconnection: * - MUST ignore any redundant `channel_ready` it receives. */ if (peer->channel_ready[REMOTE]) return; /* Too late, we're shutting down! */ if (peer->shutdown_sent[LOCAL]) return; peer->old_remote_per_commit = peer->remote_per_commit; if (!fromwire_channel_ready(msg, msg, &chanid, &peer->remote_per_commit, &tlvs)) peer_failed_warn(peer->pps, &peer->channel_id, "Bad channel_ready %s", tal_hex(msg, msg)); if (!channel_id_eq(&chanid, &peer->channel_id)) peer_failed_err(peer->pps, &chanid, "Wrong channel id in %s (expected %s)", tal_hex(tmpctx, msg), type_to_string(msg, struct channel_id, &peer->channel_id)); peer->tx_sigs_allowed = false; peer->channel_ready[REMOTE] = true; if (tlvs->short_channel_id != NULL) { status_debug( "Peer told us that they'll use alias=%s for this channel", type_to_string(tmpctx, struct short_channel_id, tlvs->short_channel_id)); peer->short_channel_ids[REMOTE] = *tlvs->short_channel_id; } wire_sync_write(MASTER_FD, take(towire_channeld_got_channel_ready( NULL, &peer->remote_per_commit, tlvs->short_channel_id))); channel_announcement_negotiate(peer); billboard_update(peer); peer->send_duplicate_announce_sigs = true; } /* Checks that key is valid, and signed this hash * * FIXME: move this inside common/utils.h */ static bool check_signed_hash_nodeid(const struct sha256_double *hash, const secp256k1_ecdsa_signature *signature, const struct node_id *id) { struct pubkey key; return pubkey_from_node_id(&key, id) && check_signed_hash(hash, signature, &key); } static void handle_peer_announcement_signatures(struct peer *peer, const u8 *msg) { const u8 *cannounce; struct channel_id chanid; struct sha256_double hash; struct short_channel_id remote_scid; if (!fromwire_announcement_signatures(msg, &chanid, &remote_scid, &peer->announcement_node_sigs[REMOTE], &peer->announcement_bitcoin_sigs[REMOTE])) peer_failed_warn(peer->pps, &peer->channel_id, "Bad announcement_signatures %s", tal_hex(msg, msg)); /* BOLT-0d8b701614b09c6ee4172b04da2203e73deec7e2 #2: * Once a node has received and sent `splice_locked`: * - Until sending OR receiving of `revoke_and_ack` * - MUST ignore `announcement_signatures` messages where * `short_channel_id` matches the pre-splice short channel id. */ if (peer->splice_state->await_commitment_succcess && !short_channel_id_eq(&remote_scid, &peer->short_channel_ids[LOCAL])) status_info("Ignoring stale announcement_signatures: expected" " %s, got %s", type_to_string(tmpctx, struct short_channel_id, &peer->short_channel_ids[REMOTE]), type_to_string(tmpctx, struct short_channel_id, &peer->short_channel_ids[LOCAL])); peer->short_channel_ids[REMOTE] = remote_scid; /* Make sure we agree on the channel ids */ if (!channel_id_eq(&chanid, &peer->channel_id)) { peer_failed_err(peer->pps, &chanid, "Wrong channel_id: expected %s, got %s", type_to_string(tmpctx, struct channel_id, &peer->channel_id), type_to_string(tmpctx, struct channel_id, &chanid)); } /* BOLT 7: * - if the node_signature OR the bitcoin_signature is NOT correct: * - MAY send a warning and close the connection, or send an error and fail the channel. * * In our case, we send an error and stop the open channel procedure. This approach is * considered overly strict since the peer can recover from it. However, this step is * optional. If the peer sends it, we assume that the signature must be correct.*/ cannounce = create_channel_announcement(tmpctx, peer); /* 2 byte msg type + 256 byte signatures */ int offset = 258; sha256_double(&hash, cannounce + offset, tal_count(cannounce) - offset); if (!check_signed_hash_nodeid(&hash, &peer->announcement_node_sigs[REMOTE], &peer->node_ids[REMOTE])) { peer_failed_warn(peer->pps, &chanid, "Bad node_signature %s hash %s" " on announcement_signatures %s", type_to_string(tmpctx, secp256k1_ecdsa_signature, &peer->announcement_node_sigs[REMOTE]), type_to_string(tmpctx, struct sha256_double, &hash), tal_hex(tmpctx, cannounce)); } if (!check_signed_hash(&hash, &peer->announcement_bitcoin_sigs[REMOTE], &peer->channel->funding_pubkey[REMOTE])) { peer_failed_warn(peer->pps, &chanid, "Bad bitcoin_signature %s hash %s" " on announcement_signatures %s", type_to_string(tmpctx, secp256k1_ecdsa_signature, &peer->announcement_bitcoin_sigs[REMOTE]), type_to_string(tmpctx, struct sha256_double, &hash), tal_hex(tmpctx, cannounce)); } peer->have_sigs[REMOTE] = true; billboard_update(peer); if (!channel_announcement_negotiate(peer) && peer->send_duplicate_announce_sigs && peer->have_sigs[LOCAL]) { peer->send_duplicate_announce_sigs = false; send_announcement_signatures(peer); } } static void handle_peer_add_htlc(struct peer *peer, const u8 *msg) { struct channel_id channel_id; u64 id; struct amount_msat amount; u32 cltv_expiry; struct sha256 payment_hash; u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)]; enum channel_add_err add_err; struct htlc *htlc; struct tlv_update_add_htlc_tlvs *tlvs; if (!fromwire_update_add_htlc(msg, msg, &channel_id, &id, &amount, &payment_hash, &cltv_expiry, onion_routing_packet, &tlvs) /* This is an *even* field: don't send if we didn't understand */ || (tlvs->blinding_point && !feature_offered(peer->our_features->bits[INIT_FEATURE], OPT_ROUTE_BLINDING))) { peer_failed_warn(peer->pps, &peer->channel_id, "Bad peer_add_htlc %s", tal_hex(msg, msg)); } add_err = channel_add_htlc(peer->channel, REMOTE, id, amount, cltv_expiry, &payment_hash, onion_routing_packet, tlvs->blinding_point, &htlc, NULL, /* We don't immediately fail incoming htlcs, * instead we wait and fail them after * they've been committed */ false); if (add_err != CHANNEL_ERR_ADD_OK) peer_failed_warn(peer->pps, &peer->channel_id, "Bad peer_add_htlc: %s", channel_add_err_name(add_err)); } /* We don't get upset if they're outside the range, as long as they're * improving (or at least, not getting worse!). */ static bool feerate_same_or_better(const struct channel *channel, u32 feerate, u32 feerate_min, u32 feerate_max) { u32 current = channel_feerate(channel, LOCAL); /* Too low? But is it going upwards? */ if (feerate < feerate_min) return feerate >= current; if (feerate > feerate_max) return feerate <= current; return true; } static void handle_peer_feechange(struct peer *peer, const u8 *msg) { struct channel_id channel_id; u32 feerate; if (!fromwire_update_fee(msg, &channel_id, &feerate)) { peer_failed_warn(peer->pps, &peer->channel_id, "Bad update_fee %s", tal_hex(msg, msg)); } /* BOLT #2: * * A receiving node: *... * - if the sender is not responsible for paying the Bitcoin fee: * - MUST send a `warning` and close the connection, or send an * `error` and fail the channel. */ if (peer->channel->opener != REMOTE) peer_failed_warn(peer->pps, &peer->channel_id, "update_fee from non-opener?"); status_debug("update_fee %u, range %u-%u", feerate, peer->feerate_min, peer->feerate_max); /* BOLT #2: * * A receiving node: * - if the `update_fee` is too low for timely processing, OR is * unreasonably large: * - MUST send a `warning` and close the connection, or send an * `error` and fail the channel. */ if (!feerate_same_or_better(peer->channel, feerate, peer->feerate_min, peer->feerate_max)) peer_failed_warn(peer->pps, &peer->channel_id, "update_fee %u outside range %u-%u" " (currently %u)", feerate, peer->feerate_min, peer->feerate_max, channel_feerate(peer->channel, LOCAL)); /* BOLT #2: * * - if the sender cannot afford the new fee rate on the receiving * node's current commitment transaction: * - SHOULD send a `warning` and close the connection, or send an * `error` and fail the channel. * - but MAY delay this check until the `update_fee` is committed. */ if (!channel_update_feerate(peer->channel, feerate)) peer_failed_warn(peer->pps, &peer->channel_id, "update_fee %u unaffordable", feerate); status_debug("peer updated fee to %u", feerate); } static void handle_peer_blockheight_change(struct peer *peer, const u8 *msg) { struct channel_id channel_id; u32 blockheight, current; if (!fromwire_update_blockheight(msg, &channel_id, &blockheight)) peer_failed_warn(peer->pps, &peer->channel_id, "Bad update_blockheight %s", tal_hex(msg, msg)); /* BOLT- #2: * A receiving node: * ... * - if the sender is not the initiator: * - MUST fail the channel. */ if (peer->channel->opener != REMOTE) peer_failed_warn(peer->pps, &peer->channel_id, "update_blockheight from non-opener?"); current = get_blockheight(peer->channel->blockheight_states, peer->channel->opener, LOCAL); status_debug("update_blockheight %u. last update height %u," " our current height %u", blockheight, current, peer->our_blockheight); /* BOLT- #2: * A receiving node: * - if the `update_blockheight` is less than the last * received `blockheight`: * - SHOULD fail the channel. * ... * - if `blockheight` is more than 1008 blocks behind * the current blockheight: * - SHOULD fail the channel */ /* Overflow check */ if (blockheight + 1008 < blockheight) peer_failed_warn(peer->pps, &peer->channel_id, "blockheight + 1008 overflow (%u)", blockheight); /* If they're behind the last one they sent, we just warn and * reconnect, as they might be catching up */ /* FIXME: track for how long they send backwards blockheight? */ if (blockheight < current) peer_failed_warn(peer->pps, &peer->channel_id, "update_blockheight %u older than previous %u", blockheight, current); /* BOLT- #2: * A receiving node: * ... * - if `blockheight` is more than 1008 blocks behind * the current blockheight: * - SHOULD fail the channel */ assert(blockheight < blockheight + 1008); if (blockheight + 1008 < peer->our_blockheight) peer_failed_err(peer->pps, &peer->channel_id, "update_blockheight %u outside" " permissible range", blockheight); channel_update_blockheight(peer->channel, blockheight); status_debug("peer updated blockheight to %u", blockheight); } static struct changed_htlc *changed_htlc_arr(const tal_t *ctx, const struct htlc **changed_htlcs) { struct changed_htlc *changed; size_t i; changed = tal_arr(ctx, struct changed_htlc, tal_count(changed_htlcs)); for (i = 0; i < tal_count(changed_htlcs); i++) { changed[i].id = changed_htlcs[i]->id; changed[i].newstate = changed_htlcs[i]->state; } return changed; } static u8 *sending_commitsig_msg(const tal_t *ctx, u64 remote_commit_index, struct penalty_base *pbase, const struct fee_states *fee_states, const struct height_states *blockheight_states, const struct htlc **changed_htlcs, const struct bitcoin_signature *commit_sig, const struct bitcoin_signature *htlc_sigs) { struct changed_htlc *changed; u8 *msg; /* We tell master what (of our) HTLCs peer will now be * committed to. */ changed = changed_htlc_arr(tmpctx, changed_htlcs); msg = towire_channeld_sending_commitsig(ctx, remote_commit_index, pbase, fee_states, blockheight_states, changed, commit_sig, htlc_sigs); return msg; } static bool shutdown_complete(const struct peer *peer) { return peer->shutdown_sent[LOCAL] && peer->shutdown_sent[REMOTE] && num_channel_htlcs(peer->channel) == 0 /* We could be awaiting revoke-and-ack for a feechange */ && peer->revocations_received == peer->next_index[REMOTE] - 1; } /* BOLT #2: * * A sending node: *... * - if there are updates pending on the receiving node's commitment * transaction: * - MUST NOT send a `shutdown`. */ /* So we only call this after reestablish or immediately after sending commit */ static void maybe_send_shutdown(struct peer *peer) { u8 *msg; struct tlv_shutdown_tlvs *tlvs; if (!peer->send_shutdown) return; /* DTODO: Ensure 'shutdown' rules around splice are followed once those * rules get settled on spec */ /* Send a disable channel_update so others don't try to route * over us */ send_channel_update(peer, ROUTING_FLAGS_DISABLED); if (peer->shutdown_wrong_funding) { tlvs = tlv_shutdown_tlvs_new(tmpctx); tlvs->wrong_funding = tal(tlvs, struct tlv_shutdown_tlvs_wrong_funding); tlvs->wrong_funding->txid = peer->shutdown_wrong_funding->txid; tlvs->wrong_funding->outnum = peer->shutdown_wrong_funding->n; } else tlvs = NULL; msg = towire_shutdown(NULL, &peer->channel_id, peer->final_scriptpubkey, tlvs); peer_write(peer->pps, take(msg)); peer->send_shutdown = false; peer->shutdown_sent[LOCAL] = true; billboard_update(peer); } static void send_shutdown_complete(struct peer *peer) { /* Now we can tell master shutdown is complete. */ wire_sync_write(MASTER_FD, take(towire_channeld_shutdown_complete(NULL))); per_peer_state_fdpass_send(MASTER_FD, peer->pps); /* Give master a chance to pass the fd along */ sleep(1); close(MASTER_FD); } /* This queues other traffic from the fd until we get reply. */ static u8 *master_wait_sync_reply(const tal_t *ctx, struct peer *peer, const u8 *msg, int replytype) { u8 *reply; status_debug("Sending master %u", fromwire_peektype(msg)); if (!wire_sync_write(MASTER_FD, msg)) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Could not set sync write to master: %s", strerror(errno)); status_debug("... , awaiting %u", replytype); for (;;) { int type; reply = wire_sync_read(ctx, MASTER_FD); if (!reply) status_failed(STATUS_FAIL_MASTER_IO, "Could not set sync read from master: %s", strerror(errno)); type = fromwire_peektype(reply); if (type == replytype) { status_debug("Got it!"); break; } status_debug("Nope, got %u instead", type); msg_enqueue(peer->from_master, take(reply)); } return reply; } /* Collect the htlcs for call to hsmd. */ static struct simple_htlc **collect_htlcs(const tal_t *ctx, const struct htlc **htlc_map) { struct simple_htlc **htlcs; htlcs = tal_arr(ctx, struct simple_htlc *, 0); size_t num_entries = tal_count(htlc_map); for (size_t ndx = 0; ndx < num_entries; ++ndx) { struct htlc const *hh = htlc_map[ndx]; if (hh) { struct simple_htlc *simple = new_simple_htlc(htlcs, htlc_state_owner(hh->state), hh->amount, &hh->rhash, hh->expiry.locktime); tal_arr_expand(&htlcs, simple); } } return htlcs; } /* Returns HTLC sigs, sets commit_sig. Also used for making commitsigs for each * splice awaiting on-chain confirmation. */ static struct bitcoin_signature *calc_commitsigs(const tal_t *ctx, const struct peer *peer, struct bitcoin_tx **txs, const u8 *funding_wscript, const struct htlc **htlc_map, u64 commit_index, struct bitcoin_signature *commit_sig) { struct simple_htlc **htlcs; size_t i; struct pubkey local_htlckey; const u8 *msg; struct bitcoin_signature *htlc_sigs; htlcs = collect_htlcs(tmpctx, htlc_map); msg = towire_hsmd_sign_remote_commitment_tx(NULL, txs[0], &peer->channel->funding_pubkey[REMOTE], &peer->remote_per_commit, channel_has(peer->channel, OPT_STATIC_REMOTEKEY), commit_index, (const struct simple_htlc **) htlcs, channel_feerate(peer->channel, REMOTE)); msg = hsm_req(tmpctx, take(msg)); if (!fromwire_hsmd_sign_tx_reply(msg, commit_sig)) status_failed(STATUS_FAIL_HSM_IO, "Reading sign_remote_commitment_tx reply: %s", tal_hex(tmpctx, msg)); status_debug("Creating commit_sig signature %"PRIu64" %s for tx %s wscript %s key %s", commit_index, type_to_string(tmpctx, struct bitcoin_signature, commit_sig), type_to_string(tmpctx, struct bitcoin_tx, txs[0]), tal_hex(tmpctx, funding_wscript), type_to_string(tmpctx, struct pubkey, &peer->channel->funding_pubkey[LOCAL])); dump_htlcs(peer->channel, "Sending commit_sig"); if (!derive_simple_key(&peer->channel->basepoints[LOCAL].htlc, &peer->remote_per_commit, &local_htlckey)) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Deriving local_htlckey"); /* BOLT #2: * * A sending node: *... * - MUST include one `htlc_signature` for every HTLC transaction * corresponding to the ordering of the commitment transaction */ htlc_sigs = tal_arr(ctx, struct bitcoin_signature, tal_count(txs) - 1); for (i = 0; i < tal_count(htlc_sigs); i++) { u8 *wscript; wscript = bitcoin_tx_output_get_witscript(tmpctx, txs[0], txs[i+1]->wtx->inputs[0].index); msg = towire_hsmd_sign_remote_htlc_tx(NULL, txs[i + 1], wscript, &peer->remote_per_commit, channel_has_anchors(peer->channel)); msg = hsm_req(tmpctx, take(msg)); if (!fromwire_hsmd_sign_tx_reply(msg, &htlc_sigs[i])) status_failed(STATUS_FAIL_HSM_IO, "Bad sign_remote_htlc_tx reply: %s", tal_hex(tmpctx, msg)); status_debug("Creating HTLC signature %s for tx %s wscript %s key %s", type_to_string(tmpctx, struct bitcoin_signature, &htlc_sigs[i]), type_to_string(tmpctx, struct bitcoin_tx, txs[1+i]), tal_hex(tmpctx, wscript), type_to_string(tmpctx, struct pubkey, &local_htlckey)); assert(check_tx_sig(txs[1+i], 0, NULL, wscript, &local_htlckey, &htlc_sigs[i])); } return htlc_sigs; } /* Peer protocol doesn't want sighash flags. */ static secp256k1_ecdsa_signature *raw_sigs(const tal_t *ctx, const struct bitcoin_signature *sigs) { secp256k1_ecdsa_signature *raw; raw = tal_arr(ctx, secp256k1_ecdsa_signature, tal_count(sigs)); for (size_t i = 0; i < tal_count(sigs); i++) raw[i] = sigs[i].s; return raw; } static struct bitcoin_signature *unraw_sigs(const tal_t *ctx, const secp256k1_ecdsa_signature *raw, bool option_anchor_outputs) { struct bitcoin_signature *sigs; sigs = tal_arr(ctx, struct bitcoin_signature, tal_count(raw)); for (size_t i = 0; i < tal_count(raw); i++) { sigs[i].s = raw[i]; /* BOLT #3: * ## HTLC-Timeout and HTLC-Success Transactions *... * * if `option_anchors` applies to this commitment * transaction, `SIGHASH_SINGLE|SIGHASH_ANYONECANPAY` is * used as described in [BOLT #5] */ if (option_anchor_outputs) sigs[i].sighash_type = SIGHASH_SINGLE|SIGHASH_ANYONECANPAY; else sigs[i].sighash_type = SIGHASH_ALL; } return sigs; } /* Do we want to update fees? */ static bool want_fee_update(const struct peer *peer, u32 *target) { u32 current, val; if (peer->channel->opener != LOCAL) return false; /* No fee update while quiescing! */ if (peer->want_stfu || is_stfu_active(peer)) return false; current = channel_feerate(peer->channel, REMOTE); /* max is *approximate*: only take it into account if we're * trying to increase feerate. */ if (peer->desired_feerate > current) { /* FIXME: We should avoid adding HTLCs until we can meet this * feerate! */ u32 max = approx_max_feerate(peer->channel); val = peer->desired_feerate; /* Respect max, but don't let us *decrease* us */ if (val > max) val = max; if (val < current) val = current; } else val = peer->desired_feerate; if (target) *target = val; return val != current; } /* Do we want to update blockheight? */ static bool want_blockheight_update(const struct peer *peer, u32 *height) { u32 last; if (peer->channel->opener != LOCAL) return false; if (peer->channel->lease_expiry == 0) return false; /* No fee update while quiescing! */ if (peer->want_stfu || is_stfu_active(peer)) return false; /* What's the current blockheight */ last = get_blockheight(peer->channel->blockheight_states, peer->channel->opener, LOCAL); if (peer->our_blockheight < last) { status_broken("current blockheight %u less than last %u", peer->our_blockheight, last); return false; } if (peer->our_blockheight == last) return false; if (height) *height = peer->our_blockheight; return true; } static u8 *send_commit_part(struct peer *peer, const struct bitcoin_outpoint *funding, struct amount_sat funding_sats, const struct htlc **changed_htlcs, bool notify_master, s64 splice_amnt, s64 remote_splice_amnt) { u8 *msg; struct bitcoin_signature commit_sig, *htlc_sigs; struct bitcoin_tx **txs; const u8 *funding_wscript; const struct htlc **htlc_map; struct wally_tx_output *direct_outputs[NUM_SIDES]; struct penalty_base *pbase; struct tlv_commitment_signed_tlvs *cs_tlv = tlv_commitment_signed_tlvs_new(tmpctx); /* In theory, peer will ignore TLV 1 as unknown, but while * spec is in flux this is dangerous, as it may change: so don't * send unless negotiated */ if (feature_negotiated(peer->our_features, peer->their_features, OPT_EXPERIMENTAL_SPLICE)) { status_debug("send_commit_part(splice: %d, remote_splice: %d)", (int)splice_amnt, (int)remote_splice_amnt); cs_tlv->splice_info = tal(cs_tlv, struct channel_id); derive_channel_id(cs_tlv->splice_info, funding); } txs = channel_splice_txs(tmpctx, funding, funding_sats, &htlc_map, direct_outputs, &funding_wscript, peer->channel, &peer->remote_per_commit, peer->next_index[REMOTE], REMOTE, splice_amnt, remote_splice_amnt); htlc_sigs = calc_commitsigs(tmpctx, peer, txs, funding_wscript, htlc_map, peer->next_index[REMOTE], &commit_sig); if (direct_outputs[LOCAL] != NULL) { pbase = penalty_base_new(tmpctx, peer->next_index[REMOTE], txs[0], direct_outputs[LOCAL]); /* Add the penalty_base to our in-memory list as well, so we * can find it again later. */ tal_arr_expand(&peer->pbases, tal_steal(peer, pbase)); } else pbase = NULL; #if DEVELOPER if (peer->dev_disable_commit) { (*peer->dev_disable_commit)--; if (*peer->dev_disable_commit == 0) status_unusual("dev-disable-commit-after: disabling"); } #endif if (notify_master) { status_debug("Telling master we're about to commit..."); /* Tell master to save this next commit to database, then wait. */ msg = sending_commitsig_msg(NULL, peer->next_index[REMOTE], pbase, peer->channel->fee_states, peer->channel->blockheight_states, changed_htlcs, &commit_sig, htlc_sigs); /* Message is empty; receiving it is the point. */ master_wait_sync_reply(tmpctx, peer, take(msg), WIRE_CHANNELD_SENDING_COMMITSIG_REPLY); status_debug("Sending commit_sig with %zu htlc sigs", tal_count(htlc_sigs)); } msg = towire_commitment_signed(NULL, &peer->channel_id, &commit_sig.s, raw_sigs(tmpctx, htlc_sigs), cs_tlv); return msg; } /* unlike amount.h, we expect negative values for a - b. */ static s64 sats_diff(struct amount_sat a, struct amount_sat b) { return (s64)a.satoshis - (s64)b.satoshis; /* Raw: splicing numbers can wrap! */ } static void send_commit(struct peer *peer) { const struct htlc **changed_htlcs; u32 our_blockheight; u32 feerate_target; u8 **msgs = tal_arr(tmpctx, u8*, 1); u8 *msg; #if DEVELOPER if (peer->dev_disable_commit && !*peer->dev_disable_commit) { peer->commit_timer = NULL; return; } #endif /* FIXME: Document this requirement in BOLT 2! */ /* We can't send two commits in a row. */ if (peer->revocations_received != peer->next_index[REMOTE] - 1) { assert(peer->revocations_received == peer->next_index[REMOTE] - 2); status_debug("Can't send commit: waiting for revoke_and_ack"); /* Mark this as done: handle_peer_revoke_and_ack will * restart. */ peer->commit_timer = NULL; return; } /* BOLT #2: * * - if no HTLCs remain in either commitment transaction (including dust HTLCs) * and neither side has a pending `revoke_and_ack` to send: * - MUST NOT send any `update` message after that point. */ if (peer->shutdown_sent[LOCAL] && !num_channel_htlcs(peer->channel)) { status_debug("Can't send commit: final shutdown phase"); peer->commit_timer = NULL; return; } /* If we wanted to update fees, do it now. */ if (want_fee_update(peer, &feerate_target)) { /* FIXME: We occasionally desynchronize with LND here, so * don't stress things by having more than one feerate change * in-flight! */ if (feerate_changes_done(peer->channel->fee_states, false)) { /* BOLT-919 #2: * * A sending node: * - if the `dust_balance_on_counterparty_tx` at the * new `dust_buffer_feerate` is superior to * `max_dust_htlc_exposure_msat`: * - MAY NOT send `update_fee` * - MAY fail the channel * - if the `dust_balance_on_holder_tx` at the * new `dust_buffer_feerate` is superior to * the `max_dust_htlc_exposure_msat`: * - MAY NOT send `update_fee` * - MAY fail the channel */ /* Is this feerate update going to push the committed * htlcs over our allowed dust limits? */ if (!htlc_dust_ok(peer->channel, feerate_target, REMOTE) || !htlc_dust_ok(peer->channel, feerate_target, LOCAL)) peer_failed_warn(peer->pps, &peer->channel_id, "Too much dust to update fee (Desired" " feerate update %d)", feerate_target); if (!channel_update_feerate(peer->channel, feerate_target)) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Could not afford feerate %u" " (vs max %u)", feerate_target, approx_max_feerate(peer->channel)); msg = towire_update_fee(NULL, &peer->channel_id, feerate_target); peer_write(peer->pps, take(msg)); } } if (want_blockheight_update(peer, &our_blockheight)) { if (blockheight_changes_done(peer->channel->blockheight_states, false)) { channel_update_blockheight(peer->channel, our_blockheight); msg = towire_update_blockheight(NULL, &peer->channel_id, our_blockheight); peer_write(peer->pps, take(msg)); } } /* BOLT #2: * * A sending node: * - MUST NOT send a `commitment_signed` message that does not include * any updates. */ changed_htlcs = tal_arr(tmpctx, const struct htlc *, 0); if (peer->splice_state->committed_count == peer->splice_state->count && !channel_sending_commit(peer->channel, &changed_htlcs)) { status_debug("Can't send commit: nothing to send," " feechange %s (%s)" " blockheight %s (%s)", want_fee_update(peer, NULL) ? "wanted": "not wanted", type_to_string(tmpctx, struct fee_states, peer->channel->fee_states), want_blockheight_update(peer, NULL) ? "wanted" : "not wanted", type_to_string(tmpctx, struct height_states, peer->channel->blockheight_states)); /* Covers the case where we've just been told to shutdown. */ maybe_send_shutdown(peer); peer->commit_timer = NULL; return; } msgs[0] = send_commit_part(peer, &peer->channel->funding, peer->channel->funding_sats, changed_htlcs, true, 0, 0); /* Loop over current inflights * BOLT-0d8b701614b09c6ee4172b04da2203e73deec7e2 #2: * * A sending node: *... * - MUST first send a `commitment_signed` for the active channel then immediately * send a `commitment_signed` for each splice awaiting confirmation, in increasing * feerate order. */ for (u32 i = 0; i < tal_count(peer->splice_state->inflights); i++) { s64 funding_diff = sats_diff(peer->splice_state->inflights[i]->amnt, peer->channel->funding_sats); s64 remote_splice_amnt = funding_diff - peer->splice_state->inflights[i]->splice_amnt; tal_arr_expand(&msgs, send_commit_part(peer, &peer->splice_state->inflights[i]->outpoint, peer->splice_state->inflights[i]->amnt, changed_htlcs, false, peer->splice_state->inflights[i]->splice_amnt, remote_splice_amnt)); } peer->next_index[REMOTE]++; for(u32 i = 0; i < tal_count(msgs); i++) peer_write(peer->pps, take(msgs[i])); peer->splice_state->committed_count = peer->splice_state->count; maybe_send_shutdown(peer); /* Timer now considered expired, you can add a new one. */ peer->commit_timer = NULL; start_commit_timer(peer); } static void send_commit_if_not_stfu(struct peer *peer) { if (!is_stfu_active(peer) && !peer->want_stfu) { send_commit(peer); } else { /* Timer now considered expired, you can add a new one. */ peer->commit_timer = NULL; start_commit_timer(peer); } } static void start_commit_timer(struct peer *peer) { /* Already armed? */ if (peer->commit_timer) return; peer->commit_timer = new_reltimer(&peer->timers, peer, time_from_msec(peer->commit_msec), send_commit_if_not_stfu, peer); } /* If old_secret is NULL, we don't care, otherwise it is filled in. */ static void get_per_commitment_point(u64 index, struct pubkey *point, struct secret *old_secret) { struct secret *s; const u8 *msg; msg = hsm_req(tmpctx, take(towire_hsmd_get_per_commitment_point(NULL, index))); if (!fromwire_hsmd_get_per_commitment_point_reply(tmpctx, msg, point, &s)) status_failed(STATUS_FAIL_HSM_IO, "Bad per_commitment_point reply %s", tal_hex(tmpctx, msg)); if (old_secret) { if (!s) status_failed(STATUS_FAIL_HSM_IO, "No secret in per_commitment_point_reply %" PRIu64, index); *old_secret = *s; } } /* revoke_index == current index - 1 (usually; not for retransmission) */ static u8 *make_revocation_msg(const struct peer *peer, u64 revoke_index, struct pubkey *point) { struct secret old_commit_secret; get_per_commitment_point(revoke_index+2, point, &old_commit_secret); return towire_revoke_and_ack(peer, &peer->channel_id, &old_commit_secret, point); } static u8 *make_revocation_msg_from_secret(const struct peer *peer, u64 revoke_index, struct pubkey *point, const struct secret *old_commit_secret, const struct pubkey *next_point) { *point = *next_point; return towire_revoke_and_ack(peer, &peer->channel_id, old_commit_secret, next_point); } /* Convert changed htlcs into parts which lightningd expects. */ static void marshall_htlc_info(const tal_t *ctx, const struct htlc **changed_htlcs, struct changed_htlc **changed, struct fulfilled_htlc **fulfilled, const struct failed_htlc ***failed, struct added_htlc **added) { *changed = tal_arr(ctx, struct changed_htlc, 0); *added = tal_arr(ctx, struct added_htlc, 0); *failed = tal_arr(ctx, const struct failed_htlc *, 0); *fulfilled = tal_arr(ctx, struct fulfilled_htlc, 0); for (size_t i = 0; i < tal_count(changed_htlcs); i++) { const struct htlc *htlc = changed_htlcs[i]; if (htlc->state == RCVD_ADD_COMMIT) { struct added_htlc a; a.id = htlc->id; a.amount = htlc->amount; a.payment_hash = htlc->rhash; a.cltv_expiry = abs_locktime_to_blocks(&htlc->expiry); memcpy(a.onion_routing_packet, htlc->routing, sizeof(a.onion_routing_packet)); a.blinding = htlc->blinding; a.fail_immediate = htlc->fail_immediate; tal_arr_expand(added, a); } else if (htlc->state == RCVD_REMOVE_COMMIT) { if (htlc->r) { struct fulfilled_htlc f; assert(!htlc->failed); f.id = htlc->id; f.payment_preimage = *htlc->r; tal_arr_expand(fulfilled, f); } else { assert(!htlc->r); tal_arr_expand(failed, htlc->failed); } } else { struct changed_htlc c; assert(htlc->state == RCVD_REMOVE_ACK_COMMIT || htlc->state == RCVD_ADD_ACK_COMMIT); c.id = htlc->id; c.newstate = htlc->state; tal_arr_expand(changed, c); } } } static void send_revocation(struct peer *peer, const struct bitcoin_signature *commit_sig, const struct bitcoin_signature *htlc_sigs, const struct htlc **changed_htlcs, const struct bitcoin_tx *committx, const struct secret *old_secret, const struct pubkey *next_point, const struct commitsig **splice_commitsigs) { struct changed_htlc *changed; struct fulfilled_htlc *fulfilled; const struct failed_htlc **failed; struct added_htlc *added; const u8 *msg; const u8 *msg_for_master; /* Marshall it now before channel_sending_revoke_and_ack changes htlcs */ /* FIXME: Make infrastructure handle state post-revoke_and_ack! */ marshall_htlc_info(tmpctx, changed_htlcs, &changed, &fulfilled, &failed, &added); /* Revoke previous commit, get new point. */ msg = make_revocation_msg_from_secret(peer, peer->next_index[LOCAL]-1, &peer->next_local_per_commit, old_secret, next_point); /* From now on we apply changes to the next commitment */ peer->next_index[LOCAL]++; /* If this queues more changes on the other end, send commit. */ if (channel_sending_revoke_and_ack(peer->channel)) { status_debug("revoke_and_ack made pending: commit timer"); start_commit_timer(peer); } /* Tell master daemon about commitsig (and by implication, that we're * sending revoke_and_ack), then wait for it to ack. */ /* We had to do this after channel_sending_revoke_and_ack, since we * want it to save the fee_states produced there. */ msg_for_master = towire_channeld_got_commitsig(NULL, peer->next_index[LOCAL] - 1, peer->channel->fee_states, peer->channel->blockheight_states, commit_sig, htlc_sigs, added, fulfilled, failed, changed, committx, splice_commitsigs); master_wait_sync_reply(tmpctx, peer, take(msg_for_master), WIRE_CHANNELD_GOT_COMMITSIG_REPLY); peer->splice_state->await_commitment_succcess = false; /* Now we can finally send revoke_and_ack to peer */ peer_write(peer->pps, take(msg)); } /* Calling `handle_peer_commit_sig` with a `commit_index` of 0 and * `changed_htlcs` of NULL will process the message, then read & process coming * consecutive commitment messages equal to the number of inflight splices. * * Returns the last commitsig received. When splicing this is the * newest splice commit sig. */ static struct commitsig *handle_peer_commit_sig(struct peer *peer, const u8 *msg, u32 commit_index, const struct htlc **changed_htlcs, s64 splice_amnt, s64 remote_splice_amnt) { struct commitsig *result; struct channel_id channel_id; struct bitcoin_signature commit_sig; secp256k1_ecdsa_signature *raw_sigs; struct bitcoin_signature *htlc_sigs; struct pubkey remote_htlckey; struct bitcoin_tx **txs; const struct htlc **htlc_map; const u8 *funding_wscript; size_t i; struct simple_htlc **htlcs; const u8 * msg2; u8 *splice_msg; int type; struct bitcoin_outpoint outpoint; struct amount_sat funding_sats; struct channel_id active_id; const struct commitsig **commitsigs; status_debug("handle_peer_commit_sig(splice: %d, remote_splice: %d)", (int)splice_amnt, (int)remote_splice_amnt); struct tlv_commitment_signed_tlvs *cs_tlv = tlv_commitment_signed_tlvs_new(tmpctx); if (!fromwire_commitment_signed(tmpctx, msg, &channel_id, &commit_sig.s, &raw_sigs, &cs_tlv)) peer_failed_warn(peer->pps, &peer->channel_id, "Bad commit_sig %s", tal_hex(msg, msg)); /* BOLT-0d8b701614b09c6ee4172b04da2203e73deec7e2 #2: * Once a node has received and sent `splice_locked`: * - Until sending OR receiving of `revoke_and_ack` * ... * - MUST ignore `commitment_signed` messages where `splice_channel_id` * does not match the `channel_id` of the confirmed splice. */ derive_channel_id(&active_id, &peer->channel->funding); if (peer->splice_state->await_commitment_succcess && !tal_count(peer->splice_state->inflights) && cs_tlv && cs_tlv->splice_info) { if (!channel_id_eq(&active_id, cs_tlv->splice_info)) { status_info("Ignoring stale commit_sig for channel_id" " %s, as %s is locked in now.", type_to_string(tmpctx, struct channel_id, cs_tlv->splice_info), type_to_string(tmpctx, struct channel_id, &active_id)); return NULL; } } /* In a race we can get here with a commitsig with too many splices * attached. In that case we ignore the main commit msg for the old * funding tx, and for the splice candidates that didnt win. But we must * listen to the one that is for the winning splice candidate */ if (!changed_htlcs) { changed_htlcs = tal_arr(msg, const struct htlc *, 0); if (!channel_rcvd_commit(peer->channel, &changed_htlcs) && peer->splice_state->count == peer->splice_state->revoked_count) { /* BOLT #2: * * A sending node: * - MUST NOT send a `commitment_signed` message that does not * include any updates. */ status_debug("Oh hi LND! Empty commitment at #%"PRIu64, peer->next_index[LOCAL]); if (peer->last_empty_commitment == peer->next_index[LOCAL] - 1) peer_failed_warn(peer->pps, &peer->channel_id, "commit_sig with no changes (again!)"); peer->last_empty_commitment = peer->next_index[LOCAL]; } } /* We were supposed to check this was affordable as we go. */ if (peer->channel->opener == REMOTE) { status_debug("Feerates are %u/%u", channel_feerate(peer->channel, LOCAL), channel_feerate(peer->channel, REMOTE)); assert(can_opener_afford_feerate(peer->channel, channel_feerate(peer->channel, LOCAL))); } /* SIGHASH_ALL is implied. */ commit_sig.sighash_type = SIGHASH_ALL; htlc_sigs = unraw_sigs(tmpctx, raw_sigs, channel_has_anchors(peer->channel)); if (commit_index) { outpoint = peer->splice_state->inflights[commit_index - 1]->outpoint; funding_sats = peer->splice_state->inflights[commit_index - 1]->amnt; } else { outpoint = peer->channel->funding; funding_sats = peer->channel->funding_sats; } txs = channel_splice_txs(tmpctx, &outpoint, funding_sats, &htlc_map, NULL, &funding_wscript, peer->channel, &peer->next_local_per_commit, peer->next_index[LOCAL], LOCAL, splice_amnt, remote_splice_amnt); /* Set the commit_sig on the commitment tx psbt */ if (!psbt_input_set_signature(txs[0]->psbt, 0, &peer->channel->funding_pubkey[REMOTE], &commit_sig)) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Unable to set signature internally"); if (!derive_simple_key(&peer->channel->basepoints[REMOTE].htlc, &peer->next_local_per_commit, &remote_htlckey)) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Deriving remote_htlckey"); status_debug("Derived key %s from basepoint %s, point %s", type_to_string(tmpctx, struct pubkey, &remote_htlckey), type_to_string(tmpctx, struct pubkey, &peer->channel->basepoints[REMOTE].htlc), type_to_string(tmpctx, struct pubkey, &peer->next_local_per_commit)); /* BOLT #2: * * A receiving node: * - once all pending updates are applied: * - if `signature` is not valid for its local commitment transaction * OR non-compliant with LOW-S-standard rule...: * - MUST send a `warning` and close the connection, or send an * `error` and fail the channel. */ if (!check_tx_sig(txs[0], 0, NULL, funding_wscript, &peer->channel->funding_pubkey[REMOTE], &commit_sig)) { dump_htlcs(peer->channel, "receiving commit_sig"); peer_failed_warn(peer->pps, &peer->channel_id, "Bad commit_sig signature %"PRIu64" %s for tx" " %s wscript %s key %s feerate %u. Cur funding" " %s, splice_info: %s, race_await_commit: %s," " inflight splice count: %zu", peer->next_index[LOCAL], type_to_string(msg, struct bitcoin_signature, &commit_sig), type_to_string(msg, struct bitcoin_tx, txs[0]), tal_hex(msg, funding_wscript), type_to_string(msg, struct pubkey, &peer->channel->funding_pubkey [REMOTE]), channel_feerate(peer->channel, LOCAL), type_to_string(tmpctx, struct channel_id, &active_id), type_to_string(tmpctx, struct channel_id, (cs_tlv ? cs_tlv->splice_info : NULL)), peer->splice_state->await_commitment_succcess ? "yes" : "no", tal_count(peer->splice_state->inflights)); } /* BOLT #2: * * A receiving node: *... * - if `num_htlcs` is not equal to the number of HTLC outputs in the * local commitment transaction: * - MUST send a `warning` and close the connection, or send an * `error` and fail the channel. */ if (tal_count(htlc_sigs) != tal_count(txs) - 1) peer_failed_warn(peer->pps, &peer->channel_id, "Expected %zu htlc sigs, not %zu", tal_count(txs) - 1, tal_count(htlc_sigs)); /* BOLT #2: * * - if any `htlc_signature` is not valid for the corresponding HTLC * transaction OR non-compliant with LOW-S-standard rule...: * - MUST send a `warning` and close the connection, or send an * `error` and fail the channel. */ for (i = 0; i < tal_count(htlc_sigs); i++) { u8 *wscript; wscript = bitcoin_tx_output_get_witscript(tmpctx, txs[0], txs[i+1]->wtx->inputs[0].index); if (!check_tx_sig(txs[1+i], 0, NULL, wscript, &remote_htlckey, &htlc_sigs[i])) peer_failed_warn(peer->pps, &peer->channel_id, "Bad commit_sig signature %s for htlc %s wscript %s key %s", type_to_string(msg, struct bitcoin_signature, &htlc_sigs[i]), type_to_string(msg, struct bitcoin_tx, txs[1+i]), tal_hex(msg, wscript), type_to_string(msg, struct pubkey, &remote_htlckey)); } status_debug("Received commit_sig with %zu htlc sigs", tal_count(htlc_sigs)); /* First pass some common error scenarios for nicer log outputs */ if (peer->splice_state->count) { if (!cs_tlv) peer_failed_warn(peer->pps, &peer->channel_id, "Bad commitment_signed mesage" " without a splice commit sig" " section during a splice."); if (tal_count(peer->splice_state->inflights) != peer->splice_state->count) peer_failed_warn(peer->pps, &peer->channel_id, "Internal splice inflight counting " "error"); } /* Validate the counterparty's signatures, returns prior per_commitment_secret. */ htlcs = collect_htlcs(NULL, htlc_map); msg2 = towire_hsmd_validate_commitment_tx(NULL, txs[0], (const struct simple_htlc **) htlcs, peer->next_index[LOCAL], channel_feerate(peer->channel, LOCAL), &commit_sig, htlc_sigs); tal_free(htlcs); msg2 = hsm_req(tmpctx, take(msg2)); struct secret *old_secret; struct pubkey next_point; if (!fromwire_hsmd_validate_commitment_tx_reply(tmpctx, msg2, &old_secret, &next_point)) status_failed(STATUS_FAIL_HSM_IO, "Reading validate_commitment_tx reply: %s", tal_hex(tmpctx, msg2)); result = tal(tmpctx, struct commitsig); result->tx = clone_bitcoin_tx(result, txs[0]); result->commit_signature = commit_sig; result->htlc_signatures = htlc_sigs; /* Only the parent call continues from here. * Return for all child calls. */ if(commit_index) return result; commitsigs = tal_arr(NULL, const struct commitsig*, 0); /* We expect multiple consequtive commit_sig messages if we have * inflight splices. Since consequtive is requred, we recurse for * each expected message, blocking until all are received. */ for (i = 0; i < tal_count(peer->splice_state->inflights); i++) { s64 funding_diff = sats_diff(peer->splice_state->inflights[i]->amnt, peer->channel->funding_sats); s64 sub_splice_amnt = peer->splice_state->inflights[i]->splice_amnt; splice_msg = peer_read(tmpctx, peer->pps); /* Check type for cleaner failure message */ type = fromwire_peektype(msg); if (type != WIRE_COMMITMENT_SIGNED) peer_failed_err(peer->pps, &peer->channel_id, "Expected splice related " "WIRE_COMMITMENT_SIGNED but got %s", peer_wire_name(type)); /* We purposely just store the last commit msg */ result = handle_peer_commit_sig(peer, splice_msg, i + 1, changed_htlcs, sub_splice_amnt, funding_diff - sub_splice_amnt); tal_arr_expand(&commitsigs, result); tal_steal(commitsigs, result); } peer->splice_state->revoked_count = peer->splice_state->count; send_revocation(peer, &commit_sig, htlc_sigs, changed_htlcs, txs[0], old_secret, &next_point, commitsigs); tal_steal(tmpctx, result); tal_free(commitsigs); /* STFU can't be activated during pending updates. * With updates finish let's handle a potentially queued stfu request. */ maybe_send_stfu(peer); /* This might have synced the feerates: if so, we may want to * update */ if (want_fee_update(peer, NULL)) start_commit_timer(peer); /* We return the last commit commit msg */ return result; } /* Pops the penalty base for the given commitnum from our internal list. There * may not be one, in which case we return NULL and leave the list * unmodified. */ static struct penalty_base * penalty_base_by_commitnum(const tal_t *ctx, struct peer *peer, u64 commitnum) { struct penalty_base *res = NULL; for (size_t i = 0; i < tal_count(peer->pbases); i++) { if (peer->pbases[i]->commitment_num == commitnum) { res = tal_steal(ctx, peer->pbases[i]); tal_arr_remove(&peer->pbases, i); break; } } return res; } static u8 *got_revoke_msg(struct peer *peer, u64 revoke_num, const struct secret *per_commitment_secret, const struct pubkey *next_per_commit_point, const struct htlc **changed_htlcs, const struct fee_states *fee_states, const struct height_states *blockheight_states) { u8 *msg; struct penalty_base *pbase; struct changed_htlc *changed = tal_arr(tmpctx, struct changed_htlc, 0); const struct bitcoin_tx *ptx = NULL; for (size_t i = 0; i < tal_count(changed_htlcs); i++) { struct changed_htlc c; const struct htlc *htlc = changed_htlcs[i]; status_debug("HTLC %"PRIu64"[%s] => %s", htlc->id, side_to_str(htlc_owner(htlc)), htlc_state_name(htlc->state)); c.id = changed_htlcs[i]->id; c.newstate = changed_htlcs[i]->state; tal_arr_expand(&changed, c); } pbase = penalty_base_by_commitnum(tmpctx, peer, revoke_num); if (pbase) { /* DTODO we need penalty tx's per splice candidate */ ptx = penalty_tx_create( NULL, peer->channel, peer->feerate_penalty, peer->final_index, peer->final_ext_key, peer->final_scriptpubkey, per_commitment_secret, &pbase->txid, pbase->outnum, pbase->amount, HSM_FD); } msg = towire_channeld_got_revoke(peer, revoke_num, per_commitment_secret, next_per_commit_point, fee_states, blockheight_states, changed, pbase, ptx); tal_free(ptx); return msg; } static void handle_peer_revoke_and_ack(struct peer *peer, const u8 *msg) { struct secret old_commit_secret; struct privkey privkey; struct channel_id channel_id; const u8 *revocation_msg; struct pubkey per_commit_point, next_per_commit; const struct htlc **changed_htlcs = tal_arr(msg, const struct htlc *, 0); if (!fromwire_revoke_and_ack(msg, &channel_id, &old_commit_secret, &next_per_commit)) { peer_failed_warn(peer->pps, &peer->channel_id, "Bad revoke_and_ack %s", tal_hex(msg, msg)); } if (peer->revocations_received != peer->next_index[REMOTE] - 2) { peer_failed_warn(peer->pps, &peer->channel_id, "Unexpected revoke_and_ack"); } /* Submit the old revocation secret to the signer so it can * independently verify that the latest state is commited. It * is also validated in this routine after the signer returns. */ revocation_msg = towire_hsmd_validate_revocation(tmpctx, peer->next_index[REMOTE] - 2, &old_commit_secret); revocation_msg = hsm_req(tmpctx, take(revocation_msg)); if (!fromwire_hsmd_validate_revocation_reply(revocation_msg)) status_failed(STATUS_FAIL_HSM_IO, "Bad hsmd_validate_revocation_reply: %s", tal_hex(tmpctx, revocation_msg)); /* BOLT #2: * * A receiving node: * - if `per_commitment_secret` is not a valid secret key or does not * generate the previous `per_commitment_point`: * - MUST send an `error` and fail the channel. */ memcpy(&privkey, &old_commit_secret, sizeof(privkey)); if (!pubkey_from_privkey(&privkey, &per_commit_point)) { peer_failed_err(peer->pps, &peer->channel_id, "Bad privkey %s", type_to_string(msg, struct privkey, &privkey)); } if (!pubkey_eq(&per_commit_point, &peer->old_remote_per_commit)) { peer_failed_err(peer->pps, &peer->channel_id, "Wrong privkey %s for %"PRIu64" %s", type_to_string(msg, struct privkey, &privkey), peer->next_index[LOCAL]-2, type_to_string(msg, struct pubkey, &peer->old_remote_per_commit)); } /* We start timer even if this returns false: we might have delayed * commit because we were waiting for this! */ if (channel_rcvd_revoke_and_ack(peer->channel, &changed_htlcs)) status_debug("Commits outstanding after recv revoke_and_ack"); else status_debug("No commits outstanding after recv revoke_and_ack"); /* Tell master about things this locks in, wait for response */ msg = got_revoke_msg(peer, peer->revocations_received++, &old_commit_secret, &next_per_commit, changed_htlcs, peer->channel->fee_states, peer->channel->blockheight_states); master_wait_sync_reply(tmpctx, peer, take(msg), WIRE_CHANNELD_GOT_REVOKE_REPLY); peer->old_remote_per_commit = peer->remote_per_commit; peer->remote_per_commit = next_per_commit; status_debug("revoke_and_ack %s: remote_per_commit = %s, old_remote_per_commit = %s", side_to_str(peer->channel->opener), type_to_string(tmpctx, struct pubkey, &peer->remote_per_commit), type_to_string(tmpctx, struct pubkey, &peer->old_remote_per_commit)); peer->splice_state->await_commitment_succcess = false; /* STFU can't be activated during pending updates. * With updates finish let's handle a potentially queued stfu request. */ maybe_send_stfu(peer); start_commit_timer(peer); } static void handle_peer_fulfill_htlc(struct peer *peer, const u8 *msg) { struct channel_id channel_id; u64 id; struct preimage preimage; enum channel_remove_err e; struct htlc *h; if (!fromwire_update_fulfill_htlc(msg, &channel_id, &id, &preimage)) { peer_failed_warn(peer->pps, &peer->channel_id, "Bad update_fulfill_htlc %s", tal_hex(msg, msg)); } e = channel_fulfill_htlc(peer->channel, LOCAL, id, &preimage, &h); switch (e) { case CHANNEL_ERR_REMOVE_OK: /* FIXME: We could send preimages to master immediately. */ start_commit_timer(peer); return; /* These shouldn't happen, because any offered HTLC (which would give * us the preimage) should have timed out long before. If we * were to get preimages from other sources, this could happen. */ case CHANNEL_ERR_NO_SUCH_ID: case CHANNEL_ERR_ALREADY_FULFILLED: case CHANNEL_ERR_HTLC_UNCOMMITTED: case CHANNEL_ERR_HTLC_NOT_IRREVOCABLE: case CHANNEL_ERR_BAD_PREIMAGE: peer_failed_warn(peer->pps, &peer->channel_id, "Bad update_fulfill_htlc: failed to fulfill %" PRIu64 " error %s", id, channel_remove_err_name(e)); } abort(); } static void handle_peer_fail_htlc(struct peer *peer, const u8 *msg) { struct channel_id channel_id; u64 id; enum channel_remove_err e; u8 *reason; struct htlc *htlc; struct failed_htlc *f; /* reason is not an onionreply because spec doesn't know about that */ if (!fromwire_update_fail_htlc(msg, msg, &channel_id, &id, &reason)) { peer_failed_warn(peer->pps, &peer->channel_id, "Bad update_fail_htlc %s", tal_hex(msg, msg)); } e = channel_fail_htlc(peer->channel, LOCAL, id, &htlc); switch (e) { case CHANNEL_ERR_REMOVE_OK: { htlc->failed = f = tal(htlc, struct failed_htlc); f->id = id; f->sha256_of_onion = NULL; f->onion = new_onionreply(f, take(reason)); start_commit_timer(peer); return; } case CHANNEL_ERR_NO_SUCH_ID: case CHANNEL_ERR_ALREADY_FULFILLED: case CHANNEL_ERR_HTLC_UNCOMMITTED: case CHANNEL_ERR_HTLC_NOT_IRREVOCABLE: case CHANNEL_ERR_BAD_PREIMAGE: peer_failed_warn(peer->pps, &peer->channel_id, "Bad update_fail_htlc: failed to remove %" PRIu64 " error %s", id, channel_remove_err_name(e)); } abort(); } static void handle_peer_fail_malformed_htlc(struct peer *peer, const u8 *msg) { struct channel_id channel_id; u64 id; enum channel_remove_err e; struct sha256 sha256_of_onion; u16 failure_code; struct htlc *htlc; struct failed_htlc *f; if (!fromwire_update_fail_malformed_htlc(msg, &channel_id, &id, &sha256_of_onion, &failure_code)) { peer_failed_warn(peer->pps, &peer->channel_id, "Bad update_fail_malformed_htlc %s", tal_hex(msg, msg)); } /* BOLT #2: * * - if the `BADONION` bit in `failure_code` is not set for * `update_fail_malformed_htlc`: * - MUST send a `warning` and close the connection, or send an * `error` and fail the channel. */ if (!(failure_code & BADONION)) { /* But LND (at least, Bitrefill to Blockstream Store) sends this? */ status_unusual("Bad update_fail_malformed_htlc failure code %u", failure_code); /* We require this internally. */ failure_code |= BADONION; } e = channel_fail_htlc(peer->channel, LOCAL, id, &htlc); switch (e) { case CHANNEL_ERR_REMOVE_OK: htlc->failed = f = tal(htlc, struct failed_htlc); f->id = id; f->onion = NULL; f->sha256_of_onion = tal_dup(f, struct sha256, &sha256_of_onion); f->badonion = failure_code; start_commit_timer(peer); return; case CHANNEL_ERR_NO_SUCH_ID: case CHANNEL_ERR_ALREADY_FULFILLED: case CHANNEL_ERR_HTLC_UNCOMMITTED: case CHANNEL_ERR_HTLC_NOT_IRREVOCABLE: case CHANNEL_ERR_BAD_PREIMAGE: peer_failed_warn(peer->pps, &peer->channel_id, "Bad update_fail_malformed_htlc: failed to remove %" PRIu64 " error %s", id, channel_remove_err_name(e)); } abort(); } static void handle_peer_shutdown(struct peer *peer, const u8 *shutdown) { struct channel_id channel_id; u8 *scriptpubkey; struct tlv_shutdown_tlvs *tlvs; struct bitcoin_outpoint *wrong_funding; /* DTODO: Ensure `shutdown` follows new splice related rules once * completed in the spec */ /* Disable the channel. */ send_channel_update(peer, ROUTING_FLAGS_DISABLED); if (!fromwire_shutdown(tmpctx, shutdown, &channel_id, &scriptpubkey, &tlvs)) peer_failed_warn(peer->pps, &peer->channel_id, "Bad shutdown %s", tal_hex(peer, shutdown)); /* FIXME: We shouldn't let them initiate a shutdown while the * channel is active (if we leased funds) */ /* BOLT #2: * * - if both nodes advertised the `option_upfront_shutdown_script` * feature, and the receiving node received a non-zero-length * `shutdown_scriptpubkey` in `open_channel` or `accept_channel`, and * that `shutdown_scriptpubkey` is not equal to `scriptpubkey`: * - MAY send a `warning`. * - MUST fail the connection. */ /* openingd only sets this if feature was negotiated at opening. */ if (tal_count(peer->remote_upfront_shutdown_script) && !memeq(scriptpubkey, tal_count(scriptpubkey), peer->remote_upfront_shutdown_script, tal_count(peer->remote_upfront_shutdown_script))) peer_failed_warn(peer->pps, &peer->channel_id, "scriptpubkey %s is not as agreed upfront (%s)", tal_hex(peer, scriptpubkey), tal_hex(peer, peer->remote_upfront_shutdown_script)); /* We only accept an wrong_funding if: * 1. It was negotiated. * 2. It's not dual-funding. * 3. They opened it. * 4. The channel was never used. */ if (tlvs->wrong_funding) { if (!feature_negotiated(peer->our_features, peer->their_features, OPT_SHUTDOWN_WRONG_FUNDING)) peer_failed_warn(peer->pps, &peer->channel_id, "wrong_funding shutdown needs" " feature %u", OPT_SHUTDOWN_WRONG_FUNDING); if (feature_negotiated(peer->our_features, peer->their_features, OPT_DUAL_FUND)) peer_failed_warn(peer->pps, &peer->channel_id, "wrong_funding shutdown invalid" " with dual-funding"); if (peer->channel->opener != REMOTE) peer_failed_warn(peer->pps, &peer->channel_id, "No shutdown wrong_funding" " for channels we opened!"); if (peer->next_index[REMOTE] != 1 || peer->next_index[LOCAL] != 1) peer_failed_warn(peer->pps, &peer->channel_id, "No shutdown wrong_funding" " for used channels!"); /* Turn into our outpoint type. */ wrong_funding = tal(tmpctx, struct bitcoin_outpoint); wrong_funding->txid = tlvs->wrong_funding->txid; wrong_funding->n = tlvs->wrong_funding->outnum; } else { wrong_funding = NULL; } /* Tell master: we don't have to wait because on reconnect other end * will re-send anyway. */ wire_sync_write(MASTER_FD, take(towire_channeld_got_shutdown(NULL, scriptpubkey, wrong_funding))); peer->shutdown_sent[REMOTE] = true; /* BOLT #2: * * A receiving node: * ... * - once there are no outstanding updates on the peer, UNLESS * it has already sent a `shutdown`: * - MUST reply to a `shutdown` message with a `shutdown` */ if (!peer->shutdown_sent[LOCAL]) { peer->send_shutdown = true; start_commit_timer(peer); } billboard_update(peer); } static void handle_unexpected_tx_sigs(struct peer *peer, const u8 *msg) { const struct witness **witnesses; struct channel_id cid; struct bitcoin_txid txid; struct tlv_txsigs_tlvs *txsig_tlvs = tlv_txsigs_tlvs_new(tmpctx); /* In a rare case, a v2 peer may re-send a tx_sigs message. * This happens when they've/we've exchanged channel_ready, * but they did not receive our channel_ready. */ if (!fromwire_tx_signatures(tmpctx, msg, &cid, &txid, cast_const3(struct witness ***, &witnesses), &txsig_tlvs)) peer_failed_warn(peer->pps, &peer->channel_id, "Bad tx_signatures %s", tal_hex(msg, msg)); status_info("Unexpected `tx_signatures` from peer-> %s", peer->tx_sigs_allowed ? "Allowing." : "Failing."); if (!peer->tx_sigs_allowed) peer_failed_warn(peer->pps, &peer->channel_id, "Unexpected `tx_signatures`"); peer->tx_sigs_allowed = false; } static void handle_unexpected_reestablish(struct peer *peer, const u8 *msg) { struct channel_id channel_id; u64 next_commitment_number; u64 next_revocation_number; struct secret your_last_per_commitment_secret; struct pubkey my_current_per_commitment_point; struct tlv_channel_reestablish_tlvs *tlvs; if (!fromwire_channel_reestablish(tmpctx, msg, &channel_id, &next_commitment_number, &next_revocation_number, &your_last_per_commitment_secret, &my_current_per_commitment_point, &tlvs)) { peer_failed_warn(peer->pps, &peer->channel_id, "Bad channel_reestablish %s", tal_hex(peer, msg)); } /* Is it the same as the peer channel ID? */ if (channel_id_eq(&channel_id, &peer->channel_id)) { /* Log this event as unusual. */ status_unusual("Got repeated WIRE_CHANNEL_REESTABLISH " "for channel %s, ignoring: %s", type_to_string(tmpctx, struct channel_id, &peer->channel_id), tal_hex(tmpctx, msg)); /* This is a mitigation for a known bug in some peer software * that sometimes double-sends a reestablish message. * * Ideally we would send some kind of `error` message to the * peer here, but if we sent an `error` message with the * same channel ID it would cause the peer to drop the * channel unilaterally. * We also cannot use 0x00...00 because that means "all * channels", so a proper peer (like C-lightning) will * unilaterally close all channels we have with it, if we * sent the 0x00...00 channel ID. * * So just do not send an error. */ return; } /* We only support one channel here, so the unexpected channel is the * peer getting its wires crossed somewhere. * Fail the channel they sent, not the channel we are actively * handling. */ peer_failed_err(peer->pps, &channel_id, "Peer sent unexpected message %u, (%s) " "for nonexistent channel %s", WIRE_CHANNEL_REESTABLISH, "WIRE_CHANNEL_REESTABLISH", type_to_string(tmpctx, struct channel_id, &channel_id)); } static bool is_initiators_serial(const struct wally_map *unknowns) { /* BOLT-f15b6b0feeffc2acd1a8466537810bbb3f824f9f #2: * The sending node: ... * - if is the *initiator*: * - MUST send even `serial_id`s * - if is the *non-initiator*: * - MUST send odd `serial_id`s */ u64 serial_id; if (!psbt_get_serial_id(unknowns, &serial_id)) status_failed(STATUS_FAIL_INTERNAL_ERROR, "PSBTs must have serial_ids set"); return serial_id % 2 == TX_INITIATOR; } static void add_amount_to_side(struct peer *peer, struct amount_msat amounts[NUM_TX_ROLES], const struct amount_sat amount, const struct wally_map *unknowns) { enum tx_role role; if (amount_sat_zero(amount)) peer_failed_warn(peer->pps, &peer->channel_id, "Unable to add 0 sat fields to calculation"); if(is_initiators_serial(unknowns)) role = TX_INITIATOR; else role = TX_ACCEPTER; if (!amount_msat_add_sat(&amounts[role], amounts[role], amount)) peer_failed_warn(peer->pps, &peer->channel_id, "Unable to add field amount %s to rolling" " total %s", fmt_amount_sat(tmpctx, amount), fmt_amount_msat(tmpctx, amounts[role])); } static bool do_i_sign_first(struct peer *peer, struct wally_psbt *psbt, enum tx_role our_role) { struct amount_msat in[NUM_TX_ROLES]; /* BOLT-0d8b701614b09c6ee4172b04da2203e73deec7e2 #2: * - MAY send `tx_signatures` first. */ if (peer->splicing->force_sign_first) return true; in[TX_INITIATOR] = AMOUNT_MSAT(0); in[TX_ACCEPTER] = AMOUNT_MSAT(0); for (size_t i = 0; i < psbt->num_inputs; i++) add_amount_to_side(peer, in, psbt_input_get_amount(psbt, i), &psbt->inputs[i].unknowns); /* BOLT-0d8b701614b09c6ee4172b04da2203e73deec7e2 #2: * - If recipient's sum(tx_add_input.amount) < peer's * sum(tx_add_input.amount); or if recipient's * sum(tx_add_input.amount) == peer's sum(tx_add_input.amount) and * recipient is the `initiator` of the splice: * - SHOULD send `tx_signatures` first for the splice transaction. */ if (amount_msat_less(in[TX_ACCEPTER], in[TX_INITIATOR])) return our_role == TX_ACCEPTER; if (amount_msat_less(in[TX_INITIATOR], in[TX_ACCEPTER])) return our_role == TX_INITIATOR; return our_role == TX_INITIATOR; } static struct wally_psbt *next_splice_step(const tal_t *ctx, struct interactivetx_context *ictx) { /* DTODO: add plugin wrapper for accepter side of splice to add to the * negotiated splice. */ if (ictx->our_role == TX_ACCEPTER) return NULL; return ictx->desired_psbt; } static const u8 *peer_expect_msg(const tal_t *ctx, struct peer *peer, enum peer_wire expect_type, enum peer_wire second_allowed_type) { u8 *msg; enum peer_wire type; msg = peer_read(ctx, peer->pps); type = fromwire_peektype(msg); if (type != expect_type && type != second_allowed_type) peer_failed_warn(peer->pps, &peer->channel_id, "Got incorrect message from peer: %s" " (should be %s) [%s]", peer_wire_name(type), peer_wire_name(expect_type), sanitize_error(tmpctx, msg, &peer->channel_id)); return msg; } /* The question of "who signs splice commitments first" is the same order as the * splice `tx_signature`s are. This function handles sending & receiving the * required commitments as part of the splicing process. */ static struct commitsig *interactive_send_commitments(struct peer *peer, struct wally_psbt *psbt, enum tx_role our_role) { struct commitsig *result; const u8 *msg, *commit_msg; commit_msg = NULL; if (do_i_sign_first(peer, psbt, our_role)) { status_debug("Splice %s: we commit first", our_role == TX_INITIATOR ? "initiator" : "accepter"); send_commit(peer); /* If both sides commit simultaneously, that's fine. */ msg = peer_expect_msg(tmpctx, peer, WIRE_REVOKE_AND_ACK, WIRE_COMMITMENT_SIGNED); /* If commitments happened simultaneously, we'll get a * commitment signed message, followed by revoke and ack. */ if (fromwire_peektype(msg) == WIRE_COMMITMENT_SIGNED) { commit_msg = msg; result = handle_peer_commit_sig(peer, commit_msg, 0, NULL, 0, 0); msg = peer_expect_msg(tmpctx, peer, WIRE_REVOKE_AND_ACK, 0); } handle_peer_revoke_and_ack(peer, msg); } if (!commit_msg) { commit_msg = peer_expect_msg(tmpctx, peer, WIRE_COMMITMENT_SIGNED, 0); result = handle_peer_commit_sig(peer, commit_msg, 0, NULL, 0, 0); } if (!do_i_sign_first(peer, psbt, our_role)) { status_debug("Splice %s: we commit second", our_role == TX_INITIATOR ? "initiator" : "accepter"); send_commit(peer); msg = peer_expect_msg(tmpctx, peer, WIRE_REVOKE_AND_ACK, 0); handle_peer_revoke_and_ack(peer, msg); } return result; } static struct wally_psbt_output *find_channel_output(struct peer *peer, struct wally_psbt *psbt, u32 *chan_output_index) { const u8 *wit_script; u8 *scriptpubkey; wit_script = bitcoin_redeem_2of2(tmpctx, &peer->channel->funding_pubkey[LOCAL], &peer->channel->funding_pubkey[REMOTE]); scriptpubkey = scriptpubkey_p2wsh(psbt, wit_script); for (size_t i = 0; i < psbt->num_outputs; i++) { if (memeq(psbt->outputs[i].script, psbt->outputs[i].script_len, scriptpubkey, tal_bytelen(scriptpubkey))) { if (chan_output_index) *chan_output_index = i; return &psbt->outputs[i]; } } status_failed(STATUS_FAIL_INTERNAL_ERROR, "Unable to find channel output"); return NULL; } static size_t calc_weight(enum tx_role role, const struct wally_psbt *psbt) { size_t weight = 0; /* BOLT-0d8b701614b09c6ee4172b04da2203e73deec7e2 #2: * The initiator: * ... * - MUST pay for the common fields. */ if (role == TX_INITIATOR) weight += bitcoin_tx_core_weight(psbt->num_inputs, psbt->num_outputs); /* BOLT-0d8b701614b09c6ee4172b04da2203e73deec7e2 #2: * Each node: * - MUST pay for their own added inputs and outputs. */ for (size_t i = 0; i < psbt->num_inputs; i++) if (is_initiators_serial(&psbt->inputs[i].unknowns)) { if (role == TX_INITIATOR) weight += psbt_input_get_weight(psbt, i); } else if (role != TX_INITIATOR) weight += psbt_input_get_weight(psbt, i); for (size_t i = 0; i < psbt->num_outputs; i++) if (is_initiators_serial(&psbt->inputs[i].unknowns)) { if (role == TX_INITIATOR) weight += psbt_output_get_weight(psbt, i); } else if (role != TX_INITIATOR) weight += psbt_output_get_weight(psbt, i); return weight; } /* Returns the total channel funding output amount if all checks pass. * Otherwise, exits via peer_failed_warn. DTODO: Change to `tx_abort`. */ static struct amount_sat check_balances(struct peer *peer, enum tx_role our_role, const struct wally_psbt *psbt, int chan_output_index, int chan_input_index) { struct amount_sat min_initiator_fee, min_accepter_fee, max_initiator_fee, max_accepter_fee, funding_amount_res; struct amount_msat funding_amount, initiator_fee, accepter_fee; struct amount_msat in[NUM_TX_ROLES], out[NUM_TX_ROLES]; bool opener = our_role == TX_INITIATOR; u8 *msg; in[TX_INITIATOR] = peer->channel->view->owed[opener ? LOCAL : REMOTE]; in[TX_ACCEPTER] = peer->channel->view->owed[opener ? REMOTE : LOCAL]; for (size_t i = 0; i < psbt->num_inputs; i++) if (i != chan_input_index) add_amount_to_side(peer, in, psbt_input_get_amount(psbt, i), &psbt->inputs[i].unknowns); /* The outgoing channel funds start as current funds, will be modified * by the splice amount later on */ out[TX_INITIATOR] = peer->channel->view->owed[opener ? LOCAL : REMOTE]; out[TX_ACCEPTER] = peer->channel->view->owed[opener ? REMOTE : LOCAL]; for (size_t i = 0; i < psbt->num_outputs; i++) if (i != chan_output_index) add_amount_to_side(peer, out, psbt_output_get_amount(psbt, i), &psbt->outputs[i].unknowns); /* Calculate total channel output amount */ if (!amount_msat_add(&funding_amount, peer->channel->view->owed[LOCAL], peer->channel->view->owed[REMOTE])) peer_failed_warn(peer->pps, &peer->channel_id, "Unable to calculate starting channel amount"); /* Tasks: * Add up total funding_amount * Check in[TX_INITIATOR] - out[TX_INITIATOR] > opener_relative * - refactor as in[TX_INITIATOR] > opener_relative + out[TX_INITIATOR] * - remainder is the fee contribution * Check in[TX_ACCEPTER] - out[TX_ACCEPTER] > accepter_relative * - refactor as in[TX_INITIATOR] > opener_relative + out[TX_INITIATOR] * - remainder is the fee contribution * * Check if fee rate is too low anywhere * Check if fee rate is too high locally * * While we're, here, adjust the output counts by splice amount. */ if(peer->splicing->opener_relative > 0) { if (!amount_msat_add_sat(&funding_amount, funding_amount, amount_sat((u64)peer->splicing->opener_relative))) peer_failed_warn(peer->pps, &peer->channel_id, "Unable to add opener funding"); if (!amount_msat_add_sat(&out[TX_INITIATOR], out[TX_INITIATOR], amount_sat((u64)peer->splicing->opener_relative))) peer_failed_warn(peer->pps, &peer->channel_id, "Unable to add opener funding to out amnt."); } else { if (!amount_msat_sub_sat(&funding_amount, funding_amount, amount_sat((u64)-peer->splicing->opener_relative))) peer_failed_warn(peer->pps, &peer->channel_id, "Unable to sub opener funding"); if (!amount_msat_sub_sat(&out[TX_INITIATOR], out[TX_INITIATOR], amount_sat((u64)peer->splicing->opener_relative))) peer_failed_warn(peer->pps, &peer->channel_id, "Unable to sub opener funding from out amnt."); } if(peer->splicing->accepter_relative > 0) { if (!amount_msat_add_sat(&funding_amount, funding_amount, amount_sat((u64)peer->splicing->accepter_relative))) peer_failed_warn(peer->pps, &peer->channel_id, "Unable to add accepter funding"); if (!amount_msat_add_sat(&out[TX_ACCEPTER], out[TX_ACCEPTER], amount_sat((u64)peer->splicing->accepter_relative))) peer_failed_warn(peer->pps, &peer->channel_id, "Unable to add accepter funding to out amnt."); } else { if (!amount_msat_sub_sat(&funding_amount, funding_amount, amount_sat((u64)-peer->splicing->accepter_relative))) peer_failed_warn(peer->pps, &peer->channel_id, "Unable to subtract accepter funding"); if (!amount_msat_sub_sat(&out[TX_ACCEPTER], out[TX_ACCEPTER], amount_sat((u64)-peer->splicing->accepter_relative))) peer_failed_warn(peer->pps, &peer->channel_id, "Unable to sub accepter funding from out amnt."); } if (amount_msat_less(in[TX_INITIATOR], out[TX_INITIATOR])) { msg = towire_channeld_splice_funding_error(NULL, in[TX_INITIATOR], out[TX_INITIATOR], true); wire_sync_write(MASTER_FD, take(msg)); peer_failed_warn(peer->pps, &peer->channel_id, "Initiator funding is less than commited" " amount. Initiator contributing %s but they" " committed to %s.", fmt_amount_msat(tmpctx, in[TX_INITIATOR]), fmt_amount_msat(tmpctx, out[TX_INITIATOR])); } if (!amount_msat_sub(&initiator_fee, in[TX_INITIATOR], out[TX_INITIATOR])) status_failed(STATUS_FAIL_INTERNAL_ERROR, "amount_sat_less / amount_sat_sub mismtach"); if (amount_msat_less(in[TX_ACCEPTER], out[TX_ACCEPTER])) { msg = towire_channeld_splice_funding_error(NULL, in[TX_INITIATOR], out[TX_INITIATOR], true); wire_sync_write(MASTER_FD, take(msg)); peer_failed_warn(peer->pps, &peer->channel_id, "Accepter funding is less than commited" " amount. Accepter contributing %s but they" " committed to %s.", fmt_amount_msat(tmpctx, in[TX_INITIATOR]), fmt_amount_msat(tmpctx, out[TX_INITIATOR])); } if (!amount_msat_sub(&accepter_fee, in[TX_ACCEPTER], out[TX_ACCEPTER])) status_failed(STATUS_FAIL_INTERNAL_ERROR, "amount_sat_less / amount_sat_sub mismtach"); min_initiator_fee = amount_tx_fee(peer->splicing->feerate_per_kw, calc_weight(TX_INITIATOR, psbt)); min_accepter_fee = amount_tx_fee(peer->splicing->feerate_per_kw, calc_weight(TX_ACCEPTER, psbt)); /* As a safeguard max feerate is checked (only) locally, if it's * particularly high we fail and tell the user but allow them to * override with `splice_force_feerate` */ max_accepter_fee = amount_tx_fee(peer->feerate_max, calc_weight(TX_ACCEPTER, psbt)); max_initiator_fee = amount_tx_fee(peer->feerate_max, calc_weight(TX_INITIATOR, psbt)); /* Check initiator fee */ if (amount_msat_less_sat(initiator_fee, min_initiator_fee)) { msg = towire_channeld_splice_feerate_error(NULL, initiator_fee, false); wire_sync_write(MASTER_FD, take(msg)); /* DTODO: Swap `peer_failed_warn` out for `tx_abort`? */ peer_failed_warn(peer->pps, &peer->channel_id, "%s fee (%s) was too low, must be at least %s", opener ? "Our" : "Your", type_to_string(tmpctx, struct amount_msat, &initiator_fee), type_to_string(tmpctx, struct amount_sat, &min_initiator_fee)); } if (!peer->splicing->force_feerate && opener && amount_msat_greater_sat(initiator_fee, max_initiator_fee)) { msg = towire_channeld_splice_feerate_error(NULL, initiator_fee, true); wire_sync_write(MASTER_FD, take(msg)); /* DTODO: Swap `peer_failed_warn` out for `tx_abort` */ peer_failed_warn(peer->pps, &peer->channel_id, "Our own fee (%s) was too high, max without" " forcing is %s.", type_to_string(tmpctx, struct amount_msat, &initiator_fee), type_to_string(tmpctx, struct amount_sat, &max_initiator_fee)); } /* Check accepter fee */ if (amount_msat_less_sat(accepter_fee, min_accepter_fee)) { msg = towire_channeld_splice_feerate_error(NULL, accepter_fee, false); wire_sync_write(MASTER_FD, take(msg)); /* DTODO: Swap `peer_failed_warn` out for `tx_abort`? */ peer_failed_warn(peer->pps, &peer->channel_id, "%s fee (%s) was too low, must be at least %s", opener ? "Your" : "Our", type_to_string(tmpctx, struct amount_msat, &accepter_fee), type_to_string(tmpctx, struct amount_sat, &min_accepter_fee)); } if (!peer->splicing->force_feerate && !opener && amount_msat_greater_sat(accepter_fee, max_accepter_fee)) { msg = towire_channeld_splice_feerate_error(NULL, accepter_fee, true); wire_sync_write(MASTER_FD, take(msg)); /* DTODO: Swap `peer_failed_warn` out for `tx_abort` */ peer_failed_warn(peer->pps, &peer->channel_id, "Our own fee (%s) was too high, max without" " forcing is %s.", type_to_string(tmpctx, struct amount_msat, &accepter_fee), type_to_string(tmpctx, struct amount_sat, &max_accepter_fee)); } /* BOLT-??? #2: * - if either side has added an output other than the new channel * funding output: * - MUST fail the negotiation if the balance for that side is less * than 1% of the total channel capacity. */ /* DTODO: Spec out reserve requirements for splices!! Lets gooo */ /* DTODO: If we were at or over the reserve at start of splice, * then we must ensure the reserve is preserved through splice. * It should only to 1% of the old balance * 1: The channel is growing * --- your balnce was underneath reserve req * Valid: YES * 2: The node's balance is shrinking * --- and it shrinks below the reserve * Valid: NO * * The reserve requirement should only matter if someone is withdrawing * from. * * Node A Node B * 1000 sat <-> 1000 sat * reserve: 20sat * * Node B desires withdraw 990 sats * Can I? * New reserve req = 1010 * 0.01 = 10 (round down from 10.1) * */ if (!amount_msat_to_sat(&funding_amount_res, funding_amount)) status_failed(STATUS_FAIL_INTERNAL_ERROR, "splice error: msat of boths sides should always" " add up to a full sat."); return funding_amount_res; } static u32 find_channel_funding_input(struct wally_psbt *psbt, struct bitcoin_outpoint *funding) { for (size_t i = 0; i < psbt->num_inputs; i++) { struct bitcoin_outpoint psbt_outpoint; wally_psbt_input_get_outpoint(&psbt->inputs[i], &psbt_outpoint); if (!bitcoin_outpoint_eq(&psbt_outpoint, funding)) continue; if (funding->n == psbt->inputs[i].index) return i; } status_failed(STATUS_FAIL_INTERNAL_ERROR, "Unable to find splice funding tx"); return UINT_MAX; } static void update_view_from_inflights(struct peer *peer) { struct inflight **inflights = peer->splice_state->inflights; for (size_t i = 0; i < tal_count(inflights); i++) { s64 splice_amnt = inflights[i]->amnt.satoshis; /* Raw: splicing */ s64 funding_diff = sats_diff(inflights[i]->amnt, peer->channel->funding_sats); s64 remote_splice_amnt = funding_diff - inflights[i]->splice_amnt; if (splice_amnt < peer->channel->view[LOCAL].lowest_splice_amnt[LOCAL]) peer->channel->view[LOCAL].lowest_splice_amnt[LOCAL] = splice_amnt; if (splice_amnt < peer->channel->view[REMOTE].lowest_splice_amnt[REMOTE]) peer->channel->view[REMOTE].lowest_splice_amnt[LOCAL] = splice_amnt; if (remote_splice_amnt < peer->channel->view[LOCAL].lowest_splice_amnt[REMOTE]) peer->channel->view[LOCAL].lowest_splice_amnt[REMOTE] = remote_splice_amnt; if (remote_splice_amnt < peer->channel->view[REMOTE].lowest_splice_amnt[LOCAL]) peer->channel->view[REMOTE].lowest_splice_amnt[REMOTE] = remote_splice_amnt; } } /* Called to finish an ongoing splice OR one restart from chanenl_reestablish */ static void resume_splice_negotiation(struct peer *peer, struct inflight *inflight, bool skip_commitments, enum tx_role our_role) { const u8 *wit_script; struct channel_id cid; enum peer_wire type; struct wally_psbt *current_psbt = inflight->psbt; struct commitsig *their_commit; struct witness **inws; const struct witness **outws; u8 der[73]; size_t der_len; struct bitcoin_signature splice_sig; struct bitcoin_tx *bitcoin_tx; u32 splice_funding_index; const u8 *msg, *sigmsg; u32 chan_output_index; struct bitcoin_signature their_sig; struct pubkey *their_pubkey; struct bitcoin_tx *final_tx; u8 **wit_stack; struct tlv_txsigs_tlvs *txsig_tlvs, *their_txsigs_tlvs; wit_script = bitcoin_redeem_2of2(tmpctx, &peer->channel->funding_pubkey[LOCAL], &peer->channel->funding_pubkey[REMOTE]); find_channel_output(peer, current_psbt, &chan_output_index); splice_funding_index = find_channel_funding_input(current_psbt, &peer->channel->funding); if (!skip_commitments) { their_commit = interactive_send_commitments(peer, current_psbt, our_role); inflight->last_tx = tal_steal(inflight, their_commit->tx); inflight->last_sig = their_commit->commit_signature; msg = towire_channeld_update_inflight(NULL, current_psbt, their_commit->tx, &their_commit->commit_signature); wire_sync_write(MASTER_FD, take(msg)); } /* DTODO Validate splice tx takes none of our funds in either: * 1) channel balance * 2) other side sneakily adding other outputs we own */ /* BOLT-a8b9f495cac28124c69cc5ee429f9ef2bacb9921 #2: * Both nodes: * - MUST sign the transaction using SIGHASH_ALL */ splice_sig.sighash_type = SIGHASH_ALL; bitcoin_tx = bitcoin_tx_with_psbt(tmpctx, current_psbt); status_info("Splice signing tx: %s", tal_hex(tmpctx, linearize_tx(tmpctx, bitcoin_tx))); msg = towire_hsmd_sign_splice_tx(tmpctx, bitcoin_tx, &peer->channel->funding_pubkey[REMOTE], splice_funding_index); msg = hsm_req(tmpctx, take(msg)); if (!fromwire_hsmd_sign_tx_reply(msg, &splice_sig)) status_failed(STATUS_FAIL_HSM_IO, "Reading sign_splice_tx reply: %s", tal_hex(tmpctx, msg)); /* Set the splice_sig on the splice funding tx psbt */ if (!psbt_input_set_signature(current_psbt, splice_funding_index, &peer->channel->funding_pubkey[LOCAL], &splice_sig)) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Unable to set signature internally " "funding_index: %d " "my pubkey: %s " "my signature: %s " "psbt: %s", splice_funding_index, type_to_string(tmpctx, struct pubkey, &peer->channel->funding_pubkey[LOCAL]), type_to_string(tmpctx, struct bitcoin_signature, &splice_sig), type_to_string(tmpctx, struct wally_psbt, current_psbt)); txsig_tlvs = tlv_txsigs_tlvs_new(tmpctx); der_len = signature_to_der(der, &splice_sig); txsig_tlvs->funding_outpoint_sig = tal_dup_arr(tmpctx, u8, der, der_len, 0); outws = psbt_to_witnesses(tmpctx, current_psbt, our_role, splice_funding_index); sigmsg = towire_tx_signatures(tmpctx, &peer->channel_id, &inflight->outpoint.txid, outws, txsig_tlvs); if (do_i_sign_first(peer, current_psbt, our_role)) { status_debug("Splice: we sign first"); msg = towire_channeld_update_inflight(NULL, current_psbt, NULL, NULL); wire_sync_write(MASTER_FD, take(msg)); peer_write(peer->pps, sigmsg); } msg = peer_read(tmpctx, peer->pps); type = fromwire_peektype(msg); if (handle_peer_error(peer->pps, &peer->channel_id, msg)) return; if (type != WIRE_TX_SIGNATURES) peer_failed_warn(peer->pps, &peer->channel_id, "Splicing got incorrect message from peer: %s " "(should be WIRE_TX_SIGNATURES)", peer_wire_name(type)); their_txsigs_tlvs = tlv_txsigs_tlvs_new(tmpctx); if (!fromwire_tx_signatures(tmpctx, msg, &cid, &inflight->outpoint.txid, cast_const3(struct witness ***, &inws), &their_txsigs_tlvs)) peer_failed_warn(peer->pps, &peer->channel_id, "Splicing bad tx_signatures %s", tal_hex(msg, msg)); /* BOLT-0d8b701614b09c6ee4172b04da2203e73deec7e2 #2: * - Upon receipt of `tx_signatures` for the splice transaction: * - MUST consider splice negotiation complete. * - MUST consider the connection no longer quiescent. */ end_stfu_mode(peer); /* BOLT-a8b9f495cac28124c69cc5ee429f9ef2bacb9921 #2: * Both nodes: * - MUST sign the transaction using SIGHASH_ALL */ their_sig.sighash_type = SIGHASH_ALL; if (!signature_from_der(their_txsigs_tlvs->funding_outpoint_sig, tal_count(their_txsigs_tlvs->funding_outpoint_sig), &their_sig)) { peer_failed_warn(peer->pps, &peer->channel_id, "Splicing bad tx_signatures %s", tal_hex(msg, msg)); } their_pubkey = &peer->channel->funding_pubkey[REMOTE]; /* Set the commit_sig on the commitment tx psbt */ if (!psbt_input_set_signature(current_psbt, splice_funding_index, their_pubkey, &their_sig)) { status_failed(STATUS_FAIL_INTERNAL_ERROR, "Unable to set signature internally " "funding_index: %d " "pubkey: %s " "signature: %s " "psbt: %s", splice_funding_index, type_to_string(tmpctx, struct pubkey, their_pubkey), type_to_string(tmpctx, struct bitcoin_signature, &their_sig), type_to_string(tmpctx, struct wally_psbt, current_psbt)); } psbt_input_set_witscript(current_psbt, splice_funding_index, wit_script); if (tal_count(inws) > current_psbt->num_inputs) peer_failed_warn(peer->pps, &peer->channel_id, "%zu too many witness elements received", tal_count(inws) - current_psbt->num_inputs); /* We put the PSBT + sigs all together */ for (size_t j = 0, i = 0; i < current_psbt->num_inputs; i++) { struct wally_psbt_input *in = &current_psbt->inputs[i]; u64 in_serial; if (!psbt_get_serial_id(&in->unknowns, &in_serial)) { status_broken("PSBT input %zu missing serial_id %s", i, type_to_string(tmpctx, struct wally_psbt, current_psbt)); return; } if (in_serial % 2 == our_role) continue; if (i == splice_funding_index) continue; if (j == tal_count(inws)) peer_failed_warn(peer->pps, &peer->channel_id, "Mismatch witness stack count %s", tal_hex(msg, msg)); psbt_finalize_input(current_psbt, in, inws[j++]); } final_tx = bitcoin_tx_with_psbt(tmpctx, current_psbt); wit_stack = bitcoin_witness_2of2(current_psbt, &splice_sig, &their_sig, &peer->channel->funding_pubkey[LOCAL], their_pubkey); bitcoin_tx_input_set_witness(final_tx, splice_funding_index, wit_stack); /* We let core validate our peer's signatures are correct. */ msg = towire_channeld_update_inflight(NULL, current_psbt, NULL, NULL); wire_sync_write(MASTER_FD, take(msg)); if (!do_i_sign_first(peer, current_psbt, our_role)) { status_debug("Splice: we sign second"); peer_write(peer->pps, sigmsg); } peer->splicing = tal_free(peer->splicing); msg = towire_channeld_splice_confirmed_signed(tmpctx, final_tx, chan_output_index); wire_sync_write(MASTER_FD, take(msg)); send_channel_update(peer, 0); } static struct inflight *inflights_new(struct peer *peer) { struct inflight *inf = tal(peer->splice_state->inflights, struct inflight); int i = tal_count(peer->splice_state->inflights); if (i) tal_resize(&peer->splice_state->inflights, i + 1); else peer->splice_state->inflights = tal_arr(peer->splice_state, struct inflight *, 1); peer->splice_state->inflights[i] = inf; return inf; } /* ACCEPTER side of the splice. Here we handle all the accepter's steps for the * splice. Since the channel must be in STFU mode we block the daemon here until * the splice is finished or aborted. */ static void splice_accepter(struct peer *peer, const u8 *inmsg) { const u8 *msg; struct interactivetx_context *ictx; u32 splice_funding_index; struct bitcoin_blkid genesis_blockhash; struct channel_id channel_id; struct amount_sat both_amount; u32 funding_feerate_perkw; u32 locktime; struct pubkey splice_remote_pubkey; char *error; struct inflight *new_inflight; struct wally_psbt_output *new_chan_output; struct bitcoin_outpoint outpoint; /* Can't start a splice with another splice still active */ assert(!peer->splicing); peer->splicing = splicing_new(peer); ictx = new_interactivetx_context(tmpctx, TX_ACCEPTER, peer->pps, peer->channel_id); if (!fromwire_splice(inmsg, &channel_id, &genesis_blockhash, &peer->splicing->opener_relative, &funding_feerate_perkw, &locktime, &splice_remote_pubkey)) peer_failed_warn(peer->pps, &peer->channel_id, "Bad wire_splice %s", tal_hex(tmpctx, inmsg)); peer->splice_state->await_commitment_succcess = false; if (!is_stfu_active(peer)) peer_failed_warn(peer->pps, &peer->channel_id, "Must be in STFU mode before intiating splice"); if (!bitcoin_blkid_eq(&genesis_blockhash, &chainparams->genesis_blockhash)) peer_failed_warn(peer->pps, &peer->channel_id, "Bad splice blockhash"); if (!channel_id_eq(&channel_id, &peer->channel_id)) peer_failed_warn(peer->pps, &peer->channel_id, "Splice internal error: mismatched channelid"); if (!pubkey_eq(&splice_remote_pubkey, &peer->channel->funding_pubkey[REMOTE])) peer_failed_warn(peer->pps, &peer->channel_id, "Splice doesnt support changing pubkeys"); if (funding_feerate_perkw < peer->feerate_min) peer_failed_warn(peer->pps, &peer->channel_id, "Splice feerate_perkw is too low"); /* TODO: Add plugin hook for user to adjust accepter amount */ peer->splicing->accepter_relative = 0; msg = towire_splice_ack(NULL, &peer->channel_id, &chainparams->genesis_blockhash, peer->splicing->accepter_relative, &peer->channel->funding_pubkey[LOCAL]); peer->splicing->mode = true; peer_write(peer->pps, take(msg)); /* Now we wait for the other side to go first. * * BOLT-0d8b701614b09c6ee4172b04da2203e73deec7e2 #2: * The receiver of `splice_ack`: * - MUST begin splice negotiation. */ ictx->next_update_fn = next_splice_step; ictx->desired_psbt = NULL; ictx->pause_when_complete = false; error = process_interactivetx_updates(tmpctx, ictx, &peer->splicing->received_tx_complete); if (error) peer_failed_err(peer->pps, &peer->channel_id, "Interactive splicing error: %s", error); assert(ictx->pause_when_complete == false); peer->splicing->sent_tx_complete = true; /* DTODO validate locktime */ ictx->current_psbt->fallback_locktime = locktime; splice_funding_index = find_channel_funding_input(ictx->current_psbt, &peer->channel->funding); new_chan_output = find_channel_output(peer, ictx->current_psbt, &outpoint.n); both_amount = check_balances(peer, TX_ACCEPTER, ictx->current_psbt, outpoint.n, splice_funding_index); new_chan_output->amount = both_amount.satoshis; /* Raw: type conv */ psbt_elements_normalize_fees(ictx->current_psbt); psbt_txid(tmpctx, ictx->current_psbt, &outpoint.txid, NULL); psbt_finalize(ictx->current_psbt); status_debug("Splice accepter adding inflight: %s", psbt_to_b64(tmpctx, ictx->current_psbt)); msg = towire_channeld_add_inflight(NULL, &outpoint.txid, outpoint.n, funding_feerate_perkw, both_amount, peer->splicing->accepter_relative, ictx->current_psbt, false); master_wait_sync_reply(tmpctx, peer, take(msg), WIRE_CHANNELD_GOT_INFLIGHT); new_inflight = inflights_new(peer); psbt_txid(new_inflight, ictx->current_psbt, &new_inflight->outpoint.txid, NULL); new_inflight->outpoint = outpoint; new_inflight->amnt = both_amount; new_inflight->psbt = tal_steal(new_inflight, ictx->current_psbt); new_inflight->splice_amnt = peer->splicing->accepter_relative; new_inflight->last_tx = NULL; new_inflight->i_am_initiator = false; update_view_from_inflights(peer); peer->splice_state->count++; resume_splice_negotiation(peer, new_inflight, false, TX_ACCEPTER); } static struct bitcoin_tx *bitcoin_tx_from_txid(struct peer *peer, struct bitcoin_txid txid) { u8 *msg; struct bitcoin_tx *tx = NULL; msg = towire_channeld_splice_lookup_tx(NULL, &txid); msg = master_wait_sync_reply(tmpctx, peer, take(msg), WIRE_CHANNELD_SPLICE_LOOKUP_TX_RESULT); if (!fromwire_channeld_splice_lookup_tx_result(tmpctx, msg, &tx)) master_badmsg(WIRE_CHANNELD_SPLICE_LOOKUP_TX_RESULT, msg); return tx; } /* splice_initiator runs when splice_ack is received by the other side. It * handles the initial splice creation while callbacks will handle later * stages. */ static void splice_initiator(struct peer *peer, const u8 *inmsg) { struct bitcoin_blkid genesis_blockhash; struct channel_id channel_id; struct pubkey splice_remote_pubkey; size_t input_index; const u8 *wit_script; u8 *outmsg; struct interactivetx_context *ictx; struct bitcoin_tx *prev_tx; u32 sequence = 0; u8 *scriptPubkey; char *error; status_debug("splice_initiator peer->stfu_wait_single_msg: %d", (int)peer->stfu_wait_single_msg); ictx = new_interactivetx_context(tmpctx, TX_INITIATOR, peer->pps, peer->channel_id); if (!fromwire_splice_ack(inmsg, &channel_id, &genesis_blockhash, &peer->splicing->accepter_relative, &splice_remote_pubkey)) peer_failed_warn(peer->pps, &peer->channel_id, "Bad wire_splice_ack %s", tal_hex(tmpctx, inmsg)); if (!bitcoin_blkid_eq(&genesis_blockhash, &chainparams->genesis_blockhash)) peer_failed_warn(peer->pps, &peer->channel_id, "Bad splice[ACK] blockhash"); if (!channel_id_eq(&channel_id, &peer->channel_id)) peer_failed_warn(peer->pps, &peer->channel_id, "Splice[ACK] internal error: mismatched channelid"); if (!pubkey_eq(&splice_remote_pubkey, &peer->channel->funding_pubkey[REMOTE])) peer_failed_warn(peer->pps, &peer->channel_id, "Splice[ACK] doesnt support changing pubkeys"); peer->splicing->received_tx_complete = false; peer->splicing->sent_tx_complete = false; peer->splice_state->locked_ready[LOCAL] = false; peer->splice_state->locked_ready[REMOTE] = false; ictx->next_update_fn = next_splice_step; ictx->pause_when_complete = true; ictx->desired_psbt = peer->splicing->current_psbt; /* We go first as the receiver of the ack. * * BOLT-0d8b701614b09c6ee4172b04da2203e73deec7e2 #2: * The receiver of `splice_ack`: * - MUST begin splice negotiation. */ BUILD_ASSERT(NUM_SIDES == 2); wit_script = bitcoin_redeem_2of2(tmpctx, &peer->channel->funding_pubkey[LOCAL], &peer->channel->funding_pubkey[REMOTE]); input_index = ictx->desired_psbt->num_inputs; /* First we spend the existing channel outpoint * * BOLT-0d8b701614b09c6ee4172b04da2203e73deec7e2 #2: * The initiator: * - MUST `tx_add_input` an input which spends the current funding * transaction output. */ psbt_append_input(ictx->desired_psbt, &peer->channel->funding, sequence, NULL, wit_script, NULL); status_debug("just added funding w/ outpoint index set to %d, value in psbt input 1 is: %d, and value in psbt input 2 is: %d", (int)peer->channel->funding.n, (int)ictx->desired_psbt->inputs[0].index, (int)ictx->desired_psbt->inputs[1].index); /* Segwit requires us to store the value of the outpoint being spent, * so let's do that */ scriptPubkey = scriptpubkey_p2wsh(ictx->desired_psbt, wit_script); psbt_input_set_wit_utxo(ictx->desired_psbt, input_index, scriptPubkey, peer->channel->funding_sats); /* We must loading the funding tx as our previous utxo */ prev_tx = bitcoin_tx_from_txid(peer, peer->channel->funding.txid); psbt_input_set_utxo(ictx->desired_psbt, input_index, prev_tx->wtx); /* PSBT v2 requires this */ psbt_input_set_outpoint(ictx->desired_psbt, input_index, peer->channel->funding); /* Next we add the new channel outpoint, with a 0 amount for now. It * will be filled in later. * * BOLT-0d8b701614b09c6ee4172b04da2203e73deec7e2 #2: * The initiator: * ... * - MUST `tx_add_output` a zero-value output which pays to the two * funding keys using the higher of the two `generation` fields. */ psbt_append_output(ictx->desired_psbt, scriptpubkey_p2wsh(ictx->desired_psbt, wit_script), amount_sat(0)); psbt_add_serials(ictx->desired_psbt, ictx->our_role); error = process_interactivetx_updates(tmpctx, ictx, &peer->splicing->received_tx_complete); if (error) peer_failed_warn(peer->pps, &peer->channel_id, "Interactive splicing_ack error: %s", error); peer->splicing->tx_add_input_count = ictx->tx_add_input_count; peer->splicing->tx_add_output_count = ictx->tx_add_output_count; if (peer->splicing->current_psbt != ictx->current_psbt) tal_free(peer->splicing->current_psbt); peer->splicing->current_psbt = tal_steal(peer->splicing, ictx->current_psbt); peer->splicing->mode = true; /* Return the current PSBT to the channel_control to give to user. */ outmsg = towire_channeld_splice_confirmed_init(NULL, ictx->current_psbt); wire_sync_write(MASTER_FD, take(outmsg)); } /* This occurs when the user has marked they are done making changes to the * PSBT. Now we continually send `tx_complete` and intake our peer's changes * inside `process_interactivetx_updates`. Once they are onboard indicated * with their sending of `tx_complete` we clean up the final PSBT and return * to the user for their final signing steps. */ static void splice_initiator_user_finalized(struct peer *peer) { u8 *outmsg; struct interactivetx_context *ictx; char *error; u32 chan_output_index, splice_funding_index; struct wally_psbt_output *new_chan_output; struct inflight *new_inflight; struct bitcoin_txid current_psbt_txid; struct amount_sat both_amount; struct commitsig *their_commit; ictx = new_interactivetx_context(tmpctx, TX_INITIATOR, peer->pps, peer->channel_id); ictx->next_update_fn = next_splice_step; ictx->pause_when_complete = false; ictx->desired_psbt = ictx->current_psbt = peer->splicing->current_psbt; ictx->tx_add_input_count = peer->splicing->tx_add_input_count; ictx->tx_add_output_count = peer->splicing->tx_add_output_count; error = process_interactivetx_updates(tmpctx, ictx, &peer->splicing->received_tx_complete); if (error) peer_failed_warn(peer->pps, &peer->channel_id, "Splice finalize error: %s", error); /* With pause_when_complete fase, this assert should never fail */ assert(peer->splicing->received_tx_complete); peer->splicing->sent_tx_complete = true; psbt_sort_by_serial_id(ictx->current_psbt); new_chan_output = find_channel_output(peer, ictx->current_psbt, &chan_output_index); splice_funding_index = find_channel_funding_input(ictx->current_psbt, &peer->channel->funding); both_amount = check_balances(peer, TX_INITIATOR, ictx->current_psbt, chan_output_index, splice_funding_index); new_chan_output->amount = both_amount.satoshis; /* Raw: type conv */ psbt_elements_normalize_fees(ictx->current_psbt); status_debug("Splice adding inflight: %s", psbt_to_b64(tmpctx, ictx->current_psbt)); psbt_txid(tmpctx, ictx->current_psbt, &current_psbt_txid, NULL); outmsg = towire_channeld_add_inflight(tmpctx, &current_psbt_txid, chan_output_index, peer->splicing->feerate_per_kw, amount_sat(new_chan_output->amount), peer->splicing->opener_relative, ictx->current_psbt, true); master_wait_sync_reply(tmpctx, peer, take(outmsg), WIRE_CHANNELD_GOT_INFLIGHT); new_inflight = inflights_new(peer); psbt_txid(tmpctx, ictx->current_psbt, &new_inflight->outpoint.txid, NULL); new_inflight->outpoint.n = chan_output_index; new_inflight->psbt = tal_steal(new_inflight, ictx->current_psbt); new_inflight->amnt = amount_sat(new_chan_output->amount); new_inflight->splice_amnt = peer->splicing->opener_relative; new_inflight->last_tx = NULL; new_inflight->i_am_initiator = true; update_view_from_inflights(peer); peer->splice_state->count++; their_commit = interactive_send_commitments(peer, ictx->current_psbt, TX_INITIATOR); new_inflight->last_tx = tal_steal(peer, their_commit->tx); new_inflight->last_sig = their_commit->commit_signature; outmsg = towire_channeld_update_inflight(NULL, ictx->current_psbt, their_commit->tx, &their_commit->commit_signature); wire_sync_write(MASTER_FD, take(outmsg)); status_debug("user_finalized peer->stfu_wait_single_msg: %d", (int)peer->stfu_wait_single_msg); if (peer->splicing->current_psbt != ictx->current_psbt) tal_free(peer->splicing->current_psbt); peer->splicing->current_psbt = tal_steal(peer->splicing, ictx->current_psbt); outmsg = towire_channeld_splice_confirmed_update(NULL, ictx->current_psbt, true); wire_sync_write(MASTER_FD, take(outmsg)); } /* During a splice the user may call splice_update mulitple times adding * new details to the active PSBT. Each user call enters here: */ static void splice_initiator_user_update(struct peer *peer, const u8 *inmsg) { u8 *outmsg, *msg; struct interactivetx_context *ictx; char *error; if (!peer->splicing) { msg = towire_channeld_splice_state_error(NULL, "Can't accept a" " splice PSBT update" " because this channel" " hasn't begun a" " splice."); wire_sync_write(MASTER_FD, take(msg)); return; } ictx = new_interactivetx_context(tmpctx, TX_INITIATOR, peer->pps, peer->channel_id); if (!fromwire_channeld_splice_update(ictx, inmsg, &ictx->desired_psbt)) master_badmsg(WIRE_CHANNELD_SPLICE_UPDATE, inmsg); if (!peer->splicing->mode) { msg = towire_channeld_splice_state_error(NULL, "Can't update a" " splice when not in" " splice mode."); wire_sync_write(MASTER_FD, take(msg)); return; } ictx->next_update_fn = next_splice_step; ictx->pause_when_complete = true; /* Should already have a current_psbt from a previously initiated one */ assert(peer->splicing->current_psbt); ictx->current_psbt = peer->splicing->current_psbt; ictx->tx_add_input_count = peer->splicing->tx_add_input_count; ictx->tx_add_output_count = peer->splicing->tx_add_output_count; /* User may not have setup serial numbers on their modifeid PSBT, so we * ensure that for them here */ psbt_add_serials(ictx->desired_psbt, ictx->our_role); status_debug("splice_update start with, current psbt version: %d," " desired: %d.", ictx->current_psbt->version, ictx->desired_psbt->version); /* If there no are no changes, we consider the splice 'user finalized' */ if (!interactivetx_has_changes(ictx, ictx->desired_psbt)) { splice_initiator_user_finalized(peer); return; } error = process_interactivetx_updates(tmpctx, ictx, &peer->splicing->received_tx_complete); if (error) peer_failed_warn(peer->pps, &peer->channel_id, "Splice update error: %s", error); peer->splicing->tx_add_input_count = ictx->tx_add_input_count; peer->splicing->tx_add_output_count = ictx->tx_add_output_count; if (peer->splicing->current_psbt != ictx->current_psbt) tal_free(peer->splicing->current_psbt); peer->splicing->current_psbt = tal_steal(peer->splicing, ictx->current_psbt); /* Peer may have modified our PSBT so we return it to the user here */ outmsg = towire_channeld_splice_confirmed_update(NULL, ictx->current_psbt, false); wire_sync_write(MASTER_FD, take(outmsg)); } static struct inflight *last_inflight(struct peer *peer) { size_t count = tal_count(peer->splice_state->inflights); if (count) return peer->splice_state->inflights[count - 1]; return NULL; } /* This occurs when the user has signed the final version of the PSBT. At this * point we do a commitment transaciton round with our peer via * `interactive_send_commitments`. * * Then we finalize the PSBT some more and sign away our funding output, * place that signature in the PSBT, and pass our signature to the peer and get * theirs back. */ static void splice_initiator_user_signed(struct peer *peer, const u8 *inmsg) { struct wally_psbt *signed_psbt; struct bitcoin_txid current_psbt_txid, signed_psbt_txid; struct inflight *inflight; const u8 *msg; if (!peer->splicing) { msg = towire_channeld_splice_state_error(NULL, "Can't accept a" " signed splice PSBT" " because this channel" " hasn't begun a" " splice."); wire_sync_write(MASTER_FD, take(msg)); return; } if (!fromwire_channeld_splice_signed(tmpctx, inmsg, &signed_psbt, &peer->splicing->force_sign_first)) master_badmsg(WIRE_CHANNELD_SPLICE_SIGNED, inmsg); if (!peer->splicing->mode) { msg = towire_channeld_splice_state_error(NULL, "Can't sign a" " splice when not in" " splice mode."); wire_sync_write(MASTER_FD, take(msg)); return; } if (!peer->splicing->received_tx_complete) { msg = towire_channeld_splice_state_error(NULL, "Can't sign a" " splice when we" " haven't received" " tx_complete yet."); wire_sync_write(MASTER_FD, take(msg)); return; } if (!peer->splicing->sent_tx_complete) { msg = towire_channeld_splice_state_error(NULL, "Can't sign a" " splice when we" " haven't sent" " tx_complete yet."); wire_sync_write(MASTER_FD, take(msg)); return; } psbt_txid(tmpctx, peer->splicing->current_psbt, &current_psbt_txid, NULL); psbt_txid(tmpctx, signed_psbt, &signed_psbt_txid, NULL); if (!bitcoin_txid_eq(&signed_psbt_txid, &current_psbt_txid)) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Signed PSBT txid %s does not match" " current_psbt_txid %s", type_to_string(tmpctx, struct bitcoin_txid, &signed_psbt_txid), type_to_string(tmpctx, struct bitcoin_txid, &current_psbt_txid)); peer->splicing->current_psbt = tal_free(peer->splicing->current_psbt); inflight = last_inflight(peer); inflight->psbt = tal_steal(inflight, signed_psbt); resume_splice_negotiation(peer, inflight, true, TX_INITIATOR); } /* This occurs once our 'stfu' transition was successful. */ static void handle_splice_stfu_success(struct peer *peer) { u8 *msg = towire_splice(tmpctx, &peer->channel_id, &chainparams->genesis_blockhash, peer->splicing->opener_relative, peer->splicing->feerate_per_kw, peer->splicing->current_psbt->fallback_locktime, &peer->channel->funding_pubkey[LOCAL]); peer->splice_state->await_commitment_succcess = false; peer_write(peer->pps, take(msg)); } /* User has begun a splice with `splice_init` command. Here we request entry * into STFU mode, when we get it, send `splice` to our peer-> * Later the peer will send `splice_ack` and the code that starts the actual * splice happens at that point in `splice_initiator()`. */ static void handle_splice_init(struct peer *peer, const u8 *inmsg) { u8 *msg; /* Can't start a splice with another splice still active */ if (peer->splicing) { msg = towire_channeld_splice_state_error(NULL, "Can't start two" " splices on the same" " channel at once."); wire_sync_write(MASTER_FD, take(msg)); return; } peer->splicing = splicing_new(peer); if (!fromwire_channeld_splice_init(peer, inmsg, &peer->splicing->current_psbt, &peer->splicing->opener_relative, &peer->splicing->feerate_per_kw, &peer->splicing->force_feerate)) master_badmsg(WIRE_CHANNELD_SPLICE_INIT, inmsg); if (peer->want_stfu) { msg = towire_channeld_splice_state_error(NULL, "Can't begin a" " splice while waiting" " for STFU."); wire_sync_write(MASTER_FD, take(msg)); return; } if (is_stfu_active(peer)) { msg = towire_channeld_splice_state_error(NULL, "Can't begin a" " splice while" " currently in STFU"); wire_sync_write(MASTER_FD, take(msg)); return; } if (peer->splicing->mode) { msg = towire_channeld_splice_state_error(NULL, "Can't begin a" " splice while already" " doing a splice."); wire_sync_write(MASTER_FD, take(msg)); return; } if (peer->splicing->feerate_per_kw < peer->feerate_min) { msg = towire_channeld_splice_state_error(NULL, tal_fmt(tmpctx, "Feerate %u is too" " low. Lower than" " channel feerate_min" " %u", peer->splicing->feerate_per_kw, peer->feerate_min)); wire_sync_write(MASTER_FD, take(msg)); return; } status_debug("Getting handle_splice_init psbt version %d", peer->splicing->current_psbt->version); peer->on_stfu_success = handle_splice_stfu_success; /* First things first we must STFU the channel */ peer->stfu_initiator = LOCAL; peer->want_stfu = true; maybe_send_stfu(peer); } static void peer_in(struct peer *peer, const u8 *msg) { enum peer_wire type = fromwire_peektype(msg); if (handle_peer_error(peer->pps, &peer->channel_id, msg)) return; /* Must get channel_ready before almost anything. */ if (!peer->channel_ready[REMOTE]) { if (type != WIRE_CHANNEL_READY && type != WIRE_SHUTDOWN /* We expect these for v2 !! */ && type != WIRE_TX_SIGNATURES /* lnd sends these early; it's harmless. */ && type != WIRE_UPDATE_FEE && type != WIRE_ANNOUNCEMENT_SIGNATURES) { peer_failed_warn(peer->pps, &peer->channel_id, "%s (%u) before funding locked", peer_wire_name(type), type); } } /* For cleaner errors, we check message is valid during STFU mode */ if (peer->stfu_wait_single_msg) if (!VALID_STFU_MESSAGE(type)) peer_failed_warn(peer->pps, &peer->channel_id, "Got invalid message during STFU " "mode: %s", peer_wire_name(type)); peer->stfu_wait_single_msg = false; switch (type) { case WIRE_CHANNEL_READY: handle_peer_channel_ready(peer, msg); return; case WIRE_ANNOUNCEMENT_SIGNATURES: handle_peer_announcement_signatures(peer, msg); return; case WIRE_UPDATE_ADD_HTLC: handle_peer_add_htlc(peer, msg); return; case WIRE_COMMITMENT_SIGNED: handle_peer_commit_sig(peer, msg, 0, NULL, 0, 0); return; case WIRE_UPDATE_FEE: handle_peer_feechange(peer, msg); return; case WIRE_UPDATE_BLOCKHEIGHT: handle_peer_blockheight_change(peer, msg); return; case WIRE_REVOKE_AND_ACK: handle_peer_revoke_and_ack(peer, msg); return; case WIRE_UPDATE_FULFILL_HTLC: handle_peer_fulfill_htlc(peer, msg); return; case WIRE_UPDATE_FAIL_HTLC: handle_peer_fail_htlc(peer, msg); return; case WIRE_UPDATE_FAIL_MALFORMED_HTLC: handle_peer_fail_malformed_htlc(peer, msg); return; case WIRE_SHUTDOWN: handle_peer_shutdown(peer, msg); return; case WIRE_STFU: handle_stfu(peer, msg); return; case WIRE_SPLICE: splice_accepter(peer, msg); return; case WIRE_SPLICE_ACK: splice_initiator(peer, msg); return; case WIRE_SPLICE_LOCKED: handle_peer_splice_locked(peer, msg); return; case WIRE_INIT: case WIRE_OPEN_CHANNEL: case WIRE_ACCEPT_CHANNEL: case WIRE_FUNDING_CREATED: case WIRE_FUNDING_SIGNED: case WIRE_CLOSING_SIGNED: case WIRE_TX_ADD_INPUT: case WIRE_TX_REMOVE_INPUT: case WIRE_TX_ADD_OUTPUT: case WIRE_TX_REMOVE_OUTPUT: case WIRE_TX_COMPLETE: case WIRE_TX_ABORT: case WIRE_OPEN_CHANNEL2: case WIRE_ACCEPT_CHANNEL2: case WIRE_TX_SIGNATURES: handle_unexpected_tx_sigs(peer, msg); return; case WIRE_TX_INIT_RBF: case WIRE_TX_ACK_RBF: break; case WIRE_CHANNEL_REESTABLISH: handle_unexpected_reestablish(peer, msg); return; /* These are all swallowed by connectd */ case WIRE_CHANNEL_ANNOUNCEMENT: case WIRE_CHANNEL_UPDATE: case WIRE_NODE_ANNOUNCEMENT: case WIRE_QUERY_SHORT_CHANNEL_IDS: case WIRE_QUERY_CHANNEL_RANGE: case WIRE_REPLY_CHANNEL_RANGE: case WIRE_GOSSIP_TIMESTAMP_FILTER: case WIRE_REPLY_SHORT_CHANNEL_IDS_END: case WIRE_PING: case WIRE_PONG: case WIRE_WARNING: case WIRE_ERROR: case WIRE_ONION_MESSAGE: case WIRE_PEER_STORAGE: case WIRE_YOUR_PEER_STORAGE: abort(); } peer_failed_warn(peer->pps, &peer->channel_id, "Peer sent unknown message %u (%s)", type, peer_wire_name(type)); } static void resend_revoke(struct peer *peer) { struct pubkey point; /* Current commit is peer->next_index[LOCAL]-1, revoke prior */ u8 *msg = make_revocation_msg(peer, peer->next_index[LOCAL]-2, &point); peer_write(peer->pps, take(msg)); } static void send_fail_or_fulfill(struct peer *peer, const struct htlc *h) { u8 *msg; if (h->failed) { const struct failed_htlc *f = h->failed; if (f->sha256_of_onion) { msg = towire_update_fail_malformed_htlc(NULL, &peer->channel_id, h->id, f->sha256_of_onion, f->badonion); } else { msg = towire_update_fail_htlc(peer, &peer->channel_id, h->id, f->onion->contents); } } else if (h->r) { msg = towire_update_fulfill_htlc(NULL, &peer->channel_id, h->id, h->r); } else peer_failed_warn(peer->pps, &peer->channel_id, "HTLC %"PRIu64" state %s not failed/fulfilled", h->id, htlc_state_name(h->state)); peer_write(peer->pps, take(msg)); } static int cmp_changed_htlc_id(const struct changed_htlc *a, const struct changed_htlc *b, void *unused) { /* ids can be the same (sender and receiver are indep) but in * that case we don't care about order. */ if (a->id > b->id) return 1; else if (a->id < b->id) return -1; return 0; } static void resend_commitment(struct peer *peer, struct changed_htlc *last) { size_t i; struct bitcoin_signature commit_sig, *htlc_sigs; u8 *msg; struct bitcoin_tx **txs; const u8 *funding_wscript; const struct htlc **htlc_map; struct wally_tx_output *direct_outputs[NUM_SIDES]; status_debug("Retransmitting commitment, feerate LOCAL=%u REMOTE=%u," " blockheight LOCAL=%u REMOTE=%u", channel_feerate(peer->channel, LOCAL), channel_feerate(peer->channel, REMOTE), channel_blockheight(peer->channel, LOCAL), channel_blockheight(peer->channel, REMOTE)); /* Note that HTLCs must be *added* in order. Simplest thing to do * is to sort them all into ascending ID order here (we could do * this when we save them in channel_sending_commit, but older versions * won't have them sorted in the db, so doing it here is better). */ if (last) asort(last, tal_count(last), cmp_changed_htlc_id, NULL); /* BOLT #2: * * - if `next_commitment_number` is equal to the commitment * number of the last `commitment_signed` message the receiving node * has sent: * - MUST reuse the same commitment number for its next * `commitment_signed`. */ /* In our case, we consider ourselves already committed to this, so * retransmission is simplest. */ /* We need to send fulfills/failures before adds, so we split them * up into two loops -- this is the 'fulfill/fail' loop */ for (i = 0; i < tal_count(last); i++) { const struct htlc *h; h = channel_get_htlc(peer->channel, htlc_state_owner(last[i].newstate), last[i].id); /* I think this can happen if we actually received revoke_and_ack * then they asked for a retransmit */ if (!h) peer_failed_warn(peer->pps, &peer->channel_id, "Can't find HTLC %"PRIu64" to resend", last[i].id); if (h->state == SENT_REMOVE_COMMIT) send_fail_or_fulfill(peer, h); } /* We need to send fulfills/failures before adds, so we split them * up into two loops -- this is the 'add' loop */ for (i = 0; i < tal_count(last); i++) { const struct htlc *h; h = channel_get_htlc(peer->channel, htlc_state_owner(last[i].newstate), last[i].id); /* I think this can happen if we actually received revoke_and_ack * then they asked for a retransmit */ if (!h) peer_failed_warn(peer->pps, &peer->channel_id, "Can't find HTLC %"PRIu64" to resend", last[i].id); if (h->state == SENT_ADD_COMMIT) { struct tlv_update_add_htlc_tlvs *tlvs; if (h->blinding) { tlvs = tlv_update_add_htlc_tlvs_new(tmpctx); tlvs->blinding_point = tal_dup(tlvs, struct pubkey, h->blinding); } else tlvs = NULL; msg = towire_update_add_htlc(NULL, &peer->channel_id, h->id, h->amount, &h->rhash, abs_locktime_to_blocks( &h->expiry), h->routing, tlvs); peer_write(peer->pps, take(msg)); } } /* Make sure they have the correct fee and blockheight. */ if (peer->channel->opener == LOCAL) { msg = towire_update_fee(NULL, &peer->channel_id, channel_feerate(peer->channel, REMOTE)); peer_write(peer->pps, take(msg)); if (peer->channel->lease_expiry > 0) { msg = towire_update_blockheight(NULL, &peer->channel_id, channel_blockheight(peer->channel, REMOTE)); peer_write(peer->pps, take(msg)); } } /* Re-send the commitment_signed itself. */ txs = channel_txs(tmpctx, &htlc_map, direct_outputs, &funding_wscript, peer->channel, &peer->remote_per_commit, peer->next_index[REMOTE]-1, REMOTE); htlc_sigs = calc_commitsigs(tmpctx, peer, txs, funding_wscript, htlc_map, peer->next_index[REMOTE]-1, &commit_sig); msg = towire_commitment_signed(NULL, &peer->channel_id, &commit_sig.s, raw_sigs(tmpctx, htlc_sigs), NULL); peer_write(peer->pps, take(msg)); /* If we have already received the revocation for the previous, the * other side shouldn't be asking for a retransmit! */ if (peer->revocations_received != peer->next_index[REMOTE] - 2) status_unusual("Retransmitted commitment_signed %"PRIu64 " but they already send revocation %"PRIu64"?", peer->next_index[REMOTE]-1, peer->revocations_received); } /* BOLT #2: * * A receiving node: * - if `option_static_remotekey` applies to the commitment transaction: * - if `next_revocation_number` is greater than expected above, AND * `your_last_per_commitment_secret` is correct for that * `next_revocation_number` minus 1: *... * - otherwise, if it supports `option_data_loss_protect`: * - if `next_revocation_number` is greater than expected above, * AND `your_last_per_commitment_secret` is correct for that * `next_revocation_number` minus 1: */ static void check_future_dataloss_fields(struct peer *peer, u64 next_revocation_number, const struct secret *last_local_per_commit_secret, /* This is NULL if option_static_remotekey */ const struct pubkey *remote_current_per_commitment_point) { const u8 *msg; bool correct; assert(next_revocation_number > peer->next_index[LOCAL] - 1); msg = towire_hsmd_check_future_secret(NULL, next_revocation_number - 1, last_local_per_commit_secret); msg = hsm_req(tmpctx, take(msg)); if (!fromwire_hsmd_check_future_secret_reply(msg, &correct)) status_failed(STATUS_FAIL_HSM_IO, "Bad hsm_check_future_secret_reply: %s", tal_hex(tmpctx, msg)); if (!correct) peer_failed_err(peer->pps, &peer->channel_id, "bad future last_local_per_commit_secret: %"PRIu64 " vs %"PRIu64, next_revocation_number, peer->next_index[LOCAL] - 1); /* Oh shit, they really are from the future! */ peer_billboard(true, "They have future commitment number %"PRIu64 " vs our %"PRIu64". We must wait for them to close!", next_revocation_number, peer->next_index[LOCAL] - 1); /* BOLT #2: * - MUST NOT broadcast its commitment transaction. * - SHOULD send an `error` to request the peer to fail the channel. * - SHOULD store `my_current_per_commitment_point` to * retrieve funds should the sending node broadcast its * commitment transaction on-chain. */ wire_sync_write(MASTER_FD, take(towire_channeld_fail_fallen_behind(NULL, remote_current_per_commitment_point))); /* We have to send them an error to trigger dropping to chain. */ peer_failed_err(peer->pps, &peer->channel_id, "Awaiting unilateral close"); } /* BOLT #2: * * A receiving node: * - if `option_static_remotekey` applies to the commitment transaction: * ... * - if `your_last_per_commitment_secret` does not match the expected values: * - SHOULD send an `error` and fail the channel. * - otherwise, if it supports `option_data_loss_protect`: *... * - otherwise (`your_last_per_commitment_secret` or * `my_current_per_commitment_point` do not match the expected values): * - SHOULD send an `error` and fail the channel. */ static void check_current_dataloss_fields(struct peer *peer, u64 next_revocation_number, u64 next_commitment_number, const struct secret *last_local_per_commit_secret, /* NULL if option_static_remotekey */ const struct pubkey *remote_current_per_commitment_point) { struct secret old_commit_secret; /* By the time we're called, we've ensured this is a valid revocation * number. */ assert(next_revocation_number == peer->next_index[LOCAL] - 2 || next_revocation_number == peer->next_index[LOCAL] - 1); /* By the time we're called, we've ensured we're within 1 of * their commitment chain */ assert(next_commitment_number == peer->next_index[REMOTE] || next_commitment_number == peer->next_index[REMOTE] - 1); if (!last_local_per_commit_secret) return; /* BOLT #2: * - if `next_revocation_number` equals 0: * - MUST set `your_last_per_commitment_secret` to all zeroes */ status_debug("next_revocation_number = %"PRIu64, next_revocation_number); if (next_revocation_number == 0) memset(&old_commit_secret, 0, sizeof(old_commit_secret)); else { struct pubkey unused; /* This gets previous revocation number, since asking for * commitment point N gives secret for N-2 */ get_per_commitment_point(next_revocation_number+1, &unused, &old_commit_secret); } if (!secret_eq_consttime(&old_commit_secret, last_local_per_commit_secret)) peer_failed_err(peer->pps, &peer->channel_id, "bad reestablish: your_last_per_commitment_secret %"PRIu64 ": %s should be %s", next_revocation_number, type_to_string(tmpctx, struct secret, last_local_per_commit_secret), type_to_string(tmpctx, struct secret, &old_commit_secret)); if (!remote_current_per_commitment_point) { status_debug("option_static_remotekey: fields are correct"); return; } status_debug("Reestablish, comparing commitments. Remote's next local commitment number" " is %"PRIu64". Our next remote is %"PRIu64" with %"PRIu64 " revocations received", next_commitment_number, peer->next_index[REMOTE], peer->revocations_received); /* Either they haven't received our commitment yet, or we're up to date */ if (next_commitment_number == peer->revocations_received + 1) { if (!pubkey_eq(remote_current_per_commitment_point, &peer->old_remote_per_commit)) { peer_failed_warn(peer->pps, &peer->channel_id, "bad reestablish: remote's " "my_current_per_commitment_point %"PRIu64 "is %s; expected %s (new is %s).", next_commitment_number - 1, type_to_string(tmpctx, struct pubkey, remote_current_per_commitment_point), type_to_string(tmpctx, struct pubkey, &peer->old_remote_per_commit), type_to_string(tmpctx, struct pubkey, &peer->remote_per_commit)); } } else { /* We've sent a commit sig but haven't gotten a revoke+ack back */ if (!pubkey_eq(remote_current_per_commitment_point, &peer->remote_per_commit)) { peer_failed_warn(peer->pps, &peer->channel_id, "bad reestablish: remote's " "my_current_per_commitment_point %"PRIu64 "is %s; expected %s (old is %s).", next_commitment_number - 1, type_to_string(tmpctx, struct pubkey, remote_current_per_commitment_point), type_to_string(tmpctx, struct pubkey, &peer->remote_per_commit), type_to_string(tmpctx, struct pubkey, &peer->old_remote_per_commit)); } } status_debug("option_data_loss_protect: fields are correct"); } /* Older LND sometimes sends channel_ready before reestablish! */ /* ... or announcement_signatures. Sigh, let's handle whatever they send. */ static bool capture_premature_msg(const u8 ***shit_lnd_says, const u8 *msg) { if (fromwire_peektype(msg) == WIRE_CHANNEL_REESTABLISH) return false; /* Don't allow infinite memory consumption. */ if (tal_count(*shit_lnd_says) > 10) return false; status_debug("Stashing early %s msg!", peer_wire_name(fromwire_peektype(msg))); tal_arr_expand(shit_lnd_says, tal_steal(*shit_lnd_says, msg)); return true; } /* Unwrap a channel_type into a raw byte array for the wire: can be NULL */ static u8 *to_bytearr(const tal_t *ctx, const struct channel_type *channel_type TAKES) { u8 *ret; bool steal; steal = taken(channel_type); if (!channel_type) return NULL; if (steal) { ret = tal_steal(ctx, channel_type->features); tal_free(channel_type); } else ret = tal_dup_talarr(ctx, u8, channel_type->features); return ret; } static void peer_reconnect(struct peer *peer, const struct secret *last_remote_per_commit_secret, bool reestablish_only) { struct channel_id channel_id; /* Note: BOLT #2 uses these names! */ u64 next_commitment_number, next_revocation_number; bool retransmit_revoke_and_ack, retransmit_commitment_signed; struct htlc_map_iter it; const struct htlc *htlc; u8 *msg; struct pubkey my_current_per_commitment_point, remote_current_per_commitment_point; struct secret last_local_per_commitment_secret; bool dataloss_protect, check_extra_fields; const u8 **premature_msgs = tal_arr(peer, const u8 *, 0); struct inflight *inflight; struct bitcoin_txid *local_next_funding, *remote_next_funding; struct tlv_channel_reestablish_tlvs *send_tlvs, *recv_tlvs; dataloss_protect = feature_negotiated(peer->our_features, peer->their_features, OPT_DATA_LOSS_PROTECT); /* Both these options give us extra fields to check. */ check_extra_fields = dataloss_protect || channel_has(peer->channel, OPT_STATIC_REMOTEKEY); /* Our current per-commitment point is the commitment point in the last * received signed commitment */ get_per_commitment_point(peer->next_index[LOCAL] - 1, &my_current_per_commitment_point, NULL); inflight = last_inflight(peer); if (peer->experimental_upgrade) { /* Subtle: we free tmpctx below as we loop, so tal off peer */ send_tlvs = tlv_channel_reestablish_tlvs_new(peer); /* If inflight with no sigs on it, send next_funding */ if (inflight && !inflight->last_tx) send_tlvs->next_funding = &inflight->outpoint.txid; /* BOLT-upgrade_protocol #2: * A node sending `channel_reestablish`, if it supports upgrading channels: * - MUST set `next_to_send` the commitment number of the next * `commitment_signed` it expects to send. */ send_tlvs->next_to_send = tal_dup(send_tlvs, u64, &peer->next_index[REMOTE]); /* BOLT-upgrade_protocol #2: * - if it initiated the channel: * - MUST set `desired_type` to the channel_type it wants for the * channel. */ if (peer->channel->opener == LOCAL) { send_tlvs->desired_channel_type = to_bytearr(send_tlvs, take(channel_desired_type(NULL, peer->channel))); } else { /* BOLT-upgrade_protocol #2: * - otherwise: * - MUST set `current_type` to the current channel_type of the * channel. * - MUST set `upgradable` to the channel types it could change * to. * - MAY not set `upgradable` if it would be empty. */ send_tlvs->current_channel_type = to_bytearr(send_tlvs, peer->channel->type); send_tlvs->upgradable_channel_type = to_bytearr(send_tlvs, take(channel_upgradable_type(NULL, peer->channel))); } } else send_tlvs = NULL; /* BOLT #2: * * - upon reconnection: * - if a channel is in an error state: * - SHOULD retransmit the error packet and ignore any other packets for * that channel. * - otherwise: * - MUST transmit `channel_reestablish` for each channel. * - MUST wait to receive the other node's `channel_reestablish` * message before sending any other messages for that channel. * * The sending node: * - MUST set `next_commitment_number` to the commitment number * of the next `commitment_signed` it expects to receive. * - MUST set `next_revocation_number` to the commitment number * of the next `revoke_and_ack` message it expects to receive. * - if `option_static_remotekey` applies to the commitment transaction: * - MUST set `my_current_per_commitment_point` to a valid point. * - otherwise: * - MUST set `my_current_per_commitment_point` to its commitment * point for the last signed commitment it received from its * channel peer (i.e. the commitment_point corresponding to the * commitment transaction the sender would use to unilaterally * close). * - if `next_revocation_number` equals 0: * - MUST set `your_last_per_commitment_secret` to all zeroes * - otherwise: * - MUST set `your_last_per_commitment_secret` to the last * `per_commitment_secret` it received */ if (channel_has(peer->channel, OPT_STATIC_REMOTEKEY)) { msg = towire_channel_reestablish (NULL, &peer->channel_id, peer->next_index[LOCAL], peer->revocations_received, last_remote_per_commit_secret, /* Can send any (valid) point here */ &peer->remote_per_commit, send_tlvs); } else { msg = towire_channel_reestablish (NULL, &peer->channel_id, peer->next_index[LOCAL], peer->revocations_received, last_remote_per_commit_secret, &my_current_per_commitment_point, send_tlvs); } peer_write(peer->pps, take(msg)); peer_billboard(false, "Sent reestablish, waiting for theirs"); /* Read until they say something interesting (don't forward * gossip *to* them yet: we might try sending channel_update * before we've reestablished channel). */ do { clean_tmpctx(); msg = peer_read(tmpctx, peer->pps); /* connectd promised us the msg was reestablish? */ if (reestablish_only) { if (fromwire_peektype(msg) != WIRE_CHANNEL_REESTABLISH) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Expected reestablish, got: %s", tal_hex(tmpctx, msg)); } } while (handle_peer_error(peer->pps, &peer->channel_id, msg) || capture_premature_msg(&premature_msgs, msg)); /* Initialize here in case we don't read it below! */ recv_tlvs = tlv_channel_reestablish_tlvs_new(tmpctx); if (!fromwire_channel_reestablish(tmpctx, msg, &channel_id, &next_commitment_number, &next_revocation_number, &last_local_per_commitment_secret, &remote_current_per_commitment_point, &recv_tlvs)) { peer_failed_warn(peer->pps, &peer->channel_id, "bad reestablish msg: %s %s", peer_wire_name(fromwire_peektype(msg)), tal_hex(msg, msg)); } if (!channel_id_eq(&channel_id, &peer->channel_id)) { peer_failed_err(peer->pps, &channel_id, "bad reestablish msg for unknown channel %s: %s", type_to_string(tmpctx, struct channel_id, &channel_id), tal_hex(msg, msg)); } status_debug("Got reestablish commit=%"PRIu64" revoke=%"PRIu64, next_commitment_number, next_revocation_number); /* BOLT #2: * * - if `next_commitment_number` is 1 in both the * `channel_reestablish` it sent and received: * - MUST retransmit `channel_ready`. * - otherwise: * - MUST NOT retransmit `channel_ready`, but MAY send * `channel_ready` with a different `short_channel_id` * `alias` field. */ if (peer->channel_ready[LOCAL] && peer->next_index[LOCAL] == 1 && next_commitment_number == 1) { struct tlv_channel_ready_tlvs *tlvs = tlv_channel_ready_tlvs_new(tmpctx); status_debug("Retransmitting channel_ready for channel %s", type_to_string(tmpctx, struct channel_id, &peer->channel_id)); /* Contains per commit point #1, for first post-opening commit */ msg = towire_channel_ready(NULL, &peer->channel_id, &peer->next_local_per_commit, tlvs); peer_write(peer->pps, take(msg)); } /* Note: next_index is the index of the current commit we're working * on, but BOLT #2 refers to the *last* commit index, so we -1 where * required. */ /* BOLT #2: * * - if `next_revocation_number` is equal to the commitment * number of the last `revoke_and_ack` the receiving node sent, AND * the receiving node hasn't already received a `closing_signed`: * - MUST re-send the `revoke_and_ack`. * - if it has previously sent a `commitment_signed` that needs to be * retransmitted: * - MUST retransmit `revoke_and_ack` and `commitment_signed` in the * same relative order as initially transmitted. * - otherwise: * - if `next_revocation_number` is not equal to 1 greater * than the commitment number of the last `revoke_and_ack` the * receiving node has sent: * - SHOULD send an `error` and fail the channel. * - if it has not sent `revoke_and_ack`, AND * `next_revocation_number` is not equal to 0: * - SHOULD send an `error` and fail the channel. */ if (next_revocation_number == peer->next_index[LOCAL] - 2) { /* Don't try to retransmit revocation index -1! */ if (peer->next_index[LOCAL] < 2) { peer_failed_err(peer->pps, &peer->channel_id, "bad reestablish revocation_number: %" PRIu64, next_revocation_number); } retransmit_revoke_and_ack = true; } else if (next_revocation_number < peer->next_index[LOCAL] - 1) { /* Send a warning here! Because this is what it looks like if peer is * in the past, and they might still recover. */ peer_failed_warn(peer->pps, &peer->channel_id, "bad reestablish revocation_number: %"PRIu64 " vs %"PRIu64, next_revocation_number, peer->next_index[LOCAL]); } else if (next_revocation_number > peer->next_index[LOCAL] - 1) { if (!check_extra_fields) /* They don't support option_data_loss_protect or * option_static_remotekey, we fail it due to * unexpected number */ peer_failed_err(peer->pps, &peer->channel_id, "bad reestablish revocation_number: %"PRIu64 " vs %"PRIu64, next_revocation_number, peer->next_index[LOCAL] - 1); /* Remote claims it's ahead of us: can it prove it? * Does not return. */ check_future_dataloss_fields(peer, next_revocation_number, &last_local_per_commitment_secret, channel_has(peer->channel, OPT_STATIC_REMOTEKEY) ? NULL : &remote_current_per_commitment_point); } else retransmit_revoke_and_ack = false; /* BOLT #2: * * - if `next_commitment_number` is equal to the commitment * number of the last `commitment_signed` message the receiving node * has sent: * - MUST reuse the same commitment number for its next * `commitment_signed`. */ if (next_commitment_number == peer->next_index[REMOTE] - 1) { /* We completed opening, we don't re-transmit that one! */ if (next_commitment_number == 0) peer_failed_err(peer->pps, &peer->channel_id, "bad reestablish commitment_number: %" PRIu64, next_commitment_number); retransmit_commitment_signed = true; /* BOLT #2: * * - otherwise: * - if `next_commitment_number` is not 1 greater than the * commitment number of the last `commitment_signed` message the * receiving node has sent: * - SHOULD send an `error` and fail the channel. */ } else if (next_commitment_number != peer->next_index[REMOTE]) peer_failed_err(peer->pps, &peer->channel_id, "bad reestablish commitment_number: %"PRIu64 " vs %"PRIu64, next_commitment_number, peer->next_index[REMOTE]); else retransmit_commitment_signed = false; /* After we checked basic sanity, we check dataloss fields if any */ if (check_extra_fields) check_current_dataloss_fields(peer, next_revocation_number, next_commitment_number, &last_local_per_commitment_secret, channel_has(peer->channel, OPT_STATIC_REMOTEKEY) ? NULL : &remote_current_per_commitment_point); /* BOLT #2: * - if it has previously sent a `commitment_signed` that needs to be * retransmitted: * - MUST retransmit `revoke_and_ack` and `commitment_signed` in the * same relative order as initially transmitted. */ if (retransmit_revoke_and_ack && !peer->last_was_revoke) resend_revoke(peer); if (retransmit_commitment_signed) resend_commitment(peer, peer->last_sent_commit); /* This covers the case where we sent revoke after commit. */ if (retransmit_revoke_and_ack && peer->last_was_revoke) resend_revoke(peer); /* BOLT #2: * * - upon reconnection: * - if it has sent a previous `shutdown`: * - MUST retransmit `shutdown`. */ /* (If we had sent `closing_signed`, we'd be in closingd). */ maybe_send_shutdown(peer); /* If we didn't send (i.e. don't support!) ignore theirs */ if (!send_tlvs) recv_tlvs = tlv_channel_reestablish_tlvs_new(tmpctx); if (recv_tlvs->desired_channel_type) status_debug("They sent desired_channel_type [%s]", fmt_featurebits(tmpctx, recv_tlvs->desired_channel_type)); if (recv_tlvs->current_channel_type) status_debug("They sent current_channel_type [%s]", fmt_featurebits(tmpctx, recv_tlvs->current_channel_type)); if (recv_tlvs->upgradable_channel_type) status_debug("They offered upgrade to [%s]", fmt_featurebits(tmpctx, recv_tlvs->upgradable_channel_type)); /* BOLT-upgrade_protocol #2: * * A node receiving `channel_reestablish`: * - if it has to retransmit `commitment_signed` or `revoke_and_ack`: * - MUST consider the channel feature change failed. */ if (retransmit_commitment_signed || retransmit_revoke_and_ack) { status_debug("No upgrade: we retransmitted"); /* BOLT-upgrade_protocol #2: * * - if `next_to_send` is missing, or not equal to the * `next_commitment_number` it sent: * - MUST consider the channel feature change failed. */ } else if (!recv_tlvs->next_to_send) { status_debug("No upgrade: no next_to_send received"); } else if (*recv_tlvs->next_to_send != peer->next_index[LOCAL]) { status_debug("No upgrade: they're retransmitting"); /* BOLT-upgrade_protocol #2: * * - if updates are pending on either sides' commitment transaction: * - MUST consider the channel feature change failed. */ /* Note that we can have HTLCs we *want* to add or remove * but haven't yet: thats OK! */ } else if (pending_updates(peer->channel, LOCAL, true) || pending_updates(peer->channel, REMOTE, true)) { status_debug("No upgrade: pending changes"); } else { const struct tlv_channel_reestablish_tlvs *initr, *ninitr; const u8 *type; if (peer->channel->opener == LOCAL) { initr = send_tlvs; ninitr = recv_tlvs; } else { initr = recv_tlvs; ninitr = send_tlvs; } /* BOLT-upgrade_protocol #2: * * - if `desired_channel_type` matches `current_channel_type` or any * `upgradable_channel_type`: * - MUST consider the channel type to be `desired_channel_type`. * - otherwise: * - MUST consider the channel type change failed. * - if there is a `current_channel_type` field: * - MUST consider the channel type to be `current_channel_type`. */ if (match_type(initr->desired_channel_type, ninitr->current_channel_type) || match_type(initr->desired_channel_type, ninitr->upgradable_channel_type)) type = initr->desired_channel_type; else if (ninitr->current_channel_type) type = ninitr->current_channel_type; else type = NULL; if (type) set_channel_type(peer->channel, type); } /* Now stop, we've been polite long enough. */ if (reestablish_only) { /* If we were successfully closing, we still go to closingd. */ if (shutdown_complete(peer)) { send_shutdown_complete(peer); daemon_shutdown(); exit(0); } peer_failed_err(peer->pps, &peer->channel_id, "Channel is already closed"); } local_next_funding = (send_tlvs ? send_tlvs->next_funding : NULL); remote_next_funding = (recv_tlvs ? recv_tlvs->next_funding : NULL); if (local_next_funding || remote_next_funding) { bool next_matches_current = false, next_matches_inflight = false; if (remote_next_funding) { next_matches_current = bitcoin_txid_eq(remote_next_funding, &peer->channel->funding.txid); if (inflight) next_matches_inflight = bitcoin_txid_eq(remote_next_funding, &inflight->outpoint.txid); } if (remote_next_funding && !next_matches_current && !next_matches_inflight) { peer_failed_err(peer->pps, &peer->channel_id, "Unrecognized next_funding txid %s", type_to_string(tmpctx, struct bitcoin_txid, remote_next_funding)); } else if (inflight && !next_matches_inflight) { /* DTODO: tx_abort */ peer_failed_warn(peer->pps, &peer->channel_id, "next_funding txid %s doesnt match" " our inflight txid %s", type_to_string(tmpctx, struct bitcoin_txid, &inflight->outpoint.txid), type_to_string(tmpctx, struct bitcoin_txid, &peer->channel->funding.txid)); } else if (!inflight && !next_matches_current) { /* DTODO: tx_abort */ peer_failed_warn(peer->pps, &peer->channel_id, "next_funding txid %s doesnt match" " our confirmed funding txid %s", type_to_string(tmpctx, struct bitcoin_txid, remote_next_funding), type_to_string(tmpctx, struct bitcoin_txid, &peer->channel->funding.txid)); } else { resume_splice_negotiation(peer, inflight, false, inflight->i_am_initiator ? TX_INITIATOR : TX_ACCEPTER); } } tal_free(send_tlvs); /* Corner case: we didn't send shutdown before because update_add_htlc * pending, but now they're cleared by restart, and we're actually * complete. In that case, their `shutdown` will trigger us. */ /* Start commit timer: if we sent revoke we might need it. */ start_commit_timer(peer); /* Now, re-send any that we're supposed to be failing. */ for (htlc = htlc_map_first(peer->channel->htlcs, &it); htlc; htlc = htlc_map_next(peer->channel->htlcs, &it)) { if (htlc->state == SENT_REMOVE_HTLC) send_fail_or_fulfill(peer, htlc); } /* We allow peer to send us tx-sigs, until funding locked received */ peer->tx_sigs_allowed = true; peer_billboard(true, "Reconnected, and reestablished."); /* BOLT #2: * - upon reconnection: *... * - MUST transmit `channel_reestablish` for each channel. * - MUST wait to receive the other node's `channel_reestablish` * message before sending any other messages for that channel. */ /* LND doesn't wait. */ for (size_t i = 0; i < tal_count(premature_msgs); i++) peer_in(peer, premature_msgs[i]); tal_free(premature_msgs); } /* ignores the funding_depth unless depth >= minimum_depth * (except to update billboard, and set peer->depth_togo). */ static void handle_funding_depth(struct peer *peer, const u8 *msg) { u32 depth; struct short_channel_id *scid, *alias_local; struct tlv_channel_ready_tlvs *tlvs; struct pubkey point; bool splicing; struct bitcoin_txid txid; if (!fromwire_channeld_funding_depth(tmpctx, msg, &scid, &alias_local, &depth, &splicing, &txid)) master_badmsg(WIRE_CHANNELD_FUNDING_DEPTH, msg); /* Too late, we're shutting down! */ if (peer->shutdown_sent[LOCAL]) return; if (depth < peer->channel->minimum_depth) { peer->depth_togo = peer->channel->minimum_depth - depth; } else { peer->depth_togo = 0; /* For splicing we only update the short channel id on mutual * splice lock */ if (splicing) { peer->splice_state->short_channel_id = *scid; status_debug("Current channel id is %s, " "splice_short_channel_id now set to %s", type_to_string(tmpctx, struct short_channel_id, &peer->short_channel_ids[LOCAL]), type_to_string(tmpctx, struct short_channel_id, &peer->splice_state->short_channel_id)); } else { /* If we know an actual short_channel_id prefer to use * that, otherwise fill in the alias. From channeld's * point of view switching from zeroconf to an actual * funding scid is just a reorg. */ if (scid) peer->short_channel_ids[LOCAL] = *scid; else if (alias_local) peer->short_channel_ids[LOCAL] = *alias_local; } if (!peer->channel_ready[LOCAL]) { status_debug("channel_ready: sending commit index" " %"PRIu64": %s", peer->next_index[LOCAL], type_to_string(tmpctx, struct pubkey, &peer->next_local_per_commit)); tlvs = tlv_channel_ready_tlvs_new(tmpctx); tlvs->short_channel_id = alias_local; /* Need to retrieve the first point again, even if we * moved on, as channel_ready explicitly includes the * first one. */ get_per_commitment_point(1, &point, NULL); msg = towire_channel_ready(NULL, &peer->channel_id, &point, tlvs); peer_write(peer->pps, take(msg)); peer->channel_ready[LOCAL] = true; } else if(splicing && !peer->splice_state->locked_ready[LOCAL]) { assert(scid); msg = towire_splice_locked(NULL, &peer->channel_id); peer->splice_state->locked_txid = txid; peer_write(peer->pps, take(msg)); peer->splice_state->locked_ready[LOCAL] = true; check_mutual_splice_locked(peer); } peer->announce_depth_reached = (depth >= ANNOUNCE_MIN_DEPTH); /* Send temporary or final announcements */ channel_announcement_negotiate(peer); } billboard_update(peer); } static const u8 *get_cupdate(const struct peer *peer) { /* Technically we only need to tell it the first time (unless it's * changed). But it's not that common. */ wire_sync_write(MASTER_FD, take(towire_channeld_used_channel_update(NULL))); return peer->channel_update; } static void handle_offer_htlc(struct peer *peer, const u8 *inmsg) { u8 *msg; u32 cltv_expiry; struct amount_msat amount; struct sha256 payment_hash; u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)]; enum channel_add_err e; const u8 *failwiremsg; const char *failstr; struct amount_sat htlc_fee; struct pubkey *blinding; struct tlv_update_add_htlc_tlvs *tlvs; if (!peer->channel_ready[LOCAL] || !peer->channel_ready[REMOTE]) status_failed(STATUS_FAIL_MASTER_IO, "funding not locked for offer_htlc"); if (!fromwire_channeld_offer_htlc(tmpctx, inmsg, &amount, &cltv_expiry, &payment_hash, onion_routing_packet, &blinding)) master_badmsg(WIRE_CHANNELD_OFFER_HTLC, inmsg); if (blinding) { tlvs = tlv_update_add_htlc_tlvs_new(tmpctx); tlvs->blinding_point = tal_dup(tlvs, struct pubkey, blinding); } else tlvs = NULL; e = channel_add_htlc(peer->channel, LOCAL, peer->htlc_id, amount, cltv_expiry, &payment_hash, onion_routing_packet, take(blinding), NULL, &htlc_fee, true); status_debug("Adding HTLC %"PRIu64" amount=%s cltv=%u gave %s", peer->htlc_id, type_to_string(tmpctx, struct amount_msat, &amount), cltv_expiry, channel_add_err_name(e)); switch (e) { case CHANNEL_ERR_ADD_OK: /* Tell the peer. */ msg = towire_update_add_htlc(NULL, &peer->channel_id, peer->htlc_id, amount, &payment_hash, cltv_expiry, onion_routing_packet, tlvs); peer_write(peer->pps, take(msg)); start_commit_timer(peer); /* Tell the master. */ msg = towire_channeld_offer_htlc_reply(NULL, peer->htlc_id, 0, ""); wire_sync_write(MASTER_FD, take(msg)); peer->htlc_id++; return; case CHANNEL_ERR_INVALID_EXPIRY: failwiremsg = towire_incorrect_cltv_expiry(inmsg, cltv_expiry, get_cupdate(peer)); failstr = tal_fmt(inmsg, "Invalid cltv_expiry %u", cltv_expiry); goto failed; case CHANNEL_ERR_DUPLICATE: case CHANNEL_ERR_DUPLICATE_ID_DIFFERENT: status_failed(STATUS_FAIL_MASTER_IO, "Duplicate HTLC %"PRIu64, peer->htlc_id); case CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED: failwiremsg = towire_required_node_feature_missing(inmsg); failstr = "Mini mode: maximum value exceeded"; goto failed; /* FIXME: Fuzz the boundaries a bit to avoid probing? */ case CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED: failwiremsg = towire_temporary_channel_failure(inmsg, get_cupdate(peer)); failstr = tal_fmt(inmsg, "Capacity exceeded - HTLC fee: %s", fmt_amount_sat(inmsg, htlc_fee)); goto failed; case CHANNEL_ERR_HTLC_BELOW_MINIMUM: failwiremsg = towire_amount_below_minimum(inmsg, amount, get_cupdate(peer)); failstr = tal_fmt(inmsg, "HTLC too small (%s minimum)", type_to_string(tmpctx, struct amount_msat, &peer->channel->config[REMOTE].htlc_minimum)); goto failed; case CHANNEL_ERR_TOO_MANY_HTLCS: failwiremsg = towire_temporary_channel_failure(inmsg, get_cupdate(peer)); failstr = "Too many HTLCs"; goto failed; case CHANNEL_ERR_DUST_FAILURE: /* BOLT-919 #2: * - upon an outgoing HTLC: * - if a HTLC's `amount_msat` is inferior the counterparty's... * - SHOULD NOT send this HTLC * - SHOULD fail this HTLC if it's forwarded */ failwiremsg = towire_temporary_channel_failure(inmsg, get_cupdate(peer)); failstr = "HTLC too dusty, allowed dust limit reached"; goto failed; } /* Shouldn't return anything else! */ abort(); failed: msg = towire_channeld_offer_htlc_reply(NULL, 0, failwiremsg, failstr); wire_sync_write(MASTER_FD, take(msg)); } static void handle_feerates(struct peer *peer, const u8 *inmsg) { u32 feerate; if (!fromwire_channeld_feerates(inmsg, &feerate, &peer->feerate_min, &peer->feerate_max, &peer->feerate_penalty)) master_badmsg(WIRE_CHANNELD_FEERATES, inmsg); /* BOLT #2: * * The node _responsible_ for paying the Bitcoin fee: * - SHOULD send `update_fee` to ensure the current fee rate is * sufficient (by a significant margin) for timely processing of the * commitment transaction. */ if (peer->channel->opener == LOCAL) { peer->desired_feerate = feerate; /* Don't do this for the first feerate, wait until something else * happens. LND seems to get upset in some cases otherwise: * see https://github.com/ElementsProject/lightning/issues/3596 */ if (peer->next_index[LOCAL] != 1 || peer->next_index[REMOTE] != 1) start_commit_timer(peer); } else { /* BOLT #2: * * The node _not responsible_ for paying the Bitcoin fee: * - MUST NOT send `update_fee`. */ /* FIXME: We could drop to chain if fees are too low, but * that's fraught too. */ } } static void handle_blockheight(struct peer *peer, const u8 *inmsg) { u32 blockheight; if (!fromwire_channeld_blockheight(inmsg, &blockheight)) master_badmsg(WIRE_CHANNELD_BLOCKHEIGHT, inmsg); /* Save it, so we know */ peer->our_blockheight = blockheight; if (peer->channel->opener == LOCAL) start_commit_timer(peer); else { u32 peer_height = get_blockheight(peer->channel->blockheight_states, peer->channel->opener, REMOTE); /* BOLT- #2: * The node _not responsible_ for initiating the channel: * ... * - if last received `blockheight` is > 1008 behind * currently known blockheight: * - SHOULD fail he channel */ assert(peer_height + 1008 > peer_height); if (peer_height + 1008 < blockheight) peer_failed_err(peer->pps, &peer->channel_id, "Peer is too far behind, terminating" " leased channel. Our current" " %u, theirs %u", blockheight, peer_height); /* We're behind them... what do. It's possible they're lying, * but if we're in a lease this is actually in our favor so * we log it but otherwise continue on unchanged */ if (peer_height > blockheight && peer_height > blockheight + 100) status_unusual("Peer reporting we've fallen %u" " blocks behind. Our height %u," " their height %u", peer_height - blockheight, blockheight, peer_height); } } static void handle_config_channel(struct peer *peer, const u8 *inmsg) { u32 *base, *ppm; struct amount_msat *htlc_min, *htlc_max; bool changed; if (!fromwire_channeld_config_channel(inmsg, inmsg, &base, &ppm, &htlc_min, &htlc_max)) master_badmsg(WIRE_CHANNELD_CONFIG_CHANNEL, inmsg); /* only send channel updates if values actually changed */ changed = false; if (base && *base != peer->fee_base) { peer->fee_base = *base; changed = true; } if (ppm && *ppm != peer->fee_per_satoshi) { peer->fee_per_satoshi = *ppm; changed = true; } if (htlc_min && !amount_msat_eq(*htlc_min, peer->htlc_minimum_msat)) { peer->htlc_minimum_msat = *htlc_min; changed = true; } if (htlc_max && !amount_msat_eq(*htlc_max, peer->htlc_maximum_msat)) { peer->htlc_maximum_msat = *htlc_max; changed = true; } if (changed) send_channel_update(peer, 0); } static void handle_preimage(struct peer *peer, const u8 *inmsg) { struct fulfilled_htlc fulfilled_htlc; struct htlc *h; if (!fromwire_channeld_fulfill_htlc(inmsg, &fulfilled_htlc)) master_badmsg(WIRE_CHANNELD_FULFILL_HTLC, inmsg); switch (channel_fulfill_htlc(peer->channel, REMOTE, fulfilled_htlc.id, &fulfilled_htlc.payment_preimage, &h)) { case CHANNEL_ERR_REMOVE_OK: send_fail_or_fulfill(peer, h); start_commit_timer(peer); return; /* These shouldn't happen, because any offered HTLC (which would give * us the preimage) should have timed out long before. If we * were to get preimages from other sources, this could happen. */ case CHANNEL_ERR_NO_SUCH_ID: case CHANNEL_ERR_ALREADY_FULFILLED: case CHANNEL_ERR_HTLC_UNCOMMITTED: case CHANNEL_ERR_HTLC_NOT_IRREVOCABLE: case CHANNEL_ERR_BAD_PREIMAGE: status_failed(STATUS_FAIL_MASTER_IO, "HTLC %"PRIu64" preimage failed", fulfilled_htlc.id); } abort(); } static void handle_fail(struct peer *peer, const u8 *inmsg) { struct failed_htlc *failed_htlc; enum channel_remove_err e; struct htlc *h; if (!fromwire_channeld_fail_htlc(inmsg, inmsg, &failed_htlc)) master_badmsg(WIRE_CHANNELD_FAIL_HTLC, inmsg); e = channel_fail_htlc(peer->channel, REMOTE, failed_htlc->id, &h); switch (e) { case CHANNEL_ERR_REMOVE_OK: h->failed = tal_steal(h, failed_htlc); send_fail_or_fulfill(peer, h); start_commit_timer(peer); return; case CHANNEL_ERR_NO_SUCH_ID: case CHANNEL_ERR_ALREADY_FULFILLED: case CHANNEL_ERR_HTLC_UNCOMMITTED: case CHANNEL_ERR_HTLC_NOT_IRREVOCABLE: case CHANNEL_ERR_BAD_PREIMAGE: status_failed(STATUS_FAIL_MASTER_IO, "HTLC %"PRIu64" removal failed: %s", failed_htlc->id, channel_remove_err_name(e)); } abort(); } static void handle_shutdown_cmd(struct peer *peer, const u8 *inmsg) { u32 *final_index; struct ext_key *final_ext_key; u8 *local_shutdown_script; if (!fromwire_channeld_send_shutdown(peer, inmsg, &final_index, &final_ext_key, &local_shutdown_script, &peer->shutdown_wrong_funding)) master_badmsg(WIRE_CHANNELD_SEND_SHUTDOWN, inmsg); tal_free(peer->final_index); peer->final_index = final_index; tal_free(peer->final_ext_key); peer->final_ext_key = final_ext_key; tal_free(peer->final_scriptpubkey); peer->final_scriptpubkey = local_shutdown_script; /* We can't send this until commit (if any) is done, so start timer. */ peer->send_shutdown = true; start_commit_timer(peer); } /* Lightningd tells us when channel_update has changed. */ static void handle_channel_update(struct peer *peer, const u8 *msg) { peer->channel_update = tal_free(peer->channel_update); if (!fromwire_channeld_channel_update(peer, msg, &peer->channel_update)) master_badmsg(WIRE_CHANNELD_CHANNEL_UPDATE, msg); } static void handle_send_error(struct peer *peer, const u8 *msg) { char *reason; if (!fromwire_channeld_send_error(msg, msg, &reason)) master_badmsg(WIRE_CHANNELD_SEND_ERROR, msg); status_debug("Send error reason: %s", reason); peer_write(peer->pps, take(towire_errorfmt(NULL, &peer->channel_id, "%s", reason))); wire_sync_write(MASTER_FD, take(towire_channeld_send_error_reply(NULL))); exit(0); } #if DEVELOPER static void handle_dev_reenable_commit(struct peer *peer) { peer->dev_disable_commit = tal_free(peer->dev_disable_commit); start_commit_timer(peer); status_debug("dev_reenable_commit"); wire_sync_write(MASTER_FD, take(towire_channeld_dev_reenable_commit_reply(NULL))); } static void handle_dev_memleak(struct peer *peer, const u8 *msg) { struct htable *memtable; bool found_leak; memtable = memleak_start(tmpctx); memleak_ptr(memtable, msg); /* Now delete peer and things it has pointers to. */ memleak_scan_obj(memtable, peer); found_leak = dump_memleak(memtable, memleak_status_broken); wire_sync_write(MASTER_FD, take(towire_channeld_dev_memleak_reply(NULL, found_leak))); } static void handle_dev_quiesce(struct peer *peer, const u8 *msg) { if (!fromwire_channeld_dev_quiesce(msg)) master_badmsg(WIRE_CHANNELD_DEV_QUIESCE, msg); /* Don't do this twice. */ if (peer->want_stfu) status_failed(STATUS_FAIL_MASTER_IO, "dev_quiesce already"); peer->want_stfu = true; peer->stfu_initiator = LOCAL; maybe_send_stfu(peer); } #endif /* DEVELOPER */ static void req_in(struct peer *peer, const u8 *msg) { enum channeld_wire t = fromwire_peektype(msg); switch (t) { case WIRE_CHANNELD_FUNDING_DEPTH: handle_funding_depth(peer, msg); return; case WIRE_CHANNELD_OFFER_HTLC: if (handle_master_request_later(peer, msg)) return; handle_offer_htlc(peer, msg); return; case WIRE_CHANNELD_FEERATES: if (handle_master_request_later(peer, msg)) return; handle_feerates(peer, msg); return; case WIRE_CHANNELD_BLOCKHEIGHT: if (handle_master_request_later(peer, msg)) return; handle_blockheight(peer, msg); return; case WIRE_CHANNELD_FULFILL_HTLC: if (handle_master_request_later(peer, msg)) return; handle_preimage(peer, msg); return; case WIRE_CHANNELD_FAIL_HTLC: if (handle_master_request_later(peer, msg)) return; handle_fail(peer, msg); return; case WIRE_CHANNELD_CONFIG_CHANNEL: if (handle_master_request_later(peer, msg)) return; handle_config_channel(peer, msg); return; case WIRE_CHANNELD_SEND_SHUTDOWN: handle_shutdown_cmd(peer, msg); return; case WIRE_CHANNELD_SEND_ERROR: handle_send_error(peer, msg); return; case WIRE_CHANNELD_CHANNEL_UPDATE: handle_channel_update(peer, msg); return; case WIRE_CHANNELD_SPLICE_INIT: handle_splice_init(peer, msg); return; case WIRE_CHANNELD_SPLICE_UPDATE: splice_initiator_user_update(peer, msg); return; case WIRE_CHANNELD_SPLICE_SIGNED: splice_initiator_user_signed(peer, msg); return; case WIRE_CHANNELD_SPLICE_CONFIRMED_INIT: case WIRE_CHANNELD_SPLICE_CONFIRMED_SIGNED: case WIRE_CHANNELD_SPLICE_CONFIRMED_UPDATE: case WIRE_CHANNELD_SPLICE_LOOKUP_TX: case WIRE_CHANNELD_SPLICE_LOOKUP_TX_RESULT: case WIRE_CHANNELD_SPLICE_FEERATE_ERROR: case WIRE_CHANNELD_SPLICE_FUNDING_ERROR: break; #if DEVELOPER case WIRE_CHANNELD_DEV_REENABLE_COMMIT: handle_dev_reenable_commit(peer); return; case WIRE_CHANNELD_DEV_MEMLEAK: handle_dev_memleak(peer, msg); return; case WIRE_CHANNELD_DEV_QUIESCE: handle_dev_quiesce(peer, msg); return; #else case WIRE_CHANNELD_DEV_REENABLE_COMMIT: case WIRE_CHANNELD_DEV_MEMLEAK: case WIRE_CHANNELD_DEV_QUIESCE: #endif /* DEVELOPER */ case WIRE_CHANNELD_INIT: case WIRE_CHANNELD_OFFER_HTLC_REPLY: case WIRE_CHANNELD_SENDING_COMMITSIG: case WIRE_CHANNELD_GOT_COMMITSIG: case WIRE_CHANNELD_GOT_REVOKE: case WIRE_CHANNELD_SENDING_COMMITSIG_REPLY: case WIRE_CHANNELD_GOT_COMMITSIG_REPLY: case WIRE_CHANNELD_GOT_REVOKE_REPLY: case WIRE_CHANNELD_GOT_CHANNEL_READY: case WIRE_CHANNELD_GOT_SPLICE_LOCKED: case WIRE_CHANNELD_GOT_ANNOUNCEMENT: case WIRE_CHANNELD_GOT_SHUTDOWN: case WIRE_CHANNELD_SHUTDOWN_COMPLETE: case WIRE_CHANNELD_DEV_REENABLE_COMMIT_REPLY: case WIRE_CHANNELD_FAIL_FALLEN_BEHIND: case WIRE_CHANNELD_DEV_MEMLEAK_REPLY: case WIRE_CHANNELD_SEND_ERROR_REPLY: case WIRE_CHANNELD_DEV_QUIESCE_REPLY: case WIRE_CHANNELD_UPGRADED: case WIRE_CHANNELD_USED_CHANNEL_UPDATE: case WIRE_CHANNELD_LOCAL_CHANNEL_UPDATE: case WIRE_CHANNELD_LOCAL_CHANNEL_ANNOUNCEMENT: case WIRE_CHANNELD_LOCAL_PRIVATE_CHANNEL: case WIRE_CHANNELD_ADD_INFLIGHT: case WIRE_CHANNELD_UPDATE_INFLIGHT: case WIRE_CHANNELD_GOT_INFLIGHT: case WIRE_CHANNELD_SPLICE_STATE_ERROR: break; } master_badmsg(-1, msg); } /* We do this synchronously. */ static void init_channel(struct peer *peer) { struct basepoints points[NUM_SIDES]; struct amount_sat funding_sats; struct amount_msat local_msat; struct pubkey funding_pubkey[NUM_SIDES]; struct channel_config conf[NUM_SIDES]; struct bitcoin_outpoint funding; enum side opener; struct existing_htlc **htlcs; bool reconnected; u32 final_index; struct ext_key final_ext_key; u8 *fwd_msg; const u8 *msg; struct fee_states *fee_states; struct height_states *blockheight_states; u32 minimum_depth, lease_expiry; struct secret last_remote_per_commit_secret; secp256k1_ecdsa_signature *remote_ann_node_sig; secp256k1_ecdsa_signature *remote_ann_bitcoin_sig; struct penalty_base *pbases; bool reestablish_only; struct channel_type *channel_type; u32 *dev_disable_commit; /* Always NULL */ bool dev_fast_gossip; assert(!(fcntl(MASTER_FD, F_GETFL) & O_NONBLOCK)); msg = wire_sync_read(tmpctx, MASTER_FD); if (!fromwire_channeld_init(peer, msg, &chainparams, &peer->our_features, &peer->channel_id, &funding, &funding_sats, &minimum_depth, &peer->our_blockheight, &blockheight_states, &lease_expiry, &conf[LOCAL], &conf[REMOTE], &fee_states, &peer->feerate_min, &peer->feerate_max, &peer->feerate_penalty, &peer->their_commit_sig, &funding_pubkey[REMOTE], &points[REMOTE], &peer->remote_per_commit, &peer->old_remote_per_commit, &opener, &peer->fee_base, &peer->fee_per_satoshi, &peer->htlc_minimum_msat, &peer->htlc_maximum_msat, &local_msat, &points[LOCAL], &funding_pubkey[LOCAL], &peer->node_ids[LOCAL], &peer->node_ids[REMOTE], &peer->commit_msec, &peer->cltv_delta, &peer->last_was_revoke, &peer->last_sent_commit, &peer->next_index[LOCAL], &peer->next_index[REMOTE], &peer->revocations_received, &peer->htlc_id, &htlcs, &peer->channel_ready[LOCAL], &peer->channel_ready[REMOTE], &peer->short_channel_ids[LOCAL], &reconnected, &peer->send_shutdown, &peer->shutdown_sent[REMOTE], &final_index, &final_ext_key, &peer->final_scriptpubkey, &peer->channel_flags, &fwd_msg, &peer->announce_depth_reached, &last_remote_per_commit_secret, &peer->their_features, &peer->remote_upfront_shutdown_script, &remote_ann_node_sig, &remote_ann_bitcoin_sig, &channel_type, &dev_fast_gossip, &dev_disable_commit, &pbases, &reestablish_only, &peer->channel_update, &peer->experimental_upgrade, &peer->splice_state->inflights)) { master_badmsg(WIRE_CHANNELD_INIT, msg); } peer->final_index = tal_dup(peer, u32, &final_index); peer->final_ext_key = tal_dup(peer, struct ext_key, &final_ext_key); peer->splice_state->committed_count = tal_count(peer->splice_state->inflights); peer->splice_state->revoked_count = tal_count(peer->splice_state->inflights); peer->splice_state->count = tal_count(peer->splice_state->inflights); #if DEVELOPER peer->dev_disable_commit = dev_disable_commit; peer->dev_fast_gossip = dev_fast_gossip; #endif status_debug("option_static_remotekey = %u," " option_anchor_outputs = %u" " option_anchors_zero_fee_htlc_tx = %u", channel_type_has(channel_type, OPT_STATIC_REMOTEKEY), channel_type_has(channel_type, OPT_ANCHOR_OUTPUTS), channel_type_has(channel_type, OPT_ANCHORS_ZERO_FEE_HTLC_TX)); /* Keeping an array of pointers is better since it allows us to avoid * extra allocations later. */ peer->pbases = tal_arr(peer, struct penalty_base *, 0); for (size_t i=0; i<tal_count(pbases); i++) tal_arr_expand(&peer->pbases, tal_dup(peer, struct penalty_base, &pbases[i])); tal_free(pbases); /* stdin == requests, 3 == peer */ peer->pps = new_per_peer_state(peer); per_peer_state_set_fd(peer->pps, 3); status_debug("init %s: remote_per_commit = %s, old_remote_per_commit = %s" " next_idx_local = %"PRIu64 " next_idx_remote = %"PRIu64 " revocations_received = %"PRIu64 " feerates %s range %u-%u" " blockheights %s, our current %u", side_to_str(opener), type_to_string(tmpctx, struct pubkey, &peer->remote_per_commit), type_to_string(tmpctx, struct pubkey, &peer->old_remote_per_commit), peer->next_index[LOCAL], peer->next_index[REMOTE], peer->revocations_received, type_to_string(tmpctx, struct fee_states, fee_states), peer->feerate_min, peer->feerate_max, type_to_string(tmpctx, struct height_states, blockheight_states), peer->our_blockheight); if (remote_ann_node_sig && remote_ann_bitcoin_sig) { peer->announcement_node_sigs[REMOTE] = *remote_ann_node_sig; peer->announcement_bitcoin_sigs[REMOTE] = *remote_ann_bitcoin_sig; peer->have_sigs[REMOTE] = true; /* Before we store announcement into DB, we have made sure * remote short_channel_id matched the local. Now we initial * it directly! */ peer->short_channel_ids[REMOTE] = peer->short_channel_ids[LOCAL]; tal_free(remote_ann_node_sig); tal_free(remote_ann_bitcoin_sig); } /* First commit is used for opening: if we've sent 0, we're on * index 1. */ assert(peer->next_index[LOCAL] > 0); assert(peer->next_index[REMOTE] > 0); get_per_commitment_point(peer->next_index[LOCAL], &peer->next_local_per_commit, NULL); peer->channel = new_full_channel(peer, &peer->channel_id, &funding, minimum_depth, take(blockheight_states), lease_expiry, funding_sats, local_msat, take(fee_states), &conf[LOCAL], &conf[REMOTE], &points[LOCAL], &points[REMOTE], &funding_pubkey[LOCAL], &funding_pubkey[REMOTE], take(channel_type), feature_offered(peer->their_features, OPT_LARGE_CHANNELS), opener); if (!channel_force_htlcs(peer->channel, cast_const2(const struct existing_htlc **, htlcs))) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Could not restore HTLCs"); /* We don't need these any more, so free them. */ tal_free(htlcs); update_view_from_inflights(peer); peer->channel_direction = node_id_idx(&peer->node_ids[LOCAL], &peer->node_ids[REMOTE]); /* Default desired feerate is the feerate we set for them last. */ if (peer->channel->opener == LOCAL) peer->desired_feerate = channel_feerate(peer->channel, REMOTE); /* from now we need keep watch over WIRE_CHANNELD_FUNDING_DEPTH */ peer->depth_togo = minimum_depth; /* OK, now we can process peer messages. */ if (reconnected) peer_reconnect(peer, &last_remote_per_commit_secret, reestablish_only); else assert(!reestablish_only); /* If we have a messages to send, send them immediately */ if (fwd_msg) peer_write(peer->pps, take(fwd_msg)); /* Reenable channel */ channel_announcement_negotiate(peer); billboard_update(peer); } int main(int argc, char *argv[]) { setup_locale(); int i, nfds; fd_set fds_in, fds_out; struct peer *peer; subdaemon_setup(argc, argv); status_setup_sync(MASTER_FD); peer = tal(NULL, struct peer); timers_init(&peer->timers, time_mono()); peer->commit_timer = NULL; peer->have_sigs[LOCAL] = peer->have_sigs[REMOTE] = false; peer->announce_depth_reached = false; peer->channel_local_active = false; peer->gossip_scid_announced = false; peer->from_master = msg_queue_new(peer, true); peer->shutdown_sent[LOCAL] = false; peer->shutdown_wrong_funding = NULL; peer->last_update_timestamp = 0; peer->last_empty_commitment = 0; peer->send_duplicate_announce_sigs = false; peer->want_stfu = false; peer->stfu_sent[LOCAL] = peer->stfu_sent[REMOTE] = false; peer->stfu_wait_single_msg = false; peer->on_stfu_success = NULL; peer->update_queue = msg_queue_new(peer, false); peer->splice_state = splice_state_new(peer); peer->splicing = NULL; /* We send these to HSM to get real signatures; don't have valgrind * complain. */ for (i = 0; i < NUM_SIDES; i++) { memset(&peer->announcement_node_sigs[i], 0, sizeof(peer->announcement_node_sigs[i])); memset(&peer->announcement_bitcoin_sigs[i], 0, sizeof(peer->announcement_bitcoin_sigs[i])); } /* Prepare the ecdh() function for use */ ecdh_hsmd_setup(HSM_FD, status_failed); /* Read init_channel message sync. */ init_channel(peer); FD_ZERO(&fds_in); FD_SET(MASTER_FD, &fds_in); FD_SET(peer->pps->peer_fd, &fds_in); FD_ZERO(&fds_out); FD_SET(peer->pps->peer_fd, &fds_out); nfds = peer->pps->peer_fd+1; while (!shutdown_complete(peer)) { struct timemono first; fd_set rfds = fds_in; struct timeval timeout, *tptr; struct timer *expired; const u8 *msg; struct timemono now = time_mono(); /* Free any temporary allocations */ clean_tmpctx(); /* For simplicity, we process one event at a time. */ msg = msg_dequeue(peer->from_master); if (msg) { status_debug("Now dealing with deferred %s", channeld_wire_name( fromwire_peektype(msg))); req_in(peer, msg); tal_free(msg); continue; } expired = timers_expire(&peer->timers, now); if (expired) { timer_expired(expired); continue; } /* Might not be waiting for anything. */ tptr = NULL; if (timer_earliest(&peer->timers, &first)) { timeout = timespec_to_timeval( timemono_between(first, now).ts); tptr = &timeout; } /* If we're in STFU mode and aren't waiting for a STFU mode * specific message, don't read from the peer. */ if (is_stfu_active(peer) && !peer->stfu_wait_single_msg) FD_CLR(peer->pps->peer_fd, &rfds); if (select(nfds, &rfds, NULL, NULL, tptr) < 0) { /* Signals OK, eg. SIGUSR1 */ if (errno == EINTR) continue; status_failed(STATUS_FAIL_INTERNAL_ERROR, "select failed: %s", strerror(errno)); } if (FD_ISSET(MASTER_FD, &rfds)) { msg = wire_sync_read(tmpctx, MASTER_FD); if (!msg) status_failed(STATUS_FAIL_MASTER_IO, "Can't read command: %s", strerror(errno)); req_in(peer, msg); } else if (FD_ISSET(peer->pps->peer_fd, &rfds)) { /* This could take forever, but who cares? */ msg = peer_read(tmpctx, peer->pps); peer_in(peer, msg); } } /* We only exit when shutdown is complete. */ assert(shutdown_complete(peer)); send_shutdown_complete(peer); daemon_shutdown(); return 0; }
c0d58be22f4dc5dda8ace5b224c4561f1fd97d27
59864cbd213b5da6f50d6255b0a021564b3d5bd4
/challenges/Enslavednode_chat/src/list.c
3a8420d31358c8ed00a05f3a98944373780e7546
[ "MIT", "BSD-3-Clause", "LicenseRef-scancode-unknown", "BSD-2-Clause" ]
permissive
trailofbits/cb-multios
8af96a4fbc3b34644367faa135347f88e0e0d0a3
810d7b24b1f62f56ef49b148fe155b0d0629cad2
refs/heads/master
2023-09-05T03:56:20.229403
2022-12-27T15:47:54
2022-12-27T15:47:54
41,688,943
522
133
MIT
2023-06-29T02:47:13
2015-08-31T17:04:31
C
UTF-8
C
false
false
3,622
c
list.c
/* * Copyright (c) 2015 Kaprica Security, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ #include "libcgc.h" #include "cgc_stdlib.h" #include "cgc_string.h" #include "cgc_common.h" #include "cgc_error.h" #include "cgc_list.h" list *cgc_init_list(const DATA d) { list *new = cgc_calloc(1, sizeof(list)); if (!new) error(EALLOC); new->d = d; return new; } void cgc_append_list(list **l, const DATA d, int dups) { if (!*l) { *l = cgc_init_list(d); return; } list *i = *l; if (!dups) { while (i) { if (!cgc_strcmp((char *)d, (char *)i->d)) return; i = i->n; } } list *new = cgc_init_list(d); i = *l; while (i->n) i = i->n; i->n = new; new->p = i; new->n = NULL; return; } list *cgc_concat_list(list *l1, list *l2) { list *l = NULL; if (!l1) return l2; if (!l2) return l1; l = l1; while (l2) { cgc_append_list(&l1, l2->d, 1); l2 = l2->n; } return l; } cgc_size_t cgc_len_list(const list *l) { if (!l) return 0; cgc_size_t s = 0; while (l) s++, l = l->n; return s; } const DATA cgc_lindex(const list *l, cgc_ssize_t i) { if (!l) return NULL; if (i < 0) { cgc_size_t t = cgc_len_list(l); while (i < 0) t--, i++; i = t; } if (i >= cgc_len_list(l)) return NULL; for (cgc_size_t k = 0; k < i; k++) l = l->n; return l->d; } list *cgc_copy_list(const list *l, cgc_size_t start, cgc_size_t stop) { if (!l) return NULL; cgc_size_t len = cgc_len_list(l); if (stop == 0 || stop > len) stop = len; if (start >= stop) return NULL; list *p = (list *)l; list *copy = NULL; // Get to start for (cgc_size_t i = 0; i < start; i++) p = p->n; // Copy from start to stop for (cgc_size_t i = start; i < stop; i++, p = p->n) cgc_append_list(&copy, p->d, 1); return copy; } void cgc_free_list(const list *l, int leave_data) { const list *it; for (it = l; it; it = it->n) { if (!leave_data) cgc_free((void *)it->d); if (it->p) cgc_free(it->p); } cgc_free((void *)it); } void cgc_free_list_of_lists(const list *l, int leave_data) { const list *it; for (it = l; it; it = it->n) { cgc_free_list((list *)l->d, leave_data - 1); if (it->p) cgc_free(it->p); } cgc_free((void *)it); } const void *cgc_random_element(list *l) { cgc_size_t i, x, len = cgc_len_list(l); if (cgc_random(&i, sizeof(cgc_size_t), &x) < 0) error(ERAND); if (x != sizeof(cgc_size_t)) return NULL; i %= len; return cgc_lindex(l, i); }
13a2ba4c5a3f3c8e1bed2d83f788704ac35b4312
eecd5e4c50d8b78a769bcc2675250576bed34066
/src/vec/is/is/tutorials/ex2.c
a7f8b98bd6f9786b9c6e44ea3dee60532fce2f77
[ "BSD-2-Clause" ]
permissive
petsc/petsc
3b1a04fea71858e0292f9fd4d04ea11618c50969
9c5460f9064ca60dd71a234a1f6faf93e7a6b0c9
refs/heads/main
2023-08-17T20:51:16.507070
2023-08-17T16:08:06
2023-08-17T16:08:06
8,691,401
341
169
NOASSERTION
2023-03-29T11:02:58
2013-03-10T20:55:21
C
UTF-8
C
false
false
1,378
c
ex2.c
static char help[] = "Demonstrates creating a stride index set.\n\n"; /* Include petscis.h so we can use PETSc IS objects. Note that this automatically includes petscsys.h. */ #include <petscis.h> #include <petscviewer.h> int main(int argc, char **argv) { PetscInt i, n, first, step; IS set; const PetscInt *indices; PetscFunctionBeginUser; PetscCall(PetscInitialize(&argc, &argv, (char *)0, help)); n = 10; first = 3; step = 2; /* Create stride index set, starting at 3 with a stride of 2 Note each processor is generating its own index set (in this case they are all identical) */ PetscCall(ISCreateStride(PETSC_COMM_SELF, n, first, step, &set)); PetscCall(ISView(set, PETSC_VIEWER_STDOUT_SELF)); /* Extract indices from set. */ PetscCall(ISGetIndices(set, &indices)); PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Printing indices directly\n")); for (i = 0; i < n; i++) PetscCall(PetscPrintf(PETSC_COMM_WORLD, "%" PetscInt_FMT "\n", indices[i])); PetscCall(ISRestoreIndices(set, &indices)); /* Determine information on stride */ PetscCall(ISStrideGetInfo(set, &first, &step)); PetscCheck(first == 3 && step == 2, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Stride info not correct!"); PetscCall(ISDestroy(&set)); PetscCall(PetscFinalize()); return 0; } /*TEST test: TEST*/
10ba6b5069611c22cd0a019a2da8090ae08388a1
93bb87f91e55d55dc2f9bf78b914e6290c3a17be
/testing/JohnTheRipper/opencl_hash_check_128.h
f092e79bc88bd1fb5eb3c56c4494a27aab706475
[ "MIT", "LicenseRef-scancode-warranty-disclaimer", "GPL-2.0-only" ]
permissive
doe300/VC4C
5bbde383fb1230af42f72bd20accb84418b8b7fa
3d89be8692ae20b8f712e9d2bc45b6998dac8259
refs/heads/master
2023-06-07T06:25:07.948224
2023-05-30T09:42:15
2023-05-30T16:11:04
106,166,771
123
38
MIT
2023-05-30T16:11:05
2017-10-08T10:11:39
C
UTF-8
C
false
false
801
h
opencl_hash_check_128.h
#include "bt_interface.h" #include "common-opencl.h" extern cl_uint num_loaded_hashes; extern cl_uint *hash_ids; extern unsigned int hash_table_size_128, offset_table_size; extern void ocl_hc_128_init(struct fmt_main *_self); extern void ocl_hc_128_prepare_table(struct db_salt *salt); extern void ocl_hc_128_prepare_table_test(void); extern char* ocl_hc_128_select_bitmap(unsigned int num_ld_hashes); extern int ocl_hc_128_extract_info(struct db_salt *, void (*)(void), void (*)(void), void (*)(unsigned int, char *), size_t, size_t *, int *); extern void ocl_hc_128_crobj(cl_kernel kernel); extern void ocl_hc_128_rlobj(void); extern int ocl_hc_128_cmp_all(void *binary, int count); extern int ocl_hc_128_cmp_one(void *binary, int index); extern int ocl_hc_128_cmp_exact(char *source, int index);
51373e75de487dfad4b2f9c89904b8a17e23de31
0744dcc5394cebf57ebcba343747af6871b67017
/external/iotivity/iotivity_1.2-rel/service/notification/src/consumer/NSConsumerMQPlugin.c
b59fc46b02d78875f4406f17688e23d398ca2562
[ "Apache-2.0", "GPL-2.0-only", "MIT", "BSD-3-Clause" ]
permissive
Samsung/TizenRT
96abf62f1853f61fcf91ff14671a5e0c6ca48fdb
1a5c2e00a4b1bbf4c505bbf5cc6a8259e926f686
refs/heads/master
2023-08-31T08:59:33.327998
2023-08-08T06:09:20
2023-08-31T04:38:20
82,517,252
590
719
Apache-2.0
2023-09-14T06:54:49
2017-02-20T04:38:30
C
UTF-8
C
false
false
7,456
c
NSConsumerMQPlugin.c
//****************************************************************** // // Copyright 2016 Samsung Electronics All Rights Reserved. // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #ifdef WITH_MQ #include "NSConstants.h" #include "NSConsumerCommon.h" #include "NSConsumerMQPlugin.h" #include "NSUtil.h" #include "oic_malloc.h" #include "oic_string.h" #include "ocpayload.h" void NSHandleMQSubscription(NSMQTopicAddress * address); OCStackApplicationResult NSConsumerIntrospectMQTopic( void * ctx, OCDoHandle handle, OCClientResponse * clientResponse); OCStackApplicationResult NSConsumerMQListener( void * ctx, OCDoHandle handle, OCClientResponse * clientResponse); void NSConsumerMQTaskProcessing(NSTask * task) { NS_VERIFY_NOT_NULL_V(task); NS_LOG_V(DEBUG, "Receive Event : %d", (int) task->taskType); switch (task->taskType) { case TASK_MQ_REQ_SUBSCRIBE: { NSMQTopicAddress * mqTopic = task->taskData; NSHandleMQSubscription(mqTopic); NSOICFree(mqTopic); break; } default: { NS_LOG(ERROR, "Unknown type of task"); break; } } NSOICFree(task); } void NSHandleMQSubscription(NSMQTopicAddress * topicAddr) { char * serverUri = topicAddr->serverAddr; char * topicName = topicAddr->topicName; OCDevAddr * addr = NSChangeAddress(serverUri); NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(addr, { NSOICFree(topicAddr->serverAddr); NSOICFree(topicAddr->topicName); }); char requestUri[100] = "coap+tcp://"; OICStrcat(requestUri, strlen(requestUri)+strlen(serverUri)+1, serverUri); OICStrcat(requestUri, strlen(requestUri)+ strlen("/oic/ps") + 1, "/oic/ps"); NS_LOG_V(DEBUG, "requestUri = %s", requestUri); OCStackResult ret = NSInvokeRequest(NULL, OC_REST_GET, addr, requestUri, NULL, NSConsumerIntrospectMQTopic, topicName, OICFree, CT_DEFAULT); NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(NSOCResultToSuccess(ret) == true ? (void *)1 : NULL, { NSOICFree(serverUri); NSOICFree(topicName); }); NSOICFree(serverUri); } OCStackApplicationResult NSConsumerIntrospectMQTopic( void * ctx, OCDoHandle handle, OCClientResponse * clientResponse) { (void) handle; if (!NSIsStartedConsumer()) { return OC_STACK_DELETE_TRANSACTION; } NS_VERIFY_NOT_NULL(clientResponse, OC_STACK_KEEP_TRANSACTION); NS_VERIFY_STACK_SUCCESS(NSOCResultToSuccess(clientResponse->result), OC_STACK_KEEP_TRANSACTION); NS_VERIFY_NOT_NULL(clientResponse->payload, OC_STACK_KEEP_TRANSACTION); NS_LOG(DEBUG, "income get response of MQ broker"); NS_LOG_V(INFO_PRIVATE, "MQ GET response income : %s:%d", clientResponse->devAddr.addr, clientResponse->devAddr.port); NS_LOG_V(DEBUG, "MQ GET response result : %d", clientResponse->result); NS_LOG_V(DEBUG, "MQ GET response sequenceNum : %d", clientResponse->sequenceNumber); NS_LOG_V(DEBUG, "MQ GET response resource uri : %s", clientResponse->resourceUri); NS_LOG_V(DEBUG, "MQ GET response Transport Type : %d", clientResponse->devAddr.adapter); char ** topicList = NULL; size_t dimensions[MAX_REP_ARRAY_DEPTH] = {0}; OCRepPayloadGetStringArray((OCRepPayload *) clientResponse->payload, NS_ATTIRBUTE_MQ_TOPICLIST, & topicList, dimensions); char * interestTopicName = (char *) ctx; for (size_t i = 0; i < dimensions[0]; ++i) { NS_LOG_V(DEBUG, "found MQ topic : %s", topicList[i]); if (!strcmp(topicList[i], interestTopicName)) { NS_LOG(DEBUG, "subscribe to MQ notification"); OCStackResult ret = NSInvokeRequest(NULL, OC_REST_OBSERVE, clientResponse->addr, topicList[i], NULL, NSConsumerMQListener, NULL, NULL, CT_DEFAULT); if (!NSOCResultToSuccess(ret)) { NS_LOG(DEBUG, "fail to subscribe to MQ notification"); continue; } } } return OC_STACK_KEEP_TRANSACTION; } OCStackApplicationResult NSConsumerMQListener( void * ctx, OCDoHandle handle, OCClientResponse * clientResponse) { (void) ctx; (void) handle; if (!NSIsStartedConsumer()) { return OC_STACK_DELETE_TRANSACTION; } NS_VERIFY_NOT_NULL(clientResponse, OC_STACK_KEEP_TRANSACTION); NS_VERIFY_STACK_SUCCESS(NSOCResultToSuccess(clientResponse->result), OC_STACK_KEEP_TRANSACTION); NS_VERIFY_NOT_NULL(clientResponse->payload, OC_STACK_KEEP_TRANSACTION); NS_LOG(DEBUG, "income observe response of MQ notification"); NS_LOG_V(INFO_PRIVATE, "MQ OBS response income : %s:%d", clientResponse->devAddr.addr, clientResponse->devAddr.port); NS_LOG_V(DEBUG, "MQ OBS response result : %d", clientResponse->result); NS_LOG_V(DEBUG, "MQ OBS response sequenceNum : %d", clientResponse->sequenceNumber); NS_LOG_V(DEBUG, "MQ OBS response resource uri : %s", clientResponse->resourceUri); NS_LOG_V(DEBUG, "MQ OBS response Transport Type : %d", clientResponse->devAddr.adapter); NSMessage * newMsg = NSGetMessage((OCRepPayload *)clientResponse->payload); NS_VERIFY_NOT_NULL(newMsg, OC_STACK_KEEP_TRANSACTION); NSTask * task = NULL; if (newMsg->type == NS_MESSAGE_READ || newMsg->type == NS_MESSAGE_DELETED) { NSSyncInfo * syncInfo = (NSSyncInfo *)OICMalloc(sizeof(NSSyncInfo)); NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(syncInfo, OC_STACK_KEEP_TRANSACTION, NSRemoveMessage(newMsg)); syncInfo->messageId = newMsg->messageId; syncInfo->state = (newMsg->type == NS_MESSAGE_READ) ? NS_SYNC_READ : NS_SYNC_DELETED; OICStrcpy(syncInfo->providerId, sizeof(char) * NS_DEVICE_ID_LENGTH, newMsg->providerId); NSRemoveMessage(newMsg); NS_LOG(DEBUG, "build NSTask for MQ message sync"); task = NSMakeTask(TASK_RECV_SYNCINFO, (void *) syncInfo); NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(task, OC_STACK_KEEP_TRANSACTION, NSOICFree(syncInfo)); } else { NS_LOG(DEBUG, "build NSTask for MQ message receive"); task = NSMakeTask(TASK_CONSUMER_RECV_MESSAGE, (void *) newMsg); NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(task, OC_STACK_KEEP_TRANSACTION, NSRemoveMessage(newMsg)); } NSConsumerPushEvent(task); return OC_STACK_KEEP_TRANSACTION; } #endif
a63064ce58133602b52ba73be222591c51a414e0
79d343002bb63a44f8ab0dbac0c9f4ec54078c3a
/lib/libc/musl/src/math/aarch64/llrint.c
a9e07a93f18f74c8f752b0503e8558f6ba7a0e2f
[ "MIT", "BSD-3-Clause", "LicenseRef-scancode-public-domain", "BSD-2-Clause", "LicenseRef-scancode-other-permissive", "LicenseRef-scancode-musl-exception" ]
permissive
ziglang/zig
4aa75d8d3bcc9e39bf61d265fd84b7f005623fc5
f4c9e19bc3213c2bc7e03d7b06d7129882f39f6c
refs/heads/master
2023-08-31T13:16:45.980913
2023-08-31T05:50:29
2023-08-31T05:50:29
40,276,274
25,560
2,399
MIT
2023-09-14T21:09:50
2015-08-06T00:51:28
Zig
UTF-8
C
false
false
151
c
llrint.c
#include <math.h> long long llrint(double x) { long long n; __asm__ ( "frintx %d1, %d1\n" "fcvtzs %x0, %d1\n" : "=r"(n), "+w"(x)); return n; }
497a9c9fb5ebff4cbf5ac4d1c1822ad1b476e8cc
f085956afa0ff005e887a079eab410242865d831
/thirdparty/picoev/picoev.c
bd6691a9d54fc6ec08ab8eec38bed7d21d4fccad
[ "MIT" ]
permissive
vlang/v
844f108863477626a61bd7580a7fb8f3365ec3e5
93d54651b5aae1299239d30b1276439d8c142d88
refs/heads/master
2023-09-01T05:13:11.841452
2023-08-31T23:04:58
2023-08-31T23:04:58
169,677,297
38,639
3,871
MIT
2023-09-14T21:45:03
2019-02-08T02:57:06
V
UTF-8
C
false
false
273
c
picoev.c
#ifdef __linux__ #include "src/picoev_epoll.c" #elif __APPLE__ #include "src/picoev_kqueue.c" #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) #include "src/picoev_kqueue.c" #else #include "src/picoev_select.c" #endif
e137742a2c667bb17a44835d10df419f6c7e5aca
1895962fec46d652d226650b7bb9b024c16d9fa6
/source/loader/playlog.h
462686c4f80be19a0c2c0405546ba3e2fbeb5fa6
[]
no_license
Fledge68/WiiFlow_Lite
6b91090c1ba375ef79fcae1ddea745e412746717
5415c95fefa44dba79e0a6e88f25b4a7a3766bf1
refs/heads/master
2023-08-23T20:14:40.332005
2023-05-26T22:32:58
2023-05-26T22:32:58
144,065,000
405
112
null
2023-08-04T11:59:08
2018-08-08T20:37:43
C
UTF-8
C
false
false
296
h
playlog.h
#ifndef _PLAYLOG_H_ #define _PLAYLOG_H_ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /* Prototypes */ u64 getWiiTime(void); int Playlog_Update(const char ID[6], const u8 title[84]); int Playlog_Delete(void); #ifdef __cplusplus } #endif /* __cplusplus */ #endif
2f38e49ced7e1e75a7794660450a534a2feea7de
7d3d2af0389f9c0dee5d7ca789660bf21d97249d
/blasfeo_hp_cm/dtrsm.c
6c3aacba854e29b3dd19c606e7b1f6ca3d32f58c
[ "BSD-2-Clause" ]
permissive
giaf/blasfeo
0ecbcd67429d0507d7f462c090037c388e84a49e
b85a0c3121eae491480f07774fedf67e76b1f038
refs/heads/master
2023-07-22T15:40:53.961071
2023-07-18T15:42:08
2023-07-18T15:42:08
70,173,581
248
78
NOASSERTION
2022-11-25T15:42:08
2016-10-06T16:48:09
Assembly
UTF-8
C
false
false
205,228
c
dtrsm.c
/************************************************************************************************** * * * This file is part of BLASFEO. * * * * BLASFEO -- BLAS for embedded optimization. * * Copyright (C) 2019 by Gianluca Frison. * * Developed at IMTEK (University of Freiburg) under the supervision of Moritz Diehl. * * All rights reserved. * * * * The 2-Clause BSD License * * * * Redistribution and use in source and binary forms, with or without * * modification, are permitted provided that the following conditions are met: * * * * 1. Redistributions of source code must retain the above copyright notice, this * * list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * * this list of conditions and the following disclaimer in the documentation * * and/or other materials provided with the distribution. * * * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * * * Author: Gianluca Frison, gianluca.frison (at) imtek.uni-freiburg.de * * * **************************************************************************************************/ #include <stdlib.h> #include <stdio.h> //#define PRINT_NAME #include <blasfeo_target.h> #include <blasfeo_block_size.h> #include <blasfeo_common.h> #include <blasfeo_d_aux.h> #include <blasfeo_d_kernel.h> #include <blasfeo_stdlib.h> #include <blasfeo_memory.h> #if ( defined(BLAS_API) & defined(MF_PANELMAJ) ) #define blasfeo_dmat blasfeo_cm_dmat #define blasfeo_hp_dtrsm_llnn blasfeo_hp_cm_dtrsm_llnn #define blasfeo_hp_dtrsm_llnu blasfeo_hp_cm_dtrsm_llnu #define blasfeo_hp_dtrsm_lltn blasfeo_hp_cm_dtrsm_lltn #define blasfeo_hp_dtrsm_lltu blasfeo_hp_cm_dtrsm_lltu #define blasfeo_hp_dtrsm_lunn blasfeo_hp_cm_dtrsm_lunn #define blasfeo_hp_dtrsm_lunu blasfeo_hp_cm_dtrsm_lunu #define blasfeo_hp_dtrsm_lutn blasfeo_hp_cm_dtrsm_lutn #define blasfeo_hp_dtrsm_lutu blasfeo_hp_cm_dtrsm_lutu #define blasfeo_hp_dtrsm_rlnn blasfeo_hp_cm_dtrsm_rlnn #define blasfeo_hp_dtrsm_rlnu blasfeo_hp_cm_dtrsm_rlnu #define blasfeo_hp_dtrsm_rltn blasfeo_hp_cm_dtrsm_rltn #define blasfeo_hp_dtrsm_rltu blasfeo_hp_cm_dtrsm_rltu #define blasfeo_hp_dtrsm_runn blasfeo_hp_cm_dtrsm_runn #define blasfeo_hp_dtrsm_runu blasfeo_hp_cm_dtrsm_runu #define blasfeo_hp_dtrsm_rutn blasfeo_hp_cm_dtrsm_rutn #define blasfeo_hp_dtrsm_rutu blasfeo_hp_cm_dtrsm_rutu #define blasfeo_dtrsm_llnn blasfeo_cm_dtrsm_llnn #define blasfeo_dtrsm_llnu blasfeo_cm_dtrsm_llnu #define blasfeo_dtrsm_lltn blasfeo_cm_dtrsm_lltn #define blasfeo_dtrsm_lltu blasfeo_cm_dtrsm_lltu #define blasfeo_dtrsm_lunn blasfeo_cm_dtrsm_lunn #define blasfeo_dtrsm_lunu blasfeo_cm_dtrsm_lunu #define blasfeo_dtrsm_lutn blasfeo_cm_dtrsm_lutn #define blasfeo_dtrsm_lutu blasfeo_cm_dtrsm_lutu #define blasfeo_dtrsm_rlnn blasfeo_cm_dtrsm_rlnn #define blasfeo_dtrsm_rlnu blasfeo_cm_dtrsm_rlnu #define blasfeo_dtrsm_rltn blasfeo_cm_dtrsm_rltn #define blasfeo_dtrsm_rltu blasfeo_cm_dtrsm_rltu #define blasfeo_dtrsm_runn blasfeo_cm_dtrsm_runn #define blasfeo_dtrsm_runu blasfeo_cm_dtrsm_runu #define blasfeo_dtrsm_rutn blasfeo_cm_dtrsm_rutn #define blasfeo_dtrsm_rutu blasfeo_cm_dtrsm_rutu #endif #if ( defined(BLAS_API) & defined(MF_PANELMAJ) ) #define blasfeo_hp_dgemm_tn blasfeo_hp_cm_dgemm_tn #endif #include <blasfeo_d_blasfeo_hp_api.h> #define CACHE_LINE_EL D_CACHE_LINE_EL #define L1_CACHE_EL D_L1_CACHE_EL #define L2_CACHE_EL D_L2_CACHE_EL #define LLC_CACHE_EL D_LLC_CACHE_EL #define PS D_PS #define M_KERNEL D_M_KERNEL #define KC D_KC #define NC D_NC #define MC D_MC #if 0 static void blasfeo_hp_dtrsm_lutn_m1(int m, int n, double alpha, double *A, int lda, double *B, int ldb, double *D, int ldd, double *pU, int sdu, double *dA) { int ii, jj; int ps = 4; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(; ii<m-11; ii+=12) { kernel_dpack_tn_4_lib4(ii+4, A+(ii+0)*lda, lda, pU+0*sdu); kernel_dpack_tn_4_lib4(ii+8, A+(ii+4)*lda, lda, pU+4*sdu); kernel_dpack_tn_4_lib4(ii+12, A+(ii+8)*lda, lda, pU+8*sdu); for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nn_ll_inv_12x4_lib4ccc4(ii, pU, sdu, D+jj*ldd, ldd, &alpha, B+jj*ldb+ii, ldb, D+jj*ldd+ii, ldd, pU+ii*ps, sdu, dA+ii); } if(jj<n) { kernel_dtrsm_nn_ll_inv_12x4_vs_lib4ccc4(ii, pU, sdu, D+jj*ldd, ldd, &alpha, B+jj*ldb+ii, ldb, D+jj*ldd+ii, ldd, pU+ii*ps, sdu, dA+ii, m-ii, n-jj); } } if(ii<m) { if(m-ii<=4) { goto lutn_m1_left_4; } else if(m-ii<=8) { goto lutn_m1_left_8; } else { goto lutn_m1_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) for(; ii<m-7; ii+=8) { kernel_dpack_tn_4_lib4(ii+4, A+(ii+0)*lda, lda, pU+0*sdu); kernel_dpack_tn_4_lib4(ii+8, A+(ii+4)*lda, lda, pU+4*sdu); for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nn_ll_inv_8x4_lib4ccc4(ii, pU, sdu, D+jj*ldd, ldd, &alpha, B+jj*ldb+ii, ldb, D+jj*ldd+ii, ldd, pU+ii*ps, sdu, dA+ii); } if(jj<n) { kernel_dtrsm_nn_ll_inv_8x4_vs_lib4ccc4(ii, pU, sdu, D+jj*ldd, ldd, &alpha, B+jj*ldb+ii, ldb, D+jj*ldd+ii, ldd, pU+ii*ps, sdu, dA+ii, m-ii, n-jj); } } if(ii<m) { if(m-ii<=4) { goto lutn_m1_left_4; } else { goto lutn_m1_left_8; } } #else for(; ii<m-3; ii+=4) { kernel_dpack_tn_4_lib4(ii+4, A+ii*lda, lda, pU); for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nn_ll_inv_4x4_lib4ccc4(ii, pU, D+jj*ldd, ldd, &alpha, B+jj*ldb+ii, ldb, D+jj*ldd+ii, ldd, pU+ii*ps, dA+ii); } if(jj<n) { kernel_dtrsm_nn_ll_inv_4x4_vs_lib4ccc4(ii, pU, D+jj*ldd, ldd, &alpha, B+jj*ldb+ii, ldb, D+jj*ldd+ii, ldd, pU+ii*ps, dA+ii, m-ii, n-jj); } } if(ii<m) { goto lutn_m1_left_4; } #endif goto lutn_m1_return; #if defined(TARGET_X64_INTEL_HASWELL) lutn_m1_left_12: kernel_dpack_tn_4_lib4(ii+4, A+(ii+0)*lda, lda, pU+0*sdu); kernel_dpack_tn_4_lib4(ii+8, A+(ii+4)*lda, lda, pU+4*sdu); kernel_dpack_tn_4_vs_lib4(m, A+(ii+8)*lda, lda, pU+8*sdu, m-ii-8); for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nn_ll_inv_12x4_vs_lib4ccc4(ii, pU, sdu, D+jj*ldd, ldd, &alpha, B+jj*ldb+ii, ldb, D+jj*ldd+ii, ldd, pU+ii*ps, sdu, dA+ii, m-ii, n-jj); } goto lutn_m1_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) lutn_m1_left_8: kernel_dpack_tn_4_lib4(ii+4, A+(ii+0)*lda, lda, pU+0*sdu); kernel_dpack_tn_4_vs_lib4(m, A+(ii+4)*lda, lda, pU+4*sdu, m-ii-4); for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nn_ll_inv_8x4_vs_lib4ccc4(ii, pU, sdu, D+jj*ldd, ldd, &alpha, B+jj*ldb+ii, ldb, D+jj*ldd+ii, ldd, pU+ii*ps, sdu, dA+ii, m-ii, n-jj); } goto lutn_m1_return; #endif lutn_m1_left_4: kernel_dpack_tn_4_vs_lib4(m, A+ii*lda, lda, pU, m-ii); for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nn_ll_inv_4x4_vs_lib4ccc4(ii, pU, D+jj*ldd, ldd, &alpha, B+jj*ldb+ii, ldb, D+jj*ldd+ii, ldd, pU+ii*ps, dA+ii, m-ii, n-jj); } goto lutn_m1_return; lutn_m1_return: return; return; } #endif static void blasfeo_hp_dtrsm_llnn_m2(int m, int n, double alpha, double *pA0, int sda0, double *dA0, double *B, int ldb, double *D, int ldd, double *pB0, int sdb0) { #if 0 double *pA = pA0; int sda = sda0; double *dA = dA0; double *pB = pB0; int sdb = sdb0; int ii, jj; #if defined(TARGET_X64_INTEL_SKYLAKE_X) const int ps = 4; // XXX TODO fix once implemented missing kernels !!! #else const int ps = PS; #endif ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) //| defined(TARGET_ARMV8A_ARM_CORTEX_A53) for(; ii<m-11; ii+=12) { for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nt_ll_inv_12x4_lib44cc4(ii, pA+ii*sda, sda, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pA+ii*sda+ii*ps, sda, dA+ii); kernel_dpack_tn_4_lib4(12, D+ii+jj*ldd, ldd, pB+jj*sdb+ii*ps); } if(jj<n) { kernel_dtrsm_nt_ll_inv_12x4_vs_lib44cc4(ii, pA+ii*sda, sda, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pA+ii*sda+ii*ps, sda, dA+ii, m-ii, n-jj); kernel_dpack_tn_4_vs_lib4(12, D+ii+jj*ldd, ldd, pB+jj*sdb+ii*ps, n-jj); } } if(ii<m) { if(m-ii<=4) { goto llnn_2_left_4; } else if(m-ii<=8) { goto llnn_2_left_8; } else { goto llnn_2_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) //| defined(TARGET_ARMV8A_ARM_CORTEX_A57) for(; ii<m-7; ii+=8) { for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nt_ll_inv_8x4_lib44cc4(ii, pA+ii*sda, sda, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pA+ii*sda+ii*ps, sda, dA+ii); kernel_dpack_tn_4_lib4(8, D+ii+jj*ldd, ldd, pB+jj*sdb+ii*ps); } if(jj<n) { kernel_dtrsm_nt_ll_inv_8x4_vs_lib44cc4(ii, pA+ii*sda, sda, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pA+ii*sda+ii*ps, sda, dA+ii, m-ii, n-jj); kernel_dpack_tn_4_vs_lib4(8, D+ii+jj*ldd, ldd, pB+jj*sdb+ii*ps, n-jj); } } if(ii<m) { if(m-ii<=4) { goto llnn_2_left_4; } else { goto llnn_2_left_8; } } #else for(; ii<m-3; ii+=4) { for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nt_ll_inv_4x4_lib44cc4(ii, pA+ii*sda, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pA+ii*sda+ii*ps, dA+ii); kernel_dpack_tn_4_lib4(4, D+ii+jj*ldd, ldd, pB+jj*sdb+ii*ps); } if(jj<n) { kernel_dtrsm_nt_ll_inv_4x4_vs_lib44cc4(ii, pA+ii*sda, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pA+ii*sda+ii*ps, dA+ii, m-ii, n-jj); kernel_dpack_tn_4_vs_lib4(4, D+ii+jj*ldd, ldd, pB+jj*sdb+ii*ps, n-jj); } } if(ii<m) { goto llnn_2_left_4; } #endif goto llnn_2_return; #if defined(TARGET_X64_INTEL_HASWELL) //| defined(TARGET_ARMV8A_ARM_CORTEX_A53) llnn_2_left_12: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nt_ll_inv_12x4_vs_lib44cc4(ii, pA+ii*sda, sda, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pA+ii*sda+ii*ps, sda, dA+ii, m-ii, n-jj); kernel_dpack_tn_4_vs_lib4(m-ii, D+ii+jj*ldd, ldd, pB+jj*sdb+ii*ps, n-jj); } goto llnn_2_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) //| defined(TARGET_ARMV8A_ARM_CORTEX_A57) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) llnn_2_left_8: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nt_ll_inv_8x4_vs_lib44cc4(ii, pA+ii*sda, sda, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pA+ii*sda+ii*ps, sda, dA+ii, m-ii, n-jj); kernel_dpack_tn_4_vs_lib4(m-ii, D+ii+jj*ldd, ldd, pB+jj*sdb+ii*ps, n-jj); } goto llnn_2_return; #endif llnn_2_left_4: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nt_ll_inv_4x4_vs_lib44cc4(ii, pA+ii*sda, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pA+ii*sda+ii*ps, dA+ii, m-ii, n-jj); kernel_dpack_tn_4_vs_lib4(m-ii, D+ii+jj*ldd, ldd, pB+jj*sdb+ii*ps, n-jj); } goto llnn_2_return; llnn_2_return: return; #else double *pA = pB0; int sda = sdb0; double *pB = pA0; int sdb = sda0; double *dB = dA0; int ii, jj; #if defined(TARGET_X64_INTEL_SKYLAKE_X) const int ps = 4; // XXX TODO fix once implemented missing kernels !!! #else const int ps = PS; #endif ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) for(; ii<n-11; ii+=12) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pA+ii*sda); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pA+(ii+4)*sda); kernel_dpack_tn_4_lib4(m, B+(ii+8)*ldb, ldb, pA+(ii+8)*sda); for(jj=0; jj<m-3; jj+=4) { kernel_dtrsm_nt_rl_inv_12x4_lib4(jj, pA+ii*sda, sda, pB+jj*sdb, &alpha, pA+ii*sda+jj*ps, sda, pA+ii*sda+jj*ps, sda, pB+jj*ps+jj*sdb, dB+jj); } if(jj<m) { kernel_dtrsm_nt_rl_inv_12x4_vs_lib4(jj, pA+ii*sda, sda, pB+jj*sdb, &alpha, pA+ii*sda+jj*ps, sda, pA+ii*sda+jj*ps, sda, pB+jj*ps+jj*sdb, dB+jj, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pA+ii*sda, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pA+(ii+4)*sda, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pA+(ii+8)*sda, D+(ii+8)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto llnn_2_left_4; } if(n-ii<=8) { goto llnn_2_left_8; } else { goto llnn_2_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) for(; ii<n-7; ii+=8) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pA+ii*sda); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pA+(ii+4)*sda); for(jj=0; jj<m-3; jj+=4) { kernel_dtrsm_nt_rl_inv_8x4_lib4(jj, pA+ii*sda, sda, pB+jj*sdb, &alpha, pA+ii*sda+jj*ps, sda, pA+ii*sda+jj*ps, sda, pB+jj*ps+jj*sdb, dB+jj); } if(jj<m) { kernel_dtrsm_nt_rl_inv_8x4_vs_lib4(jj, pA+ii*sda, sda, pB+jj*sdb, &alpha, pA+ii*sda+jj*ps, sda, pA+ii*sda+jj*ps, sda, pB+jj*ps+jj*sdb, dB+jj, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pA+ii*sda, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pA+(ii+4)*sda, D+(ii+4)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto llnn_2_left_4; } else { goto llnn_2_left_8; } } #else for(; ii<n-3; ii+=4) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pA+ii*sda); for(jj=0; jj<m-3; jj+=4) { kernel_dtrsm_nt_rl_inv_4x4_lib4(jj, pA+ii*sda, pB+jj*sdb, &alpha, pA+ii*sda+jj*ps, pA+ii*sda+jj*ps, pB+jj*ps+jj*sdb, dB+jj); } if(jj<m) { kernel_dtrsm_nt_rl_inv_4x4_vs_lib4(jj, pA+ii*sda, pB+jj*sdb, &alpha, pA+ii*sda+jj*ps, pA+ii*sda+jj*ps, pB+jj*ps+jj*sdb, dB+jj, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pA+ii*sda, D+ii*ldd, ldd); } if(ii<n) { goto llnn_2_left_4; } #endif goto llnn_2_return; #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) llnn_2_left_12: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pA+ii*sda); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pA+(ii+4)*sda); kernel_dpack_tn_4_vs_lib4(m, B+(ii+8)*ldb, ldb, pA+(ii+8)*sda, n-ii); for(jj=0; jj<m; jj+=4) { kernel_dtrsm_nt_rl_inv_12x4_vs_lib4(jj, pA+ii*sda, sda, pB+jj*sdb, &alpha, pA+ii*sda+jj*ps, sda, pA+ii*sda+jj*ps, sda, pB+jj*ps+jj*sdb, dB+jj, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pA+ii*sda, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pA+(ii+4)*sda, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pA+(ii+8)*sda, D+(ii+8)*ldd, ldd, n-ii-8); goto llnn_2_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) llnn_2_left_8: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pA+ii*sda); kernel_dpack_tn_4_vs_lib4(m, B+(ii+4)*ldb, ldb, pA+(ii+4)*sda, n-ii); for(jj=0; jj<m; jj+=4) { kernel_dtrsm_nt_rl_inv_8x4_vs_lib4(jj, pA+ii*sda, sda, pB+jj*sdb, &alpha, pA+ii*sda+jj*ps, sda, pA+ii*sda+jj*ps, sda, pB+jj*ps+jj*sdb, dB+jj, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pA+ii*sda, D+ii*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pA+(ii+4)*sda, D+(ii+4)*ldd, ldd, n-ii-4); goto llnn_2_return; #endif llnn_2_left_4: kernel_dpack_tn_4_vs_lib4(m, B+ii*ldb, ldb, pA+ii*sda, n-ii); for(jj=0; jj<m; jj+=4) { kernel_dtrsm_nt_rl_inv_4x4_vs_lib4(jj, pA+ii*sda, pB+jj*sdb, &alpha, pA+ii*sda+jj*ps, pA+ii*sda+jj*ps, pB+jj*ps+jj*sdb, dB+jj, n-ii, m-jj); } kernel_dunpack_nt_4_vs_lib4(m, pA+ii*sda, D+ii*ldd, ldd, n-ii); goto llnn_2_return; llnn_2_return: return; #endif } static void blasfeo_hp_dtrsm_rltn_m2(int m, int n, double alpha, double *pA0, int sda0, double *dA0, double *B, int ldb, double *D, int ldd, double *pA, int sda) { double *pB = pA0; double *dB = dA0; int sdb = sda0; int ii, jj; #if defined(TARGET_X64_INTEL_SKYLAKE_X) const int ps = 4; // XXX TODO fix once implemented missing kernels !!! #else const int ps = PS; #endif ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) for(ii=0; ii<m-11; ii+=12) { for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nt_rl_inv_12x4_lib44cc4(jj, pA+ii*sda, sda, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, dB+jj); kernel_dpack_nn_12_lib4(4, D+ii+jj*ldd, ldd, pA+ii*sda+jj*ps, sda); } if(jj<n) { kernel_dtrsm_nt_rl_inv_12x4_vs_lib44cc4(jj, pA+ii*sda, sda, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, dB+jj, m-ii, n-jj); // kernel_dpack_nn_4_lib4(n-jj, D+ii+jj*ldd, ldd, pA+ii*sda+jj*ps); } } if(ii<m) { if(m-ii<=4) { goto rltn_2_left_4; } if(m-ii<=8) { goto rltn_2_left_8; } else { goto rltn_2_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) for(ii=0; ii<m-7; ii+=8) { for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nt_rl_inv_8x4_lib44cc4(jj, pA+ii*sda, sda, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, dB+jj); kernel_dpack_nn_8_lib4(4, D+ii+jj*ldd, ldd, pA+ii*sda+jj*ps, sda); } if(jj<n) { kernel_dtrsm_nt_rl_inv_8x4_vs_lib44cc4(jj, pA+ii*sda, sda, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, dB+jj, m-ii, n-jj); // kernel_dpack_nn_4_lib4(n-jj, D+ii+jj*ldd, ldd, pA+ii*sda+jj*ps); } } if(ii<m) { if(m-ii<=4) { goto rltn_2_left_4; } else { goto rltn_2_left_8; } } #else for(ii=0; ii<m-3; ii+=4) { for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nt_rl_inv_4x4_lib44cc4(jj, pA+ii*sda, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, dB+jj); kernel_dpack_nn_4_lib4(4, D+ii+jj*ldd, ldd, pA+ii*sda+jj*ps); } if(jj<n) { kernel_dtrsm_nt_rl_inv_4x4_vs_lib44cc4(jj, pA+ii*sda, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, dB+jj, m-ii, n-jj); // kernel_dpack_nn_4_lib4(n-jj, D+ii+jj*ldd, ldd, pA+ii*sda+jj*ps); } } if(ii<m) { goto rltn_2_left_4; } #endif goto rltn_2_return; #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) rltn_2_left_12: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nt_rl_inv_12x4_vs_lib44cc4(jj, pA+ii*sda, sda, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, dB+jj, m-ii, n-jj); kernel_dpack_nn_12_vs_lib4(n-jj, D+ii+jj*ldd, ldd, pA+ii*sda+jj*ps, sda, m-ii); } goto rltn_2_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) rltn_2_left_8: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nt_rl_inv_8x4_vs_lib44cc4(jj, pA+ii*sda, sda, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, dB+jj, m-ii, n-jj); kernel_dpack_nn_8_vs_lib4(n-jj, D+ii+jj*ldd, ldd, pA+ii*sda+jj*ps, sda, m-ii); } goto rltn_2_return; #endif rltn_2_left_4: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nt_rl_inv_4x4_vs_lib44cc4(jj, pA+ii*sda, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, dB+jj, m-ii, n-jj); kernel_dpack_nn_4_vs_lib4(n-jj, D+ii+jj*ldd, ldd, pA+ii*sda+jj*ps, m-ii); } goto rltn_2_return; rltn_2_return: return; } static void blasfeo_hp_dtrsm_rutn_m2(int m, int n, double alpha, double *pA0, int sda0, double *dA0, double *B, int ldb, double *D, int ldd, double *pA, int sda) { double *pB = pA0; double *dB = dA0; int sdb = sda0; int ii, jj; int n4, nn4, idx; #if defined(TARGET_X64_INTEL_SKYLAKE_X) const int ps = 4; // XXX TODO fix once implemented missing kernels !!! #else const int ps = PS; #endif nn4 = n%4; n4 = n - nn4; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(; ii<m-11; ii+=12) { if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_inv_12x4_vs_lib44cc4(0, pA+ii*sda+(idx+4)*ps, sda, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, dB+idx, m-ii, nn4); kernel_dpack_nn_12_vs_lib4(nn4, D+ii+idx*ldd, ldd, pA+ii*sda+idx*ps, sda, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_inv_12x4_lib44cc4(jj+nn4, pA+ii*sda+(idx+4)*ps, sda, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, dB+idx); kernel_dpack_nn_12_lib4(4, D+ii+idx*ldd, ldd, pA+ii*sda+idx*ps, sda); } } if(ii<m) { if(m-ii<=4) { goto rutn_2_left_4; } else if(m-ii<=8) { goto rutn_2_left_8; } else { goto rutn_2_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) for(; ii<m-7; ii+=8) { if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_inv_8x4_vs_lib44cc4(0, pA+ii*sda+(idx+4)*ps, sda, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, dB+idx, m-ii, nn4); kernel_dpack_nn_8_vs_lib4(nn4, D+ii+idx*ldd, ldd, pA+ii*sda+idx*ps, sda, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_inv_8x4_lib44cc4(jj+nn4, pA+ii*sda+(idx+4)*ps, sda, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, dB+idx); kernel_dpack_nn_8_lib4(4, D+ii+idx*ldd, ldd, pA+ii*sda+idx*ps, sda); } } if(ii<m) { if(m-ii<=4) { goto rutn_2_left_4; } else { goto rutn_2_left_8; } } #else for(; ii<m-3; ii+=4) { if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_inv_4x4_vs_lib44cc4(0, pA+ii*sda+(idx+4)*ps, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, dB+idx, m-ii, nn4); kernel_dpack_nn_4_vs_lib4(nn4, D+ii+idx*ldd, ldd, pA+ii*sda+idx*ps, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_inv_4x4_lib44cc4(jj+nn4, pA+ii*sda+(idx+4)*ps, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, dB+idx); kernel_dpack_nn_4_lib4(4, D+ii+idx*ldd, ldd, pA+ii*sda+idx*ps); } } if(ii<m) { goto rutn_2_left_4; } #endif goto rutn_2_return; #if defined(TARGET_X64_INTEL_HASWELL) rutn_2_left_12: if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_inv_12x4_vs_lib44cc4(0, pA+ii*sda+(idx+4)*ps, sda, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, dB+idx, m-ii, nn4); kernel_dpack_nn_12_vs_lib4(nn4, D+ii+idx*ldd, ldd, pA+ii*sda+idx*ps, sda, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_inv_12x4_vs_lib44cc4(jj+nn4, pA+ii*sda+(idx+4)*ps, sda, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, dB+idx, m-ii, 4); kernel_dpack_nn_12_vs_lib4(4, D+ii+idx*ldd, ldd, pA+ii*sda+idx*ps, sda, m-ii); } goto rutn_2_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) rutn_2_left_8: if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_inv_8x4_vs_lib44cc4(0, pA+ii*sda+(idx+4)*ps, sda, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, dB+idx, m-ii, nn4); kernel_dpack_nn_8_vs_lib4(nn4, D+ii+idx*ldd, ldd, pA+ii*sda+idx*ps, sda, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_inv_8x4_vs_lib44cc4(jj+nn4, pA+ii*sda+(idx+4)*ps, sda, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, dB+idx, m-ii, 4); kernel_dpack_nn_8_vs_lib4(4, D+ii+idx*ldd, ldd, pA+ii*sda+idx*ps, sda, m-ii); } goto rutn_2_return; #endif rutn_2_left_4: if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_inv_4x4_vs_lib44cc4(0, pA+ii*sda+(idx+4)*ps, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, dB+idx, m-ii, nn4); kernel_dpack_nn_4_vs_lib4(nn4, D+ii+idx*ldd, ldd, pA+ii*sda+idx*ps, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_inv_4x4_vs_lib44cc4(jj+nn4, pA+ii*sda+(idx+4)*ps, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, dB+idx, m-ii, 4); kernel_dpack_nn_4_vs_lib4(4, D+ii+idx*ldd, ldd, pA+ii*sda+idx*ps, m-ii); } goto rutn_2_return; rutn_2_return: return; } void blasfeo_hp_dtrsm_llnn(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { #if defined(PRINT_NAME) printf("\nblasfeo_hp_dtrsm_llnn (cm) %d %d %f %p %d %d %p %d %d %p %d %d\n", m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); #endif if(m<=0 | n<=0) return; // extract pointer to column-major matrices from structures int lda = sA->m; int ldb = sB->m; int ldd = sD->m; double *A = sA->pA + ai + aj*lda; double *B = sB->pA + bi + bj*ldb; double *D = sD->pA + di + dj*ldb; // printf("\n%p %d %p %d %p %d\n", A, lda, B, ldb); int ii, jj; const int ps = 4; //D_PS; #if defined(TARGET_GENERIC) double pd0[K_MAX_STACK]; #else ALIGNED( double pd0[K_MAX_STACK], 64 ); #endif #if defined(TARGET_GENERIC) double pU0[M_KERNEL*K_MAX_STACK]; #else ALIGNED( double pU0[M_KERNEL*K_MAX_STACK], 64 ); #endif int k0; // TODO update if necessary !!!!! // if(*side=='l' | *side=='L') k0 = m; // else // k0 = n; int sdu0 = (k0+3)/4*4; sdu0 = sdu0<K_MAX_STACK ? sdu0 : K_MAX_STACK; struct blasfeo_pm_dmat tA, tB; int sda, sdb; int tA_size, tB_size; void *mem; char *mem_align; int m1, n1, k1; int pack_B; double *pU, *dA, *pB, *dB; int sdu; const int m_kernel = M_KERNEL; const int l1_cache_el = L1_CACHE_EL; const int reals_per_cache_line = CACHE_LINE_EL; const int m_cache = (m+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int n_cache = (n+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; // const int k_cache = (k+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int m_kernel_cache = (m_kernel+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; int m_min = m_cache<m_kernel_cache ? m_cache : m_kernel_cache; // int n_min = n_cache<m_kernel_cache ? n_cache : m_kernel_cache; #if defined(TARGET_X64_INTEL_HASWELL) if(m>=200 | n>=200 | m>K_MAX_STACK) #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) if(m>=64 | n>=64 | m>K_MAX_STACK) #else if(m>=12 | n>=12 | m>K_MAX_STACK) #endif { goto llnn_2; } else { goto llnn_1; } // never to get here return; llnn_1: pU = pU0; sdu = sdu0; dA = pd0; for(ii=0; ii<m; ii++) dA[ii] = 1.0/A[ii+ii*lda]; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(; ii<n-11; ii+=12) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu); for(jj=0; jj<m-3; jj+=4) { kernel_dtrsm_nt_rl_inv_12x4_lib4c44c(jj, pU, sdu, A+jj, lda, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, A+jj+jj*lda, lda, dA+jj); } if(jj<m) { kernel_dtrsm_nt_rl_inv_12x4_vs_lib4c44c(jj, pU, sdu, A+jj, lda, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, A+jj+jj*lda, lda, dA+jj, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto llnn_1_left_4; } if(n-ii<=8) { goto llnn_1_left_8; } else { goto llnn_1_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) for(; ii<n-7; ii+=8) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+ps*sdu); for(jj=0; jj<m-3; jj+=4) { kernel_dtrsm_nt_rl_inv_8x4_lib4c44c(jj, pU, sdu, A+jj, lda, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, A+jj+jj*lda, lda, dA+jj); } if(jj<m) { kernel_dtrsm_nt_rl_inv_8x4_vs_lib4c44c(jj, pU, sdu, A+jj, lda, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, A+jj+jj*lda, lda, dA+jj, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+ps*sdu, D+(ii+4)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto llnn_1_left_4; } else { goto llnn_1_left_8; } } #else for(; ii<n-3; ii+=4) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); for(jj=0; jj<m-3; jj+=4) { kernel_dtrsm_nt_rl_inv_4x4_lib4c44c(jj, pU, A+jj, lda, &alpha, pU+jj*ps, pU+jj*ps, A+jj+jj*lda, lda, dA+jj); } if(jj<m) { kernel_dtrsm_nt_rl_inv_4x4_vs_lib4c44c(jj, pU, A+jj, lda, &alpha, pU+jj*ps, pU+jj*ps, A+jj+jj*lda, lda, dA+jj, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); } if(ii<n) { goto llnn_1_left_4; } #endif goto llnn_1_return; #if defined(TARGET_X64_INTEL_HASWELL) llnn_1_left_12: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_vs_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu, n-(ii+8)); for(jj=0; jj<m; jj+=4) { kernel_dtrsm_nt_rl_inv_12x4_vs_lib4c44c(jj, pU, sdu, A+jj, lda, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, A+jj+jj*lda, lda, dA+jj, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd, n-(ii+8)); goto llnn_1_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) llnn_1_left_8: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_vs_lib4(m, B+(ii+4)*ldb, ldb, pU+ps*sdu, n-(ii+4)); for(jj=0; jj<m; jj+=4) { kernel_dtrsm_nt_rl_inv_8x4_vs_lib4c44c(jj, pU, sdu, A+jj, lda, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, A+jj+jj*lda, lda, dA+jj, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+ps*sdu, D+(ii+4)*ldd, ldd, n-(ii+4)); goto llnn_1_return; #endif llnn_1_left_4: kernel_dpack_tn_4_vs_lib4(m, B+ii*ldb, ldb, pU, n-ii); for(jj=0; jj<m; jj+=4) { kernel_dtrsm_nt_rl_inv_4x4_vs_lib4c44c(jj, pU, A+jj, lda, &alpha, pU+jj*ps, pU+jj*ps, A+jj+jj*lda, lda, dA+jj, n-ii, m-jj); } kernel_dunpack_nt_4_vs_lib4(m, pU, D+ii*ldd, ldd, n-ii); goto llnn_1_return; llnn_1_return: return; llnn_2: m1 = (m+128-1)/128*128; tA_size = blasfeo_pm_memsize_dmat(ps, m_kernel, m1); tB_size = blasfeo_pm_memsize_dmat(ps, m1, m1); mem = malloc(tA_size+tB_size+64); blasfeo_align_64_byte(mem, (void **) &mem_align); blasfeo_pm_create_dmat(ps, m_kernel, m, &tA, (void *) mem_align); blasfeo_pm_create_dmat(ps, m, m, &tB, (void *) (mem_align+tA_size)); pU = tA.pA; sdu = tA.cn; pB = tB.pA; sdb = tB.cn; dB = tB.dA; // lower to lower for(ii=0; ii<m-3; ii+=4) { kernel_dpack_tt_4_lib4(m-ii, A+ii+ii*lda, lda, pB+ii*ps+ii*sdb, sdb); } if(ii<m) { kernel_dpack_tt_4_vs_lib4(m-ii, A+ii+ii*lda, lda, pB+ii*ps+ii*sdb, sdb, m-ii); } for(ii=0; ii<m; ii++) dB[ii] = 1.0/A[ii+ii*lda]; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) for(; ii<n-11; ii+=12) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu); for(jj=0; jj<m-3; jj+=4) { kernel_dtrsm_nt_rl_inv_12x4_lib4(jj, pU, sdu, pB+jj*sdb, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, pB+jj*ps+jj*sdb, dB+jj); } if(jj<m) { kernel_dtrsm_nt_rl_inv_12x4_vs_lib4(jj, pU, sdu, pB+jj*sdb, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, pB+jj*ps+jj*sdb, dB+jj, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto llnn_2_left_4; } if(n-ii<=8) { goto llnn_2_left_8; } else { goto llnn_2_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) for(; ii<n-7; ii+=8) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); for(jj=0; jj<m-3; jj+=4) { kernel_dtrsm_nt_rl_inv_8x4_lib4(jj, pU, sdu, pB+jj*sdb, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, pB+jj*ps+jj*sdb, dB+jj); } if(jj<m) { kernel_dtrsm_nt_rl_inv_8x4_vs_lib4(jj, pU, sdu, pB+jj*sdb, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, pB+jj*ps+jj*sdb, dB+jj, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto llnn_2_left_4; } else { goto llnn_2_left_8; } } #else for(; ii<n-3; ii+=4) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); for(jj=0; jj<m-3; jj+=4) { kernel_dtrsm_nt_rl_inv_4x4_lib4(jj, pU, pB+jj*sdb, &alpha, pU+jj*ps, pU+jj*ps, pB+jj*ps+jj*sdb, dB+jj); } if(jj<m) { kernel_dtrsm_nt_rl_inv_4x4_vs_lib4(jj, pU, pB+jj*sdb, &alpha, pU+jj*ps, pU+jj*ps, pB+jj*ps+jj*sdb, dB+jj, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); } if(ii<n) { goto llnn_2_left_4; } #endif goto llnn_2_return; #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) llnn_2_left_12: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_vs_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu, n-ii); for(jj=0; jj<m; jj+=4) { kernel_dtrsm_nt_rl_inv_12x4_vs_lib4(jj, pU, sdu, pB+jj*sdb, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, pB+jj*ps+jj*sdb, dB+jj, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd, n-ii-8); goto llnn_2_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) llnn_2_left_8: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_vs_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu, n-ii); for(jj=0; jj<m; jj+=4) { kernel_dtrsm_nt_rl_inv_8x4_vs_lib4(jj, pU, sdu, pB+jj*sdb, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, pB+jj*ps+jj*sdb, dB+jj, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd, n-ii-4); goto llnn_2_return; #endif llnn_2_left_4: kernel_dpack_tn_4_vs_lib4(m, B+ii*ldb, ldb, pU, n-ii); for(jj=0; jj<m; jj+=4) { kernel_dtrsm_nt_rl_inv_4x4_vs_lib4(jj, pU, pB+jj*sdb, &alpha, pU+jj*ps, pU+jj*ps, pB+jj*ps+jj*sdb, dB+jj, n-ii, m-jj); } kernel_dunpack_nt_4_vs_lib4(m, pU, D+ii*ldd, ldd, n-ii); goto llnn_2_return; llnn_2_return: free(mem); return; // never to get here return; } void blasfeo_hp_dtrsm_llnu(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { #if defined(PRINT_NAME) printf("\nblasfeo_hp_dtrsm_llnu (cm) %d %d %f %p %d %d %p %d %d %p %d %d\n", m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); #endif if(m<=0 | n<=0) return; // extract pointer to column-major matrices from structures int lda = sA->m; int ldb = sB->m; int ldd = sD->m; double *A = sA->pA + ai + aj*lda; double *B = sB->pA + bi + bj*ldb; double *D = sD->pA + di + dj*ldb; // printf("\n%p %d %p %d %p %d\n", A, lda, B, ldb); int ii, jj; const int ps = 4; //D_PS; #if defined(TARGET_GENERIC) double pd0[K_MAX_STACK]; #else ALIGNED( double pd0[K_MAX_STACK], 64 ); #endif #if defined(TARGET_GENERIC) double pU0[M_KERNEL*K_MAX_STACK]; #else ALIGNED( double pU0[M_KERNEL*K_MAX_STACK], 64 ); #endif int k0; // TODO update if necessary !!!!! // if(*side=='l' | *side=='L') k0 = m; // else // k0 = n; int sdu0 = (k0+3)/4*4; sdu0 = sdu0<K_MAX_STACK ? sdu0 : K_MAX_STACK; struct blasfeo_pm_dmat tA, tB; int sda, sdb; int tA_size, tB_size; void *mem; char *mem_align; int m1, n1, k1; int pack_B; double *pU, *dA, *pB, *dB; int sdu; const int m_kernel = M_KERNEL; const int l1_cache_el = L1_CACHE_EL; const int reals_per_cache_line = CACHE_LINE_EL; const int m_cache = (m+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int n_cache = (n+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; // const int k_cache = (k+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int m_kernel_cache = (m_kernel+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; int m_min = m_cache<m_kernel_cache ? m_cache : m_kernel_cache; // int n_min = n_cache<m_kernel_cache ? n_cache : m_kernel_cache; #if defined(TARGET_X64_INTEL_HASWELL) if(m>=200 | n>=200 | m>K_MAX_STACK) #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) if(m>=64 | n>=64 | m>K_MAX_STACK) #else if(m>=12 | n>=12 | m>K_MAX_STACK) #endif { goto llnu_2; } else { goto llnu_1; } return; // never to get here return; llnu_1: pU = pU0; sdu = sdu0; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(; ii<n-11; ii+=12) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu); for(jj=0; jj<m-3; jj+=4) { kernel_dtrsm_nt_rl_one_12x4_lib4c44c(jj, pU, sdu, A+jj, lda, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, A+jj+jj*lda, lda); } if(jj<m) { kernel_dtrsm_nt_rl_one_12x4_vs_lib4c44c(jj, pU, sdu, A+jj, lda, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, A+jj+jj*lda, lda, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto llnu_1_left_4; } if(n-ii<=8) { goto llnu_1_left_8; } else { goto llnu_1_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) for(; ii<n-7; ii+=8) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+ps*sdu); for(jj=0; jj<m-3; jj+=4) { kernel_dtrsm_nt_rl_one_8x4_lib4c44c(jj, pU, sdu, A+jj, lda, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, A+jj+jj*lda, lda); } if(jj<m) { kernel_dtrsm_nt_rl_one_8x4_vs_lib4c44c(jj, pU, sdu, A+jj, lda, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, A+jj+jj*lda, lda, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+ps*sdu, D+(ii+4)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto llnu_1_left_4; } else { goto llnu_1_left_8; } } #else for(; ii<n-3; ii+=4) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); for(jj=0; jj<m-3; jj+=4) { kernel_dtrsm_nt_rl_one_4x4_lib4c44c(jj, pU, A+jj, lda, &alpha, pU+jj*ps, pU+jj*ps, A+jj+jj*lda, lda); } if(jj<m) { kernel_dtrsm_nt_rl_one_4x4_vs_lib4c44c(jj, pU, A+jj, lda, &alpha, pU+jj*ps, pU+jj*ps, A+jj+jj*lda, lda, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); } if(ii<n) { goto llnu_1_left_4; } #endif goto llnu_1_return; #if defined(TARGET_X64_INTEL_HASWELL) llnu_1_left_12: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_vs_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu, n-(ii+8)); for(jj=0; jj<m; jj+=4) { kernel_dtrsm_nt_rl_one_12x4_vs_lib4c44c(jj, pU, sdu, A+jj, lda, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, A+jj+jj*lda, lda, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd, n-(ii+8)); goto llnu_1_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) llnu_1_left_8: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_vs_lib4(m, B+(ii+4)*ldb, ldb, pU+ps*sdu, n-(ii+4)); for(jj=0; jj<m; jj+=4) { kernel_dtrsm_nt_rl_one_8x4_vs_lib4c44c(jj, pU, sdu, A+jj, lda, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, A+jj+jj*lda, lda, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+ps*sdu, D+(ii+4)*ldd, ldd, n-(ii+4)); goto llnu_1_return; #endif llnu_1_left_4: kernel_dpack_tn_4_vs_lib4(m, B+ii*ldb, ldb, pU, n-ii); for(jj=0; jj<m; jj+=4) { kernel_dtrsm_nt_rl_one_4x4_vs_lib4c44c(jj, pU, A+jj, lda, &alpha, pU+jj*ps, pU+jj*ps, A+jj+jj*lda, lda, n-ii, m-jj); } kernel_dunpack_nt_4_vs_lib4(m, pU, D+ii*ldd, ldd, n-ii); goto llnu_1_return; llnu_1_return: return; llnu_2: m1 = (m+128-1)/128*128; tA_size = blasfeo_pm_memsize_dmat(ps, m_kernel, m1); tB_size = blasfeo_pm_memsize_dmat(ps, m1, m1); mem = malloc(tA_size+tB_size+64); blasfeo_align_64_byte(mem, (void **) &mem_align); blasfeo_pm_create_dmat(ps, m_kernel, m, &tA, (void *) mem_align); blasfeo_pm_create_dmat(ps, m, m, &tB, (void *) (mem_align+tA_size)); pU = tA.pA; sdu = tA.cn; pB = tB.pA; sdb = tB.cn; dB = tB.dA; // lower to lower for(ii=0; ii<m-3; ii+=4) { kernel_dpack_tt_4_lib4(m-ii, A+ii+ii*lda, lda, pB+ii*ps+ii*sdb, sdb); } if(ii<m) { kernel_dpack_tt_4_vs_lib4(m-ii, A+ii+ii*lda, lda, pB+ii*ps+ii*sdb, sdb, m-ii); } ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) for(; ii<n-11; ii+=12) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu); for(jj=0; jj<m-3; jj+=4) { kernel_dtrsm_nt_rl_one_12x4_lib4(jj, pU, sdu, pB+jj*sdb, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, pB+jj*ps+jj*sdb); } if(jj<m) { kernel_dtrsm_nt_rl_one_12x4_vs_lib4(jj, pU, sdu, pB+jj*sdb, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, pB+jj*ps+jj*sdb, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto llnu_2_left_4; } if(n-ii<=8) { goto llnu_2_left_8; } else { goto llnu_2_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) for(; ii<n-7; ii+=8) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); for(jj=0; jj<m-3; jj+=4) { kernel_dtrsm_nt_rl_one_8x4_lib4(jj, pU, sdu, pB+jj*sdb, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, pB+jj*ps+jj*sdb); } if(jj<m) { kernel_dtrsm_nt_rl_one_8x4_vs_lib4(jj, pU, sdu, pB+jj*sdb, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, pB+jj*ps+jj*sdb, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto llnu_2_left_4; } else { goto llnu_2_left_8; } } #else for(; ii<n-3; ii+=4) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); for(jj=0; jj<m-3; jj+=4) { kernel_dtrsm_nt_rl_one_4x4_lib4(jj, pU, pB+jj*sdb, &alpha, pU+jj*ps, pU+jj*ps, pB+jj*ps+jj*sdb); } if(jj<m) { kernel_dtrsm_nt_rl_one_4x4_vs_lib4(jj, pU, pB+jj*sdb, &alpha, pU+jj*ps, pU+jj*ps, pB+jj*ps+jj*sdb, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); } if(ii<n) { goto llnu_2_left_4; } #endif goto llnu_2_return; #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) llnu_2_left_12: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_vs_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu, n-ii-8); for(jj=0; jj<m; jj+=4) { kernel_dtrsm_nt_rl_one_12x4_vs_lib4(jj, pU, sdu, pB+jj*sdb, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, pB+jj*ps+jj*sdb, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd, n-ii-8); goto llnu_2_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) llnu_2_left_8: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_vs_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu, n-ii-4); for(jj=0; jj<m; jj+=4) { kernel_dtrsm_nt_rl_one_8x4_vs_lib4(jj, pU, sdu, pB+jj*sdb, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, pB+jj*ps+jj*sdb, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd, n-ii-4); goto llnu_2_return; #endif llnu_2_left_4: kernel_dpack_tn_4_vs_lib4(m, B+ii*ldb, ldb, pU, n-ii); for(jj=0; jj<m; jj+=4) { kernel_dtrsm_nt_rl_one_4x4_vs_lib4(jj, pU, pB+jj*sdb, &alpha, pU+jj*ps, pU+jj*ps, pB+jj*ps+jj*sdb, n-ii, m-jj); } kernel_dunpack_nt_4_vs_lib4(m, pU, D+ii*ldd, ldd, n-ii); goto llnu_2_return; llnu_2_return: free(mem); return; // never to get here return; } void blasfeo_hp_dtrsm_lltn(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { #if defined(PRINT_NAME) printf("\nblasfeo_hp_dtrsm_lltn (cm) %d %d %f %p %d %d %p %d %d %p %d %d\n", m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); #endif if(m<=0 | n<=0) return; // extract pointer to column-major matrices from structures int lda = sA->m; int ldb = sB->m; int ldd = sD->m; double *A = sA->pA + ai + aj*lda; double *B = sB->pA + bi + bj*ldb; double *D = sD->pA + di + dj*ldb; // printf("\n%p %d %p %d %p %d\n", A, lda, B, ldb); int ii, jj; const int ps = 4; //D_PS; #if defined(TARGET_GENERIC) double pd0[K_MAX_STACK]; #else ALIGNED( double pd0[K_MAX_STACK], 64 ); #endif #if defined(TARGET_GENERIC) double pU0[M_KERNEL*K_MAX_STACK]; #else ALIGNED( double pU0[M_KERNEL*K_MAX_STACK], 64 ); #endif int k0; // TODO update if necessary !!!!! // if(*side=='l' | *side=='L') k0 = m; // else // k0 = n; int sdu0 = (k0+3)/4*4; sdu0 = sdu0<K_MAX_STACK ? sdu0 : K_MAX_STACK; struct blasfeo_pm_dmat tA, tB; int sda, sdb; int tA_size, tB_size; void *mem; char *mem_align; int m1, n1, k1; int pack_B; double *pU, *dA, *pB, *dB; int sdu, idx, m4, mn4; const int m_kernel = M_KERNEL; const int l1_cache_el = L1_CACHE_EL; const int reals_per_cache_line = CACHE_LINE_EL; const int m_cache = (m+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int n_cache = (n+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; // const int k_cache = (k+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int m_kernel_cache = (m_kernel+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; int m_min = m_cache<m_kernel_cache ? m_cache : m_kernel_cache; // int n_min = n_cache<m_kernel_cache ? n_cache : m_kernel_cache; #if defined(TARGET_X64_INTEL_HASWELL) if(m>=300 | n>=300 | m>K_MAX_STACK) #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) if(m>=64 | n>=64 | m>K_MAX_STACK) #else if(m>=12 | n>=12 | m>K_MAX_STACK) #endif { goto lunn_2; } else { goto lltn_1; } return; // never to get here return; lltn_1: // XXX limits of ii and jj swapped !!! pU = pU0; sdu = sdu0; dA = pd0; for(ii=0; ii<m; ii++) dA[ii] = 1.0/A[ii+ii*lda]; mn4 = m%4; m4 = m - mn4; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(; ii<n-11; ii+=12) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu); if(mn4!=0) { idx = m4; kernel_dtrsm_nn_rl_inv_12x4_vs_lib4c44c(0, pU+(idx+4)*ps, sdu, A+idx+4+idx*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, dA+idx, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nn_rl_inv_12x4_lib4c44c(jj+mn4, pU+(idx+4)*ps, sdu, A+idx+4+idx*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, dA+idx); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto lltn_1_left_4; } else if(n-ii<=8) { goto lltn_1_left_8; } else { goto lltn_1_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) for(; ii<n-7; ii+=8) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); if(mn4!=0) { idx = m4; kernel_dtrsm_nn_rl_inv_8x4_vs_lib4c44c(0, pU+(idx+4)*ps, sdu, A+idx+4+idx*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, dA+idx, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nn_rl_inv_8x4_lib4c44c(jj+mn4, pU+(idx+4)*ps, sdu, A+idx+4+idx*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, dA+idx); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+ps*sdu, D+(ii+4)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto lltn_1_left_4; } else { goto lltn_1_left_8; } } #else for(; ii<n-3; ii+=4) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); if(mn4!=0) { idx = m4; kernel_dtrsm_nn_rl_inv_4x4_vs_lib4c44c(0, pU+(idx+4)*ps, A+idx+4+idx*lda, lda, &alpha, pU+idx*ps, pU+idx*ps, A+idx+idx*lda, lda, dA+idx, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nn_rl_inv_4x4_lib4c44c(jj+mn4, pU+(idx+4)*ps, A+idx+4+idx*lda, lda, &alpha, pU+idx*ps, pU+idx*ps, A+idx+idx*lda, lda, dA+idx); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); } if(ii<n) { goto lltn_1_left_4; } #endif goto lltn_1_return; #if defined(TARGET_X64_INTEL_HASWELL) lltn_1_left_12: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_vs_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu, n-ii-8); if(mn4!=0) { idx = m4; kernel_dtrsm_nn_rl_inv_12x4_vs_lib4c44c(0, pU+(idx+4)*ps, sdu, A+idx+4+idx*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, dA+idx, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nn_rl_inv_12x4_vs_lib4c44c(jj+mn4, pU+(idx+4)*ps, sdu, A+idx+4+idx*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, dA+idx, n-ii, 4); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd, n-(ii+8)); goto lltn_1_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) lltn_1_left_8: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_vs_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu, n-ii-4); if(mn4!=0) { idx = m4; kernel_dtrsm_nn_rl_inv_8x4_vs_lib4c44c(0, pU+(idx+4)*ps, sdu, A+idx+4+idx*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, dA+idx, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nn_rl_inv_8x4_vs_lib4c44c(jj+mn4, pU+(idx+4)*ps, sdu, A+idx+4+idx*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, dA+idx, n-ii, 4); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+ps*sdu, D+(ii+4)*ldd, ldd, n-(ii+4)); goto lltn_1_return; #endif lltn_1_left_4: kernel_dpack_tn_4_vs_lib4(m, B+ii*ldb, ldb, pU, n-ii); if(mn4!=0) { idx = m4; kernel_dtrsm_nn_rl_inv_4x4_vs_lib4c44c(0, pU+(idx+4)*ps, A+idx+4+idx*lda, lda, &alpha, pU+idx*ps, pU+idx*ps, A+idx+idx*lda, lda, dA+idx, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nn_rl_inv_4x4_vs_lib4c44c(jj+mn4, pU+(idx+4)*ps, A+idx+4+idx*lda, lda, &alpha, pU+idx*ps, pU+idx*ps, A+idx+idx*lda, lda, dA+idx, n-ii, 4); } kernel_dunpack_nt_4_vs_lib4(m, pU, D+ii*ldd, ldd, n-ii); goto lltn_1_return; lltn_1_return: return; lunn_2: // XXX limits of ii and jj swapped !!! m1 = (m+128-1)/128*128; tA_size = blasfeo_pm_memsize_dmat(ps, m_kernel, m1); tB_size = blasfeo_pm_memsize_dmat(ps, m1, m1); mem = malloc(tA_size+tB_size+64); blasfeo_align_64_byte(mem, (void **) &mem_align); blasfeo_pm_create_dmat(ps, m_kernel, m, &tA, (void *) mem_align); blasfeo_pm_create_dmat(ps, m, m, &tB, (void *) (mem_align+tA_size)); pU = tA.pA; sdu = tA.cn; pB = tB.pA; sdb = tB.cn; dB = tB.dA; // lower to upper for(ii=0; ii<m-3; ii+=4) { kernel_dpack_tn_4_lib4(m-ii, A+ii+ii*lda, lda, pB+ii*ps+ii*sdb); } if(ii<m) { kernel_dpack_tn_4_vs_lib4(m-ii, A+ii+ii*lda, lda, pB+ii*ps+ii*sdb, m-ii); } for(ii=0; ii<m; ii++) dB[ii] = 1.0/A[ii+ii*lda]; mn4 = m%4; m4 = m - mn4; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(; ii<n-11; ii+=12) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_inv_12x4_vs_lib4(0, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, dB+idx, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_inv_12x4_lib4(jj+mn4, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, dB+idx); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto lunn_2_left_4; } if(n-ii<=8) { goto lunn_2_left_8; } else { goto lunn_2_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) for(; ii<n-7; ii+=8) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_inv_8x4_vs_lib4(0, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, dB+idx, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_inv_8x4_lib4(jj+mn4, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, dB+idx); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto lunn_2_left_4; } else { goto lunn_2_left_8; } } #else for(; ii<n-3; ii+=4) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_inv_4x4_vs_lib4(0, pU+(idx+4)*ps, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, pU+idx*ps, pB+idx*ps+idx*sdb, dB+idx, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_inv_4x4_lib4(jj+mn4, pU+(idx+4)*ps, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, pU+idx*ps, pB+idx*ps+idx*sdb, dB+idx); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); } if(ii<n) { goto lunn_2_left_4; } #endif goto lunn_2_return; #if defined(TARGET_X64_INTEL_HASWELL) lunn_2_left_12: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_vs_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu, n-ii-8); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_inv_12x4_vs_lib4(0, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, dB+idx, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_inv_12x4_vs_lib4(jj+mn4, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, dB+idx, n-ii, 4); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd, n-ii-8); goto lunn_2_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) lunn_2_left_8: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_vs_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu, n-ii-4); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_inv_8x4_vs_lib4(0, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, dB+idx, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_inv_8x4_vs_lib4(jj+mn4, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, dB+idx, n-ii, 4); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd, n-ii-4); goto lunn_2_return; #endif lunn_2_left_4: kernel_dpack_tn_4_vs_lib4(m, B+ii*ldb, ldb, pU, n-ii); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_inv_4x4_vs_lib4(0, pU+(idx+4)*ps, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, pU+idx*ps, pB+idx*ps+idx*sdb, dB+idx, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_inv_4x4_vs_lib4(jj+mn4, pU+(idx+4)*ps, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, pU+idx*ps, pB+idx*ps+idx*sdb, dB+idx, n-ii, 4); } kernel_dunpack_nt_4_vs_lib4(m, pU, D+ii*ldd, ldd, n-ii); goto lunn_2_return; lunn_2_return: free(mem); return; // never to get here return; } void blasfeo_hp_dtrsm_lltu(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { #if defined(PRINT_NAME) printf("\nblasfeo_hp_dtrsm_lltu (cm) %d %d %f %p %d %d %p %d %d %p %d %d\n", m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); #endif if(m<=0 | n<=0) return; // extract pointer to column-major matrices from structures int lda = sA->m; int ldb = sB->m; int ldd = sD->m; double *A = sA->pA + ai + aj*lda; double *B = sB->pA + bi + bj*ldb; double *D = sD->pA + di + dj*ldd; // printf("\n%p %d %p %d %p %d\n", A, lda, B, ldb); int ii, jj; const int ps = 4; //D_PS; #if defined(TARGET_GENERIC) double pd0[K_MAX_STACK]; #else ALIGNED( double pd0[K_MAX_STACK], 64 ); #endif #if defined(TARGET_GENERIC) double pU0[M_KERNEL*K_MAX_STACK]; #else ALIGNED( double pU0[M_KERNEL*K_MAX_STACK], 64 ); #endif int k0; // TODO update if necessary !!!!! // if(*side=='l' | *side=='L') k0 = m; // else // k0 = n; int sdu0 = (k0+3)/4*4; sdu0 = sdu0<K_MAX_STACK ? sdu0 : K_MAX_STACK; struct blasfeo_pm_dmat tA, tB; int sda, sdb; int tA_size, tB_size; void *mem; char *mem_align; int m1, n1, k1; int pack_B; double *pU, *dA, *pB, *dB; int sdu, idx, m4, mn4; const int m_kernel = M_KERNEL; const int l1_cache_el = L1_CACHE_EL; const int reals_per_cache_line = CACHE_LINE_EL; const int m_cache = (m+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int n_cache = (n+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; // const int k_cache = (k+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int m_kernel_cache = (m_kernel+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; int m_min = m_cache<m_kernel_cache ? m_cache : m_kernel_cache; // int n_min = n_cache<m_kernel_cache ? n_cache : m_kernel_cache; #if defined(TARGET_X64_INTEL_HASWELL) if(m>=300 | n>=300 | m>K_MAX_STACK) #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) if(m>=64 | n>=64 | m>K_MAX_STACK) #else if(m>=12 | n>=12 | m>K_MAX_STACK) #endif { goto lunu_2; } else { goto lltu_1; } return; // never to get here return; lltu_1: // XXX limits of ii and jj swapped !!! pU = pU0; sdu = sdu0; mn4 = m%4; m4 = m - mn4; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(; ii<n-11; ii+=12) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu); if(mn4!=0) { idx = m4; kernel_dtrsm_nn_rl_one_12x4_vs_lib4c44c(0, pU+(idx+4)*ps, sdu, A+idx+4+idx*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nn_rl_one_12x4_lib4c44c(jj+mn4, pU+(idx+4)*ps, sdu, A+idx+4+idx*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto lltu_1_left_4; } else if(n-ii<=8) { goto lltu_1_left_8; } else { goto lltu_1_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) for(; ii<n-7; ii+=8) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); if(mn4!=0) { idx = m4; kernel_dtrsm_nn_rl_one_8x4_vs_lib4c44c(0, pU+(idx+4)*ps, sdu, A+idx+4+idx*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nn_rl_one_8x4_lib4c44c(jj+mn4, pU+(idx+4)*ps, sdu, A+idx+4+idx*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+ps*sdu, D+(ii+4)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto lltu_1_left_4; } else { goto lltu_1_left_8; } } #else for(; ii<n-3; ii+=4) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); if(mn4!=0) { idx = m4; kernel_dtrsm_nn_rl_one_4x4_vs_lib4c44c(0, pU+(idx+4)*ps, A+idx+4+idx*lda, lda, &alpha, pU+idx*ps, pU+idx*ps, A+idx+idx*lda, lda, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nn_rl_one_4x4_lib4c44c(jj+mn4, pU+(idx+4)*ps, A+idx+4+idx*lda, lda, &alpha, pU+idx*ps, pU+idx*ps, A+idx+idx*lda, lda); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); } if(ii<n) { goto lltu_1_left_4; } #endif goto lltu_1_return; #if defined(TARGET_X64_INTEL_HASWELL) lltu_1_left_12: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_vs_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu, n-ii-8); if(mn4!=0) { idx = m4; kernel_dtrsm_nn_rl_one_12x4_vs_lib4c44c(0, pU+(idx+4)*ps, sdu, A+idx+4+idx*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nn_rl_one_12x4_vs_lib4c44c(jj+mn4, pU+(idx+4)*ps, sdu, A+idx+4+idx*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, n-ii, 4); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd, n-(ii+8)); goto lltu_1_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) lltu_1_left_8: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_vs_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu, n-ii-4); if(mn4!=0) { idx = m4; kernel_dtrsm_nn_rl_one_8x4_vs_lib4c44c(0, pU+(idx+4)*ps, sdu, A+idx+4+idx*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nn_rl_one_8x4_vs_lib4c44c(jj+mn4, pU+(idx+4)*ps, sdu, A+idx+4+idx*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, n-ii, 4); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+ps*sdu, D+(ii+4)*ldd, ldd, n-(ii+4)); goto lltu_1_return; #endif lltu_1_left_4: kernel_dpack_tn_4_vs_lib4(m, B+ii*ldb, ldb, pU, n-ii); if(mn4!=0) { idx = m4; kernel_dtrsm_nn_rl_one_4x4_vs_lib4c44c(0, pU+(idx+4)*ps, A+idx+4+idx*lda, lda, &alpha, pU+idx*ps, pU+idx*ps, A+idx+idx*lda, lda, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nn_rl_one_4x4_vs_lib4c44c(jj+mn4, pU+(idx+4)*ps, A+idx+4+idx*lda, lda, &alpha, pU+idx*ps, pU+idx*ps, A+idx+idx*lda, lda, n-ii, 4); } kernel_dunpack_nt_4_vs_lib4(m, pU, D+ii*ldd, ldd, n-ii); goto lltu_1_return; lltu_1_return: return; lunu_2: // XXX limits of ii and jj swapped !!! m1 = (m+128-1)/128*128; tA_size = blasfeo_pm_memsize_dmat(ps, m_kernel, m1); tB_size = blasfeo_pm_memsize_dmat(ps, m1, m1); mem = malloc(tA_size+tB_size+64); blasfeo_align_64_byte(mem, (void **) &mem_align); blasfeo_pm_create_dmat(ps, m_kernel, m, &tA, (void *) mem_align); blasfeo_pm_create_dmat(ps, m, m, &tB, (void *) (mem_align+tA_size)); pU = tA.pA; sdu = tA.cn; pB = tB.pA; sdb = tB.cn; dB = tB.dA; // lower to upper for(ii=0; ii<m-3; ii+=4) { kernel_dpack_tn_4_lib4(m-ii, A+ii+ii*lda, lda, pB+ii*ps+ii*sdb); } if(ii<m) { kernel_dpack_tn_4_vs_lib4(m-ii, A+ii+ii*lda, lda, pB+ii*ps+ii*sdb, m-ii); } mn4 = m%4; m4 = m - mn4; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(; ii<n-11; ii+=12) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_one_12x4_vs_lib4(0, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_one_12x4_lib4(jj+mn4, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto lunu_2_left_4; } if(n-ii<=8) { goto lunu_2_left_8; } else { goto lunu_2_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) for(; ii<n-7; ii+=8) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_one_8x4_vs_lib4(0, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_one_8x4_lib4(jj+mn4, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto lunu_2_left_4; } else { goto lunu_2_left_8; } } #else for(; ii<n-3; ii+=4) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_one_4x4_vs_lib4(0, pU+(idx+4)*ps, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, pU+idx*ps, pB+idx*ps+idx*sdb, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_one_4x4_lib4(jj+mn4, pU+(idx+4)*ps, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, pU+idx*ps, pB+idx*ps+idx*sdb); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); } if(ii<n) { goto lunu_2_left_4; } #endif goto lunu_2_return; #if defined(TARGET_X64_INTEL_HASWELL) lunu_2_left_12: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_vs_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu, n-ii-8); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_one_12x4_vs_lib4(0, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_one_12x4_vs_lib4(jj+mn4, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, n-ii, 4); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd, n-ii-8); goto lunu_2_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) lunu_2_left_8: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_vs_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu, n-ii-4); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_one_8x4_vs_lib4(0, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_one_8x4_vs_lib4(jj+mn4, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, n-ii, 4); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd, n-ii-4); goto lunu_2_return; #endif lunu_2_left_4: kernel_dpack_tn_4_vs_lib4(m, B+ii*ldb, ldb, pU, n-ii); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_one_4x4_vs_lib4(0, pU+(idx+4)*ps, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, pU+idx*ps, pB+idx*ps+idx*sdb, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_one_4x4_vs_lib4(jj+mn4, pU+(idx+4)*ps, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, pU+idx*ps, pB+idx*ps+idx*sdb, n-ii, 4); } kernel_dunpack_nt_4_vs_lib4(m, pU, D+ii*ldd, ldd, n-ii); goto lunu_2_return; lunu_2_return: free(mem); return; // never to get here return; } void blasfeo_hp_dtrsm_lunn(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { #if defined(PRINT_NAME) printf("\nblasfeo_hp_dtrsm_lunn (cm) %d %d %f %p %d %d %p %d %d %p %d %d\n", m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); #endif if(m<=0 | n<=0) return; // extract pointer to column-major matrices from structures int lda = sA->m; int ldb = sB->m; int ldd = sD->m; double *A = sA->pA + ai + aj*lda; double *B = sB->pA + bi + bj*ldb; double *D = sD->pA + di + dj*ldd; // printf("\n%p %d %p %d %p %d\n", A, lda, B, ldb); int ii, jj; const int ps = 4; //D_PS; #if defined(TARGET_GENERIC) double pd0[K_MAX_STACK]; #else ALIGNED( double pd0[K_MAX_STACK], 64 ); #endif #if defined(TARGET_GENERIC) double pU0[M_KERNEL*K_MAX_STACK]; #else ALIGNED( double pU0[M_KERNEL*K_MAX_STACK], 64 ); #endif int k0; // TODO update if necessary !!!!! // if(*side=='l' | *side=='L') k0 = m; // else // k0 = n; int sdu0 = (k0+3)/4*4; sdu0 = sdu0<K_MAX_STACK ? sdu0 : K_MAX_STACK; struct blasfeo_pm_dmat tA, tB; int sda, sdb; int tA_size, tB_size; void *mem; char *mem_align; int m1, n1, k1; int pack_B; double *pU, *dA, *pB, *dB; int sdu, idx, m4, mn4; const int m_kernel = M_KERNEL; const int l1_cache_el = L1_CACHE_EL; const int reals_per_cache_line = CACHE_LINE_EL; const int m_cache = (m+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int n_cache = (n+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; // const int k_cache = (k+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int m_kernel_cache = (m_kernel+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; int m_min = m_cache<m_kernel_cache ? m_cache : m_kernel_cache; // int n_min = n_cache<m_kernel_cache ? n_cache : m_kernel_cache; lunn: #if defined(TARGET_X64_INTEL_HASWELL) if(m>=200 | n>=200 | m>K_MAX_STACK) #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) if(m>=64 | n>=64 | m>K_MAX_STACK) #else if(m>=12 | n>=12 | m>K_MAX_STACK) #endif { goto lunn_2; } else { goto lunn_1; } // never to get here return; lunn_1: // XXX limits of ii and jj swapped !!! pU = pU0; sdu = sdu0; dA = pd0; for(ii=0; ii<m; ii++) dA[ii] = 1.0/A[ii+ii*lda]; mn4 = m%4; m4 = m - mn4; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(; ii<n-11; ii+=12) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_inv_12x4_vs_lib4c44c(0, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, dA+idx, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_inv_12x4_lib4c44c(jj+mn4, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, dA+idx); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto lunn_1_left_4; } if(n-ii<=8) { goto lunn_1_left_8; } else { goto lunn_1_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) for(; ii<n-7; ii+=8) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_inv_8x4_vs_lib4c44c(0, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, dA+idx, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_inv_8x4_lib4c44c(jj+mn4, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, dA+idx); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+ps*sdu, D+(ii+4)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto lunn_1_left_4; } else { goto lunn_1_left_8; } } #else for(; ii<n-3; ii+=4) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_inv_4x4_vs_lib4c44c(0, pU+(idx+4)*ps, A+idx+(idx+4)*lda, lda, &alpha, pU+idx*ps, pU+idx*ps, A+idx+idx*lda, lda, dA+idx, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_inv_4x4_lib4c44c(jj+mn4, pU+(idx+4)*ps, A+idx+(idx+4)*lda, lda, &alpha, pU+idx*ps, pU+idx*ps, A+idx+idx*lda, lda, dA+idx); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); } if(ii<n) { goto lunn_1_left_4; } #endif goto lunn_1_return; #if defined(TARGET_X64_INTEL_HASWELL) lunn_1_left_12: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_vs_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu, n-ii-8); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_inv_12x4_vs_lib4c44c(0, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, dA+idx, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_inv_12x4_vs_lib4c44c(jj+mn4, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, dA+idx, n-ii, 4); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd, n-(ii+8)); goto lunn_1_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) lunn_1_left_8: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_vs_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu, n-ii-4); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_inv_8x4_vs_lib4c44c(0, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, dA+idx, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_inv_8x4_vs_lib4c44c(jj+mn4, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, dA+idx, n-ii, 4); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+ps*sdu, D+(ii+4)*ldd, ldd, n-(ii+4)); goto lunn_1_return; #endif lunn_1_left_4: kernel_dpack_tn_4_vs_lib4(m, B+ii*ldb, ldb, pU, n-ii); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_inv_4x4_vs_lib4c44c(0, pU+(idx+4)*ps, A+idx+(idx+4)*lda, lda, &alpha, pU+idx*ps, pU+idx*ps, A+idx+idx*lda, lda, dA+idx, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_inv_4x4_vs_lib4c44c(jj+mn4, pU+(idx+4)*ps, A+idx+(idx+4)*lda, lda, &alpha, pU+idx*ps, pU+idx*ps, A+idx+idx*lda, lda, dA+idx, n-ii, 4); } kernel_dunpack_nt_4_vs_lib4(m, pU, D+ii*ldd, ldd, n-ii); goto lunn_1_return; lunn_1_return: return; lunn_2: // XXX limits of ii and jj swapped !!! m1 = (m+128-1)/128*128; tA_size = blasfeo_pm_memsize_dmat(ps, m_kernel, m1); tB_size = blasfeo_pm_memsize_dmat(ps, m1, m1); mem = malloc(tA_size+tB_size+64); blasfeo_align_64_byte(mem, (void **) &mem_align); blasfeo_pm_create_dmat(ps, m_kernel, m, &tA, (void *) mem_align); blasfeo_pm_create_dmat(ps, m, m, &tB, (void *) (mem_align+tA_size)); pU = tA.pA; sdu = tA.cn; pB = tB.pA; sdb = tB.cn; dB = tB.dA; // upper to upper for(ii=0; ii<m-3; ii+=4) { kernel_dpack_tt_4_lib4(ii+4, A+ii*lda, lda, pB+ii*ps, sdb); } if(ii<m) { kernel_dpack_tt_4_vs_lib4(m, A+ii*lda, lda, pB+ii*ps, sdb, m-ii); } for(ii=0; ii<m; ii++) dB[ii] = 1.0/A[ii+ii*lda]; mn4 = m%4; m4 = m - mn4; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(; ii<n-11; ii+=12) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_inv_12x4_vs_lib4(0, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, dB+idx, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_inv_12x4_lib4(jj+mn4, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, dB+idx); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto lunn_2_left_4; } if(n-ii<=8) { goto lunn_2_left_8; } else { goto lunn_2_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) for(; ii<n-7; ii+=8) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_inv_8x4_vs_lib4(0, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, dB+idx, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_inv_8x4_lib4(jj+mn4, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, dB+idx); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto lunn_2_left_4; } else { goto lunn_2_left_8; } } #else for(; ii<n-3; ii+=4) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_inv_4x4_vs_lib4(0, pU+(idx+4)*ps, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, pU+idx*ps, pB+idx*ps+idx*sdb, dB+idx, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_inv_4x4_lib4(jj+mn4, pU+(idx+4)*ps, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, pU+idx*ps, pB+idx*ps+idx*sdb, dB+idx); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); } if(ii<n) { goto lunn_2_left_4; } #endif goto lunn_2_return; #if defined(TARGET_X64_INTEL_HASWELL) lunn_2_left_12: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_vs_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu, n-ii-8); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_inv_12x4_vs_lib4(0, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, dB+idx, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_inv_12x4_vs_lib4(jj+mn4, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, dB+idx, n-ii, 4); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd, n-ii-8); goto lunn_2_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) lunn_2_left_8: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_vs_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu, n-ii-4); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_inv_8x4_vs_lib4(0, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, dB+idx, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_inv_8x4_vs_lib4(jj+mn4, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, dB+idx, n-ii, 4); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd, n-ii-4); goto lunn_2_return; #endif lunn_2_left_4: kernel_dpack_tn_4_vs_lib4(m, B+ii*ldb, ldb, pU, n-ii); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_inv_4x4_vs_lib4(0, pU+(idx+4)*ps, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, pU+idx*ps, pB+idx*ps+idx*sdb, dB+idx, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_inv_4x4_vs_lib4(jj+mn4, pU+(idx+4)*ps, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, pU+idx*ps, pB+idx*ps+idx*sdb, dB+idx, n-ii, 4); } kernel_dunpack_nt_4_vs_lib4(m, pU, D+ii*ldd, ldd, n-ii); goto lunn_2_return; lunn_2_return: free(mem); return; // never to get here return; } void blasfeo_hp_dtrsm_lunu(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { #if defined(PRINT_NAME) printf("\nblasfeo_hp_dtrsm_lunu (cm) %d %d %f %p %d %d %p %d %d %p %d %d\n", m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); #endif if(m<=0 | n<=0) return; // extract pointer to column-major matrices from structures int lda = sA->m; int ldb = sB->m; int ldd = sD->m; double *A = sA->pA + ai + aj*lda; double *B = sB->pA + bi + bj*ldb; double *D = sD->pA + di + dj*ldd; // printf("\n%p %d %p %d %p %d\n", A, lda, B, ldb); int ii, jj; const int ps = 4; //D_PS; #if defined(TARGET_GENERIC) double pd0[K_MAX_STACK]; #else ALIGNED( double pd0[K_MAX_STACK], 64 ); #endif #if defined(TARGET_GENERIC) double pU0[M_KERNEL*K_MAX_STACK]; #else ALIGNED( double pU0[M_KERNEL*K_MAX_STACK], 64 ); #endif int k0; // TODO update if necessary !!!!! // if(*side=='l' | *side=='L') k0 = m; // else // k0 = n; int sdu0 = (k0+3)/4*4; sdu0 = sdu0<K_MAX_STACK ? sdu0 : K_MAX_STACK; struct blasfeo_pm_dmat tA, tB; int sda, sdb; int tA_size, tB_size; void *mem; char *mem_align; int m1, n1, k1; int pack_B; double *pU, *dA, *pB, *dB; int sdu, idx, m4, mn4; const int m_kernel = M_KERNEL; const int l1_cache_el = L1_CACHE_EL; const int reals_per_cache_line = CACHE_LINE_EL; const int m_cache = (m+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int n_cache = (n+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; // const int k_cache = (k+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int m_kernel_cache = (m_kernel+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; int m_min = m_cache<m_kernel_cache ? m_cache : m_kernel_cache; // int n_min = n_cache<m_kernel_cache ? n_cache : m_kernel_cache; lunu: #if defined(TARGET_X64_INTEL_HASWELL) if(m>=200 | n>=200 | m>K_MAX_STACK) #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) if(m>=64 | n>=64 | m>K_MAX_STACK) #else if(m>=12 | n>=12 | m>K_MAX_STACK) #endif { goto lunu_2; } else { goto lunu_1; } lunu_1: // XXX limits of ii and jj swapped !!! pU = pU0; sdu = sdu0; mn4 = m%4; m4 = m - mn4; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(; ii<n-11; ii+=12) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_one_12x4_vs_lib4c44c(0, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_one_12x4_lib4c44c(jj+mn4, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto lunu_1_left_4; } if(n-ii<=8) { goto lunu_1_left_8; } else { goto lunu_1_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) for(; ii<n-7; ii+=8) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_one_8x4_vs_lib4c44c(0, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_one_8x4_lib4c44c(jj+mn4, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+ps*sdu, D+(ii+4)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto lunu_1_left_4; } else { goto lunu_1_left_8; } } #else for(; ii<n-3; ii+=4) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_one_4x4_vs_lib4c44c(0, pU+(idx+4)*ps, A+idx+(idx+4)*lda, lda, &alpha, pU+idx*ps, pU+idx*ps, A+idx+idx*lda, lda, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_one_4x4_lib4c44c(jj+mn4, pU+(idx+4)*ps, A+idx+(idx+4)*lda, lda, &alpha, pU+idx*ps, pU+idx*ps, A+idx+idx*lda, lda); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); } if(ii<n) { goto lunu_1_left_4; } #endif goto lunu_1_return; #if defined(TARGET_X64_INTEL_HASWELL) lunu_1_left_12: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_vs_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu, n-ii-8); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_one_12x4_vs_lib4c44c(0, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_one_12x4_vs_lib4c44c(jj+mn4, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, n-ii, 4); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd, n-(ii+8)); goto lunu_1_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) lunu_1_left_8: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_vs_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu, n-ii-4); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_one_8x4_vs_lib4c44c(0, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_one_8x4_vs_lib4c44c(jj+mn4, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, A+idx+idx*lda, lda, n-ii, 4); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+ps*sdu, D+(ii+4)*ldd, ldd, n-(ii+4)); goto lunu_1_return; #endif lunu_1_left_4: kernel_dpack_tn_4_vs_lib4(m, B+ii*ldb, ldb, pU, n-ii); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_one_4x4_vs_lib4c44c(0, pU+(idx+4)*ps, A+idx+(idx+4)*lda, lda, &alpha, pU+idx*ps, pU+idx*ps, A+idx+idx*lda, lda, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_one_4x4_vs_lib4c44c(jj+mn4, pU+(idx+4)*ps, A+idx+(idx+4)*lda, lda, &alpha, pU+idx*ps, pU+idx*ps, A+idx+idx*lda, lda, n-ii, 4); } kernel_dunpack_nt_4_vs_lib4(m, pU, D+ii*ldd, ldd, n-ii); goto lunu_1_return; lunu_1_return: return; lunu_2: // XXX limits of ii and jj swapped !!! m1 = (m+128-1)/128*128; tA_size = blasfeo_pm_memsize_dmat(ps, m_kernel, m1); tB_size = blasfeo_pm_memsize_dmat(ps, m1, m1); mem = malloc(tA_size+tB_size+64); blasfeo_align_64_byte(mem, (void **) &mem_align); blasfeo_pm_create_dmat(ps, m_kernel, m, &tA, (void *) mem_align); blasfeo_pm_create_dmat(ps, m, m, &tB, (void *) (mem_align+tA_size)); pU = tA.pA; sdu = tA.cn; pB = tB.pA; sdb = tB.cn; dB = tB.dA; // upper to upper for(ii=0; ii<m-3; ii+=4) { kernel_dpack_tt_4_lib4(ii+4, A+ii*lda, lda, pB+ii*ps, sdb); } if(ii<m) { kernel_dpack_tt_4_vs_lib4(m, A+ii*lda, lda, pB+ii*ps, sdb, m-ii); } mn4 = m%4; m4 = m - mn4; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(; ii<n-11; ii+=12) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_one_12x4_vs_lib4(0, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_one_12x4_lib4(jj+mn4, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto lunu_2_left_4; } if(n-ii<=8) { goto lunu_2_left_8; } else { goto lunu_2_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) for(; ii<n-7; ii+=8) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_one_8x4_vs_lib4(0, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_one_8x4_lib4(jj+mn4, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto lunu_2_left_4; } else { goto lunu_2_left_8; } } #else for(; ii<n-3; ii+=4) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_one_4x4_vs_lib4(0, pU+(idx+4)*ps, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, pU+idx*ps, pB+idx*ps+idx*sdb, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_one_4x4_lib4(jj+mn4, pU+(idx+4)*ps, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, pU+idx*ps, pB+idx*ps+idx*sdb); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); } if(ii<n) { goto lunu_2_left_4; } #endif goto lunu_2_return; #if defined(TARGET_X64_INTEL_HASWELL) lunu_2_left_12: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_vs_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu, n-ii-8); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_one_12x4_vs_lib4(0, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_one_12x4_vs_lib4(jj+mn4, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, n-ii, 4); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd, n-ii-8); goto lunu_2_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) lunu_2_left_8: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_vs_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu, n-ii-4); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_one_8x4_vs_lib4(0, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_one_8x4_vs_lib4(jj+mn4, pU+(idx+4)*ps, sdu, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, sdu, pU+idx*ps, sdu, pB+idx*ps+idx*sdb, n-ii, 4); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd, n-ii-4); goto lunu_2_return; #endif lunu_2_left_4: kernel_dpack_tn_4_vs_lib4(m, B+ii*ldb, ldb, pU, n-ii); if(mn4!=0) { idx = m4; kernel_dtrsm_nt_ru_one_4x4_vs_lib4(0, pU+(idx+4)*ps, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, pU+idx*ps, pB+idx*ps+idx*sdb, n-ii, mn4); } for(jj=0; jj<m4-3; jj+=4) { idx = m4-jj-4; kernel_dtrsm_nt_ru_one_4x4_vs_lib4(jj+mn4, pU+(idx+4)*ps, pB+(idx+4)*ps+idx*sdb, &alpha, pU+idx*ps, pU+idx*ps, pB+idx*ps+idx*sdb, n-ii, 4); } kernel_dunpack_nt_4_vs_lib4(m, pU, D+ii*ldd, ldd, n-ii); goto lunu_2_return; lunu_2_return: free(mem); return; // never to get here return; } void blasfeo_hp_dtrsm_lutn(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { #if defined(PRINT_NAME) printf("\nblasfeo_hp_dtrsm_lutn (cm) %d %d %f %p %d %d %p %d %d %p %d %d\n", m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); #endif if(m<=0 | n<=0) return; // extract pointer to column-major matrices from structures int lda = sA->m; int ldb = sB->m; int ldd = sD->m; double *A = sA->pA + ai + aj*lda; double *B = sB->pA + bi + bj*ldb; double *D = sD->pA + di + dj*ldd; // printf("\n%p %d %p %d %p %d\n", A, lda, B, ldb); int ii, jj, ll; int ii0, ll0, jj0, iii; int mc, nc, kc; int mleft, nleft, kleft; int mc0, nc0, kc0; int ldc1; double beta1; double *pA, *pB, *pT, *C1, *dA, *dB, *dT; #if defined(TARGET_X64_INTEL_SKYLAKE_X) const int ps = 4; // XXX TODO fix once implemented missing kernels !!! #else const int ps = PS; #endif int k0; // TODO update if necessary !!!!! // if(*side=='l' | *side=='L') k0 = m; // else // k0 = n; #if defined(TARGET_GENERIC) double pU_stack[M_KERNEL*K_MAX_STACK]; double pd_stack[K_MAX_STACK]; #else ALIGNED( double pU_stack[M_KERNEL*K_MAX_STACK], 64 ); ALIGNED( double pd_stack[K_MAX_STACK], 64 ); #endif int sdu_stack = K_MAX_STACK; int k4 = (k0+3)/4*4; struct blasfeo_pm_dmat tA, tB, tT; int sda, sdb, sdt; int tA_size, tB_size, tT_size; void *mem; char *mem_align; int m1, n1, k1; int pack_B; double *pU; int sdu; int pU_size; const int m_kernel = M_KERNEL; const int l1_cache_el = L1_CACHE_EL; const int reals_per_cache_line = CACHE_LINE_EL; const int m_cache = (m+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int n_cache = (n+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; // const int k_cache = (k+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int m_kernel_cache = (m_kernel+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; int m_min = m_cache<m_kernel_cache ? m_cache : m_kernel_cache; // int n_min = n_cache<m_kernel_cache ? n_cache : m_kernel_cache; double d_1 = 1.0; double d_minvalpha = -1.0/alpha; double *C; int ldc; struct blasfeo_dmat *sC; lutn: // goto lutn_m1; // goto llnn_2; #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) if(m<300 & n<300 & k0<=K_MAX_STACK) #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) if(m<64 & n<64 & k0<=K_MAX_STACK) #else if(m<12 & n<12 & k0<=K_MAX_STACK) #endif { goto lutn_n1; } else { goto llnn_2; } // never to get here return; #if 0 lutn_m1: pU = pU_stack; sdu = sdu_stack; dA = pd_stack; nc = 256; // no block over m for now for(ii=0; ii<m; ii++) dA[ii] = 1.0/A[ii+ii*lda]; // block over n for(jj=0; jj<n; jj+=nleft) { nleft = n-jj<nc ? n-jj : nc; blasfeo_hp_dtrsm_lutn_m1(m, nleft, alpha, A, lda, B+jj*ldb, ldb, D+jj*ldd, ldd, pU, sdu, dA); } return; #endif lutn_n1: // XXX limits of ii and jj swapped !!! pU = pU_stack; sdu = sdu_stack; dA = pd_stack; for(ii=0; ii<m; ii++) dA[ii] = 1.0/A[ii+ii*lda]; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(; ii<n-11; ii+=12) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu); for(jj=0; jj<m-3; jj+=4) { kernel_dtrsm_nn_ru_inv_12x4_lib4c44c(jj, pU, sdu, A+jj*lda, lda, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, A+jj+jj*lda, lda, dA+jj); } if(jj<m) { kernel_dtrsm_nn_ru_inv_12x4_vs_lib4c44c(jj, pU, sdu, A+jj*lda, lda, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, A+jj+jj*lda, lda, dA+jj, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto lutn_n1_left_4; } if(n-ii<=8) { goto lutn_n1_left_8; } else { goto lutn_n1_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) for(; ii<n-7; ii+=8) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+ps*sdu); for(jj=0; jj<m-3; jj+=4) { kernel_dtrsm_nn_ru_inv_8x4_lib4c44c(jj, pU, sdu, A+jj*lda, lda, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, A+jj+jj*lda, lda, dA+jj); } if(jj<m) { kernel_dtrsm_nn_ru_inv_8x4_vs_lib4c44c(jj, pU, sdu, A+jj*lda, lda, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, A+jj+jj*lda, lda, dA+jj, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+ps*sdu, D+(ii+4)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto lutn_n1_left_4; } else { goto lutn_n1_left_8; } } #else for(; ii<n-3; ii+=4) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); for(jj=0; jj<m-3; jj+=4) { kernel_dtrsm_nn_ru_inv_4x4_lib4c44c(jj, pU, A+jj*lda, lda, &alpha, pU+jj*ps, pU+jj*ps, A+jj+jj*lda, lda, dA+jj); } if(jj<m) { kernel_dtrsm_nn_ru_inv_4x4_vs_lib4c44c(jj, pU, A+jj*lda, lda, &alpha, pU+jj*ps, pU+jj*ps, A+jj+jj*lda, lda, dA+jj, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); } if(ii<n) { goto lutn_n1_left_4; } #endif goto lutn_n1_return; #if defined(TARGET_X64_INTEL_HASWELL) lutn_n1_left_12: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_vs_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu, n-(ii+8)); for(jj=0; jj<m; jj+=4) { kernel_dtrsm_nn_ru_inv_12x4_vs_lib4c44c(jj, pU, sdu, A+jj*lda, lda, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, A+jj+jj*lda, lda, dA+jj, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd, n-(ii+8)); goto lutn_n1_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) lutn_n1_left_8: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_vs_lib4(m, B+(ii+4)*ldb, ldb, pU+ps*sdu, n-(ii+4)); for(jj=0; jj<m; jj+=4) { kernel_dtrsm_nn_ru_inv_8x4_vs_lib4c44c(jj, pU, sdu, A+jj*lda, lda, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, A+jj+jj*lda, lda, dA+jj, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+ps*sdu, D+(ii+4)*ldd, ldd, n-(ii+4)); goto lutn_n1_return; #endif lutn_n1_left_4: kernel_dpack_tn_4_vs_lib4(m, B+ii*ldb, ldb, pU, n-ii); for(jj=0; jj<m; jj+=4) { kernel_dtrsm_nn_ru_inv_4x4_vs_lib4c44c(jj, pU, A+jj*lda, lda, &alpha, pU+jj*ps, pU+jj*ps, A+jj+jj*lda, lda, dA+jj, n-ii, m-jj); } kernel_dunpack_nt_4_vs_lib4(m, pU, D+ii*ldd, ldd, n-ii); goto lutn_n1_return; lutn_n1_return: return; llnn_2: #if ! defined(TARGET_X64_INTEL_SKYLAKE_X) #if 1 // cache blocking alg mc0 = MC; nc0 = NC; kc0 = KC; // these must all be multiple of ps !!! // mc0 = 12; // nc0 = 4; // kc0 = 8; mc = m<mc0 ? m : mc0; nc = n<nc0 ? n : nc0; // kc = k<kc0 ? k : kc0; kc = m<kc0 ? m : kc0; tA_size = blasfeo_pm_memsize_dmat(ps, mc0, kc0); tB_size = blasfeo_pm_memsize_dmat(ps, nc0, kc0); tT_size = blasfeo_pm_memsize_dmat(ps, kc0, kc0); tA_size = (tA_size + 4096 - 1) / 4096 * 4096; tB_size = (tB_size + 4096 - 1) / 4096 * 4096; tT_size = (tT_size + 4096 - 1) / 4096 * 4096; if(blasfeo_is_init()==0) { blasfeo_malloc(&mem, tA_size+tB_size+tT_size+2*4096); } else { mem = blasfeo_get_buffer(); } blasfeo_align_4096_byte(mem, (void **) &mem_align); blasfeo_pm_create_dmat(ps, mc0, kc0, &tA, (void *) mem_align); mem_align += tA_size; blasfeo_pm_create_dmat(ps, kc0, kc0, &tT, (void *) mem_align); mem_align += tT_size; mem_align += 4096-4*128; blasfeo_pm_create_dmat(ps, nc0, kc0, &tB, (void *) mem_align); mem_align += tB_size; pA = tA.pA; pB = tB.pA; pT = tT.pA; dT = tT.dA; for(ii=0; ii<m; ii+=mleft) { mleft = m-ii<mc ? m-ii : mc; C = B; ldc = ldb; sC = sB; #if 0 if(ii>0) { blasfeo_hp_dgemm_tn(mleft, n, ii, d_minvalpha, sA, 0, ii, sD, 0, 0, d_1, sC, ii, 0, sD, ii, 0); #else for(ll=0; ll<ii; ll+=kleft) { kleft = ii-ll<kc ? ii-ll : kc; sda = (kleft+4-1)/4*4; // XXX sdb = (kleft+4-1)/4*4; // XXX // pack and tran A #if defined(TARGET_X64_INTEL_SKYLAKE_X) #else kernel_dpack_buffer_ft(kleft, mleft, A+ll+ii*lda, lda, pA, sda); #endif for(jj=0; jj<n; jj+=nleft) { nleft = n-jj<nc ? n-jj : nc; // pack and tran B #if defined(TARGET_X64_INTEL_SKYLAKE_X) #else kernel_dpack_buffer_ft(kleft, nleft, D+ll+jj*ldd, ldd, pB, sdb); #endif blasfeo_hp_dgemm_nt_m2(mleft, nleft, kleft, d_minvalpha, pA, sda, pB, sdb, d_1, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd); } #endif C = D; ldc = ldd; sC = sD; } for(ll=0; ll<mleft; ll+=kleft) { kleft = mleft-ll<kc ? mleft-ll : kc; sda = (kleft+4-1)/4*4; // XXX sdb = (kleft+4-1)/4*4; // XXX sdt = (kleft+4-1)/4*4; // XXX // pack and tran A #if defined(TARGET_X64_INTEL_SKYLAKE_X) #else kernel_dpack_buffer_ut(kleft, A+ii+ll+(ii+ll)*lda, lda, pT, sdt); kernel_dpack_buffer_ft(kleft, mleft-ll-kleft, A+ii+ll+(ii+ll+kleft)*lda, lda, pA, sda); #endif // diag A for(iii=0; iii<kleft; iii++) dT[iii] = 1.0/A[ii+ll+iii+(ii+ll+iii)*lda]; for(jj=0; jj<n; jj+=nleft) { nleft = n-jj<nc ? n-jj : nc; blasfeo_hp_dtrsm_llnn_m2(kleft, nleft, alpha, pT, sdt, dT, C+ii+ll+jj*ldc, ldc, D+ii+ll+jj*ldd, ldd, pB, sdb); blasfeo_hp_dgemm_nt_m2(mleft-ll-kleft, nleft, kleft, d_minvalpha, pA, sda, pB, sdb, d_1, C+ii+ll+kleft+jj*ldc, ldc, D+ii+ll+kleft+jj*ldd, ldd); } C = D; ldc = ldd; sC = sD; } } free(mem); return; #else // cache blocking alg mc0 = NC; // XXX nc0 = MC; // XXX kc0 = KC; // these must all be multiple of ps !!! // mc0 = 4; // nc0 = 12; // kc0 = 8; mc = m<mc0 ? m : mc0; nc = n<nc0 ? n : nc0; // kc = k<kc0 ? k : kc0; kc = m<kc0 ? m : kc0; tA_size = blasfeo_pm_memsize_dmat(ps, mc0, kc0); tB_size = blasfeo_pm_memsize_dmat(ps, nc0, kc0); tT_size = blasfeo_pm_memsize_dmat(ps, kc0, kc0); tA_size = (tA_size + 4096 - 1) / 4096 * 4096; tB_size = (tB_size + 4096 - 1) / 4096 * 4096; tT_size = (tT_size + 4096 - 1) / 4096 * 4096; if(blasfeo_is_init()==0) { blasfeo_malloc(&mem, tA_size+tB_size+tT_size+2*4096); } else { mem = blasfeo_get_buffer(); } blasfeo_align_4096_byte(mem, (void **) &mem_align); blasfeo_pm_create_dmat(ps, mc0, kc0, &tA, (void *) mem_align); mem_align += tA_size; blasfeo_pm_create_dmat(ps, kc0, kc0, &tT, (void *) mem_align); mem_align += tT_size; mem_align += 4096-4*128; blasfeo_pm_create_dmat(ps, nc0, kc0, &tB, (void *) mem_align); mem_align += tB_size; pA = tA.pA; pB = tB.pA; pT = tT.pA; dT = tT.dA; for(jj=0; jj<n; jj+=nleft) { nleft = n-jj<nc ? n-jj : nc; C = B; ldc = ldb; for(ll=0; ll<m; ll+=kleft) { kleft = m-ll<kc ? m-ll : kc; sda = (kleft+4-1)/4*4; // XXX sdb = (kleft+4-1)/4*4; // XXX sdt = (kleft+4-1)/4*4; // XXX for(ii=0; ii<kleft; ii+=mleft) { mleft = kleft-ii<mc ? kleft-ii : mc; // pack and tran A #if defined(TARGET_X64_INTEL_SKYLAKE_X) #else kernel_dpack_buffer_ut(mleft, A+ll+ii+(ll+ii)*lda, lda, pT, sdt); kernel_dpack_buffer_ft(ii, mleft, A+ll+(ll+ii)*lda, lda, pA, sda); #endif // diag A for(iii=0; iii<mleft; iii++) dT[iii] = 1.0/A[ll+ii+iii+(ll+ii+iii)*lda]; blasfeo_hp_dgemm_nt_n2(mleft, nleft, ii, d_minvalpha, pA, sda, pB, sdb, d_1, C+ll+ii+jj*ldc, ldc, D+ll+ii+jj*ldd, ldd); blasfeo_hp_dtrsm_llnn_m2(mleft, nleft, alpha, pT, sdt, dT, D+ll+ii+jj*ldd, ldd, D+ll+ii+jj*ldd, ldd, pB+ii*ps, sdb); } for(ii=ll+kleft; ii<m; ii+=mleft) { mleft = m-ii<mc ? m-ii : mc; // pack and tran A #if defined(TARGET_X64_INTEL_SKYLAKE_X) #else kernel_dpack_buffer_ft(kleft, mleft, A+ll+ii*lda, lda, pA, sda); #endif blasfeo_hp_dgemm_nt_n2(mleft, nleft, kleft, d_minvalpha, pA, sda, pB, sdb, d_1, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd); } C = D; ldc = ldd; } } free(mem); return; #endif #else m1 = (m+128-1)/128*128; n1 = (n+128-1)/128*128; tA_size = blasfeo_pm_memsize_dmat(ps, m1, m1); tB_size = blasfeo_pm_memsize_dmat(ps, m1, n1); mem = malloc(tA_size+tB_size+64); blasfeo_align_64_byte(mem, (void **) &mem_align); blasfeo_pm_create_dmat(ps, m, m, &tA, (void *) mem_align); blasfeo_pm_create_dmat(ps, m, n, &tB, (void *) (mem_align+tA_size)); pA = tA.pA; sda = tA.cn; dA = tA.dA; pB = tB.pA; sdb = tB.cn; // pack A // upper to lower kernel_dpack_buffer_ut(m, A, lda, pA, sda); // diag A for(ii=0; ii<m; ii++) dA[ii] = 1.0/A[ii+ii*lda]; blasfeo_hp_dtrsm_llnn_m2(m, n, alpha, pA, sda, dA, B, ldb, D, ldd, pB, sdb); free(mem); return; #endif // never to get here return; } void blasfeo_hp_dtrsm_lutu(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { #if defined(PRINT_NAME) printf("\nblasfeo_hp_dtrsm_lutu (cm) %d %d %f %p %d %d %p %d %d %p %d %d\n", m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); #endif if(m<=0 | n<=0) return; // extract pointer to column-major matrices from structures int lda = sA->m; int ldb = sB->m; int ldd = sD->m; double *A = sA->pA + ai + aj*lda; double *B = sB->pA + bi + bj*ldb; double *D = sD->pA + di + dj*ldd; // printf("\n%p %d %p %d %p %d\n", A, lda, B, ldb); int ii, jj; const int ps = 4; //D_PS; #if defined(TARGET_GENERIC) double pd0[K_MAX_STACK]; #else ALIGNED( double pd0[K_MAX_STACK], 64 ); #endif #if defined(TARGET_GENERIC) double pU0[M_KERNEL*K_MAX_STACK]; #else ALIGNED( double pU0[M_KERNEL*K_MAX_STACK], 64 ); #endif int k0; // TODO update if necessary !!!!! // if(*side=='l' | *side=='L') k0 = m; // else // k0 = n; int sdu0 = (k0+3)/4*4; sdu0 = sdu0<K_MAX_STACK ? sdu0 : K_MAX_STACK; struct blasfeo_pm_dmat tA, tB; int sda, sdb; int tA_size, tB_size; void *mem; char *mem_align; int m1, n1, k1; int pack_B; double *pU, *dA, *pB, *dB; int sdu; const int m_kernel = M_KERNEL; const int l1_cache_el = L1_CACHE_EL; const int reals_per_cache_line = CACHE_LINE_EL; const int m_cache = (m+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int n_cache = (n+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; // const int k_cache = (k+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int m_kernel_cache = (m_kernel+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; int m_min = m_cache<m_kernel_cache ? m_cache : m_kernel_cache; // int n_min = n_cache<m_kernel_cache ? n_cache : m_kernel_cache; lutu: #if defined(TARGET_X64_INTEL_HASWELL) if(m>=300 | n>=300 | m>K_MAX_STACK) #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) if(m>=64 | n>=64 | m>K_MAX_STACK) #else if(m>=12 | n>=12 | m>K_MAX_STACK) #endif { goto llnu_2; } else { goto lutu_1; } // never to get here return; lutu_1: // XXX limits of ii and jj swapped !!! pU = pU0; sdu = sdu0; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(; ii<n-11; ii+=12) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu); for(jj=0; jj<m-3; jj+=4) { kernel_dtrsm_nn_ru_one_12x4_lib4c44c(jj, pU, sdu, A+jj*lda, lda, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, A+jj+jj*lda, lda); } if(jj<m) { kernel_dtrsm_nn_ru_one_12x4_vs_lib4c44c(jj, pU, sdu, A+jj*lda, lda, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, A+jj+jj*lda, lda, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto lutu_1_left_4; } if(n-ii<=8) { goto lutu_1_left_8; } else { goto lutu_1_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) for(; ii<n-7; ii+=8) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+ps*sdu); for(jj=0; jj<m-3; jj+=4) { kernel_dtrsm_nn_ru_one_8x4_lib4c44c(jj, pU, sdu, A+jj*lda, lda, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, A+jj+jj*lda, lda); } if(jj<m) { kernel_dtrsm_nn_ru_one_8x4_vs_lib4c44c(jj, pU, sdu, A+jj*lda, lda, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, A+jj+jj*lda, lda, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+ps*sdu, D+(ii+4)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto lutu_1_left_4; } else { goto lutu_1_left_8; } } #else for(; ii<n-3; ii+=4) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); for(jj=0; jj<m-3; jj+=4) { kernel_dtrsm_nn_ru_one_4x4_lib4c44c(jj, pU, A+jj*lda, lda, &alpha, pU+jj*ps, pU+jj*ps, A+jj+jj*lda, lda); } if(jj<m) { kernel_dtrsm_nn_ru_one_4x4_vs_lib4c44c(jj, pU, A+jj*lda, lda, &alpha, pU+jj*ps, pU+jj*ps, A+jj+jj*lda, lda, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); } if(ii<n) { goto lutu_1_left_4; } #endif goto lutu_1_return; #if defined(TARGET_X64_INTEL_HASWELL) lutu_1_left_12: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_vs_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu, n-(ii+8)); for(jj=0; jj<m; jj+=4) { kernel_dtrsm_nn_ru_one_12x4_vs_lib4c44c(jj, pU, sdu, A+jj*lda, lda, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, A+jj+jj*lda, lda, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd, n-(ii+8)); goto lutu_1_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) lutu_1_left_8: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_vs_lib4(m, B+(ii+4)*ldb, ldb, pU+ps*sdu, n-(ii+4)); for(jj=0; jj<m; jj+=4) { kernel_dtrsm_nn_ru_one_8x4_vs_lib4c44c(jj, pU, sdu, A+jj*lda, lda, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, A+jj+jj*lda, lda, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+ps*sdu, D+(ii+4)*ldd, ldd, n-(ii+4)); goto lutu_1_return; #endif lutu_1_left_4: kernel_dpack_tn_4_vs_lib4(m, B+ii*ldb, ldb, pU, n-ii); for(jj=0; jj<m; jj+=4) { kernel_dtrsm_nn_ru_one_4x4_vs_lib4c44c(jj, pU, A+jj*lda, lda, &alpha, pU+jj*ps, pU+jj*ps, A+jj+jj*lda, lda, n-ii, m-jj); } kernel_dunpack_nt_4_vs_lib4(m, pU, D+ii*ldd, ldd, n-ii); goto lutu_1_return; lutu_1_return: return; llnu_2: m1 = (m+128-1)/128*128; tA_size = blasfeo_pm_memsize_dmat(ps, m_kernel, m1); tB_size = blasfeo_pm_memsize_dmat(ps, m1, m1); mem = malloc(tA_size+tB_size+64); blasfeo_align_64_byte(mem, (void **) &mem_align); blasfeo_pm_create_dmat(ps, m_kernel, m, &tA, (void *) mem_align); blasfeo_pm_create_dmat(ps, m, m, &tB, (void *) (mem_align+tA_size)); pU = tA.pA; sdu = tA.cn; pB = tB.pA; sdb = tB.cn; dB = tB.dA; // upper to lower for(ii=0; ii<m-3; ii+=4) { kernel_dpack_tn_4_lib4(ii+4, A+ii*lda, lda, pB+ii*sdb); } if(ii<m) { kernel_dpack_tn_4_vs_lib4(m, A+ii*lda, lda, pB+ii*sdb, m-ii); } ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) for(; ii<n-11; ii+=12) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu); for(jj=0; jj<m-3; jj+=4) { kernel_dtrsm_nt_rl_one_12x4_lib4(jj, pU, sdu, pB+jj*sdb, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, pB+jj*ps+jj*sdb); } if(jj<m) { kernel_dtrsm_nt_rl_one_12x4_vs_lib4(jj, pU, sdu, pB+jj*sdb, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, pB+jj*ps+jj*sdb, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto llnu_2_left_4; } if(n-ii<=8) { goto llnu_2_left_8; } else { goto llnu_2_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) for(; ii<n-7; ii+=8) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); for(jj=0; jj<m-3; jj+=4) { kernel_dtrsm_nt_rl_one_8x4_lib4(jj, pU, sdu, pB+jj*sdb, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, pB+jj*ps+jj*sdb); } if(jj<m) { kernel_dtrsm_nt_rl_one_8x4_vs_lib4(jj, pU, sdu, pB+jj*sdb, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, pB+jj*ps+jj*sdb, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); } if(ii<n) { if(n-ii<=4) { goto llnu_2_left_4; } else { goto llnu_2_left_8; } } #else for(; ii<n-3; ii+=4) { kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); for(jj=0; jj<m-3; jj+=4) { kernel_dtrsm_nt_rl_one_4x4_lib4(jj, pU, pB+jj*sdb, &alpha, pU+jj*ps, pU+jj*ps, pB+jj*ps+jj*sdb); } if(jj<m) { kernel_dtrsm_nt_rl_one_4x4_vs_lib4(jj, pU, pB+jj*sdb, &alpha, pU+jj*ps, pU+jj*ps, pB+jj*ps+jj*sdb, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); } if(ii<n) { goto llnu_2_left_4; } #endif goto llnu_2_return; #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) llnu_2_left_12: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu); kernel_dpack_tn_4_vs_lib4(m, B+(ii+8)*ldb, ldb, pU+8*sdu, n-ii-8); for(jj=0; jj<m; jj+=4) { kernel_dtrsm_nt_rl_one_12x4_vs_lib4(jj, pU, sdu, pB+jj*sdb, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, pB+jj*ps+jj*sdb, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+8*sdu, D+(ii+8)*ldd, ldd, n-ii-8); goto llnu_2_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) llnu_2_left_8: kernel_dpack_tn_4_lib4(m, B+ii*ldb, ldb, pU); kernel_dpack_tn_4_vs_lib4(m, B+(ii+4)*ldb, ldb, pU+4*sdu, n-ii-4); for(jj=0; jj<m; jj+=4) { kernel_dtrsm_nt_rl_one_8x4_vs_lib4(jj, pU, sdu, pB+jj*sdb, &alpha, pU+jj*ps, sdu, pU+jj*ps, sdu, pB+jj*ps+jj*sdb, n-ii, m-jj); } kernel_dunpack_nt_4_lib4(m, pU, D+ii*ldd, ldd); kernel_dunpack_nt_4_vs_lib4(m, pU+4*sdu, D+(ii+4)*ldd, ldd, n-ii-4); goto llnu_2_return; #endif llnu_2_left_4: kernel_dpack_tn_4_vs_lib4(m, B+ii*ldb, ldb, pU, n-ii); for(jj=0; jj<m; jj+=4) { kernel_dtrsm_nt_rl_one_4x4_vs_lib4(jj, pU, pB+jj*sdb, &alpha, pU+jj*ps, pU+jj*ps, pB+jj*ps+jj*sdb, n-ii, m-jj); } kernel_dunpack_nt_4_vs_lib4(m, pU, D+ii*ldd, ldd, n-ii); goto llnu_2_return; llnu_2_return: free(mem); return; // never to get here return; } // TODO optimize for cortex A57 !!!!! void blasfeo_hp_dtrsm_rlnn(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { #if defined(PRINT_NAME) printf("\nblasfeo_hp_dtrsm_rlnn (cm) %d %d %f %p %d %d %p %d %d %p %d %d\n", m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); #endif if(m<=0 | n<=0) return; // extract pointer to column-major matrices from structures int lda = sA->m; int ldb = sB->m; int ldd = sD->m; double *A = sA->pA + ai + aj*lda; double *B = sB->pA + bi + bj*ldb; double *D = sD->pA + di + dj*ldd; // printf("\n%p %d %p %d %p %d\n", A, lda, B, ldb); int ii, jj, ll; int ii0, ll0, jj0, iii; int mc, nc, kc; int mleft, nleft, kleft; int mc0, nc0, kc0; int ldc1; double beta1; double *pA, *pB, *pT, *C1, *dA, *dB, *dT; #if defined(TARGET_X64_INTEL_SKYLAKE_X) const int ps = 4; // XXX TODO fix once implemented missing kernels !!! #else const int ps = PS; #endif int k0; // TODO update if necessary !!!!! // if(*side=='l' | *side=='L') // k0 = m; // else k0 = n; #if defined(TARGET_GENERIC) double pU_stack[M_KERNEL*K_MAX_STACK]; double pd_stack[K_MAX_STACK]; #else ALIGNED( double pU_stack[M_KERNEL*K_MAX_STACK], 64 ); ALIGNED( double pd_stack[K_MAX_STACK], 64 ); #endif int sdu_stack = K_MAX_STACK; int k4 = (k0+3)/4*4; struct blasfeo_pm_dmat tA, tB, tT; int sda, sdb, sdt; int tA_size, tB_size, tT_size; void *mem; char *mem_align; int m1, n1, k1; int pack_B; double *pU; int sdu; int pU_size; int idx, nn4, n4; const int m_kernel = M_KERNEL; const int l1_cache_el = L1_CACHE_EL; const int reals_per_cache_line = CACHE_LINE_EL; const int m_cache = (m+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int n_cache = (n+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; // const int k_cache = (k+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int m_kernel_cache = (m_kernel+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; int m_min = m_cache<m_kernel_cache ? m_cache : m_kernel_cache; // int n_min = n_cache<m_kernel_cache ? n_cache : m_kernel_cache; double d_1 = 1.0; double d_minvalpha = -1.0/alpha; double *C; int ldc; // goto rlnn_1; // goto rutn_2; #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) if(m<=300 & n<=300 & k0<=K_MAX_STACK) #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) if(m<64 & n<64 & k0<=K_MAX_STACK) #else if(m<12 & n<12 & k0<=K_MAX_STACK) #endif { goto rlnn_1; } else { goto rutn_2; } // never to get here return; rlnn_1: pU = pU_stack; sdu = sdu_stack; dA = pd_stack; for(ii=0; ii<n; ii++) dA[ii] = 1.0/A[ii+ii*lda]; nn4 = n%4; n4 = n - nn4; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(; ii<m-11; ii+=12) { if(nn4!=0) { idx = n4; kernel_dtrsm_nn_rl_inv_12x4_vs_lib4cccc(0, pU+(idx+4)*ps, sdu, A+(idx+4)+idx*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, dA+idx, m-ii, nn4); kernel_dpack_nn_12_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nn_rl_inv_12x4_lib4cccc(jj+nn4, pU+(idx+4)*ps, sdu, A+(idx+4)+idx*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, dA+idx); kernel_dpack_nn_12_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu); } } if(ii<m) { if(m-ii<=4) { goto rlnn_1_left_4; } else if(m-ii<=8) { goto rlnn_1_left_8; } else { goto rlnn_1_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) for(; ii<m-7; ii+=8) { if(nn4!=0) { idx = n4; kernel_dtrsm_nn_rl_inv_8x4_vs_lib4cccc(0, pU+(idx+4)*ps, sdu, A+(idx+4)+idx*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, dA+idx, m-ii, nn4); kernel_dpack_nn_8_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nn_rl_inv_8x4_lib4cccc(jj+nn4, pU+(idx+4)*ps, sdu, A+(idx+4)+idx*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, dA+idx); kernel_dpack_nn_8_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu); } } if(ii<m) { if(m-ii<=4) { goto rlnn_1_left_4; } else { goto rlnn_1_left_8; } } #else for(; ii<m-3; ii+=4) { if(nn4!=0) { idx = n4; kernel_dtrsm_nn_rl_inv_4x4_vs_lib4cccc(0, pU+(idx+4)*ps, A+(idx+4)+idx*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, dA+idx, m-ii, nn4); kernel_dpack_nn_4_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nn_rl_inv_4x4_lib4cccc(jj+nn4, pU+(idx+4)*ps, A+(idx+4)+idx*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, dA+idx); kernel_dpack_nn_4_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps); } } if(ii<m) { goto rlnn_1_left_4; } #endif goto rlnn_1_return; #if defined(TARGET_X64_INTEL_HASWELL) rlnn_1_left_12: if(nn4!=0) { idx = n4; kernel_dtrsm_nn_rl_inv_12x4_vs_lib4cccc(0, pU+(idx+4)*ps, sdu, A+(idx+4)+idx*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, dA+idx, m-ii, nn4); kernel_dpack_nn_12_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nn_rl_inv_12x4_vs_lib4cccc(jj+nn4, pU+(idx+4)*ps, sdu, A+(idx+4)+idx*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, dA+idx, m-ii, 4); kernel_dpack_nn_12_vs_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } goto rlnn_1_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) rlnn_1_left_8: if(nn4!=0) { idx = n4; kernel_dtrsm_nn_rl_inv_8x4_vs_lib4cccc(0, pU+(idx+4)*ps, sdu, A+(idx+4)+idx*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, dA+idx, m-ii, nn4); kernel_dpack_nn_8_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nn_rl_inv_8x4_vs_lib4cccc(jj+nn4, pU+(idx+4)*ps, sdu, A+(idx+4)+idx*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, dA+idx, m-ii, 4); kernel_dpack_nn_8_vs_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } goto rlnn_1_return; #endif rlnn_1_left_4: if(nn4!=0) { idx = n4; kernel_dtrsm_nn_rl_inv_4x4_vs_lib4cccc(0, pU+(idx+4)*ps, A+(idx+4)+idx*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, dA+idx, m-ii, nn4); kernel_dpack_nn_4_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nn_rl_inv_4x4_vs_lib4cccc(jj+nn4, pU+(idx+4)*ps, A+(idx+4)+idx*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, dA+idx, m-ii, 4); kernel_dpack_nn_4_vs_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, m-ii); } goto rlnn_1_return; rlnn_1_return: return; rutn_2: #if ! defined(TARGET_X64_INTEL_SKYLAKE_X) // cache blocking alg mc0 = MC; nc0 = NC; kc0 = KC; // these must all be multiple of ps !!! // mc0 = 20; // nc0 = 4; // kc0 = 8; mc = m<mc0 ? m : mc0; nc = n<nc0 ? n : nc0; // kc = k<kc0 ? k : kc0; kc = n<kc0 ? n : kc0; tA_size = blasfeo_pm_memsize_dmat(ps, mc0, kc0); tB_size = blasfeo_pm_memsize_dmat(ps, nc0, kc0); tT_size = blasfeo_pm_memsize_dmat(ps, nc0, nc0); tA_size = (tA_size + 4096 - 1) / 4096 * 4096; tB_size = (tB_size + 4096 - 1) / 4096 * 4096; tT_size = (tT_size + 4096 - 1) / 4096 * 4096; if(blasfeo_is_init()==0) { blasfeo_malloc(&mem, tA_size+tB_size+tT_size+2*4096); } else { mem = blasfeo_get_buffer(); } blasfeo_align_4096_byte(mem, (void **) &mem_align); blasfeo_pm_create_dmat(ps, mc0, kc0, &tA, (void *) mem_align); mem_align += tA_size; mem_align += 4096-4*128; blasfeo_pm_create_dmat(ps, nc0, kc0, &tB, (void *) mem_align); mem_align += tB_size; blasfeo_pm_create_dmat(ps, nc0, nc0, &tT, (void *) mem_align); mem_align += tT_size; pA = tA.pA; pB = tB.pA; pT = tT.pA; dT = tT.dA; for(ii=0; ii<m; ii+=mleft) { mleft = m-ii<mc ? m-ii : mc; C = B; ldc = ldb; for(ll=0; ll<n; ll+=kleft) { kleft = n-ll<kc ? n-ll : kc; ll0 = n-ll-kleft; sda = (kleft+4-1)/4*4; // XXX sdb = (kleft+4-1)/4*4; // XXX for(jj=0; jj<kleft; jj+=nleft) { nleft = kleft-jj<nc ? kleft-jj : nc; jj0 = kleft-jj-nleft; sdt = (nleft+4-1)/4*4; // XXX // pack and tran B #if defined(TARGET_X64_INTEL_SKYLAKE_X) #else kernel_dpack_buffer_lt(nleft, A+ll0+jj0+(ll0+jj0)*lda, lda, pT, sdt); kernel_dpack_buffer_ft(jj, nleft, A+ll0+jj0+nleft+(ll0+jj0)*lda, lda, pB, sdb); #endif // diag B for(iii=0; iii<nleft; iii++) dT[iii] = 1.0/A[ll0+jj0+iii+(ll0+jj0+iii)*lda]; blasfeo_hp_dgemm_nt_m2(mleft, nleft, jj, d_minvalpha, pA+(jj0+nleft)*ps, sda, pB, sdb, d_1, C+ii+(ll0+jj0)*ldc, ldc, D+ii+(ll0+jj0)*ldd, ldd); blasfeo_hp_dtrsm_rutn_m2(mleft, nleft, alpha, pT, sdt, dT, D+ii+(ll0+jj0)*ldd, ldd, D+ii+(ll0+jj0)*ldd, ldd, pA+jj0*ps, sda); } for(jj=0; jj<ll0; jj+=nleft) { nleft = ll0-jj<nc ? ll0-jj : nc; jj0 = ll0-jj-nleft; // pack and tran B #if defined(TARGET_X64_INTEL_SKYLAKE_X) #else kernel_dpack_buffer_ft(kleft, nleft, A+ll0+jj0*lda, lda, pB, sdb); #endif blasfeo_hp_dgemm_nt_m2(mleft, nleft, kleft, d_minvalpha, pA, sda, pB, sdb, d_1, C+ii+jj0*ldc, ldc, D+ii+jj0*ldd, ldd); } C = D; ldc = ldd; } } free(mem); return; #else m1 = (m+128-1)/128*128; n1 = (n+128-1)/128*128; tA_size = blasfeo_pm_memsize_dmat(ps, n1, n1); tB_size = blasfeo_pm_memsize_dmat(ps, m1, n1); mem = malloc(tA_size+tB_size+64); blasfeo_align_64_byte(mem, (void **) &mem_align); blasfeo_pm_create_dmat(ps, n, n, &tA, (void *) mem_align); blasfeo_pm_create_dmat(ps, m, n, &tB, (void *) (mem_align+tA_size)); pA = tA.pA; sda = tA.cn; dA = tA.dA; pB = tB.pA; sdb = tB.cn; // pack A // lower to upper kernel_dpack_buffer_lt(n, A, lda, pA, sda); // diag A for(ii=0; ii<n; ii++) dA[ii] = 1.0/A[ii+ii*lda]; blasfeo_hp_dtrsm_rutn_m2(m, n, alpha, pA, sda, dA, B, ldb, D, ldd, pB, sdb); free(mem); return; #endif // never to get here return; } void blasfeo_hp_dtrsm_rlnu(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { #if defined(PRINT_NAME) printf("\nblasfeo_hp_dtrsm_rlnu (cm) %d %d %f %p %d %d %p %d %d %p %d %d\n", m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); #endif if(m<=0 | n<=0) return; // extract pointer to column-major matrices from structures int lda = sA->m; int ldb = sB->m; int ldd = sD->m; double *A = sA->pA + ai + aj*lda; double *B = sB->pA + bi + bj*ldb; double *D = sD->pA + di + dj*ldd; // printf("\n%p %d %p %d %p %d\n", A, lda, B, ldb); int ii, jj; const int ps = 4; //D_PS; #if defined(TARGET_GENERIC) double pd0[K_MAX_STACK]; #else ALIGNED( double pd0[K_MAX_STACK], 64 ); #endif #if defined(TARGET_GENERIC) double pU0[M_KERNEL*K_MAX_STACK]; #else ALIGNED( double pU0[M_KERNEL*K_MAX_STACK], 64 ); #endif int k0; // TODO update if necessary !!!!! // if(*side=='l' | *side=='L') // k0 = m; // else k0 = n; int sdu0 = (k0+3)/4*4; sdu0 = sdu0<K_MAX_STACK ? sdu0 : K_MAX_STACK; struct blasfeo_pm_dmat tA, tB; int sda, sdb; int tA_size, tB_size; void *mem; char *mem_align; int m1, n1, k1; int pack_B; double *pU, *dA, *pB, *dB; int sdu; int idx, nn4, n4; const int m_kernel = M_KERNEL; const int l1_cache_el = L1_CACHE_EL; const int reals_per_cache_line = CACHE_LINE_EL; const int m_cache = (m+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int n_cache = (n+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; // const int k_cache = (k+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int m_kernel_cache = (m_kernel+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; int m_min = m_cache<m_kernel_cache ? m_cache : m_kernel_cache; // int n_min = n_cache<m_kernel_cache ? n_cache : m_kernel_cache; rlnu: #if defined(TARGET_X64_INTEL_HASWELL) if(m>300 | n>300 | n>K_MAX_STACK) #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) if(m>=64 | n>=64 | n>K_MAX_STACK) #else if(m>=12 | n>=12 | n>K_MAX_STACK) #endif { // pack_tran = 1; goto rutu_2; } else { goto rlnu_1; } // never to get here return; rlnu_1: pU = pU0; sdu = sdu0; nn4 = n%4; n4 = n - nn4; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(; ii<m-11; ii+=12) { if(nn4!=0) { idx = n4; kernel_dtrsm_nn_rl_one_12x4_vs_lib4cccc(0, pU+(idx+4)*ps, sdu, A+(idx+4)+idx*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, m-ii, nn4); kernel_dpack_nn_12_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nn_rl_one_12x4_lib4cccc(jj+nn4, pU+(idx+4)*ps, sdu, A+(idx+4)+idx*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda); kernel_dpack_nn_12_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu); } } if(ii<m) { if(m-ii<=4) { goto rlnu_1_left_4; } else if(m-ii<=8) { goto rlnu_1_left_8; } else { goto rlnu_1_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) for(; ii<m-7; ii+=8) { if(nn4!=0) { idx = n4; kernel_dtrsm_nn_rl_one_8x4_vs_lib4cccc(0, pU+(idx+4)*ps, sdu, A+(idx+4)+idx*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, m-ii, nn4); kernel_dpack_nn_8_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nn_rl_one_8x4_lib4cccc(jj+nn4, pU+(idx+4)*ps, sdu, A+(idx+4)+idx*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda); kernel_dpack_nn_8_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu); } } if(ii<m) { if(m-ii<=4) { goto rlnu_1_left_4; } else { goto rlnu_1_left_8; } } #else for(; ii<m-3; ii+=4) { if(nn4!=0) { idx = n4; kernel_dtrsm_nn_rl_one_4x4_vs_lib4cccc(0, pU+(idx+4)*ps, A+(idx+4)+idx*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, m-ii, nn4); kernel_dpack_nn_4_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nn_rl_one_4x4_lib4cccc(jj+nn4, pU+(idx+4)*ps, A+(idx+4)+idx*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda); kernel_dpack_nn_4_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps); } } if(ii<m) { goto rlnu_1_left_4; } #endif goto rlnu_1_return; #if defined(TARGET_X64_INTEL_HASWELL) rlnu_1_left_12: if(nn4!=0) { idx = n4; kernel_dtrsm_nn_rl_one_12x4_vs_lib4cccc(0, pU+(idx+4)*ps, sdu, A+(idx+4)+idx*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, m-ii, nn4); kernel_dpack_nn_12_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nn_rl_one_12x4_vs_lib4cccc(jj+nn4, pU+(idx+4)*ps, sdu, A+(idx+4)+idx*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, m-ii, 4); kernel_dpack_nn_12_vs_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } goto rlnu_1_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) rlnu_1_left_8: if(nn4!=0) { idx = n4; kernel_dtrsm_nn_rl_one_8x4_vs_lib4cccc(0, pU+(idx+4)*ps, sdu, A+(idx+4)+idx*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, m-ii, nn4); kernel_dpack_nn_8_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nn_rl_one_8x4_vs_lib4cccc(jj+nn4, pU+(idx+4)*ps, sdu, A+(idx+4)+idx*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, m-ii, 4); kernel_dpack_nn_8_vs_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } goto rlnu_1_return; #endif rlnu_1_left_4: if(nn4!=0) { idx = n4; kernel_dtrsm_nn_rl_one_4x4_vs_lib4cccc(0, pU+(idx+4)*ps, A+(idx+4)+idx*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, m-ii, nn4); kernel_dpack_nn_4_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nn_rl_one_4x4_vs_lib4cccc(jj+nn4, pU+(idx+4)*ps, A+(idx+4)+idx*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, m-ii, 4); kernel_dpack_nn_4_vs_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, m-ii); } goto rlnu_1_return; rlnu_1_return: return; rutu_2: n1 = (n+128-1)/128*128; tA_size = blasfeo_pm_memsize_dmat(ps, m_kernel, n1); tB_size = blasfeo_pm_memsize_dmat(ps, n1, n1); mem = malloc(tA_size+tB_size+64); blasfeo_align_64_byte(mem, (void **) &mem_align); blasfeo_pm_create_dmat(ps, m_kernel, n, &tA, (void *) mem_align); blasfeo_pm_create_dmat(ps, n, n, &tB, (void *) (mem_align+tA_size)); pU = tA.pA; sdu = tA.cn; pB = tB.pA; sdb = tB.cn; dB = tB.dA; // lower to upper for(ii=0; ii<n-3; ii+=4) { kernel_dpack_tn_4_lib4(n-ii, A+ii+ii*lda, lda, pB+ii*ps+ii*sdb); } if(ii<n) { kernel_dpack_tn_4_vs_lib4(n-ii, A+ii+ii*lda, lda, pB+ii*ps+ii*sdb, n-ii); } nn4 = n%4; n4 = n - nn4; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(; ii<m-11; ii+=12) { if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_one_12x4_vs_lib44cc4(0, pU+(idx+4)*ps, sdu, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, m-ii, nn4); kernel_dpack_nn_12_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_one_12x4_lib44cc4(jj+nn4, pU+(idx+4)*ps, sdu, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps); kernel_dpack_nn_12_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu); } } if(ii<m) { if(m-ii<=4) { goto rutu_2_left_4; } else if(m-ii<=8) { goto rutu_2_left_8; } else { goto rutu_2_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) for(; ii<m-7; ii+=8) { if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_one_8x4_vs_lib44cc4(0, pU+(idx+4)*ps, sdu, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, m-ii, nn4); kernel_dpack_nn_8_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_one_8x4_lib44cc4(jj+nn4, pU+(idx+4)*ps, sdu, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps); kernel_dpack_nn_8_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu); } } if(ii<m) { if(m-ii<=4) { goto rutu_2_left_4; } else { goto rutu_2_left_8; } } #else for(; ii<m-3; ii+=4) { if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_one_4x4_vs_lib44cc4(0, pU+(idx+4)*ps, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, m-ii, nn4); kernel_dpack_nn_4_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_one_4x4_lib44cc4(jj+nn4, pU+(idx+4)*ps, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps); kernel_dpack_nn_4_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps); } } if(ii<m) { goto rutu_2_left_4; } #endif goto rutu_2_return; #if defined(TARGET_X64_INTEL_HASWELL) rutu_2_left_12: if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_one_12x4_vs_lib44cc4(0, pU+(idx+4)*ps, sdu, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, m-ii, nn4); kernel_dpack_nn_12_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_one_12x4_vs_lib44cc4(jj+nn4, pU+(idx+4)*ps, sdu, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, m-ii, 4); kernel_dpack_nn_12_vs_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } goto rutu_2_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) rutu_2_left_8: if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_one_8x4_vs_lib44cc4(0, pU+(idx+4)*ps, sdu, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, m-ii, nn4); kernel_dpack_nn_8_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_one_8x4_vs_lib44cc4(jj+nn4, pU+(idx+4)*ps, sdu, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, m-ii, 4); kernel_dpack_nn_8_vs_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } goto rutu_2_return; #endif rutu_2_left_4: if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_one_4x4_vs_lib44cc4(0, pU+(idx+4)*ps, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, m-ii, nn4); kernel_dpack_nn_4_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_one_4x4_vs_lib44cc4(jj+nn4, pU+(idx+4)*ps, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, m-ii, 4); kernel_dpack_nn_4_vs_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, m-ii); } goto rutu_2_return; rutu_2_return: free(mem); return; // never to get here return; } void blasfeo_hp_dtrsm_rltn(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { #if defined(PRINT_NAME) printf("\nblasfeo_hp_dtrsm_rltn (cm) %d %d %f %p %d %d %p %d %d %p %d %d\n", m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); #endif if(m<=0 | n<=0) return; // extract pointer to column-major matrices from structures int lda = sA->m; int ldb = sB->m; int ldd = sD->m; double *A = sA->pA + ai + aj*lda; double *B = sB->pA + bi + bj*ldb; double *D = sD->pA + di + dj*ldd; // printf("\n%p %d %p %d %p %d\n", A, lda, B, ldb); int ii, jj, ll; int ii0, ll0, jj0, iii; int mc, nc, kc; int mleft, nleft, kleft; int mc0, nc0, kc0; int ldc1; double beta1; double *pA, *pB, *pT, *C1, *dA, *dB, *dT; #if defined(TARGET_X64_INTEL_SKYLAKE_X) const int ps = 4; // XXX TODO fix once implemented missing kernels !!! #else const int ps = PS; #endif int k0; // TODO update if necessary !!!!! // if(*side=='l' | *side=='L') // k0 = m; // else k0 = n; #if defined(TARGET_GENERIC) double pU_stack[M_KERNEL*K_MAX_STACK]; double pd_stack[K_MAX_STACK]; #else ALIGNED( double pU_stack[M_KERNEL*K_MAX_STACK], 64 ); ALIGNED( double pd_stack[K_MAX_STACK], 64 ); #endif int sdu_stack = K_MAX_STACK; int k4 = (k0+3)/4*4; struct blasfeo_pm_dmat tA, tB, tT; int sda, sdb, sdt; int tA_size, tB_size, tT_size; void *mem; char *mem_align; int m1, n1, k1; int pack_B; double *pU; int sdu; int pU_size; int idx, nn4, n4; const int m_kernel = M_KERNEL; const int l1_cache_el = L1_CACHE_EL; const int reals_per_cache_line = CACHE_LINE_EL; const int m_cache = (m+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int n_cache = (n+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; // const int k_cache = (k+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int m_kernel_cache = (m_kernel+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; int m_min = m_cache<m_kernel_cache ? m_cache : m_kernel_cache; // int n_min = n_cache<m_kernel_cache ? n_cache : m_kernel_cache; double d_1 = 1.0; double d_minvalpha = -1.0/alpha; double *C; int ldc; // goto rltn_1; // goto rltn_2; #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) if(m<200 & n<200 & k0<=K_MAX_STACK) // if(m<256 & n<256 & k0<=K_MAX_STACK) #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) if(m<64 & n<64 & k0<=K_MAX_STACK) #else if(m<12 & n<12 & k0<=K_MAX_STACK) #endif { goto rltn_1; } else { goto rltn_2; } // never to get here return; rltn_1: pU = pU_stack; sdu = sdu_stack; dA = pd_stack; for(ii=0; ii<n; ii++) dA[ii] = 1.0/A[ii+ii*lda]; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(ii=0; ii<m-11; ii+=12) { for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nt_rl_inv_12x4_lib4cccc(jj, pU, sdu, A+jj, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, dA+jj); kernel_dpack_nn_12_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps, sdu); } if(jj<n) { kernel_dtrsm_nt_rl_inv_12x4_vs_lib4cccc(jj, pU, sdu, A+jj, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, dA+jj, m-ii, n-jj); // kernel_dpack_nn_4_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps); } } if(ii<m) { if(m-ii<=4) { goto rltn_1_left_4; } if(m-ii<=8) { goto rltn_1_left_8; } else { goto rltn_1_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) for(ii=0; ii<m-7; ii+=8) { for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nt_rl_inv_8x4_lib4cccc(jj, pU, sdu, A+jj, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, dA+jj); kernel_dpack_nn_8_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps, sdu); } if(jj<n) { kernel_dtrsm_nt_rl_inv_8x4_vs_lib4cccc(jj, pU, sdu, A+jj, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, dA+jj, m-ii, n-jj); // kernel_dpack_nn_4_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps); } } if(ii<m) { if(m-ii<=4) { goto rltn_1_left_4; } else { goto rltn_1_left_8; } } #else for(ii=0; ii<m-3; ii+=4) { for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nt_rl_inv_4x4_lib4cccc(jj, pU, A+jj, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, dA+jj); kernel_dpack_nn_4_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps); } if(jj<n) { kernel_dtrsm_nt_rl_inv_4x4_vs_lib4cccc(jj, pU, A+jj, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, dA+jj, m-ii, n-jj); // kernel_dpack_nn_4_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps); } } if(ii<m) { goto rltn_1_left_4; } #endif goto rltn_1_return; #if defined(TARGET_X64_INTEL_HASWELL) rltn_1_left_12: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nt_rl_inv_12x4_vs_lib4cccc(jj, pU, sdu, A+jj, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, dA+jj, m-ii, n-jj); kernel_dpack_nn_12_vs_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, sdu, m-ii); } goto rltn_1_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) rltn_1_left_8: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nt_rl_inv_8x4_vs_lib4cccc(jj, pU, sdu, A+jj, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, dA+jj, m-ii, n-jj); kernel_dpack_nn_8_vs_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, sdu, m-ii); } goto rltn_1_return; #endif rltn_1_left_4: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nt_rl_inv_4x4_vs_lib4cccc(jj, pU, A+jj, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, dA+jj, m-ii, n-jj); kernel_dpack_nn_4_vs_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, m-ii); } goto rltn_1_return; rltn_1_return: return; rltn_2: #if ! defined(TARGET_X64_INTEL_SKYLAKE_X) // cache blocking alg mc0 = MC; nc0 = NC; kc0 = KC; // these must all be multiple of ps !!! // mc0 = 12; // nc0 = 4; // kc0 = 8; mc = m<mc0 ? m : mc0; nc = n<nc0 ? n : nc0; // kc = k<kc0 ? k : kc0; kc = n<kc0 ? n : kc0; tA_size = blasfeo_pm_memsize_dmat(ps, mc0, kc0); tB_size = blasfeo_pm_memsize_dmat(ps, nc0, kc0); tT_size = blasfeo_pm_memsize_dmat(ps, nc0, nc0); tA_size = (tA_size + 4096 - 1) / 4096 * 4096; tB_size = (tB_size + 4096 - 1) / 4096 * 4096; tT_size = (tT_size + 4096 - 1) / 4096 * 4096; if(blasfeo_is_init()==0) { blasfeo_malloc(&mem, tA_size+tB_size+tT_size+2*4096); } else { mem = blasfeo_get_buffer(); } blasfeo_align_4096_byte(mem, (void **) &mem_align); blasfeo_pm_create_dmat(ps, mc0, kc0, &tA, (void *) mem_align); mem_align += tA_size; mem_align += 4096-4*128; blasfeo_pm_create_dmat(ps, nc0, kc0, &tB, (void *) mem_align); mem_align += tB_size; blasfeo_pm_create_dmat(ps, nc0, nc0, &tT, (void *) mem_align); mem_align += tT_size; pA = tA.pA; pB = tB.pA; pT = tT.pA; dT = tT.dA; for(ii=0; ii<m; ii+=mleft) { mleft = m-ii<mc ? m-ii : mc; C = B; ldc = ldb; for(ll=0; ll<n; ll+=kleft) { kleft = n-ll<kc ? n-ll : kc; sda = (kleft+4-1)/4*4; // XXX sdb = (kleft+4-1)/4*4; // XXX for(jj=0; jj<kleft; jj+=nleft) { nleft = kleft-jj<nc ? kleft-jj : nc; sdt = (nleft+4-1)/4*4; // XXX // pack and tran B #if defined(TARGET_X64_INTEL_SKYLAKE_X) #else kernel_dpack_buffer_fn(nleft, jj, A+ll+jj+ll*lda, lda, pB, sdb); kernel_dpack_buffer_ln(nleft, A+ll+jj+(ll+jj)*lda, lda, pT, sdt); #endif // diag B for(iii=0; iii<nleft; iii++) dT[iii] = 1.0/A[ll+jj+iii+(ll+jj+iii)*lda]; blasfeo_hp_dgemm_nt_m2(mleft, nleft, jj, d_minvalpha, pA, sda, pB, sdb, d_1, C+ii+(ll+jj)*ldc, ldc, D+ii+(ll+jj)*ldd, ldd); blasfeo_hp_dtrsm_rltn_m2(mleft, nleft, alpha, pT, sdt, dT, D+ii+(ll+jj)*ldd, ldd, D+ii+(ll+jj)*ldd, ldd, pA+jj*ps, sda); } for(jj=ll+kleft; jj<n; jj+=nleft) { nleft = n-jj<nc ? n-jj : nc; // pack and tran B #if defined(TARGET_X64_INTEL_SKYLAKE_X) #else kernel_dpack_buffer_fn(nleft, kleft, A+jj+ll*lda, lda, pB, sdb); #endif blasfeo_hp_dgemm_nt_m2(mleft, nleft, kleft, d_minvalpha, pA, sda, pB, sdb, d_1, C+ii+jj*ldc, ldc, D+ii+jj*ldd, ldd); } C = D; ldc = ldd; } } free(mem); return; #else m1 = (m+128-1)/128*128; n1 = (n+128-1)/128*128; tA_size = blasfeo_pm_memsize_dmat(ps, n1, n1); tB_size = blasfeo_pm_memsize_dmat(ps, m1, n1); mem = malloc(tA_size+tB_size+64); blasfeo_align_64_byte(mem, (void **) &mem_align); blasfeo_pm_create_dmat(ps, n, n, &tA, (void *) mem_align); blasfeo_pm_create_dmat(ps, m, n, &tB, (void *) (mem_align+tA_size)); pA = tA.pA; sda = tA.cn; dA = tA.dA; pB = tB.pA; sdb = tB.cn; // pack A // lower to lower kernel_dpack_buffer_ln(n, A, lda, pA, sda); // diag A for(ii=0; ii<n; ii++) dA[ii] = 1.0/A[ii+ii*lda]; blasfeo_hp_dtrsm_rltn_m2(m, n, alpha, pA, sda, dA, B, ldb, D, ldd, pB, sdb); free(mem); return; #endif // never to get here return; } void blasfeo_hp_dtrsm_rltu(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { #if defined(PRINT_NAME) printf("\nblasfeo_hp_dtrsm_rltu (cm) %d %d %f %p %d %d %p %d %d %p %d %d\n", m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); #endif if(m<=0 | n<=0) return; // extract pointer to column-major matrices from structures int lda = sA->m; int ldb = sB->m; int ldd = sD->m; double *A = sA->pA + ai + aj*lda; double *B = sB->pA + bi + bj*ldb; double *D = sD->pA + di + dj*ldd; // printf("\n%p %d %p %d %p %d\n", A, lda, B, ldb); int ii, jj; const int ps = 4; //D_PS; #if defined(TARGET_GENERIC) double pd0[K_MAX_STACK]; #else ALIGNED( double pd0[K_MAX_STACK], 64 ); #endif #if defined(TARGET_GENERIC) double pU0[M_KERNEL*K_MAX_STACK]; #else ALIGNED( double pU0[M_KERNEL*K_MAX_STACK], 64 ); #endif int k0; // TODO update if necessary !!!!! // if(*side=='l' | *side=='L') // k0 = m; // else k0 = n; int sdu0 = (k0+3)/4*4; sdu0 = sdu0<K_MAX_STACK ? sdu0 : K_MAX_STACK; struct blasfeo_pm_dmat tA, tB; int sda, sdb; int tA_size, tB_size; void *mem; char *mem_align; int m1, n1, k1; int pack_B; double *pU, *dA, *pB, *dB; int sdu; int idx, nn4, n4; const int m_kernel = M_KERNEL; const int l1_cache_el = L1_CACHE_EL; const int reals_per_cache_line = CACHE_LINE_EL; const int m_cache = (m+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int n_cache = (n+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; // const int k_cache = (k+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int m_kernel_cache = (m_kernel+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; int m_min = m_cache<m_kernel_cache ? m_cache : m_kernel_cache; // int n_min = n_cache<m_kernel_cache ? n_cache : m_kernel_cache; rltu: #if defined(TARGET_X64_INTEL_HASWELL) if(m>=200 | n>=200 | n>K_MAX_STACK) #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) if(m>=64 | n>=64 | n>K_MAX_STACK) #else if(m>=12 | n>=12 | n>K_MAX_STACK) #endif { // pack_tran = 0; goto rltu_2; } else { goto rltu_1; } // never to get here return; rltu_1: pU = pU0; sdu = sdu0; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(ii=0; ii<m-11; ii+=12) { for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nt_rl_one_12x4_lib4cccc(jj, pU, sdu, A+jj, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda); kernel_dpack_nn_12_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps, sdu); } if(jj<n) { kernel_dtrsm_nt_rl_one_12x4_vs_lib4cccc(jj, pU, sdu, A+jj, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, m-ii, n-jj); // kernel_dpack_nn_4_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps); } } if(ii<m) { if(m-ii<=4) { goto rltu_1_left_4; } if(m-ii<=8) { goto rltu_1_left_8; } else { goto rltu_1_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) for(ii=0; ii<m-7; ii+=8) { for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nt_rl_one_8x4_lib4cccc(jj, pU, sdu, A+jj, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda); kernel_dpack_nn_8_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps, sdu); } if(jj<n) { kernel_dtrsm_nt_rl_one_8x4_vs_lib4cccc(jj, pU, sdu, A+jj, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, m-ii, n-jj); // kernel_dpack_nn_4_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps); } } if(ii<m) { if(m-ii<=4) { goto rltu_1_left_4; } else { goto rltu_1_left_8; } } #else for(ii=0; ii<m-3; ii+=4) { for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nt_rl_one_4x4_lib4cccc(jj, pU, A+jj, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda); kernel_dpack_nn_4_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps); } if(jj<n) { kernel_dtrsm_nt_rl_one_4x4_vs_lib4cccc(jj, pU, A+jj, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, m-ii, n-jj); // kernel_dpack_nn_4_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps); } } if(ii<m) { goto rltu_1_left_4; } #endif goto rltu_1_return; #if defined(TARGET_X64_INTEL_HASWELL) rltu_1_left_12: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nt_rl_one_12x4_vs_lib4cccc(jj, pU, sdu, A+jj, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, m-ii, n-jj); kernel_dpack_nn_12_vs_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, sdu, m-ii); } goto rltu_1_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) rltu_1_left_8: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nt_rl_one_8x4_vs_lib4cccc(jj, pU, sdu, A+jj, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, m-ii, n-jj); kernel_dpack_nn_8_vs_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, sdu, m-ii); } goto rltu_1_return; #endif rltu_1_left_4: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nt_rl_one_4x4_vs_lib4cccc(jj, pU, A+jj, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, m-ii, n-jj); kernel_dpack_nn_4_vs_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, m-ii); } goto rltu_1_return; rltu_1_return: return; rltu_2: n1 = (n+128-1)/128*128; tA_size = blasfeo_pm_memsize_dmat(ps, m_kernel, n1); tB_size = blasfeo_pm_memsize_dmat(ps, n1, n1); mem = malloc(tA_size+tB_size+64); blasfeo_align_64_byte(mem, (void **) &mem_align); blasfeo_pm_create_dmat(ps, m_kernel, n, &tA, (void *) mem_align); blasfeo_pm_create_dmat(ps, n, n, &tB, (void *) (mem_align+tA_size)); pU = tA.pA; sdu = tA.cn; pB = tB.pA; sdb = tB.cn; dB = tB.dA; // if(pack_tran) // upper to lower // { // for(ii=0; ii<n-3; ii+=4) // { // kernel_dpack_tn_4_lib4(ii+4, A+ii*lda, lda, pB+ii*sdb); // } // if(ii<n) // { // kernel_dpack_tn_4_vs_lib4(n, A+ii*lda, lda, pB+ii*sdb, n-ii); // } // } // else // lower to lower // { // for(ii=0; ii<n-3; ii+=4) // { // kernel_dpack_nn_4_lib4(ii+4, A+ii, lda, pB+ii*sdb); // } // if(ii<n) // { // kernel_dpack_nn_4_vs_lib4(n, A+ii, lda, pB+ii*sdb, n-ii); // } // } // lower to lower for(ii=0; ii<n-3; ii+=4) { kernel_dpack_tt_4_lib4(n-ii, A+ii+ii*lda, lda, pB+ii*sdb+ii*ps, sdb); } if(ii<n) { kernel_dpack_tt_4_vs_lib4(n-ii, A+ii+ii*lda, lda, pB+ii*sdb+ii*ps, sdb, n-ii); } ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) for(; ii<m-11; ii+=12) { #if 0 kernel_dpack_nn_12_lib4(n, B+ii, ldb, pU, sdu); for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nt_rl_one_12x4_lib4(jj, pU, sdu, pB+jj*sdb, &alpha, pU+jj*ps, sdu, pU+ii+jj*ps, sdu, pB+jj*ps+jj*sdb); } if(jj<n) { kernel_dtrsm_nt_rl_one_12x4_vs_lib4(jj, pU, sdu, pB+jj*sdb, &alpha, pU+ii+jj*ps, sdu, pU+ii+jj*ps, sdu, pB+jj*ps+jj*sdb, m-ii, n-jj); } kernel_dunpack_nn_12_lib4(n, pU, sdu, D+ii, ldd); #else for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nt_rl_one_12x4_lib44cc4(jj, pU, sdu, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb); kernel_dpack_nn_12_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps, sdu); } if(jj<n) { kernel_dtrsm_nt_rl_one_12x4_vs_lib44cc4(jj, pU, sdu, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, m-ii, n-jj); // kernel_dpack_nn_4_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps); } #endif } if(ii<m) { if(m-ii<=4) { goto rltu_2_left_4; } if(m-ii<=8) { goto rltu_2_left_8; } else { goto rltu_2_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) for(; ii<m-7; ii+=8) { for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nt_rl_one_8x4_lib44cc4(jj, pU, sdu, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb); kernel_dpack_nn_8_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps, sdu); } if(jj<n) { kernel_dtrsm_nt_rl_one_8x4_vs_lib44cc4(jj, pU, sdu, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, m-ii, n-jj); // kernel_dpack_nn_4_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps); } } if(ii<m) { if(m-ii<=4) { goto rltu_2_left_4; } else { goto rltu_2_left_8; } } #else for(; ii<m-3; ii+=4) { for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nt_rl_one_4x4_lib44cc4(jj, pU, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb); kernel_dpack_nn_4_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps); } if(jj<n) { kernel_dtrsm_nt_rl_one_4x4_vs_lib44cc4(jj, pU, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, m-ii, n-jj); // kernel_dpack_nn_4_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps); } } if(ii<m) { goto rltu_2_left_4; } #endif goto rltu_2_return; #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) rltu_2_left_12: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nt_rl_one_12x4_vs_lib44cc4(jj, pU, sdu, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, m-ii, n-jj); kernel_dpack_nn_12_vs_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, sdu, m-ii); } goto rltu_2_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) rltu_2_left_8: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nt_rl_one_8x4_vs_lib44cc4(jj, pU, sdu, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, m-ii, n-jj); kernel_dpack_nn_8_vs_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, sdu, m-ii); } goto rltu_2_return; #endif rltu_2_left_4: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nt_rl_one_4x4_vs_lib44cc4(jj, pU, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, m-ii, n-jj); kernel_dpack_nn_4_vs_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, m-ii); } goto rltu_2_return; rltu_2_return: free(mem); return; // never to get here return; } void blasfeo_hp_dtrsm_runn(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { #if defined(PRINT_NAME) printf("\nblasfeo_hp_dtrsm_runn (cm) %d %d %f %p %d %d %p %d %d %p %d %d\n", m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); #endif if(m<=0 | n<=0) return; // extract pointer to column-major matrices from structures int lda = sA->m; int ldb = sB->m; int ldd = sD->m; double *A = sA->pA + ai + aj*lda; double *B = sB->pA + bi + bj*ldb; double *D = sD->pA + di + dj*ldd; // printf("\n%p %d %p %d %p %d\n", A, lda, B, ldb); int ii, jj; const int ps = 4; //D_PS; #if defined(TARGET_GENERIC) double pd0[K_MAX_STACK]; #else ALIGNED( double pd0[K_MAX_STACK], 64 ); #endif #if defined(TARGET_GENERIC) double pU0[M_KERNEL*K_MAX_STACK]; #else ALIGNED( double pU0[M_KERNEL*K_MAX_STACK], 64 ); #endif int k0; // TODO update if necessary !!!!! // if(*side=='l' | *side=='L') // k0 = m; // else k0 = n; int sdu0 = (k0+3)/4*4; sdu0 = sdu0<K_MAX_STACK ? sdu0 : K_MAX_STACK; struct blasfeo_pm_dmat tA, tB; int sda, sdb; int tA_size, tB_size; void *mem; char *mem_align; int m1, n1, k1; int pack_B; double *pU, *dA, *pB, *dB; int sdu; int idx, nn4, n4; const int m_kernel = M_KERNEL; const int l1_cache_el = L1_CACHE_EL; const int reals_per_cache_line = CACHE_LINE_EL; const int m_cache = (m+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int n_cache = (n+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; // const int k_cache = (k+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int m_kernel_cache = (m_kernel+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; int m_min = m_cache<m_kernel_cache ? m_cache : m_kernel_cache; // int n_min = n_cache<m_kernel_cache ? n_cache : m_kernel_cache; runn: #if defined(TARGET_X64_INTEL_HASWELL) if(m>=300 | n>=300 | n>K_MAX_STACK) #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) if(m>=64 | n>=64 | n>K_MAX_STACK) #else if(m>=12 | n>=12 | n>K_MAX_STACK) #endif { // pack_tran = 1; goto rltn_2; } else { goto runn_1; } // never to get here return; runn_1: pU = pU0; sdu = sdu0; dA = pd0; for(ii=0; ii<n; ii++) dA[ii] = 1.0/A[ii+ii*lda]; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(ii=0; ii<m-11; ii+=12) { for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nn_ru_inv_12x4_lib4cccc(jj, pU, sdu, A+jj*lda, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, dA+jj); kernel_dpack_nn_12_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps, sdu); } if(jj<n) { kernel_dtrsm_nn_ru_inv_12x4_vs_lib4cccc(jj, pU, sdu, A+jj*lda, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, dA+jj, m-ii, n-jj); // kernel_dpack_nn_12_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, sdu); } } if(ii<m) { if(m-ii<=4) { goto runn_1_left_4; } else if(m-ii<=8) { goto runn_1_left_8; } else { goto runn_1_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) for(ii=0; ii<m-7; ii+=8) { for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nn_ru_inv_8x4_lib4cccc(jj, pU, sdu, A+jj*lda, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, dA+jj); kernel_dpack_nn_8_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps, sdu); } if(jj<n) { kernel_dtrsm_nn_ru_inv_8x4_vs_lib4cccc(jj, pU, sdu, A+jj*lda, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, dA+jj, m-ii, n-jj); // kernel_dpack_nn_8_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, sdu); } } if(ii<m) { if(m-ii<=4) { goto runn_1_left_4; } else { goto runn_1_left_8; } } #else for(ii=0; ii<m-3; ii+=4) { for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nn_ru_inv_4x4_lib4cccc(jj, pU, A+jj*lda, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, dA+jj); kernel_dpack_nn_4_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps); } if(jj<n) { kernel_dtrsm_nn_ru_inv_4x4_vs_lib4cccc(jj, pU, A+jj*lda, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, dA+jj, m-ii, n-jj); // kernel_dpack_nn_4_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps); } } if(ii<m) { goto runn_1_left_4; } #endif goto runn_1_return; #if defined(TARGET_X64_INTEL_HASWELL) runn_1_left_12: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nn_ru_inv_12x4_vs_lib4cccc(jj, pU, sdu, A+jj*lda, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, dA+jj, m-ii, n-jj); kernel_dpack_nn_12_vs_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, sdu, m-ii); } goto runn_1_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) runn_1_left_8: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nn_ru_inv_8x4_vs_lib4cccc(jj, pU, sdu, A+jj*lda, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, dA+jj, m-ii, n-jj); kernel_dpack_nn_8_vs_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, sdu, m-ii); } goto runn_1_return; #endif runn_1_left_4: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nn_ru_inv_4x4_vs_lib4cccc(jj, pU, A+jj*lda, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, dA+jj, m-ii, n-jj); kernel_dpack_nn_4_vs_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, m-ii); } goto runn_1_return; runn_1_return: return; rltn_2: n1 = (n+128-1)/128*128; tA_size = blasfeo_pm_memsize_dmat(ps, m_kernel, n1); tB_size = blasfeo_pm_memsize_dmat(ps, n1, n1); mem = malloc(tA_size+tB_size+64); blasfeo_align_64_byte(mem, (void **) &mem_align); blasfeo_pm_create_dmat(ps, m_kernel, n, &tA, (void *) mem_align); blasfeo_pm_create_dmat(ps, n, n, &tB, (void *) (mem_align+tA_size)); pU = tA.pA; sdu = tA.cn; pB = tB.pA; sdb = tB.cn; dB = tB.dA; // upper to lower for(ii=0; ii<n-3; ii+=4) { kernel_dpack_tn_4_lib4(ii+4, A+ii*lda, lda, pB+ii*sdb); } if(ii<n) { kernel_dpack_tn_4_vs_lib4(n, A+ii*lda, lda, pB+ii*sdb, n-ii); } for(ii=0; ii<n; ii++) dB[ii] = 1.0/A[ii+ii*lda]; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) for(ii=0; ii<m-11; ii+=12) { #if 0 kernel_dpack_nn_12_lib4(n, B+ii, ldb, pU, sdu); for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nt_rl_inv_12x4_lib4(jj, pU, sdu, pB+jj*sdb, &alpha, pU+jj*ps, sdu, pU+ii+jj*ps, sdu, pB+jj*ps+jj*sdb, dB+jj); } if(jj<n) { kernel_dtrsm_nt_rl_inv_12x4_vs_lib4(jj, pU, sdu, pB+jj*sdb, &alpha, pU+ii+jj*ps, sdu, pU+ii+jj*ps, sdu, pB+jj*ps+jj*sdb, dB+jj, m-ii, n-jj); } kernel_dunpack_nn_12_lib4(n, pU, sdu, D+ii, ldd); #else for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nt_rl_inv_12x4_lib44cc4(jj, pU, sdu, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, dB+jj); kernel_dpack_nn_12_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps, sdu); } if(jj<n) { kernel_dtrsm_nt_rl_inv_12x4_vs_lib44cc4(jj, pU, sdu, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, dB+jj, m-ii, n-jj); // kernel_dpack_nn_4_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps); } #endif } if(ii<m) { if(m-ii<=4) { goto rltn_2_left_4; } if(m-ii<=8) { goto rltn_2_left_8; } else { goto rltn_2_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) for(ii=0; ii<m-7; ii+=8) { for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nt_rl_inv_8x4_lib44cc4(jj, pU, sdu, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, dB+jj); kernel_dpack_nn_8_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps, sdu); } if(jj<n) { kernel_dtrsm_nt_rl_inv_8x4_vs_lib44cc4(jj, pU, sdu, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, dB+jj, m-ii, n-jj); // kernel_dpack_nn_4_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps); } } if(ii<m) { if(m-ii<=4) { goto rltn_2_left_4; } else { goto rltn_2_left_8; } } #else for(ii=0; ii<m-3; ii+=4) { for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nt_rl_inv_4x4_lib44cc4(jj, pU, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, dB+jj); kernel_dpack_nn_4_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps); } if(jj<n) { kernel_dtrsm_nt_rl_inv_4x4_vs_lib44cc4(jj, pU, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, dB+jj, m-ii, n-jj); // kernel_dpack_nn_4_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps); } } if(ii<m) { goto rltn_2_left_4; } #endif goto rltn_2_return; #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) rltn_2_left_12: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nt_rl_inv_12x4_vs_lib44cc4(jj, pU, sdu, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, dB+jj, m-ii, n-jj); kernel_dpack_nn_12_vs_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, sdu, m-ii); } goto rltn_2_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) rltn_2_left_8: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nt_rl_inv_8x4_vs_lib44cc4(jj, pU, sdu, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, dB+jj, m-ii, n-jj); kernel_dpack_nn_8_vs_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, sdu, m-ii); } goto rltn_2_return; #endif rltn_2_left_4: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nt_rl_inv_4x4_vs_lib44cc4(jj, pU, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, dB+jj, m-ii, n-jj); kernel_dpack_nn_4_vs_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, m-ii); } goto rltn_2_return; rltn_2_return: free(mem); return; // never to get here return; } void blasfeo_hp_dtrsm_runu(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { #if defined(PRINT_NAME) printf("\nblasfeo_hp_dtrsm_runu (cm) %d %d %f %p %d %d %p %d %d %p %d %d\n", m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); #endif if(m<=0 | n<=0) return; // extract pointer to column-major matrices from structures int lda = sA->m; int ldb = sB->m; int ldd = sD->m; double *A = sA->pA + ai + aj*lda; double *B = sB->pA + bi + bj*ldb; double *D = sD->pA + di + dj*ldd; // printf("\n%p %d %p %d %p %d\n", A, lda, B, ldb); int ii, jj; const int ps = 4; //D_PS; #if defined(TARGET_GENERIC) double pd0[K_MAX_STACK]; #else ALIGNED( double pd0[K_MAX_STACK], 64 ); #endif #if defined(TARGET_GENERIC) double pU0[M_KERNEL*K_MAX_STACK]; #else ALIGNED( double pU0[M_KERNEL*K_MAX_STACK], 64 ); #endif int k0; // TODO update if necessary !!!!! // if(*side=='l' | *side=='L') // k0 = m; // else k0 = n; int sdu0 = (k0+3)/4*4; sdu0 = sdu0<K_MAX_STACK ? sdu0 : K_MAX_STACK; struct blasfeo_pm_dmat tA, tB; int sda, sdb; int tA_size, tB_size; void *mem; char *mem_align; int m1, n1, k1; int pack_B; double *pU, *dA, *pB, *dB; int sdu; int idx, nn4, n4; const int m_kernel = M_KERNEL; const int l1_cache_el = L1_CACHE_EL; const int reals_per_cache_line = CACHE_LINE_EL; const int m_cache = (m+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int n_cache = (n+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; // const int k_cache = (k+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int m_kernel_cache = (m_kernel+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; int m_min = m_cache<m_kernel_cache ? m_cache : m_kernel_cache; // int n_min = n_cache<m_kernel_cache ? n_cache : m_kernel_cache; runu: #if defined(TARGET_X64_INTEL_HASWELL) if(m>=300 | n>=300 | n>K_MAX_STACK) #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) if(m>=64 | n>=64 | n>K_MAX_STACK) #else if(m>=12 | n>=12 | n>K_MAX_STACK) #endif { // pack_tran = 1; goto rltu_2; } else { goto runu_1; } // never to get here return; runu_1: pU = pU0; sdu = sdu0; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(ii=0; ii<m-11; ii+=12) { for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nn_ru_one_12x4_lib4cccc(jj, pU, sdu, A+jj*lda, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda); kernel_dpack_nn_12_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps, sdu); } if(jj<n) { kernel_dtrsm_nn_ru_one_12x4_vs_lib4cccc(jj, pU, sdu, A+jj*lda, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, m-ii, n-jj); // kernel_dpack_nn_12_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, sdu); } } if(ii<m) { if(m-ii<=4) { goto runu_1_left_4; } else if(m-ii<=8) { goto runu_1_left_8; } else { goto runu_1_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) for(ii=0; ii<m-7; ii+=8) { for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nn_ru_one_8x4_lib4cccc(jj, pU, sdu, A+jj*lda, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda); kernel_dpack_nn_8_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps, sdu); } if(jj<n) { kernel_dtrsm_nn_ru_one_8x4_vs_lib4cccc(jj, pU, sdu, A+jj*lda, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, m-ii, n-jj); // kernel_dpack_nn_8_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, sdu); } } if(ii<m) { if(m-ii<=4) { goto runu_1_left_4; } else { goto runu_1_left_8; } } #else for(ii=0; ii<m-3; ii+=4) { for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nn_ru_one_4x4_lib4cccc(jj, pU, A+jj*lda, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda); kernel_dpack_nn_4_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps); } if(jj<n) { kernel_dtrsm_nn_ru_one_4x4_vs_lib4cccc(jj, pU, A+jj*lda, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, m-ii, n-jj); // kernel_dpack_nn_4_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps); } } if(ii<m) { goto runu_1_left_4; } #endif goto runu_1_return; #if defined(TARGET_X64_INTEL_HASWELL) runu_1_left_12: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nn_ru_one_12x4_vs_lib4cccc(jj, pU, sdu, A+jj*lda, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, m-ii, n-jj); kernel_dpack_nn_12_vs_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, sdu, m-ii); } goto runu_1_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) runu_1_left_8: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nn_ru_one_8x4_vs_lib4cccc(jj, pU, sdu, A+jj*lda, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, m-ii, n-jj); kernel_dpack_nn_8_vs_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, sdu, m-ii); } goto runu_1_return; #endif runu_1_left_4: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nn_ru_one_4x4_vs_lib4cccc(jj, pU, A+jj*lda, lda, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, A+jj+jj*lda, lda, m-ii, n-jj); kernel_dpack_nn_4_vs_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, m-ii); } goto runu_1_return; runu_1_return: return; rltu_2: n1 = (n+128-1)/128*128; tA_size = blasfeo_pm_memsize_dmat(ps, m_kernel, n1); tB_size = blasfeo_pm_memsize_dmat(ps, n1, n1); mem = malloc(tA_size+tB_size+64); blasfeo_align_64_byte(mem, (void **) &mem_align); blasfeo_pm_create_dmat(ps, m_kernel, n, &tA, (void *) mem_align); blasfeo_pm_create_dmat(ps, n, n, &tB, (void *) (mem_align+tA_size)); pU = tA.pA; sdu = tA.cn; pB = tB.pA; sdb = tB.cn; dB = tB.dA; // lower to upper for(ii=0; ii<n-3; ii+=4) { kernel_dpack_tn_4_lib4(ii+4, A+ii*lda, lda, pB+ii*sdb); } if(ii<n) { kernel_dpack_tn_4_vs_lib4(n, A+ii*lda, lda, pB+ii*sdb, n-ii); } ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) for(; ii<m-11; ii+=12) { #if 0 kernel_dpack_nn_12_lib4(n, B+ii, ldb, pU, sdu); for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nt_rl_one_12x4_lib4(jj, pU, sdu, pB+jj*sdb, &alpha, pU+jj*ps, sdu, pU+ii+jj*ps, sdu, pB+jj*ps+jj*sdb); } if(jj<n) { kernel_dtrsm_nt_rl_one_12x4_vs_lib4(jj, pU, sdu, pB+jj*sdb, &alpha, pU+ii+jj*ps, sdu, pU+ii+jj*ps, sdu, pB+jj*ps+jj*sdb, m-ii, n-jj); } kernel_dunpack_nn_12_lib4(n, pU, sdu, D+ii, ldd); #else for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nt_rl_one_12x4_lib44cc4(jj, pU, sdu, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb); kernel_dpack_nn_12_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps, sdu); } if(jj<n) { kernel_dtrsm_nt_rl_one_12x4_vs_lib44cc4(jj, pU, sdu, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, m-ii, n-jj); // kernel_dpack_nn_4_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps); } #endif } if(ii<m) { if(m-ii<=4) { goto rltu_2_left_4; } if(m-ii<=8) { goto rltu_2_left_8; } else { goto rltu_2_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) for(; ii<m-7; ii+=8) { for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nt_rl_one_8x4_lib44cc4(jj, pU, sdu, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb); kernel_dpack_nn_8_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps, sdu); } if(jj<n) { kernel_dtrsm_nt_rl_one_8x4_vs_lib44cc4(jj, pU, sdu, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, m-ii, n-jj); // kernel_dpack_nn_4_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps); } } if(ii<m) { if(m-ii<=4) { goto rltu_2_left_4; } else { goto rltu_2_left_8; } } #else for(; ii<m-3; ii+=4) { for(jj=0; jj<n-3; jj+=4) { kernel_dtrsm_nt_rl_one_4x4_lib44cc4(jj, pU, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb); kernel_dpack_nn_4_lib4(4, D+ii+jj*ldd, ldd, pU+jj*ps); } if(jj<n) { kernel_dtrsm_nt_rl_one_4x4_vs_lib44cc4(jj, pU, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, m-ii, n-jj); // kernel_dpack_nn_4_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps); } } if(ii<m) { goto rltu_2_left_4; } #endif goto rltu_2_return; #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) rltu_2_left_12: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nt_rl_one_12x4_vs_lib44cc4(jj, pU, sdu, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, m-ii, n-jj); kernel_dpack_nn_12_vs_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, sdu, m-ii); } goto rltu_2_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) | defined(TARGET_ARMV8A_ARM_CORTEX_A57) | defined(TARGET_ARMV8A_ARM_CORTEX_A53) rltu_2_left_8: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nt_rl_one_8x4_vs_lib44cc4(jj, pU, sdu, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, m-ii, n-jj); kernel_dpack_nn_8_vs_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, sdu, m-ii); } goto rltu_2_return; #endif rltu_2_left_4: for(jj=0; jj<n; jj+=4) { kernel_dtrsm_nt_rl_one_4x4_vs_lib44cc4(jj, pU, pB+jj*sdb, &alpha, B+ii+jj*ldb, ldb, D+ii+jj*ldd, ldd, pB+jj*ps+jj*sdb, m-ii, n-jj); kernel_dpack_nn_4_vs_lib4(n-jj, D+ii+jj*ldd, ldd, pU+jj*ps, m-ii); } goto rltu_2_return; rltu_2_return: free(mem); return; // never to get here return; } void blasfeo_hp_dtrsm_rutn(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { #if defined(PRINT_NAME) printf("\nblasfeo_hp_dtrsm_rutn (cm) %d %d %f %p %d %d %p %d %d %p %d %d\n", m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); #endif if(m<=0 | n<=0) return; // extract pointer to column-major matrices from structures int lda = sA->m; int ldb = sB->m; int ldd = sD->m; double *A = sA->pA + ai + aj*lda; double *B = sB->pA + bi + bj*ldb; double *D = sD->pA + di + dj*ldd; // printf("\n%p %d %p %d %p %d\n", A, lda, B, ldb); int ii, jj; const int ps = 4; //D_PS; #if defined(TARGET_GENERIC) double pd0[K_MAX_STACK]; #else ALIGNED( double pd0[K_MAX_STACK], 64 ); #endif #if defined(TARGET_GENERIC) double pU0[M_KERNEL*K_MAX_STACK]; #else ALIGNED( double pU0[M_KERNEL*K_MAX_STACK], 64 ); #endif int k0; // TODO update if necessary !!!!! // if(*side=='l' | *side=='L') // k0 = m; // else k0 = n; int sdu0 = (k0+3)/4*4; sdu0 = sdu0<K_MAX_STACK ? sdu0 : K_MAX_STACK; struct blasfeo_pm_dmat tA, tB; int sda, sdb; int tA_size, tB_size; void *mem; char *mem_align; int m1, n1, k1; int pack_B; double *pU, *dA, *pB, *dB; int sdu; int idx, nn4, n4; const int m_kernel = M_KERNEL; const int l1_cache_el = L1_CACHE_EL; const int reals_per_cache_line = CACHE_LINE_EL; const int m_cache = (m+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int n_cache = (n+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; // const int k_cache = (k+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int m_kernel_cache = (m_kernel+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; int m_min = m_cache<m_kernel_cache ? m_cache : m_kernel_cache; // int n_min = n_cache<m_kernel_cache ? n_cache : m_kernel_cache; rutn: #if defined(TARGET_X64_INTEL_HASWELL) if(m>=200 | n>=200 | n>K_MAX_STACK) #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) if(m>=64 | n>=64 | n>K_MAX_STACK) #else if(m>=12 | n>=12 | n>K_MAX_STACK) #endif { goto rutn_2; } else { goto rutn_1; } // never to get here return; rutn_1: pU = pU0; sdu = sdu0; dA = pd0; for(ii=0; ii<n; ii++) dA[ii] = 1.0/A[ii+ii*lda]; nn4 = n%4; n4 = n - nn4; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(; ii<m-11; ii+=12) { if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_inv_12x4_vs_lib4cccc(0, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, dA+idx, m-ii, nn4); kernel_dpack_nn_12_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_inv_12x4_lib4cccc(jj+nn4, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, dA+idx); kernel_dpack_nn_12_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu); } } if(ii<m) { if(m-ii<=4) { goto rutn_1_left_4; } else if(m-ii<=8) { goto rutn_1_left_8; } else { goto rutn_1_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) for(; ii<m-7; ii+=8) { if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_inv_8x4_vs_lib4cccc(0, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, dA+idx, m-ii, nn4); kernel_dpack_nn_8_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_inv_8x4_lib4cccc(jj+nn4, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, dA+idx); kernel_dpack_nn_8_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu); } } if(ii<m) { if(m-ii<=4) { goto rutn_1_left_4; } else { goto rutn_1_left_8; } } #else for(; ii<m-3; ii+=4) { if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_inv_4x4_vs_lib4cccc(0, pU+(idx+4)*ps, A+idx+(idx+4)*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, dA+idx, m-ii, nn4); kernel_dpack_nn_4_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_inv_4x4_lib4cccc(jj+nn4, pU+(idx+4)*ps, A+idx+(idx+4)*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, dA+idx); kernel_dpack_nn_4_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps); } } if(ii<m) { goto rutn_1_left_4; } #endif goto rutn_1_return; rutn_1_left_4: if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_inv_4x4_vs_lib4cccc(0, pU+(idx+4)*ps, A+idx+(idx+4)*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, dA+idx, m-ii, nn4); kernel_dpack_nn_4_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_inv_4x4_vs_lib4cccc(jj+nn4, pU+(idx+4)*ps, A+idx+(idx+4)*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, dA+idx, m-ii, 4); kernel_dpack_nn_4_vs_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, m-ii); } goto rutn_1_return; #if defined(TARGET_X64_INTEL_HASWELL) rutn_1_left_12: if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_inv_12x4_vs_lib4cccc(0, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, dA+idx, m-ii, nn4); kernel_dpack_nn_12_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_inv_12x4_vs_lib4cccc(jj+nn4, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, dA+idx, m-ii, 4); kernel_dpack_nn_12_vs_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } goto rutn_1_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) rutn_1_left_8: if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_inv_8x4_vs_lib4cccc(0, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, dA+idx, m-ii, nn4); kernel_dpack_nn_8_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_inv_8x4_vs_lib4cccc(jj+nn4, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, dA+idx, m-ii, 4); kernel_dpack_nn_8_vs_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } goto rutn_1_return; #endif rutn_1_return: return; rutn_2: n1 = (n+128-1)/128*128; tA_size = blasfeo_pm_memsize_dmat(ps, m_kernel, n1); tB_size = blasfeo_pm_memsize_dmat(ps, n1, n1); mem = malloc(tA_size+tB_size+64); blasfeo_align_64_byte(mem, (void **) &mem_align); blasfeo_pm_create_dmat(ps, m_kernel, n, &tA, (void *) mem_align); blasfeo_pm_create_dmat(ps, n, n, &tB, (void *) (mem_align+tA_size)); pU = tA.pA; sdu = tA.cn; pB = tB.pA; sdb = tB.cn; dB = tB.dA; // upper to upper #if 1 for(ii=0; ii<n-3; ii+=4) { kernel_dpack_tt_4_lib4(ii+4, A+ii*lda, lda, pB+ii*ps, sdb); } if(ii<n) { kernel_dpack_tt_4_vs_lib4(n, A+ii*lda, lda, pB+ii*ps, sdb, n-ii); } #else for(ii=0; ii<n-3; ii+=4) { kernel_dpack_nn_4_lib4(n-ii, A+ii+ii*lda, lda, pB+ii*ps+ii*sdb); } if(ii<n) { kernel_dpack_nn_4_vs_lib4(n-ii, A+ii+ii*lda, lda, pB+ii*ps+ii*sdb, n-ii); } #endif for(ii=0; ii<n; ii++) dB[ii] = 1.0/A[ii+ii*lda]; nn4 = n%4; n4 = n - nn4; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(; ii<m-11; ii+=12) { if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_inv_12x4_vs_lib44cc4(0, pU+(idx+4)*ps, sdu, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, dB+idx, m-ii, nn4); kernel_dpack_nn_12_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_inv_12x4_lib44cc4(jj+nn4, pU+(idx+4)*ps, sdu, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, dB+idx); kernel_dpack_nn_12_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu); } } if(ii<m) { if(m-ii<=4) { goto rutn_2_left_4; } else if(m-ii<=8) { goto rutn_2_left_8; } else { goto rutn_2_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) for(; ii<m-7; ii+=8) { if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_inv_8x4_vs_lib44cc4(0, pU+(idx+4)*ps, sdu, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, dB+idx, m-ii, nn4); kernel_dpack_nn_8_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_inv_8x4_lib44cc4(jj+nn4, pU+(idx+4)*ps, sdu, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, dB+idx); kernel_dpack_nn_8_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu); } } if(ii<m) { if(m-ii<=4) { goto rutn_2_left_4; } else { goto rutn_2_left_8; } } #else for(; ii<m-3; ii+=4) { if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_inv_4x4_vs_lib44cc4(0, pU+(idx+4)*ps, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, dB+idx, m-ii, nn4); kernel_dpack_nn_4_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_inv_4x4_lib44cc4(jj+nn4, pU+(idx+4)*ps, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, dB+idx); kernel_dpack_nn_4_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps); } } if(ii<m) { goto rutn_2_left_4; } #endif goto rutn_2_return; #if defined(TARGET_X64_INTEL_HASWELL) rutn_2_left_12: if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_inv_12x4_vs_lib44cc4(0, pU+(idx+4)*ps, sdu, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, dB+idx, m-ii, nn4); kernel_dpack_nn_12_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_inv_12x4_vs_lib44cc4(jj+nn4, pU+(idx+4)*ps, sdu, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, dB+idx, m-ii, 4); kernel_dpack_nn_12_vs_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } goto rutn_2_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) rutn_2_left_8: if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_inv_8x4_vs_lib44cc4(0, pU+(idx+4)*ps, sdu, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, dB+idx, m-ii, nn4); kernel_dpack_nn_8_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_inv_8x4_vs_lib44cc4(jj+nn4, pU+(idx+4)*ps, sdu, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, dB+idx, m-ii, 4); kernel_dpack_nn_8_vs_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } goto rutn_2_return; #endif rutn_2_left_4: if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_inv_4x4_vs_lib44cc4(0, pU+(idx+4)*ps, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, dB+idx, m-ii, nn4); kernel_dpack_nn_4_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_inv_4x4_vs_lib44cc4(jj+nn4, pU+(idx+4)*ps, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, dB+idx, m-ii, 4); kernel_dpack_nn_4_vs_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, m-ii); } goto rutn_2_return; rutn_2_return: free(mem); return; // never to get here return; } void blasfeo_hp_dtrsm_rutu(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { #if defined(PRINT_NAME) printf("\nblasfeo_hp_dtrsm_rutu (cm) %d %d %f %p %d %d %p %d %d %p %d %d\n", m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); #endif if(m<=0 | n<=0) return; // extract pointer to column-major matrices from structures int lda = sA->m; int ldb = sB->m; int ldd = sD->m; double *A = sA->pA + ai + aj*lda; double *B = sB->pA + bi + bj*ldb; double *D = sD->pA + di + dj*ldd; // printf("\n%p %d %p %d %p %d\n", A, lda, B, ldb); int ii, jj; const int ps = 4; //D_PS; #if defined(TARGET_GENERIC) double pd0[K_MAX_STACK]; #else ALIGNED( double pd0[K_MAX_STACK], 64 ); #endif #if defined(TARGET_GENERIC) double pU0[M_KERNEL*K_MAX_STACK]; #else ALIGNED( double pU0[M_KERNEL*K_MAX_STACK], 64 ); #endif int k0; // TODO update if necessary !!!!! // if(*side=='l' | *side=='L') // k0 = m; // else k0 = n; int sdu0 = (k0+3)/4*4; sdu0 = sdu0<K_MAX_STACK ? sdu0 : K_MAX_STACK; struct blasfeo_pm_dmat tA, tB; int sda, sdb; int tA_size, tB_size; void *mem; char *mem_align; int m1, n1, k1; int pack_B; double *pU, *dA, *pB, *dB; int sdu; int idx, nn4, n4; const int m_kernel = M_KERNEL; const int l1_cache_el = L1_CACHE_EL; const int reals_per_cache_line = CACHE_LINE_EL; const int m_cache = (m+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int n_cache = (n+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; // const int k_cache = (k+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; const int m_kernel_cache = (m_kernel+reals_per_cache_line-1)/reals_per_cache_line*reals_per_cache_line; int m_min = m_cache<m_kernel_cache ? m_cache : m_kernel_cache; // int n_min = n_cache<m_kernel_cache ? n_cache : m_kernel_cache; rutu: #if defined(TARGET_X64_INTEL_HASWELL) if(m>=200 | n>=200 | n>K_MAX_STACK) #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) if(m>=64 | n>=64 | n>K_MAX_STACK) #else if(m>=12 | n>=12 | n>K_MAX_STACK) #endif { // pack_tran = 0; goto rutu_2; } else { goto rutu_1; } // never to get here return; rutu_1: pU = pU0; sdu = sdu0; nn4 = n%4; n4 = n - nn4; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(; ii<m-11; ii+=12) { if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_one_12x4_vs_lib4cccc(0, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, m-ii, nn4); kernel_dpack_nn_12_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_one_12x4_lib4cccc(jj+nn4, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda); kernel_dpack_nn_12_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu); } } if(ii<m) { if(m-ii<=4) { goto rutu_1_left_4; } else if(m-ii<=8) { goto rutu_1_left_8; } else { goto rutu_1_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) for(; ii<m-7; ii+=8) { if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_one_8x4_vs_lib4cccc(0, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, m-ii, nn4); kernel_dpack_nn_8_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_one_8x4_lib4cccc(jj+nn4, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda); kernel_dpack_nn_8_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu); } } if(ii<m) { if(m-ii<=4) { goto rutu_1_left_4; } else { goto rutu_1_left_8; } } #else for(; ii<m-3; ii+=4) { if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_one_4x4_vs_lib4cccc(0, pU+(idx+4)*ps, A+idx+(idx+4)*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, m-ii, nn4); kernel_dpack_nn_4_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_one_4x4_lib4cccc(jj+nn4, pU+(idx+4)*ps, A+idx+(idx+4)*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda); kernel_dpack_nn_4_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps); } } if(ii<m) { goto rutu_1_left_4; } #endif goto rutu_1_return; rutu_1_left_4: if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_one_4x4_vs_lib4cccc(0, pU+(idx+4)*ps, A+idx+(idx+4)*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, m-ii, nn4); kernel_dpack_nn_4_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_one_4x4_vs_lib4cccc(jj+nn4, pU+(idx+4)*ps, A+idx+(idx+4)*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, m-ii, 4); kernel_dpack_nn_4_vs_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, m-ii); } goto rutu_1_return; #if defined(TARGET_X64_INTEL_HASWELL) rutu_1_left_12: if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_one_12x4_vs_lib4cccc(0, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, m-ii, nn4); kernel_dpack_nn_12_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_one_12x4_vs_lib4cccc(jj+nn4, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, m-ii, 4); kernel_dpack_nn_12_vs_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } goto rutu_1_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) rutu_1_left_8: if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_one_8x4_vs_lib4cccc(0, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, m-ii, nn4); kernel_dpack_nn_8_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_one_8x4_vs_lib4cccc(jj+nn4, pU+(idx+4)*ps, sdu, A+idx+(idx+4)*lda, lda, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, A+idx+idx*lda, lda, m-ii, 4); kernel_dpack_nn_8_vs_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } goto rutu_1_return; #endif rutu_1_return: return; rutu_2: n1 = (n+128-1)/128*128; tA_size = blasfeo_pm_memsize_dmat(ps, m_kernel, n1); tB_size = blasfeo_pm_memsize_dmat(ps, n1, n1); mem = malloc(tA_size+tB_size+64); blasfeo_align_64_byte(mem, (void **) &mem_align); blasfeo_pm_create_dmat(ps, m_kernel, n, &tA, (void *) mem_align); blasfeo_pm_create_dmat(ps, n, n, &tB, (void *) (mem_align+tA_size)); pU = tA.pA; sdu = tA.cn; pB = tB.pA; sdb = tB.cn; dB = tB.dA; #if 1 for(ii=0; ii<n-3; ii+=4) { kernel_dpack_tt_4_lib4(ii+4, A+ii*lda, lda, pB+ii*ps, sdb); } if(ii<n) { kernel_dpack_tt_4_vs_lib4(n, A+ii*lda, lda, pB+ii*ps, sdb, n-ii); } #else for(ii=0; ii<n-3; ii+=4) { kernel_dpack_nn_4_lib4(n-ii, A+ii+ii*lda, lda, pB+ii*ps+ii*sdb); } if(ii<n) { kernel_dpack_nn_4_vs_lib4(n-ii, A+ii+ii*lda, lda, pB+ii*ps+ii*sdb, n-ii); } #endif nn4 = n%4; n4 = n - nn4; ii = 0; #if defined(TARGET_X64_INTEL_HASWELL) for(; ii<m-11; ii+=12) { if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_one_12x4_vs_lib44cc4(0, pU+(idx+4)*ps, sdu, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, m-ii, nn4); kernel_dpack_nn_12_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_one_12x4_lib44cc4(jj+nn4, pU+(idx+4)*ps, sdu, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps); kernel_dpack_nn_12_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu); } } if(ii<m) { if(m-ii<=4) { goto rutu_2_left_4; } else if(m-ii<=8) { goto rutu_2_left_8; } else { goto rutu_2_left_12; } } #elif defined(TARGET_X64_INTEL_SANDY_BRIDGE) for(; ii<m-7; ii+=8) { if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_one_8x4_vs_lib44cc4(0, pU+(idx+4)*ps, sdu, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, m-ii, nn4); kernel_dpack_nn_8_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_one_8x4_lib44cc4(jj+nn4, pU+(idx+4)*ps, sdu, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps); kernel_dpack_nn_8_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu); } } if(ii<m) { if(m-ii<=4) { goto rutu_2_left_4; } else { goto rutu_2_left_8; } } #else for(; ii<m-3; ii+=4) { if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_one_4x4_vs_lib44cc4(0, pU+(idx+4)*ps, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, m-ii, nn4); kernel_dpack_nn_4_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_one_4x4_lib44cc4(jj+nn4, pU+(idx+4)*ps, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps); kernel_dpack_nn_4_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps); } } if(ii<m) { goto rutu_2_left_4; } #endif goto rutu_2_return; #if defined(TARGET_X64_INTEL_HASWELL) rutu_2_left_12: if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_one_12x4_vs_lib44cc4(0, pU+(idx+4)*ps, sdu, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, m-ii, nn4); kernel_dpack_nn_12_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_one_12x4_vs_lib44cc4(jj+nn4, pU+(idx+4)*ps, sdu, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, m-ii, 4); kernel_dpack_nn_12_vs_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } goto rutu_2_return; #endif #if defined(TARGET_X64_INTEL_HASWELL) | defined(TARGET_X64_INTEL_SANDY_BRIDGE) rutu_2_left_8: if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_one_8x4_vs_lib44cc4(0, pU+(idx+4)*ps, sdu, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, m-ii, nn4); kernel_dpack_nn_8_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_one_8x4_vs_lib44cc4(jj+nn4, pU+(idx+4)*ps, sdu, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, m-ii, 4); kernel_dpack_nn_8_vs_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, sdu, m-ii); } goto rutu_2_return; #endif rutu_2_left_4: if(nn4!=0) { idx = n4; kernel_dtrsm_nt_ru_one_4x4_vs_lib44cc4(0, pU+(idx+4)*ps, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, m-ii, nn4); kernel_dpack_nn_4_vs_lib4(nn4, D+ii+idx*ldd, ldd, pU+idx*ps, m-ii); } for(jj=0; jj<n4-3; jj+=4) { idx = n4-jj-4; kernel_dtrsm_nt_ru_one_4x4_vs_lib44cc4(jj+nn4, pU+(idx+4)*ps, pB+idx*sdb+(idx+4)*ps, &alpha, B+ii+idx*ldb, ldb, D+ii+idx*ldd, ldd, pB+idx*sdb+idx*ps, m-ii, 4); kernel_dpack_nn_4_vs_lib4(4, D+ii+idx*ldd, ldd, pU+idx*ps, m-ii); } goto rutu_2_return; rutu_2_return: free(mem); return; // never to get here return; } #if defined(LA_HIGH_PERFORMANCE) void blasfeo_dtrsm_llnn(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { blasfeo_hp_dtrsm_llnn(m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); return; } void blasfeo_dtrsm_llnu(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { blasfeo_hp_dtrsm_llnu(m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); return; } void blasfeo_dtrsm_lltn(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { blasfeo_hp_dtrsm_lltn(m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); return; } void blasfeo_dtrsm_lltu(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { blasfeo_hp_dtrsm_lltu(m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); return; } void blasfeo_dtrsm_lunn(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { blasfeo_hp_dtrsm_lunn(m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); return; } void blasfeo_dtrsm_lunu(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { blasfeo_hp_dtrsm_lunu(m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); return; } void blasfeo_dtrsm_lutn(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { blasfeo_hp_dtrsm_lutn(m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); return; } void blasfeo_dtrsm_lutu(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { blasfeo_hp_dtrsm_lutu(m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); return; } void blasfeo_dtrsm_rlnn(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { blasfeo_hp_dtrsm_rlnn(m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); return; } void blasfeo_dtrsm_rlnu(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { blasfeo_hp_dtrsm_rlnu(m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); return; } void blasfeo_dtrsm_rltn(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { blasfeo_hp_dtrsm_rltn(m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); return; } void blasfeo_dtrsm_rltu(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { blasfeo_hp_dtrsm_rltu(m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); return; } void blasfeo_dtrsm_runn(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { blasfeo_hp_dtrsm_runn(m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); return; } void blasfeo_dtrsm_runu(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { blasfeo_hp_dtrsm_runu(m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); return; } void blasfeo_dtrsm_rutn(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { blasfeo_hp_dtrsm_rutn(m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); return; } void blasfeo_dtrsm_rutu(int m, int n, double alpha, struct blasfeo_dmat *sA, int ai, int aj, struct blasfeo_dmat *sB, int bi, int bj, struct blasfeo_dmat *sD, int di, int dj) { blasfeo_hp_dtrsm_rutu(m, n, alpha, sA, ai, aj, sB, bi, bj, sD, di, dj); return; } #endif
749fc8a80c40b156915a682e4749b7e1a1e7de7f
d61b532db0d3e08818338cfaac530a1ced1ffe3b
/lang/cem/cemcom/options.c
62e3dc9f65db6e8f954bb6a5ba1c3352f4c0504c
[ "LicenseRef-scancode-other-permissive" ]
permissive
davidgiven/ack
61049c7a8e95ff61a77b1edd3c22bb290720e276
db5a32c68c4a60ca26a3927a799ea662b5b2b0e5
refs/heads/default
2023-08-29T07:33:12.771205
2023-07-08T20:17:27
2023-07-08T20:17:27
37,686,316
376
74
NOASSERTION
2023-07-08T20:17:28
2015-06-18T21:33:42
C
UTF-8
C
false
false
7,559
c
options.c
/* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ /* $Id$ */ /* U S E R O P T I O N - H A N D L I N G */ #include <stdlib.h> #include <stdio.h> #include <string.h> #include "lint.h" #include "botch_free.h" #include <alloc.h> #include "nofloat.h" #include "nopp.h" #include "idfsize.h" #include "nobitfield.h" #include "class.h" #include "macro.h" #include "idf.h" #include "arith.h" #include "sizes.h" #include "align.h" #include "use_tmp.h" #include "dataflow.h" #include "noRoption.h" #include "dbsymtab.h" #ifndef NOPP extern char **inctable; extern int inc_pos; extern int inc_max; extern int inc_total; int do_dependencies = 0; char *dep_file = 0; #endif /* NOPP */ char options[128]; /* one for every char */ #ifdef LINT char loptions[128]; /* one for every char */ #endif /* LINT */ extern int idfsize; extern int density; static int txt2int(); do_option(text) char *text; { register char opt; next_option: /* to allow combined one-char options */ switch (opt = *text++) { case 0: /* to end the goto next_option loop */ break; default: #ifndef LINT fatal("illegal option: %c", opt); #else /* LINT */ warning("illegal option: %c", opt); #endif /* LINT */ break; case '-': options[*text++] = 1; /* flags, debug options etc. */ goto next_option; #ifndef LINT #ifdef DATAFLOW case 'd': #endif /* DATAFLOW */ case 'p': /* procentry/procexit */ case 'L' : /* no fil/lin */ case 'n': /* use no registers */ case 'w': /* no warnings will be given */ options[opt] = 1; goto next_option; #endif /* LINT */ #ifdef LINT case 'h': /* heuristic tests */ case 'v': /* no complaints about unused arguments */ case 'a': /* check long->int int->long conversions */ case 'b': /* don't report unreachable break-statements */ case 'x': /* complain about unused extern declared variables */ case 'u': /* no "used but not defined"; for pass 2 */ case 'L': /* lintlibrary */ loptions[opt] = 1; goto next_option; #endif /* LINT */ #ifndef LINT #ifndef NOPP case 'A' : /* Amake dependency generation */ do_dependencies = 1; if (*text) { dep_file = text; } break; case 'i': case 'm': options[opt] = 1; break; #endif /* NOPP */ #endif /* LINT */ #ifdef DBSYMTAB case 'g': /* symbol table for debugger */ options['g'] = 1; options['n'] = 1; break; #endif /* DBSYMTAB */ case 'R': /* strict version */ #ifndef NOROPTION options[opt] = 1; #else /* NOROPTION */ warning("-R option not implemented"); #endif /* NOROPTION */ goto next_option; #ifdef ___XXX___ deleted, is now a debug-flag case 'C' : /* E option + comment output */ #ifndef NOPP options['E'] = 1; warning("-C: comment is not output"); #else /* NOPP */ warning("-C option ignored"); #endif /* NOPP */ break; #endif /* ___XXX___ */ case 'D' : { /* -Dname : predefine name */ #ifndef NOPP register char *cp = text, *name, *mactext; if (class(*cp) != STIDF) { error("identifier missing in -D%s", text); break; } name = cp; while (*cp && in_idf(*cp)) { ++cp; } if (!*cp) { /* -Dname */ mactext = "1"; } else if (*cp == '=') { /* -Dname=text */ *cp++ = '\0'; /* end of name */ mactext = cp; } else { /* -Dname?? */ error("malformed option -D%s", text); break; } macro_def(str2idf(name), mactext, -1, strlen(mactext), NOFLAG); #else /* NOPP */ warning("-D option ignored"); #endif /* NOPP */ break; } #ifdef ___XXX___ deleted, is now a debug-flag case 'E' : /* run preprocessor only, with #<int> */ #ifndef NOPP options['E'] = 1; #else /* NOPP */ warning("-E option ignored"); #endif /* NOPP */ break; #endif /* ___XXX___ */ case 'I' : /* -Ipath : insert "path" into include list */ #ifndef NOPP if (*text) { int i; register char *new = text; if (++inc_total > inc_max) { inctable = (char **) Realloc((char *) inctable,(inc_max+=10)*sizeof(char *)); } for (i = inc_pos++; i < inc_total; i++) { char *tmp = inctable[i]; inctable[i] = new; new = tmp; } } else inctable[inc_pos] = 0; #else /* NOPP */ warning("-I option ignored"); #endif /* NOPP */ break; case 'M': /* maximum identifier length */ idfsize = txt2int(&text); if (*text || idfsize <= 0) fatal("malformed -M option"); if (idfsize > IDFSIZE) fatal("maximum identifier length is %d", IDFSIZE); break; #ifdef ___XXX___ deleted, is now a debug-flag case 'P' : /* run preprocessor stand-alone, without #'s */ #ifndef NOPP options['E'] = 1; options['P'] = 1; #else /* NOPP */ warning("-P option ignored"); #endif /* NOPP */ break; #endif /* ___XXX___ */ #ifdef LINT case 'S' : { /* -Sint : static scope number for lint */ extern int stat_number; stat_number = txt2int(&text); break; } #endif /* LINT */ case 'T' : { #ifdef USE_TMP extern char *C_tmpdir; if (*text) C_tmpdir = text; else C_tmpdir = "."; #else /* USE_TMP */ warning("-T option ignored"); #endif /* USE_TMP */ break; } case 'U' : { /* -Uname : undefine predefined */ #ifndef NOPP register struct idf *idef; if (*text) { if ((idef = str2idf(text))->id_macro) { free_macro(idef->id_macro); idef->id_macro = (struct macro *) 0; } } #else /* NOPP */ warning("-U option ignored"); #endif /* NOPP */ break; } #ifndef LINT case 'V' : /* set object sizes and alignment requirements */ #ifdef NOCROSS warning("-V option ignored"); break; #else /* NOCROSS */ { register arith sz, algn; char c; while (c = *text++) { sz = txt2int(&text); algn = 0; if (*text == '.') { text++; algn = txt2int(&text); } switch (c) { case 's': /* short */ if (sz != (arith)0) short_size = sz; if (algn != 0) short_align = algn; break; case 'w': /* word */ if (sz != (arith)0) dword_size = (word_size = sz) << 1; if (algn != 0) word_align = algn; break; case 'i': /* int */ if (sz != (arith)0) int_size = sz; if (algn != 0) int_align = algn; break; case 'l': /* long */ if (sz != (arith)0) long_size = sz; if (algn != 0) long_align = algn; break; case 'f': /* float */ #ifndef NOFLOAT if (sz != (arith)0) float_size = sz; if (algn != 0) float_align = algn; #endif /* NOFLOAT */ break; case 'd': /* double */ #ifndef NOFLOAT if (sz != (arith)0) double_size = sz; if (algn != 0) double_align = algn; #endif /* NOFLOAT */ break; case 'p': /* pointer */ if (sz != (arith)0) pointer_size = sz; if (algn != 0) pointer_align = algn; break; case 'r': /* adjust bitfields right */ #ifndef NOBITFIELD options['r'] = 1; #else /* NOBITFIELD */ warning("bitfields are not implemented"); #endif /* NOBITFIELD */ break; case 'S': /* initial struct alignment */ if (sz != (arith)0) struct_align = sz; break; case 'U': /* initial union alignment */ if (sz != (arith)0) union_align = sz; break; default: error("-V: bad type indicator %c\n", c); } } break; } #endif /* NOCROSS */ case 'S': density = txt2int(&text); break; #endif /* LINT */ } } static int txt2int(tp) register char **tp; { /* the integer pointed to by *tp is read, while increasing *tp; the resulting value is yielded. */ register int val = 0, ch; while (ch = **tp, ch >= '0' && ch <= '9') { val = val * 10 + ch - '0'; (*tp)++; } return val; }
da98479003e1e32d4a3cd0d455d253c175f4a85c
fff6d13af91db925a94b3e3474108fafd519bba0
/flex/main.c
455eea75205c7d12fad978846a2e39d9619a3ecf
[ "LicenseRef-scancode-warranty-disclaimer", "LicenseRef-scancode-flex-2.5" ]
permissive
shinyquagsire23/OpenJKDF2
94f1364628924ac944466107606b91c6faeec3df
b79b8c210878b6f276ed3d1a5dad91d9219e6ce1
refs/heads/master
2023-07-08T16:41:38.986577
2023-06-28T08:47:39
2023-06-28T08:47:39
139,542,792
381
34
NOASSERTION
2023-06-28T08:47:40
2018-07-03T07:09:45
C
UTF-8
C
false
false
19,459
c
main.c
/* flex - tool to generate fast lexical analyzers */ /*- * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. * * This code is derived from software contributed to Berkeley by * Vern Paxson. * * The United States Government has rights in this work pursuant * to contract no. DE-AC03-76SF00098 between the United States * Department of Energy and the University of California. * * Redistribution and use in source and binary forms are permitted provided * that: (1) source distributions retain this entire copyright notice and * comment, and (2) distributions including binaries display the following * acknowledgement: ``This product includes software developed by the * University of California, Berkeley and its contributors'' in the * documentation or other materials provided with the distribution and in * all advertising materials mentioning features or use of this software. * Neither the name of the University nor the names of its contributors may * be used to endorse or promote products derived from this software without * specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef lint char copyright[] = "@(#) Copyright (c) 1990 The Regents of the University of California.\n\ All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char rcsid[] = "@(#) $Header: /usr/fsys/odin/a/vern/flex/RCS/main.c,v 2.9 90/06/27 23:48:24 vern Exp $ (LBL)"; #endif #include "flexdef.h" static char flex_version[] = "2.3"; /* declare functions that have forward references */ void flexinit PROTO((int, char**)); void readin PROTO(()); void set_up_initial_allocations PROTO(()); /* these globals are all defined and commented in flexdef.h */ int printstats, syntaxerror, eofseen, ddebug, trace, spprdflt; int interactive, caseins, useecs, fulltbl, usemecs; int fullspd, gen_line_dirs, performance_report, backtrack_report, csize; int yymore_used, reject, real_reject, continued_action; int yymore_really_used, reject_really_used; int datapos, dataline, linenum; FILE *skelfile = NULL; char *infilename = NULL; int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE]; int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp; int current_mns, num_rules, current_max_rules, lastnfa; int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2; int *accptnum, *assoc_rule, *state_type, *rule_type, *rule_linenum; int current_state_type; int variable_trailing_context_rules; int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP]; int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE]; int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs, tecfwd[CSIZE + 1]; int tecbck[CSIZE + 1]; int *xlation = (int *) 0; int num_xlations; int lastsc, current_max_scs, *scset, *scbol, *scxclu, *sceof, *actvsc; char **scname; int current_max_dfa_size, current_max_xpairs; int current_max_template_xpairs, current_max_dfas; int lastdfa, *nxt, *chk, *tnxt; int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, *dfasiz; union dfaacc_union *dfaacc; int *accsiz, *dhash, numas; int numsnpairs, jambase, jamstate; int lastccl, current_maxccls, *cclmap, *ccllen, *cclng, cclreuse; int current_max_ccl_tbl_size; Char *ccltbl; char *starttime, *endtime, nmstr[MAXLINE]; int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs; int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave; int num_backtracking, bol_needed; FILE *temp_action_file; FILE *backtrack_file; int end_of_buffer_state; char *action_file_name = NULL; char **input_files; int num_input_files; char *program_name; #ifndef SHORT_FILE_NAMES static char *outfile = "lex.yy.c"; #else static char *outfile = "lexyy.c"; #endif static int outfile_created = 0; static int use_stdout; static char *skelname = NULL; int main( argc, argv ) int argc; char **argv; { flexinit( argc, argv ); readin(); if ( syntaxerror ) flexend( 1 ); if ( yymore_really_used == REALLY_USED ) yymore_used = true; else if ( yymore_really_used == REALLY_NOT_USED ) yymore_used = false; if ( reject_really_used == REALLY_USED ) reject = true; else if ( reject_really_used == REALLY_NOT_USED ) reject = false; if ( performance_report ) { if ( interactive ) fprintf( stderr, "-I (interactive) entails a minor performance penalty\n" ); if ( yymore_used ) fprintf( stderr, "yymore() entails a minor performance penalty\n" ); if ( reject ) fprintf( stderr, "REJECT entails a large performance penalty\n" ); if ( variable_trailing_context_rules ) fprintf( stderr, "Variable trailing context rules entail a large performance penalty\n" ); } if ( reject ) real_reject = true; if ( variable_trailing_context_rules ) reject = true; if ( (fulltbl || fullspd) && reject ) { if ( real_reject ) flexerror( "REJECT cannot be used with -f or -F" ); else flexerror( "variable trailing context rules cannot be used with -f or -F" ); } ntod(); /* generate the C state transition tables from the DFA */ make_tables(); /* note, flexend does not return. It exits with its argument as status. */ flexend( 0 ); /*NOTREACHED*/ } /* flexend - terminate flex * * synopsis * int status; * flexend( status ); * * status is exit status. * * note * This routine does not return. */ void flexend( status ) int status; { int tblsiz; char *flex_gettime(); if ( skelfile != NULL ) { if ( ferror( skelfile ) ) flexfatal( "error occurred when writing skeleton file" ); else if ( fclose( skelfile ) ) flexfatal( "error occurred when closing skeleton file" ); } if ( temp_action_file ) { if ( ferror( temp_action_file ) ) flexfatal( "error occurred when writing temporary action file" ); else if ( fclose( temp_action_file ) ) flexfatal( "error occurred when closing temporary action file" ); else if ( unlink( action_file_name ) ) flexfatal( "error occurred when deleting temporary action file" ); } if ( status != 0 && outfile_created ) { if ( ferror( stdout ) ) flexfatal( "error occurred when writing output file" ); else if ( fclose( stdout ) ) flexfatal( "error occurred when closing output file" ); else if ( unlink( outfile ) ) flexfatal( "error occurred when deleting output file" ); } if ( backtrack_report && backtrack_file ) { if ( num_backtracking == 0 ) fprintf( backtrack_file, "No backtracking.\n" ); else if ( fullspd || fulltbl ) fprintf( backtrack_file, "%d backtracking (non-accepting) states.\n", num_backtracking ); else fprintf( backtrack_file, "Compressed tables always backtrack.\n" ); if ( ferror( backtrack_file ) ) flexfatal( "error occurred when writing backtracking file" ); else if ( fclose( backtrack_file ) ) flexfatal( "error occurred when closing backtracking file" ); } if ( printstats ) { endtime = flex_gettime(); fprintf( stderr, "%s version %s usage statistics:\n", program_name, flex_version ); fprintf( stderr, " started at %s, finished at %s\n", starttime, endtime ); fprintf( stderr, " scanner options: -" ); if ( backtrack_report ) putc( 'b', stderr ); if ( ddebug ) putc( 'd', stderr ); if ( interactive ) putc( 'I', stderr ); if ( caseins ) putc( 'i', stderr ); if ( ! gen_line_dirs ) putc( 'L', stderr ); if ( performance_report ) putc( 'p', stderr ); if ( spprdflt ) putc( 's', stderr ); if ( use_stdout ) putc( 't', stderr ); if ( trace ) putc( 'T', stderr ); if ( printstats ) putc( 'v', stderr ); /* always true! */ if ( csize == 256 ) putc( '8', stderr ); fprintf( stderr, " -C" ); if ( fulltbl ) putc( 'f', stderr ); if ( fullspd ) putc( 'F', stderr ); if ( useecs ) putc( 'e', stderr ); if ( usemecs ) putc( 'm', stderr ); if ( strcmp( skelname, DEFAULT_SKELETON_FILE ) ) fprintf( stderr, " -S%s", skelname ); putc( '\n', stderr ); fprintf( stderr, " %d/%d NFA states\n", lastnfa, current_mns ); fprintf( stderr, " %d/%d DFA states (%d words)\n", lastdfa, current_max_dfas, totnst ); fprintf( stderr, " %d rules\n", num_rules - 1 /* - 1 for def. rule */ ); if ( num_backtracking == 0 ) fprintf( stderr, " No backtracking\n" ); else if ( fullspd || fulltbl ) fprintf( stderr, " %d backtracking (non-accepting) states\n", num_backtracking ); else fprintf( stderr, " compressed tables always backtrack\n" ); if ( bol_needed ) fprintf( stderr, " Beginning-of-line patterns used\n" ); fprintf( stderr, " %d/%d start conditions\n", lastsc, current_max_scs ); fprintf( stderr, " %d epsilon states, %d double epsilon states\n", numeps, eps2 ); if ( lastccl == 0 ) fprintf( stderr, " no character classes\n" ); else fprintf( stderr, " %d/%d character classes needed %d/%d words of storage, %d reused\n", lastccl, current_maxccls, cclmap[lastccl] + ccllen[lastccl], current_max_ccl_tbl_size, cclreuse ); fprintf( stderr, " %d state/nextstate pairs created\n", numsnpairs ); fprintf( stderr, " %d/%d unique/duplicate transitions\n", numuniq, numdup ); if ( fulltbl ) { tblsiz = lastdfa * numecs; fprintf( stderr, " %d table entries\n", tblsiz ); } else { tblsiz = 2 * (lastdfa + numtemps) + 2 * tblend; fprintf( stderr, " %d/%d base-def entries created\n", lastdfa + numtemps, current_max_dfas ); fprintf( stderr, " %d/%d (peak %d) nxt-chk entries created\n", tblend, current_max_xpairs, peakpairs ); fprintf( stderr, " %d/%d (peak %d) template nxt-chk entries created\n", numtemps * nummecs, current_max_template_xpairs, numtemps * numecs ); fprintf( stderr, " %d empty table entries\n", nummt ); fprintf( stderr, " %d protos created\n", numprots ); fprintf( stderr, " %d templates created, %d uses\n", numtemps, tmpuses ); } if ( useecs ) { tblsiz = tblsiz + csize; fprintf( stderr, " %d/%d equivalence classes created\n", numecs, csize ); } if ( usemecs ) { tblsiz = tblsiz + numecs; fprintf( stderr, " %d/%d meta-equivalence classes created\n", nummecs, csize ); } fprintf( stderr, " %d (%d saved) hash collisions, %d DFAs equal\n", hshcol, hshsave, dfaeql ); fprintf( stderr, " %d sets of reallocations needed\n", num_reallocs ); fprintf( stderr, " %d total table entries needed\n", tblsiz ); } #ifndef VMS exit( status ); #else exit( status + 1 ); #endif } /* flexinit - initialize flex * * synopsis * int argc; * char **argv; * flexinit( argc, argv ); */ void flexinit( argc, argv ) int argc; char **argv; { int i, sawcmpflag; char *arg, *flex_gettime(), *mktemp(); printstats = syntaxerror = trace = spprdflt = interactive = caseins = false; backtrack_report = performance_report = ddebug = fulltbl = fullspd = false; yymore_used = continued_action = reject = false; yymore_really_used = reject_really_used = false; gen_line_dirs = usemecs = useecs = true; sawcmpflag = false; use_stdout = false; csize = DEFAULT_CSIZE; program_name = argv[0]; /* read flags */ for ( --argc, ++argv; argc ; --argc, ++argv ) { if ( argv[0][0] != '-' || argv[0][1] == '\0' ) break; arg = argv[0]; for ( i = 1; arg[i] != '\0'; ++i ) switch ( arg[i] ) { case 'b': backtrack_report = true; break; case 'c': fprintf( stderr, "%s: Assuming use of deprecated -c flag is really intended to be -C\n", program_name ); /* fall through */ case 'C': if ( i != 1 ) flexerror( "-C flag must be given separately" ); if ( ! sawcmpflag ) { useecs = false; usemecs = false; fulltbl = false; sawcmpflag = true; } for ( ++i; arg[i] != '\0'; ++i ) switch ( arg[i] ) { case 'e': useecs = true; break; case 'F': fullspd = true; break; case 'f': fulltbl = true; break; case 'm': usemecs = true; break; default: lerrif( "unknown -C option '%c'", (int) arg[i] ); break; } goto get_next_arg; case 'd': ddebug = true; break; case 'f': useecs = usemecs = false; fulltbl = true; break; case 'F': useecs = usemecs = false; fullspd = true; break; case 'I': interactive = true; break; case 'i': caseins = true; break; case 'L': gen_line_dirs = false; break; case 'n': /* stupid do-nothing deprecated option */ break; case 'p': performance_report = true; break; case 'S': if ( i != 1 ) flexerror( "-S flag must be given separately" ); skelname = arg + i + 1; goto get_next_arg; case 's': spprdflt = true; break; case 't': use_stdout = true; break; case 'T': trace = true; break; case 'v': printstats = true; break; case '8': csize = CSIZE; break; default: lerrif( "unknown flag '%c'", (int) arg[i] ); break; } get_next_arg: /* used by -C and -S flags in lieu of a "continue 2" control */ ; } if ( (fulltbl || fullspd) && usemecs ) flexerror( "full table and -Cm don't make sense together" ); if ( (fulltbl || fullspd) && interactive ) flexerror( "full table and -I are (currently) incompatible" ); if ( fulltbl && fullspd ) flexerror( "full table and -F are mutually exclusive" ); if ( ! skelname ) { static char skeleton_name_storage[400]; skelname = skeleton_name_storage; (void) strcpy( skelname, DEFAULT_SKELETON_FILE ); } if ( ! use_stdout ) { FILE *prev_stdout = freopen( outfile, "w", stdout ); if ( prev_stdout == NULL ) lerrsf( "could not create %s", outfile ); outfile_created = 1; } num_input_files = argc; input_files = argv; set_input_file( num_input_files > 0 ? input_files[0] : NULL ); if ( backtrack_report ) { #ifndef SHORT_FILE_NAMES backtrack_file = fopen( "lex.backtrack", "w" ); #else backtrack_file = fopen( "lex.bck", "w" ); #endif if ( backtrack_file == NULL ) flexerror( "could not create lex.backtrack" ); } else backtrack_file = NULL; lastccl = 0; lastsc = 0; /* initialize the statistics */ starttime = flex_gettime(); if ( (skelfile = fopen( skelname, "r" )) == NULL ) lerrsf( "can't open skeleton file %s", skelname ); #ifdef SYS_V action_file_name = tmpnam( NULL ); #endif if ( action_file_name == NULL ) { static char temp_action_file_name[32]; #ifndef SHORT_FILE_NAMES (void) strcpy( temp_action_file_name, "/tmp/flexXXXXXX" ); #else (void) strcpy( temp_action_file_name, "flexXXXXXX.tmp" ); #endif (void) mktemp( temp_action_file_name ); action_file_name = temp_action_file_name; } if ( (temp_action_file = fopen( action_file_name, "w" )) == NULL ) lerrsf( "can't open temporary action file %s", action_file_name ); lastdfa = lastnfa = num_rules = numas = numsnpairs = tmpuses = 0; numecs = numeps = eps2 = num_reallocs = hshcol = dfaeql = totnst = 0; numuniq = numdup = hshsave = eofseen = datapos = dataline = 0; num_backtracking = onesp = numprots = 0; variable_trailing_context_rules = bol_needed = false; linenum = sectnum = 1; firstprot = NIL; /* used in mkprot() so that the first proto goes in slot 1 * of the proto queue */ lastprot = 1; if ( useecs ) { /* set up doubly-linked equivalence classes */ /* We loop all the way up to csize, since ecgroup[csize] is the * position used for NUL characters */ ecgroup[1] = NIL; for ( i = 2; i <= csize; ++i ) { ecgroup[i] = i - 1; nextecm[i - 1] = i; } nextecm[csize] = NIL; } else { /* put everything in its own equivalence class */ for ( i = 1; i <= csize; ++i ) { ecgroup[i] = i; nextecm[i] = BAD_SUBSCRIPT; /* to catch errors */ } } set_up_initial_allocations(); } /* readin - read in the rules section of the input file(s) * * synopsis * readin(); */ void readin() { skelout(); if ( ddebug ) puts( "#define FLEX_DEBUG" ); if ( csize == 256 ) puts( "#define YY_CHAR unsigned char" ); else puts( "#define YY_CHAR char" ); line_directive_out( stdout ); if ( yyparse() ) { pinpoint_message( "fatal parse error" ); flexend( 1 ); } if ( xlation ) { numecs = ecs_from_xlation( ecgroup ); useecs = true; } else if ( useecs ) numecs = cre8ecs( nextecm, ecgroup, csize ); else numecs = csize; /* now map the equivalence class for NUL to its expected place */ ecgroup[0] = ecgroup[csize]; NUL_ec = abs( ecgroup[0] ); if ( useecs ) ccl2ecl(); } /* set_up_initial_allocations - allocate memory for internal tables */ void set_up_initial_allocations() { current_mns = INITIAL_MNS; firstst = allocate_integer_array( current_mns ); lastst = allocate_integer_array( current_mns ); finalst = allocate_integer_array( current_mns ); transchar = allocate_integer_array( current_mns ); trans1 = allocate_integer_array( current_mns ); trans2 = allocate_integer_array( current_mns ); accptnum = allocate_integer_array( current_mns ); assoc_rule = allocate_integer_array( current_mns ); state_type = allocate_integer_array( current_mns ); current_max_rules = INITIAL_MAX_RULES; rule_type = allocate_integer_array( current_max_rules ); rule_linenum = allocate_integer_array( current_max_rules ); current_max_scs = INITIAL_MAX_SCS; scset = allocate_integer_array( current_max_scs ); scbol = allocate_integer_array( current_max_scs ); scxclu = allocate_integer_array( current_max_scs ); sceof = allocate_integer_array( current_max_scs ); scname = allocate_char_ptr_array( current_max_scs ); actvsc = allocate_integer_array( current_max_scs ); current_maxccls = INITIAL_MAX_CCLS; cclmap = allocate_integer_array( current_maxccls ); ccllen = allocate_integer_array( current_maxccls ); cclng = allocate_integer_array( current_maxccls ); current_max_ccl_tbl_size = INITIAL_MAX_CCL_TBL_SIZE; ccltbl = allocate_character_array( current_max_ccl_tbl_size ); current_max_dfa_size = INITIAL_MAX_DFA_SIZE; current_max_xpairs = INITIAL_MAX_XPAIRS; nxt = allocate_integer_array( current_max_xpairs ); chk = allocate_integer_array( current_max_xpairs ); current_max_template_xpairs = INITIAL_MAX_TEMPLATE_XPAIRS; tnxt = allocate_integer_array( current_max_template_xpairs ); current_max_dfas = INITIAL_MAX_DFAS; base = allocate_integer_array( current_max_dfas ); def = allocate_integer_array( current_max_dfas ); dfasiz = allocate_integer_array( current_max_dfas ); accsiz = allocate_integer_array( current_max_dfas ); dhash = allocate_integer_array( current_max_dfas ); dss = allocate_int_ptr_array( current_max_dfas ); dfaacc = allocate_dfaacc_union( current_max_dfas ); nultrans = (int *) 0; }
230e4067f06bb25bbb084d8e37f4b9988dea2d00
f8cc1dd4b1378490386def2e0571561fab10b275
/src/libenvexec/envdir_noclamp.c
f0e6796992e379954414ff378365d8e528bc3f6b
[ "ISC" ]
permissive
skarnet/skalibs
b1eb2a0e38663cbfa918ee0a7916f56227bd7c2d
1f2d5f95684e93f8523e369ef1fed7a75c444082
refs/heads/master
2023-08-23T07:33:20.996016
2023-08-08T09:39:15
2023-08-08T09:39:15
31,461,366
104
32
ISC
2021-04-11T10:10:54
2015-02-28T12:01:41
C
UTF-8
C
false
false
2,532
c
envdir_noclamp.c
/* ISC license. */ #include <unistd.h> #include <string.h> #include <errno.h> #include <skalibs/bytestr.h> #include <skalibs/buffer.h> #include <skalibs/env.h> #include <skalibs/direntry.h> #include <skalibs/stralloc.h> #include <skalibs/djbunix.h> #include <skalibs/skamisc.h> #include "envdir-internal.h" #define N 4096 int envdir_internal_noclamp (char const *path, stralloc *modifs, unsigned int options, char nullis) { unsigned int n = 0 ; size_t pathlen = strlen(path) ; size_t modifbase = modifs->len ; int wasnull = !modifs->s ; int fd ; DIR *dir = opendir(path) ; if (!dir) return -1 ; for (;;) { direntry *d ; size_t len, pos ; errno = 0 ; d = readdir(dir) ; if (!d) break ; if (d->d_name[0] == '.') continue ; len = strlen(d->d_name) ; if (str_chr(d->d_name, '=') < len) continue ; { char tmp[pathlen + len + 2] ; memcpy(tmp, path, pathlen) ; tmp[pathlen] = '/' ; memcpy(tmp + pathlen + 1, d->d_name, len + 1) ; fd = openc_readb(tmp) ; } if (fd < 0) { if (errno == ENOENT) errno = EIDRM ; goto err ; } if (!stralloc_catb(modifs, d->d_name, len) || !stralloc_catb(modifs, "=", 1)) goto errfd ; pos = modifs->len ; if (options & SKALIBS_ENVDIR_VERBATIM) { if (!slurp(modifs, fd)) goto errfd ; if (modifs->len == pos) modifs->len = pos - 1 ; if (!(options & SKALIBS_ENVDIR_NOCHOMP) && (modifs->s[modifs->len - 1] == '\n')) modifs->len-- ; } else { int r ; char buf[N] ; buffer b = BUFFER_INIT(&buffer_read, fd, buf, N) ; r = skagetln(&b, modifs, '\n') ; if (r == -1) { if (errno != EPIPE) goto errfd ; if (!(options & SKALIBS_ENVDIR_NOCHOMP)) modifs->len = pos ; modifs->len++ ; } if (!r) modifs->len = pos - 1 ; else { modifs->len-- ; if (!(options & SKALIBS_ENVDIR_NOCHOMP)) { while (modifs->len-- > pos) { char c = modifs->s[modifs->len] ; if ((c != ' ') && (c != '\t') && (c != '\r')) break ; } modifs->len++ ; } } } fd_close(fd) ; for (; pos < modifs->len ; pos++) if (!modifs->s[pos]) modifs->s[pos] = nullis ; if (!stralloc_0(modifs)) goto err ; n++ ; } if (errno) goto err ; dir_close(dir) ; return n ; errfd: fd_close(fd) ; err: dir_close(dir) ; if (wasnull) stralloc_free(modifs) ; else modifs->len = modifbase ; return -1 ; }
c0626da77dde585dc555f0ead0b1f88b07ab187a
8149d6751e142ecbc200b43c2da2d5a94c0735df
/test/mock/cert.c
de8bb3f51c9697366be0f6178ba531e4728c9663
[ "BSD-3-Clause" ]
permissive
baresip/baresip
3c8ebef031f6a01a1462a9f36264197f90ce6ffe
5ace2f75b317bba60d46030ca3fd5e8fa045fecf
refs/heads/main
2023-08-25T12:55:24.860248
2023-08-17T06:56:31
2023-08-17T06:56:31
16,664,594
834
205
BSD-3-Clause
2023-09-14T12:47:57
2014-02-09T10:44:09
C
UTF-8
C
false
false
1,548
c
cert.c
/** * @file cert.c TLS Certificate * * Copyright (C) 2010 Alfred E. Heggestad */ #include <re.h> #include "../test.h" /** * X509/PEM certificate with ECDSA keypair * * $ openssl ecparam -out ec_key.pem -name prime256v1 -genkey * $ openssl req -new -key ec_key.pem -x509 -nodes -days 3650 -out cert.pem */ const char test_certificate[] = "-----BEGIN CERTIFICATE-----\r\n" "MIICBzCCAa2gAwIBAgIUZy0UqzsDq7fGUsZh6QxkXgCa030wCgYIKoZIzj0EAwIw\r\n" "WTELMAkGA1UEBhMCTk8xEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGElu\r\n" "dGVybmV0IFdpZGdpdHMgUHR5IEx0ZDESMBAGA1UEAwwJMTI3LjAuMC4xMB4XDTE5\r\n" "MDUyNDE5NTM0OFoXDTI5MDUyMTE5NTM0OFowWTELMAkGA1UEBhMCTk8xEzARBgNV\r\n" "BAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0\r\n" "ZDESMBAGA1UEAwwJMTI3LjAuMC4xMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE\r\n" "inP/oBEqBbXRxDzyk7sbh8rRJbfbXBRG2uJl2g6YhSkYZkifGyEueJ7+A9D9LfBh\r\n" "b5+lKXuJc02XQW5IwUmToqNTMFEwHQYDVR0OBBYEFH1vSH2IBZvKYNDPfPOk41Dw\r\n" "hyTWMB8GA1UdIwQYMBaAFH1vSH2IBZvKYNDPfPOk41DwhyTWMA8GA1UdEwEB/wQF\r\n" "MAMBAf8wCgYIKoZIzj0EAwIDSAAwRQIhAOm79QetPxioy/S0Rk9lhPgfBslgM6f4\r\n" "tihVBSpe0FdJAiAC6Usj7p3H8dvu9Oa1gtOXSJkh1MT6pkfW21YseRWP4A==\r\n" "-----END CERTIFICATE-----\r\n" "-----BEGIN EC PARAMETERS-----\r\n" "BggqhkjOPQMBBw==\r\n" "-----END EC PARAMETERS-----\r\n" "-----BEGIN EC PRIVATE KEY-----\r\n" "MHcCAQEEIMWTO9/z24fiq13MM5UF1CVD3yJjVXRe0qpTCmmZU5ppoAoGCCqGSM49\r\n" "AwEHoUQDQgAEinP/oBEqBbXRxDzyk7sbh8rRJbfbXBRG2uJl2g6YhSkYZkifGyEu\r\n" "eJ7+A9D9LfBhb5+lKXuJc02XQW5IwUmTog==\r\n" "-----END EC PRIVATE KEY-----\r\n" ;
fd1559f2f753057294ae9eb7e216dce596bffcd1
79d343002bb63a44f8ab0dbac0c9f4ec54078c3a
/lib/libc/musl/include/spawn.h
8eb73e003a65e3cb40abdc3c47371084522b9864
[ "MIT", "BSD-3-Clause", "LicenseRef-scancode-public-domain", "BSD-2-Clause", "LicenseRef-scancode-other-permissive", "LicenseRef-scancode-musl-exception" ]
permissive
ziglang/zig
4aa75d8d3bcc9e39bf61d265fd84b7f005623fc5
f4c9e19bc3213c2bc7e03d7b06d7129882f39f6c
refs/heads/master
2023-08-31T13:16:45.980913
2023-08-31T05:50:29
2023-08-31T05:50:29
40,276,274
25,560
2,399
MIT
2023-09-14T21:09:50
2015-08-06T00:51:28
Zig
UTF-8
C
false
false
2,913
h
spawn.h
#ifndef _SPAWN_H #define _SPAWN_H #ifdef __cplusplus extern "C" { #endif #include <features.h> #define __NEED_mode_t #define __NEED_pid_t #define __NEED_sigset_t #include <bits/alltypes.h> struct sched_param; #define POSIX_SPAWN_RESETIDS 1 #define POSIX_SPAWN_SETPGROUP 2 #define POSIX_SPAWN_SETSIGDEF 4 #define POSIX_SPAWN_SETSIGMASK 8 #define POSIX_SPAWN_SETSCHEDPARAM 16 #define POSIX_SPAWN_SETSCHEDULER 32 #define POSIX_SPAWN_USEVFORK 64 #define POSIX_SPAWN_SETSID 128 typedef struct { int __flags; pid_t __pgrp; sigset_t __def, __mask; int __prio, __pol; void *__fn; char __pad[64-sizeof(void *)]; } posix_spawnattr_t; typedef struct { int __pad0[2]; void *__actions; int __pad[16]; } posix_spawn_file_actions_t; int posix_spawn(pid_t *__restrict, const char *__restrict, const posix_spawn_file_actions_t *, const posix_spawnattr_t *__restrict, char *const *__restrict, char *const *__restrict); int posix_spawnp(pid_t *__restrict, const char *__restrict, const posix_spawn_file_actions_t *, const posix_spawnattr_t *__restrict, char *const *__restrict, char *const *__restrict); int posix_spawnattr_init(posix_spawnattr_t *); int posix_spawnattr_destroy(posix_spawnattr_t *); int posix_spawnattr_setflags(posix_spawnattr_t *, short); int posix_spawnattr_getflags(const posix_spawnattr_t *__restrict, short *__restrict); int posix_spawnattr_setpgroup(posix_spawnattr_t *, pid_t); int posix_spawnattr_getpgroup(const posix_spawnattr_t *__restrict, pid_t *__restrict); int posix_spawnattr_setsigmask(posix_spawnattr_t *__restrict, const sigset_t *__restrict); int posix_spawnattr_getsigmask(const posix_spawnattr_t *__restrict, sigset_t *__restrict); int posix_spawnattr_setsigdefault(posix_spawnattr_t *__restrict, const sigset_t *__restrict); int posix_spawnattr_getsigdefault(const posix_spawnattr_t *__restrict, sigset_t *__restrict); int posix_spawnattr_setschedparam(posix_spawnattr_t *__restrict, const struct sched_param *__restrict); int posix_spawnattr_getschedparam(const posix_spawnattr_t *__restrict, struct sched_param *__restrict); int posix_spawnattr_setschedpolicy(posix_spawnattr_t *, int); int posix_spawnattr_getschedpolicy(const posix_spawnattr_t *__restrict, int *__restrict); int posix_spawn_file_actions_init(posix_spawn_file_actions_t *); int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *); int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *__restrict, int, const char *__restrict, int, mode_t); int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *, int); int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *, int, int); #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) int posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t *__restrict, const char *__restrict); int posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t *, int); #endif #ifdef __cplusplus } #endif #endif
230d021cdc28b2fd43ba00ac688424198531c802
505585f1d89447adea3f9519f12255602acdb1b2
/examples/idas/serial/idasRoberts_FSA_sps.c
108d997d5b2359b0e50c4ff24b1746970d6dde6a
[ "BSD-3-Clause" ]
permissive
LLNL/sundials
11a879f8c8e7a5e40d78d13d0f9baed04d37a280
1ea097bb3bce207335ac35f0b5e78df5d71c6409
refs/heads/main
2023-08-31T12:36:23.500757
2023-07-20T16:50:46
2023-07-20T16:50:46
105,918,649
396
120
BSD-3-Clause
2023-09-14T20:38:05
2017-10-05T17:20:03
C
UTF-8
C
false
false
25,910
c
idasRoberts_FSA_sps.c
/* ----------------------------------------------------------------- * Programmer(s): Ting Yan @ SMU * Based on idasRoberts_FSA_dns.c and modified to use SuperLUMT * ----------------------------------------------------------------- * SUNDIALS Copyright Start * Copyright (c) 2002-2023, Lawrence Livermore National Security * and Southern Methodist University. * All rights reserved. * * See the top-level LICENSE and NOTICE files for details. * * SPDX-License-Identifier: BSD-3-Clause * SUNDIALS Copyright End * ----------------------------------------------------------------- * Example problem: * * This simple example problem for IDA, due to Robertson, * is from chemical kinetics, and consists of the following three * equations: * * dy1/dt = -p1*y1 + p2*y2*y3 * dy2/dt = p1*y1 - p2*y2*y3 - p3*y2**2 * 0 = y1 + y2 + y3 - 1 * * on the interval from t = 0.0 to t = 4.e10, with initial * conditions: y1 = 1, y2 = y3 = 0.The reaction rates are: p1=0.04, * p2=1e4, and p3=3e7 * * Optionally, IDAS can compute sensitivities with respect to the * problem parameters p1, p2, and p3. * The sensitivity right hand side is given analytically through the * user routine fS (of type SensRhs1Fn). * Any of two sensitivity methods (SIMULTANEOUS and STAGGERED can be * used and sensitivities may be included in the error test or not *(error control set on SUNTRUE or SUNFALSE, respectively). * * Execution: * * If no sensitivities are desired: * % idasRoberts_FSA_sps -nosensi * If sensitivities are to be computed: * % idasRoberts_FSA_sps -sensi sensi_meth err_con * where sensi_meth is one of {sim, stg} and err_con is one of * {t, f}. * -----------------------------------------------------------------*/ #include <stdio.h> #include <stdlib.h> #include <string.h> /* Header files with a description of contents used */ #include <idas/idas.h> /* prototypes for IDA fcts., consts. */ #include <nvector/nvector_serial.h> /* access to serial N_Vector */ #include <sunmatrix/sunmatrix_sparse.h> /* access to sparse SUNMatrix */ #include <sunlinsol/sunlinsol_superlumt.h> /* access to SuperLUMT linear solver */ #include <sundials/sundials_types.h> /* defs. of realtype, sunindextype */ #include <sundials/sundials_math.h> /* defs. of SUNRabs, SUNRexp, etc. */ /* Accessor macros */ #define Ith(v,i) NV_Ith_S(v,i-1) /* i-th vector component i=1..NEQ */ /* Problem Constants */ #define NEQ 3 /* number of equations */ #define T0 RCONST(0.0) /* initial time */ #define T1 RCONST(0.4) /* first output time */ #define TMULT RCONST(10.0) /* output time factor */ #define NOUT 12 /* number of output times */ #define NP 3 /* number of problem parameters */ #define NS 3 /* number of sensitivities computed */ #define ZERO RCONST(0.0) #define ONE RCONST(1.0) /* Type : UserData */ typedef struct { realtype p[3]; /* problem parameters */ realtype coef; } *UserData; /* Prototypes of functions by IDAS */ static int res(realtype t, N_Vector y, N_Vector yp, N_Vector resval, void *user_data); static int Jac(realtype t, realtype cj, N_Vector yy, N_Vector yp, N_Vector resvec, SUNMatrix JJ, void *user_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3); static int resS(int Ns, realtype t, N_Vector y, N_Vector yp, N_Vector resval, N_Vector *yyS, N_Vector *ypS, N_Vector *resvalS, void *user_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3); static int rhsQ(realtype tres, N_Vector yy, N_Vector yp, N_Vector rrQ, void *user_data); /* Prototypes of private functions */ static void ProcessArgs(int argc, char *argv[], booleantype *sensi, int *sensi_meth, booleantype *err_con); static void WrongArgs(char *name); static void PrintIC(N_Vector y, N_Vector yp); static void PrintSensIC(N_Vector y, N_Vector yp, N_Vector* yS, N_Vector* ypS); static void PrintOutput(void *ida_mem, realtype t, N_Vector u); static void PrintSensOutput(N_Vector *uS); static void PrintFinalStats(void *ida_mem, booleantype sensi); static int check_retval(void *returnvalue, char *funcname, int opt); /* *-------------------------------------------------------------------- * MAIN PROGRAM *-------------------------------------------------------------------- */ int main(int argc, char *argv[]) { SUNContext ctx; void *ida_mem; SUNMatrix A; SUNLinearSolver LS; UserData data; realtype reltol, t, tout; N_Vector y, yp, abstol, id; int iout, retval, nthreads, nnz; realtype pbar[NS]; int is; N_Vector *yS, *ypS; booleantype sensi, err_con; int sensi_meth; N_Vector yQ, *yQS; ida_mem = NULL; data = NULL; y = NULL; yS = NULL; ypS = NULL; A = NULL; LS = NULL; /* Process arguments */ ProcessArgs(argc, argv, &sensi, &sensi_meth, &err_con); /* Create the SUNDIALS context object for this simulation */ retval = SUNContext_Create(NULL, &ctx); if (check_retval(&retval, "SUNContext_Create", 1)) return 1; /* User data structure */ data = (UserData) malloc(sizeof *data); if (check_retval((void *)data, "malloc", 2)) return(1); data->p[0] = RCONST(0.040); data->p[1] = RCONST(1.0e4); data->p[2] = RCONST(3.0e7); data->coef = RCONST(0.5); /* Initial conditions */ y = N_VNew_Serial(NEQ, ctx); if (check_retval((void *)y, "N_VNew_Serial", 0)) return(1); Ith(y,1) = ONE; Ith(y,2) = ZERO; Ith(y,3) = ZERO; yp = N_VClone(y); if(check_retval((void *)yp, "N_VNew_Serial", 0)) return(1); /* These initial conditions are NOT consistent. See IDACalcIC below. */ Ith(yp,1) = RCONST(0.1); Ith(yp,2) = ZERO; Ith(yp,3) = ZERO; /* Create IDAS object */ ida_mem = IDACreate(ctx); if (check_retval((void *)ida_mem, "IDACreate", 0)) return(1); /* Allocate space for IDAS */ retval = IDAInit(ida_mem, res, T0, y, yp); if (check_retval(&retval, "IDAInit", 1)) return(1); /* Specify scalar relative tol. and vector absolute tol. */ reltol = RCONST(1.0e-6); abstol = N_VClone(y); Ith(abstol,1) = RCONST(1.0e-8); Ith(abstol,2) = RCONST(1.0e-14); Ith(abstol,3) = RCONST(1.0e-6); retval = IDASVtolerances(ida_mem, reltol, abstol); if (check_retval(&retval, "IDASVtolerances", 1)) return(1); /* Set ID vector */ id = N_VClone(y); Ith(id,1) = 1.0; Ith(id,2) = 1.0; Ith(id,3) = 0.0; retval = IDASetId(ida_mem, id); if (check_retval(&retval, "IDASetId", 1)) return(1); /* Attach user data */ retval = IDASetUserData(ida_mem, data); if (check_retval(&retval, "IDASetUserData", 1)) return(1); /* Create sparse SUNMatrix for use in linear solves */ nnz = NEQ * NEQ; A = SUNSparseMatrix(NEQ, NEQ, nnz, CSC_MAT, ctx); if(check_retval((void *)A, "SUNSparseMatrix", 0)) return(1); /* Create SuperLUMT SUNLinearSolver object (one thread) */ nthreads = 1; LS = SUNLinSol_SuperLUMT(y, A, nthreads, ctx); if(check_retval((void *)LS, "SUNLinSol_SuperLUMT", 0)) return(1); /* Attach the matrix and linear solver */ retval = IDASetLinearSolver(ida_mem, LS, A); if(check_retval(&retval, "IDASetLinearSolver", 1)) return(1); /* Set the user-supplied Jacobian routine */ retval = IDASetJacFn(ida_mem, Jac); if(check_retval(&retval, "IDASetJacFn", 1)) return(1); printf("\n3-species chemical kinetics problem\n"); /* Sensitivity-related settings */ if (sensi) { pbar[0] = data->p[0]; pbar[1] = data->p[1]; pbar[2] = data->p[2]; yS = N_VCloneVectorArray(NS, y); if (check_retval((void *)yS, "N_VCloneVectorArray", 0)) return(1); for (is=0;is<NS;is++) N_VConst(ZERO, yS[is]); ypS = N_VCloneVectorArray(NS, y); if (check_retval((void *)ypS, "N_VCloneVectorArray", 0)) return(1); for (is=0;is<NS;is++) N_VConst(ZERO, ypS[is]); /* * Only non-zero sensitivity I.C. are ypS[0]: * - Ith(ypS[0],1) = -ONE; * - Ith(ypS[0],2) = ONE; * * They are not set. IDACalcIC also computes consistent IC for sensitivities. */ retval = IDASensInit(ida_mem, NS, sensi_meth, resS, yS, ypS); if(check_retval(&retval, "IDASensInit", 1)) return(1); retval = IDASensEEtolerances(ida_mem); if(check_retval(&retval, "IDASensEEtolerances", 1)) return(1); retval = IDASetSensErrCon(ida_mem, err_con); if (check_retval(&retval, "IDASetSensErrCon", 1)) return(1); retval = IDASetSensParams(ida_mem, data->p, pbar, NULL); if (check_retval(&retval, "IDASetSensParams", 1)) return(1); printf("Sensitivity: YES "); if(sensi_meth == IDA_SIMULTANEOUS) printf("( SIMULTANEOUS +"); else printf("( STAGGERED +"); if(err_con) printf(" FULL ERROR CONTROL )"); else printf(" PARTIAL ERROR CONTROL )"); } else { printf("Sensitivity: NO "); } /*---------------------------------------------------------- * Q U A D R A T U R E S * ---------------------------------------------------------*/ yQ = N_VNew_Serial(2, ctx); Ith(yQ,1) = 0; Ith(yQ,2) = 0; IDAQuadInit(ida_mem, rhsQ, yQ); yQS = N_VCloneVectorArray(NS, yQ); for (is=0;is<NS;is++) N_VConst(ZERO, yQS[is]); IDAQuadSensInit(ida_mem, NULL, yQS); /* Call IDACalcIC to compute consistent initial conditions. If sensitivity is enabled, this function also try to find consistent IC for the sensitivities. */ retval = IDACalcIC(ida_mem, IDA_YA_YDP_INIT, T1);; if (check_retval(&retval, "IDACalcIC", 1)) return(1); retval = IDAGetConsistentIC(ida_mem, y, yp); if (check_retval(&retval, "IDAGetConsistentIC", 1)) return(1); PrintIC(y, yp); if(sensi) { IDAGetSensConsistentIC(ida_mem, yS, ypS); PrintSensIC(y, yp, yS, ypS); } /* In loop over output points, call IDA, print results, test for error */ printf("\n\n"); printf("==========================================="); printf("============================\n"); printf(" T Q H NST y1"); printf(" y2 y3 \n"); printf("==========================================="); printf("============================\n"); for (iout=1, tout=T1; iout <= NOUT; iout++, tout *= TMULT) { retval = IDASolve(ida_mem, tout, &t, y, yp, IDA_NORMAL); if (check_retval(&retval, "IDASolve", 1)) break; PrintOutput(ida_mem, t, y); if (sensi) { retval = IDAGetSens(ida_mem, &t, yS); if (check_retval(&retval, "IDAGetSens", 1)) break; PrintSensOutput(yS); } printf("-----------------------------------------"); printf("------------------------------\n"); } printf("\nQuadrature:\n"); IDAGetQuad(ida_mem, &t, yQ); #if defined(SUNDIALS_EXTENDED_PRECISION) printf("G: %10.4Le\n", Ith(yQ,1)); #else printf("G: %10.4e\n", Ith(yQ,1)); #endif if(sensi) { IDAGetQuadSens(ida_mem, &t, yQS); #if defined(SUNDIALS_EXTENDED_PRECISION) printf("\nSensitivities at t=%Lg:\n",t); printf("dG/dp1: %11.4Le\n", Ith(yQS[0], 1)); printf("dG/dp1: %11.4Le\n", Ith(yQS[1], 1)); printf("dG/dp1: %11.4Le\n", Ith(yQS[2], 1)); #else printf("\nSensitivities at t=%g:\n",t); printf("dG/dp1: %11.4e\n", Ith(yQS[0], 1)); printf("dG/dp1: %11.4e\n", Ith(yQS[1], 1)); printf("dG/dp1: %11.4e\n", Ith(yQS[2], 1)); #endif } /* Print final statistics */ PrintFinalStats(ida_mem, sensi); /* Free memory */ N_VDestroy(y); N_VDestroy(yp); N_VDestroy(abstol); N_VDestroy(id); if (sensi) { N_VDestroyVectorArray(yS, NS); N_VDestroyVectorArray(ypS, NS); } free(data); IDAFree(&ida_mem); SUNLinSolFree(LS); SUNMatDestroy(A); N_VDestroy(yQ); N_VDestroyVectorArray(yQS, NS); SUNContext_Free(&ctx); return(0); } /* *-------------------------------------------------------------------- * FUNCTIONS CALLED BY IDAS *-------------------------------------------------------------------- */ /* * Residual routine. Compute F(t,y,y',p). */ static int res(realtype t, N_Vector yy, N_Vector yp, N_Vector resval, void *user_data) { UserData data; realtype p1, p2, p3; realtype y1, y2, y3; realtype yp1, yp2; data = (UserData) user_data; p1 = data->p[0]; p2 = data->p[1]; p3 = data->p[2]; y1 = Ith(yy,1); y2 = Ith(yy,2); y3 = Ith(yy,3); yp1 = Ith(yp,1); yp2 = Ith(yp,2); Ith(resval,1) = yp1 + p1*y1 - p2*y2*y3; Ith(resval,2) = yp2 - p1*y1 + p2*y2*y3 + p3*y2*y2; Ith(resval,3) = y1 + y2 + y3 - ONE; return(0); } /* * Jacobian routine. Compute J(t,y). */ static int Jac(realtype t, realtype cj, N_Vector yy, N_Vector yp, N_Vector resvec, SUNMatrix JJ, void *user_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3) { realtype *yval; sunindextype *colptrs = SUNSparseMatrix_IndexPointers(JJ); sunindextype *rowvals = SUNSparseMatrix_IndexValues(JJ); realtype *data = SUNSparseMatrix_Data(JJ); UserData userdata; realtype p1, p2, p3; yval = N_VGetArrayPointer(yy); userdata = (UserData) user_data; p1 = userdata->p[0]; p2 = userdata->p[1]; p3 = userdata->p[2]; SUNMatZero(JJ); colptrs[0] = 0; colptrs[1] = 3; colptrs[2] = 6; colptrs[3] = 9; data[0] = p1+cj; rowvals[0] = 0; data[1] = -p1; rowvals[1] = 1; data[2] = ONE; rowvals[2] = 2; data[3] = -p2*yval[2]; rowvals[3] = 0; data[4] = p2*yval[2]+2*p3*yval[1]+cj; rowvals[4] = 1; data[5] = ONE; rowvals[5] = 2; data[6] = -p2*yval[1]; rowvals[6] = 0; data[7] = p2*yval[1]; rowvals[7] = 1; data[8] = ONE; rowvals[8] = 2; return(0); } /* * resS routine. Compute sensitivity r.h.s. */ static int resS(int Ns, realtype t, N_Vector yy, N_Vector yp, N_Vector resval, N_Vector *yyS, N_Vector *ypS, N_Vector *resvalS, void *user_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3) { UserData data; realtype p1, p2, p3; realtype y1, y2, y3; realtype s1, s2, s3; realtype sd1, sd2; realtype rs1, rs2, rs3; int is; data = (UserData) user_data; p1 = data->p[0]; p2 = data->p[1]; p3 = data->p[2]; y1 = Ith(yy,1); y2 = Ith(yy,2); y3 = Ith(yy,3); for (is=0; is<NS; is++) { s1 = Ith(yyS[is],1); s2 = Ith(yyS[is],2); s3 = Ith(yyS[is],3); sd1 = Ith(ypS[is],1); sd2 = Ith(ypS[is],2); rs1 = sd1 + p1*s1 - p2*y3*s2 - p2*y2*s3; rs2 = sd2 - p1*s1 + p2*y3*s2 + p2*y2*s3 + 2*p3*y2*s2; rs3 = s1 + s2 + s3; switch (is) { case 0: rs1 += y1; rs2 -= y1; break; case 1: rs1 -= y2*y3; rs2 += y2*y3; break; case 2: rs2 += y2*y2; break; } Ith(resvalS[is],1) = rs1; Ith(resvalS[is],2) = rs2; Ith(resvalS[is],3) = rs3; } return(0); } static int rhsQ(realtype t, N_Vector y, N_Vector yp, N_Vector ypQ, void* user_data) { UserData data; data = (UserData) user_data; Ith(ypQ,1) = Ith(y,3); Ith(ypQ,2) = data->coef*( Ith(y,1)*Ith(y,1)+ Ith(y,2)*Ith(y,2)+ Ith(y,3)*Ith(y,3) ); return(0); } /* *-------------------------------------------------------------------- * PRIVATE FUNCTIONS *-------------------------------------------------------------------- */ /* * Process and verify arguments to idasfwddenx. */ static void ProcessArgs(int argc, char *argv[], booleantype *sensi, int *sensi_meth, booleantype *err_con) { *sensi = SUNFALSE; *sensi_meth = -1; *err_con = SUNFALSE; if (argc < 2) WrongArgs(argv[0]); if (strcmp(argv[1],"-nosensi") == 0) *sensi = SUNFALSE; else if (strcmp(argv[1],"-sensi") == 0) *sensi = SUNTRUE; else WrongArgs(argv[0]); if (*sensi) { if (argc != 4) WrongArgs(argv[0]); if (strcmp(argv[2],"sim") == 0) *sensi_meth = IDA_SIMULTANEOUS; else if (strcmp(argv[2],"stg") == 0) *sensi_meth = IDA_STAGGERED; else WrongArgs(argv[0]); if (strcmp(argv[3],"t") == 0) *err_con = SUNTRUE; else if (strcmp(argv[3],"f") == 0) *err_con = SUNFALSE; else WrongArgs(argv[0]); } } static void WrongArgs(char *name) { printf("\nUsage: %s [-nosensi] [-sensi sensi_meth err_con]\n",name); printf(" sensi_meth = sim or stg\n"); printf(" err_con = t or f\n"); exit(0); } static void PrintIC(N_Vector y, N_Vector yp) { realtype* data; data = N_VGetArrayPointer(y); printf("\n\nConsistent IC:\n"); printf("\ty = "); #if defined(SUNDIALS_EXTENDED_PRECISION) printf("%12.4Le %12.4Le %12.4Le \n", data[0], data[1], data[2]); #elif defined(SUNDIALS_DOUBLE_PRECISION) printf("%12.4e %12.4e %12.4e \n", data[0], data[1], data[2]); #else printf("%12.4e %12.4e %12.4e \n", data[0], data[1], data[2]); #endif data = N_VGetArrayPointer(yp); printf("\typ= "); #if defined(SUNDIALS_EXTENDED_PRECISION) printf("%12.4Le %12.4Le %12.4Le \n", data[0], data[1], data[2]); #elif defined(SUNDIALS_DOUBLE_PRECISION) printf("%12.4e %12.4e %12.4e \n", data[0], data[1], data[2]); #else printf("%12.4e %12.4e %12.4e \n", data[0], data[1], data[2]); #endif } static void PrintSensIC(N_Vector y, N_Vector yp, N_Vector* yS, N_Vector* ypS) { realtype *sdata; sdata = N_VGetArrayPointer(yS[0]); printf(" Sensitivity 1 "); printf("\n\ts1 = "); #if defined(SUNDIALS_EXTENDED_PRECISION) printf("%12.4Le %12.4Le %12.4Le \n", sdata[0], sdata[1], sdata[2]); #elif defined(SUNDIALS_DOUBLE_PRECISION) printf("%12.4e %12.4e %12.4e \n", sdata[0], sdata[1], sdata[2]); #else printf("%12.4e %12.4e %12.4e \n", sdata[0], sdata[1], sdata[2]); #endif sdata = N_VGetArrayPointer(ypS[0]); printf("\ts1'= "); #if defined(SUNDIALS_EXTENDED_PRECISION) printf("%12.4Le %12.4Le %12.4Le \n", sdata[0], sdata[1], sdata[2]); #elif defined(SUNDIALS_DOUBLE_PRECISION) printf("%12.4e %12.4e %12.4e \n", sdata[0], sdata[1], sdata[2]); #else printf("%12.4e %12.4e %12.4e \n", sdata[0], sdata[1], sdata[2]); #endif printf(" Sensitivity 2 "); sdata = N_VGetArrayPointer(yS[1]); printf("\n\ts2 = "); #if defined(SUNDIALS_EXTENDED_PRECISION) printf("%12.4Le %12.4Le %12.4Le \n", sdata[0], sdata[1], sdata[2]); #elif defined(SUNDIALS_DOUBLE_PRECISION) printf("%12.4e %12.4e %12.4e \n", sdata[0], sdata[1], sdata[2]); #else printf("%12.4e %12.4e %12.4e \n", sdata[0], sdata[1], sdata[2]); #endif sdata = N_VGetArrayPointer(ypS[1]); printf("\ts2'= "); #if defined(SUNDIALS_EXTENDED_PRECISION) printf("%12.4Le %12.4Le %12.4Le \n", sdata[0], sdata[1], sdata[2]); #elif defined(SUNDIALS_DOUBLE_PRECISION) printf("%12.4e %12.4e %12.4e \n", sdata[0], sdata[1], sdata[2]); #else printf("%12.4e %12.4e %12.4e \n", sdata[0], sdata[1], sdata[2]); #endif printf(" Sensitivity 3 "); sdata = N_VGetArrayPointer(yS[2]); printf("\n\ts3 = "); #if defined(SUNDIALS_EXTENDED_PRECISION) printf("%12.4Le %12.4Le %12.4Le \n", sdata[0], sdata[1], sdata[2]); #elif defined(SUNDIALS_DOUBLE_PRECISION) printf("%12.4e %12.4e %12.4e \n", sdata[0], sdata[1], sdata[2]); #else printf("%12.4e %12.4e %12.4e \n", sdata[0], sdata[1], sdata[2]); #endif sdata = N_VGetArrayPointer(ypS[2]); printf("\ts3'= "); #if defined(SUNDIALS_EXTENDED_PRECISION) printf("%12.4Le %12.4Le %12.4Le \n", sdata[0], sdata[1], sdata[2]); #elif defined(SUNDIALS_DOUBLE_PRECISION) printf("%12.4e %12.4e %12.4e \n", sdata[0], sdata[1], sdata[2]); #else printf("%12.4e %12.4e %12.4e \n", sdata[0], sdata[1], sdata[2]); #endif } /* * Print current t, step count, order, stepsize, and solution. */ static void PrintOutput(void *ida_mem, realtype t, N_Vector u) { long int nst; int qu, retval; realtype hu, *udata; udata = N_VGetArrayPointer(u); retval = IDAGetNumSteps(ida_mem, &nst); check_retval(&retval, "IDAGetNumSteps", 1); retval = IDAGetLastOrder(ida_mem, &qu); check_retval(&retval, "IDAGetLastOrder", 1); retval = IDAGetLastStep(ida_mem, &hu); check_retval(&retval, "IDAGetLastStep", 1); #if defined(SUNDIALS_EXTENDED_PRECISION) printf("%8.3Le %2d %8.3Le %5ld\n", t, qu, hu, nst); #elif defined(SUNDIALS_DOUBLE_PRECISION) printf("%8.3e %2d %8.3e %5ld\n", t, qu, hu, nst); #else printf("%8.3e %2d %8.3e %5ld\n", t, qu, hu, nst); #endif printf(" Solution "); #if defined(SUNDIALS_EXTENDED_PRECISION) printf("%12.4Le %12.4Le %12.4Le \n", udata[0], udata[1], udata[2]); #elif defined(SUNDIALS_DOUBLE_PRECISION) printf("%12.4e %12.4e %12.4e \n", udata[0], udata[1], udata[2]); #else printf("%12.4e %12.4e %12.4e \n", udata[0], udata[1], udata[2]); #endif } /* * Print sensitivities. */ static void PrintSensOutput(N_Vector *uS) { realtype *sdata; sdata = N_VGetArrayPointer(uS[0]); printf(" Sensitivity 1 "); #if defined(SUNDIALS_EXTENDED_PRECISION) printf("%12.4Le %12.4Le %12.4Le \n", sdata[0], sdata[1], sdata[2]); #elif defined(SUNDIALS_DOUBLE_PRECISION) printf("%12.4e %12.4e %12.4e \n", sdata[0], sdata[1], sdata[2]); #else printf("%12.4e %12.4e %12.4e \n", sdata[0], sdata[1], sdata[2]); #endif sdata = N_VGetArrayPointer(uS[1]); printf(" Sensitivity 2 "); #if defined(SUNDIALS_EXTENDED_PRECISION) printf("%12.4Le %12.4Le %12.4Le \n", sdata[0], sdata[1], sdata[2]); #elif defined(SUNDIALS_DOUBLE_PRECISION) printf("%12.4e %12.4e %12.4e \n", sdata[0], sdata[1], sdata[2]); #else printf("%12.4e %12.4e %12.4e \n", sdata[0], sdata[1], sdata[2]); #endif sdata = N_VGetArrayPointer(uS[2]); printf(" Sensitivity 3 "); #if defined(SUNDIALS_EXTENDED_PRECISION) printf("%12.4Le %12.4Le %12.4Le \n", sdata[0], sdata[1], sdata[2]); #elif defined(SUNDIALS_DOUBLE_PRECISION) printf("%12.4e %12.4e %12.4e \n", sdata[0], sdata[1], sdata[2]); #else printf("%12.4e %12.4e %12.4e \n", sdata[0], sdata[1], sdata[2]); #endif } /* * Print some final statistics from the IDAS memory. */ static void PrintFinalStats(void *ida_mem, booleantype sensi) { long int nst; long int nfe, nsetups, nni, nnf, ncfn, netf; long int nfSe, nfeS, nsetupsS, nniS, nnfS, ncfnS, netfS; long int nje, nfeLS; int retval; retval = IDAGetNumSteps(ida_mem, &nst); check_retval(&retval, "IDAGetNumSteps", 1); retval = IDAGetNumResEvals(ida_mem, &nfe); check_retval(&retval, "IDAGetNumRhsEvals", 1); retval = IDAGetNumLinSolvSetups(ida_mem, &nsetups); check_retval(&retval, "IDAGetNumLinSolvSetups", 1); retval = IDAGetNumErrTestFails(ida_mem, &netf); check_retval(&retval, "IDAGetNumErrTestFails", 1); retval = IDAGetNumNonlinSolvIters(ida_mem, &nni); check_retval(&retval, "IDAGetNumNonlinSolvIters", 1); retval = IDAGetNumNonlinSolvConvFails(ida_mem, &nnf); check_retval(&retval, "IDAGetNumNonlinSolvConvFails", 1); retval = IDAGetNumStepSolveFails(ida_mem, &ncfn); check_retval(&retval, "IDAGetNumStepSolveFails", 1); if (sensi) { retval = IDAGetSensNumResEvals(ida_mem, &nfSe); check_retval(&retval, "IDAGetSensNumRhsEvals", 1); retval = IDAGetNumResEvalsSens(ida_mem, &nfeS); check_retval(&retval, "IDAGetNumResEvalsSens", 1); retval = IDAGetSensNumLinSolvSetups(ida_mem, &nsetupsS); check_retval(&retval, "IDAGetSensNumLinSolvSetups", 1); retval = IDAGetSensNumErrTestFails(ida_mem, &netfS); check_retval(&retval, "IDAGetSensNumErrTestFails", 1); retval = IDAGetSensNumNonlinSolvIters(ida_mem, &nniS); check_retval(&retval, "IDAGetSensNumNonlinSolvIters", 1); retval = IDAGetSensNumNonlinSolvConvFails(ida_mem, &nnfS); check_retval(&retval, "IDAGetSensNumNonlinSolvConvFails", 1); retval = IDAGetNumStepSensSolveFails(ida_mem, &ncfnS); check_retval(&retval, "IDAGetNumStepSolveFails", 1); } retval = IDAGetNumJacEvals(ida_mem, &nje); check_retval(&retval, "IDAGetNumJacEvals", 1); retval = IDAGetNumLinResEvals(ida_mem, &nfeLS); check_retval(&retval, "IDAGetNumLinResEvals", 1); printf("\nFinal Statistics\n\n"); printf("nst = %5ld\n\n", nst); printf("nfe = %5ld\n", nfe); printf("netf = %5ld nsetups = %5ld\n", netf, nsetups); printf("nni = %5ld nnf = %5ld\n", nni, nnf); printf("ncfn = %5ld\n", ncfn); if(sensi) { printf("\n"); printf("nfSe = %5ld nfeS = %5ld\n", nfSe, nfeS); printf("netfs = %5ld nsetupsS = %5ld\n", netfS, nsetupsS); printf("nniS = %5ld nnfS = %5ld\n", nniS, nnfS); printf("ncfnS = %5ld\n", ncfnS); } printf("\n"); printf("nje = %5ld nfeLS = %5ld\n", nje, nfeLS); } /* * Check function return value. * opt == 0 means SUNDIALS function allocates memory so check if * returned NULL pointer * opt == 1 means SUNDIALS function returns an integer value so check if * retval < 0 * opt == 2 means function allocates memory so check if returned * NULL pointer */ static int check_retval(void *returnvalue, char *funcname, int opt) { int *retval; /* Check if SUNDIALS function returned NULL pointer - no memory allocated */ if (opt == 0 && returnvalue == NULL) { fprintf(stderr, "\nSUNDIALS_ERROR: %s() failed - returned NULL pointer\n\n", funcname); return(1); } /* Check if retval < 0 */ else if (opt == 1) { retval = (int *) returnvalue; if (*retval < 0) { fprintf(stderr, "\nSUNDIALS_ERROR: %s() failed with retval = %d\n\n", funcname, *retval); return(1); }} /* Check if function returned NULL pointer - no memory allocated */ else if (opt == 2 && returnvalue == NULL) { fprintf(stderr, "\nMEMORY_ERROR: %s() failed - returned NULL pointer\n\n", funcname); return(1); } return(0); }
b3fbd4614d63225f9fece664fbe22270c827f23d
5c72e3dec37038e313beab6250acaa54b4b03b93
/vioserial/app/win/sys/time.h
69607c3d84fd4ce392a03f395ea52ec474f26ca1
[ "BSD-3-Clause", "GPL-1.0-or-later" ]
permissive
virtio-win/kvm-guest-drivers-windows
eb29c92b6949d6bfb0ee8c70004e359180ee2398
19a79901f36aa552b85f8b4c3c9645ebe90d9ec5
refs/heads/master
2023-09-06T00:50:32.529282
2023-08-25T10:21:53
2023-08-31T07:30:16
2,524,933
1,424
294
BSD-3-Clause
2023-08-26T16:02:39
2011-10-06T09:06:41
C
UTF-8
C
false
false
139
h
time.h
#ifndef __win_sys_time_h__ #define __win_sys_time_h__ #define clock_gettime(x, data) ((timespec_get(data, TIME_UTC) != 0) ? 0 : 1) #endif
0bcb16c6c238976da54fe0e48c058453e077dd6c
c30beb817a4788c3eb9027c5cede0c7ae4006578
/demos/FPL_NoCRT/tinycrt.h
c825ab35aef3602f1c845518846e55bbda9aaf48
[ "MIT" ]
permissive
f1nalspace/final_game_tech
232c34ce6d737b9069073b53c665bf14e513898c
33b63dc0664e16682d4298371f3166869c233b0f
refs/heads/master
2023-06-25T07:27:01.747802
2021-09-07T08:03:17
2021-09-07T08:08:08
91,165,055
178
18
MIT
2023-01-04T12:40:05
2017-05-13T09:59:36
C
UTF-8
C
false
false
14,248
h
tinycrt.h
#include <final_platform_layer.h> // ############################################################################ // // No C-Runtime Support // // This block contains stuff to make FPL compilable without the CRT. // // ############################################################################ #if defined(FPL_NO_CRT) // @NOTE(final): At the moment only MSVC requires this i assume #if defined(FPL_COMPILER_MSVC) #if defined(__cplusplus) extern "C" { #endif __declspec(selectany) int _fltused = 0; // CRT-Math routines, based on: // https://gist.github.com/mmozeiko/6a365d6c483fc721b63a#file-win32_crt_float-cpp // libSDL # ifdef _M_IX86 __declspec(naked) void _ftol2() { __asm { fistp qword ptr [esp-8] mov edx,[esp-4] mov eax,[esp-8] ret } } __declspec(naked) void _ftol2_sse() { __asm { fistp dword ptr [esp-4] mov eax,[esp-4] ret } } __declspec(naked) void _ltod3() { __asm { } } __declspec(naked) void _ultod3() { __asm { } } __declspec(naked) void _ftoui3() { __asm { } } // 64-bit math for 32-bit void __declspec(naked) _allmul() { __asm { mov eax, dword ptr[esp + 8] mov ecx, dword ptr[esp + 10h] or ecx, eax mov ecx, dword ptr[esp + 0Ch] jne hard mov eax, dword ptr[esp + 4] mul ecx ret 10h hard : push ebx mul ecx mov ebx, eax mov eax, dword ptr[esp + 8] mul dword ptr[esp + 14h] add ebx, eax mov eax, dword ptr[esp + 8] mul ecx add edx, ebx pop ebx ret 10h } } void __declspec(naked) _alldiv() { __asm { push edi push esi push ebx xor edi, edi mov eax, dword ptr[esp + 14h] or eax, eax jge L1 inc edi mov edx, dword ptr[esp + 10h] neg eax neg edx sbb eax, 0 mov dword ptr[esp + 14h], eax mov dword ptr[esp + 10h], edx L1 : mov eax, dword ptr[esp + 1Ch] or eax, eax jge L2 inc edi mov edx, dword ptr[esp + 18h] neg eax neg edx sbb eax, 0 mov dword ptr[esp + 1Ch], eax mov dword ptr[esp + 18h], edx L2 : or eax, eax jne L3 mov ecx, dword ptr[esp + 18h] mov eax, dword ptr[esp + 14h] xor edx, edx div ecx mov ebx, eax mov eax, dword ptr[esp + 10h] div ecx mov edx, ebx jmp L4 L3 : mov ebx, eax mov ecx, dword ptr[esp + 18h] mov edx, dword ptr[esp + 14h] mov eax, dword ptr[esp + 10h] L5 : shr ebx, 1 rcr ecx, 1 shr edx, 1 rcr eax, 1 or ebx, ebx jne L5 div ecx mov esi, eax mul dword ptr[esp + 1Ch] mov ecx, eax mov eax, dword ptr[esp + 18h] mul esi add edx, ecx jb L6 cmp edx, dword ptr[esp + 14h] ja L6 jb L7 cmp eax, dword ptr[esp + 10h] jbe L7 L6 : dec esi L7 : xor edx, edx mov eax, esi L4 : dec edi jne L8 neg edx neg eax sbb edx, 0 L8 : pop ebx pop esi pop edi ret 10h } } void __declspec(naked) _aulldiv() { __asm { push ebx push esi mov eax, dword ptr[esp + 18h] or eax, eax jne L1 mov ecx, dword ptr[esp + 14h] mov eax, dword ptr[esp + 10h] xor edx, edx div ecx mov ebx, eax mov eax, dword ptr[esp + 0Ch] div ecx mov edx, ebx jmp L2 L1 : mov ecx, eax mov ebx, dword ptr[esp + 14h] mov edx, dword ptr[esp + 10h] mov eax, dword ptr[esp + 0Ch] L3 : shr ecx, 1 rcr ebx, 1 shr edx, 1 rcr eax, 1 or ecx, ecx jne L3 div ebx mov esi, eax mul dword ptr[esp + 18h] mov ecx, eax mov eax, dword ptr[esp + 14h] mul esi add edx, ecx jb L4 cmp edx, dword ptr[esp + 10h] ja L4 jb L5 cmp eax, dword ptr[esp + 0Ch] jbe L5 L4 : dec esi L5 : xor edx, edx mov eax, esi L2 : pop esi pop ebx ret 10h } } void __declspec(naked) _allrem() { __asm { push ebx push edi xor edi, edi mov eax, dword ptr[esp + 10h] or eax, eax jge L1 inc edi mov edx, dword ptr[esp + 0Ch] neg eax neg edx sbb eax, 0 mov dword ptr[esp + 10h], eax mov dword ptr[esp + 0Ch], edx L1 : mov eax, dword ptr[esp + 18h] or eax, eax jge L2 mov edx, dword ptr[esp + 14h] neg eax neg edx sbb eax, 0 mov dword ptr[esp + 18h], eax mov dword ptr[esp + 14h], edx L2 : or eax, eax jne L3 mov ecx, dword ptr[esp + 14h] mov eax, dword ptr[esp + 10h] xor edx, edx div ecx mov eax, dword ptr[esp + 0Ch] div ecx mov eax, edx xor edx, edx dec edi jns L4 jmp L8 L3 : mov ebx, eax mov ecx, dword ptr[esp + 14h] mov edx, dword ptr[esp + 10h] mov eax, dword ptr[esp + 0Ch] L5 : shr ebx, 1 rcr ecx, 1 shr edx, 1 rcr eax, 1 or ebx, ebx jne L5 div ecx mov ecx, eax mul dword ptr[esp + 18h] xchg eax, ecx mul dword ptr[esp + 14h] add edx, ecx jb L6 cmp edx, dword ptr[esp + 10h] ja L6 jb L7 cmp eax, dword ptr[esp + 0Ch] jbe L7 L6 : sub eax, dword ptr[esp + 14h] sbb edx, dword ptr[esp + 18h] L7 : sub eax, dword ptr[esp + 0Ch] sbb edx, dword ptr[esp + 10h] dec edi jns L8 L4 : neg edx neg eax sbb edx, 0 L8 : pop edi pop ebx ret 10h } } void __declspec(naked) _aullrem() { __asm { push ebx mov eax, dword ptr[esp + 14h] or eax, eax jne L1 mov ecx, dword ptr[esp + 10h] mov eax, dword ptr[esp + 0Ch] xor edx, edx div ecx mov eax, dword ptr[esp + 8] div ecx mov eax, edx xor edx, edx jmp L2 L1 : mov ecx, eax mov ebx, dword ptr[esp + 10h] mov edx, dword ptr[esp + 0Ch] mov eax, dword ptr[esp + 8] L3 : shr ecx, 1 rcr ebx, 1 shr edx, 1 rcr eax, 1 or ecx, ecx jne L3 div ebx mov ecx, eax mul dword ptr[esp + 14h] xchg eax, ecx mul dword ptr[esp + 10h] add edx, ecx jb L4 cmp edx, dword ptr[esp + 0Ch] ja L4 jb L5 cmp eax, dword ptr[esp + 8] jbe L5 L4 : sub eax, dword ptr[esp + 10h] sbb edx, dword ptr[esp + 14h] L5 : sub eax, dword ptr[esp + 8] sbb edx, dword ptr[esp + 0Ch] neg edx neg eax sbb edx, 0 L2 : pop ebx ret 10h } } void __declspec(naked) _alldvrm() { __asm { push edi push esi push ebp xor edi, edi xor ebp, ebp mov eax, dword ptr[esp + 14h] or eax, eax jge L1 inc edi inc ebp mov edx, dword ptr[esp + 10h] neg eax neg edx sbb eax, 0 mov dword ptr[esp + 14h], eax mov dword ptr[esp + 10h], edx L1 : mov eax, dword ptr[esp + 1Ch] or eax, eax jge L2 inc edi mov edx, dword ptr[esp + 18h] neg eax neg edx sbb eax, 0 mov dword ptr[esp + 1Ch], eax mov dword ptr[esp + 18h], edx L2 : or eax, eax jne L3 mov ecx, dword ptr[esp + 18h] mov eax, dword ptr[esp + 14h] xor edx, edx div ecx mov ebx, eax mov eax, dword ptr[esp + 10h] div ecx mov esi, eax mov eax, ebx mul dword ptr[esp + 18h] mov ecx, eax mov eax, esi mul dword ptr[esp + 18h] add edx, ecx jmp L4 L3 : mov ebx, eax mov ecx, dword ptr[esp + 18h] mov edx, dword ptr[esp + 14h] mov eax, dword ptr[esp + 10h] L5 : shr ebx, 1 rcr ecx, 1 shr edx, 1 rcr eax, 1 or ebx, ebx jne L5 div ecx mov esi, eax mul dword ptr[esp + 1Ch] mov ecx, eax mov eax, dword ptr[esp + 18h] mul esi add edx, ecx jb L6 cmp edx, dword ptr[esp + 14h] ja L6 jb L7 cmp eax, dword ptr[esp + 10h] jbe L7 L6 : dec esi sub eax, dword ptr[esp + 18h] sbb edx, dword ptr[esp + 1Ch] L7 : xor ebx, ebx L4 : sub eax, dword ptr[esp + 10h] sbb edx, dword ptr[esp + 14h] dec ebp jns L9 neg edx neg eax sbb edx, 0 L9: mov ecx, edx mov edx, ebx mov ebx, ecx mov ecx, eax mov eax, esi dec edi jne L8 neg edx neg eax sbb edx, 0 L8: pop ebp pop esi pop edi ret 10h } } void __declspec(naked) _aulldvrm() { __asm { push esi mov eax, dword ptr[esp + 14h] or eax, eax jne L1 mov ecx, dword ptr[esp + 10h] mov eax, dword ptr[esp + 0Ch] xor edx, edx div ecx mov ebx, eax mov eax, dword ptr[esp + 8] div ecx mov esi, eax mov eax, ebx mul dword ptr[esp + 10h] mov ecx, eax mov eax, esi mul dword ptr[esp + 10h] add edx, ecx jmp L2 L1 : mov ecx, eax mov ebx, dword ptr[esp + 10h] mov edx, dword ptr[esp + 0Ch] mov eax, dword ptr[esp + 8] L3 : shr ecx, 1 rcr ebx, 1 shr edx, 1 rcr eax, 1 or ecx, ecx jne L3 div ebx mov esi, eax mul dword ptr[esp + 14h] mov ecx, eax mov eax, dword ptr[esp + 10h] mul esi add edx, ecx jb L4 cmp edx, dword ptr[esp + 0Ch] ja L4 jb L5 cmp eax, dword ptr[esp + 8] jbe L5 L4 : dec esi sub eax, dword ptr[esp + 10h] sbb edx, dword ptr[esp + 14h] L5 : xor ebx, ebx L2 : sub eax, dword ptr[esp + 8] sbb edx, dword ptr[esp + 0Ch] neg edx neg eax sbb edx, 0 mov ecx, edx mov edx, ebx mov ebx, ecx mov ecx, eax mov eax, esi pop esi ret 10h } } void __declspec(naked) _allshl() { __asm { cmp cl, 40h jae RETZERO cmp cl, 20h jae MORE32 shld edx, eax, cl shl eax, cl ret MORE32 : mov edx, eax xor eax, eax and cl, 1Fh shl edx, cl ret RETZERO : xor eax, eax xor edx, edx ret } } void __declspec(naked) _allshr() { __asm { cmp cl, 40h jae RETZERO cmp cl, 20h jae MORE32 shrd eax, edx, cl sar edx, cl ret MORE32 : mov eax, edx xor edx, edx and cl, 1Fh sar eax, cl ret RETZERO : xor eax, eax xor edx, edx ret } } void __declspec(naked) _aullshr() { __asm { cmp cl, 40h jae RETZERO cmp cl, 20h jae MORE32 shrd eax, edx, cl shr edx, cl ret MORE32 : mov eax, edx xor edx, edx and cl, 1Fh shr eax, cl ret RETZERO : xor eax, eax xor edx, edx ret } } # endif // // Intrinsics // # pragma function(memset) void *memset(void *dest, int value, size_t count) { fplMemorySet(dest, value, count); return (dest); } # pragma function(memcpy) void *memcpy(void *dest, const void *source, size_t count) { fplMemoryCopy(source, count, dest); return (dest); } // // Run-Time-Checks // void __cdecl _RTC_InitBase(void) { } void __cdecl _RTC_Shutdown(void) { } void __cdecl _RTC_CheckEsp(void) { } void __fastcall _RTC_CheckStackVars(void *_Esp, struct _RTC_framedesc *_Fd) { } #if defined(__cplusplus) }; #endif #endif // FPL_COMPILER_MSVC #endif // FPL_NO_CRT
43375c3ae35d9a3c0ee36cb6a8d1fe758b33a9a6
aa5c1a530f95d629e686ac9124caf1a49a9f23e9
/compiler/src/iree/compiler/Codegen/Dialect/UKernelOps.h
c6b610eded3c2471dd22a0ee814aac79e9822199
[ "Apache-2.0", "LLVM-exception", "LicenseRef-scancode-unknown-license-reference" ]
permissive
openxla/iree
eacf5b239559e1d3b40c38039ac4c26315b523f7
13ef677e556d0a1d154e45b052fe016256057f65
refs/heads/main
2023-09-06T01:19:49.598662
2023-09-04T07:01:30
2023-09-04T07:01:30
208,145,128
387
110
Apache-2.0
2023-09-14T20:48:00
2019-09-12T20:57:39
C++
UTF-8
C
false
false
752
h
UKernelOps.h
// Copyright 2023 The IREE Authors // // Licensed under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception #ifndef IREE_COMPILER_CODEGEN_DIALECT_UKERNELOPS_H_ #define IREE_COMPILER_CODEGEN_DIALECT_UKERNELOPS_H_ #include "iree/compiler/Codegen/Interfaces/UKernelOpInterface.h" #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/Operation.h" #include "mlir/Interfaces/DestinationStyleOpInterface.h" // clang-format off #define GET_OP_CLASSES #include "iree/compiler/Codegen/Dialect/UKernelOps.h.inc" // IWYU pragma: export // clang-format on #endif // #ifndef IREE_COMPILER_CODEGEN_DIALECT_UKERNELOPS_H_
9330a8ef5730c36efdc7e57f645500375df6022a
fdbb74a95924e2677466614f6ab6e2bb13b2a95a
/libc/nt/struct/privilegeset.h
3f027c0510daf17efa7f9b1fda9f13a27d260f54
[ "ISC" ]
permissive
jart/cosmopolitan
fb11b5658939023977060a7c6c71a74093d9cb44
0d748ad58e1063dd1f8560f18a0c75293b9415b7
refs/heads/master
2023-09-06T09:17:29.303607
2023-09-02T03:49:13
2023-09-02T03:50:18
272,457,606
11,887
435
ISC
2023-09-14T17:47:58
2020-06-15T14:16:13
C
UTF-8
C
false
false
411
h
privilegeset.h
#ifndef COSMOPOLITAN_LIBC_NT_STRUCT_PRIVILEGESET_H_ #define COSMOPOLITAN_LIBC_NT_STRUCT_PRIVILEGESET_H_ #include "libc/nt/struct/luidandattributes.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) struct NtPrivilegeSet { uint32_t PrivilegeCount; uint32_t Control; struct NtLuidAndAttributes Privilege[1]; }; #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_STRUCT_PRIVILEGESET_H_ */
920f585a89a8fb647e0d80f3f4d60e2840c5b8ec
88ae8695987ada722184307301e221e1ba3cc2fa
/third_party/ffmpeg/compat/float/float.h
1f0d3ab4b507da3094c9658ee66f96242c8c0d76
[ "Apache-2.0", "LGPL-2.0-or-later", "MIT", "GPL-1.0-or-later", "BSD-3-Clause", "LGPL-2.1-only", "LGPL-3.0-only", "GPL-2.0-only", "LGPL-2.1-or-later", "GPL-3.0-or-later", "LGPL-3.0-or-later", "IJG", "LicenseRef-scancode-other-permissive", "GPL-2.0-or-later", "GPL-3.0-only" ]
permissive
iridium-browser/iridium-browser
71d9c5ff76e014e6900b825f67389ab0ccd01329
5ee297f53dc7f8e70183031cff62f37b0f19d25f
refs/heads/master
2023-08-03T16:44:16.844552
2023-07-20T15:17:00
2023-07-23T16:09:30
220,016,632
341
40
BSD-3-Clause
2021-08-13T13:54:45
2019-11-06T14:32:31
null
UTF-8
C
false
false
1,140
h
float.h
/* * Work around broken floating point limits on some systems. * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include_next <float.h> #ifdef FLT_MAX #undef FLT_MAX #define FLT_MAX 3.40282346638528859812e+38F #undef FLT_MIN #define FLT_MIN 1.17549435082228750797e-38F #undef DBL_MAX #define DBL_MAX ((double)1.79769313486231570815e+308L) #undef DBL_MIN #define DBL_MIN ((double)2.22507385850720138309e-308L) #endif
f4b97d4f9284b27f624b22ef9116fc94caa48d74
e86dcbd1aae3b7df6832db50c71105df39fe931b
/demo/object.c
47e1ade6d42dc535e10e6182d88968434cbd3fa8
[ "Apache-2.0", "LicenseRef-scancode-unknown-license-reference" ]
permissive
vrogier/ocilib
3ae34dc73d21bb043c297fd8c5eaaab1cca62628
3ce8accd5d4a81ca6c9ffa2e58147b2371b4cbc9
refs/heads/master
2023-08-30T02:26:21.285990
2023-02-09T21:17:06
2023-02-09T21:17:06
37,376,268
327
147
Apache-2.0
2023-02-10T20:16:06
2015-06-13T15:20:02
C
UTF-8
C
false
false
1,869
c
object.c
#include "ocilib.h" /* requires script demo/object.sql */ void err_handler(OCI_Error *err) { printf("%s\n", OCI_ErrorGetString(err)); } int main(void) { OCI_Connection *cn; OCI_Statement *st; OCI_Resultset *rs; OCI_Object *sale, *vendor; OCI_Date *date; if (!OCI_Initialize(err_handler, NULL, OCI_ENV_DEFAULT)) { return EXIT_FAILURE; } cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT); st = OCI_StatementCreate(cn); date = OCI_DateCreate(NULL); OCI_DateSysDate(date); vendor = OCI_ObjectCreate(cn, OCI_TypeInfoGet(cn, "t_vendor", OCI_TIF_TYPE)); OCI_ObjectSetInt(vendor, "CODE", 134); OCI_ObjectSetString(vendor, "NAME", "JOHN SMITH"); sale = OCI_ObjectCreate(cn, OCI_TypeInfoGet(cn, "t_sale", OCI_TIF_TYPE)); OCI_ObjectSetInt(sale, "CODE", 1); OCI_ObjectSetDouble(sale, "PRICE", 12.99); OCI_ObjectSetString(sale, "NAME", "USB KEY 2go"); OCI_ObjectSetString(sale, "REF", "A56547WSAA"); OCI_ObjectSetObject(sale, "VENDOR", vendor); OCI_ObjectSetDate(sale, "DATE_SALE", date); OCI_Prepare(st, "insert into sales values(:sale)"); OCI_BindObject(st, ":sale", sale); OCI_Execute(st); printf("\n%d row(s) inserted\n", OCI_GetAffectedRows(st)); OCI_ObjectFree(sale); OCI_ObjectFree(vendor); OCI_ExecuteStmt(st, "select * from sales"); rs = OCI_GetResultset(st); while (OCI_FetchNext(rs)) { sale = OCI_GetObject(rs, 1); vendor = OCI_ObjectGetObject(sale, "VENDOR"); printf("Sale %d - %s vendor %s\n", OCI_ObjectGetInt(sale, "CODE"), OCI_ObjectGetString(sale, "NAME"), OCI_ObjectGetString(vendor, "NAME")); } OCI_StatementFree(st); OCI_ConnectionFree(cn); OCI_Cleanup(); return EXIT_SUCCESS; }
65dabe565b36192cfa4bb3410643032ea381712d
b71097386a6da0e3ca65f19a1906f0ebe11eac18
/src/prchunk.c
22b8c6bb4c992a0aeb54f6ceaba5433de3d392cb
[ "BSD-3-Clause" ]
permissive
hroptatyr/dateutils
0584063e4a35c511ad3600c27efb2f4214af24c6
c57828809a018061147bc806a058aa4c4b9c449a
refs/heads/master
2023-09-05T20:26:30.356886
2023-07-05T12:19:20
2023-07-05T12:19:20
2,341,061
517
44
NOASSERTION
2023-06-26T12:04:46
2011-09-07T11:19:46
C
UTF-8
C
false
false
11,381
c
prchunk.c
/*** prchunk.c -- guessing line oriented data formats * * Copyright (C) 2010-2022 Sebastian Freundt * * Author: Sebastian Freundt <freundt@ga-group.nl> * * This file is part of uterus. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * 3. Neither the name of the author 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 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 REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ***/ #define PRCHUNK_C #if defined HAVE_CONFIG_H # include "config.h" #endif /* HAVE_CONFIG_H */ #if defined MAP_ANON_NEEDS_DARWIN_SOURCE # define _DARWIN_C_SOURCE #endif /* MAP_ANON_NEEDS_DARWIN_SOURCE */ #if defined MAP_ANON_NEEDS_ALL_SOURCE # define _ALL_SOURCE #endif /* MAP_ANON_NEEDS_ALL_SOURCE */ #include <stddef.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <string.h> #include <stdint.h> #include <sys/mman.h> #include <stdarg.h> #include <errno.h> #include "nifty.h" #include "prchunk.h" #define MAX_NLINES (16384) #define MAX_LLEN (1024) #if !defined MAP_ANONYMOUS && defined MAP_ANON # define MAP_ANONYMOUS (MAP_ANON) #elif !defined MAP_ANON # define MAP_ANON (0x1000U) #endif /* MAP_ANON->MAP_ANONYMOUS */ #if defined __INTEL_COMPILER # pragma warning(disable: 981) #endif /* __INTEL_COMPILER */ typedef uint32_t off32_t; typedef uint16_t off16_t; struct prch_ctx_s { /* file descriptor */ int fd; /* buffer */ char *buf; /* number of lines in the buffer */ uint32_t tot_lno; /* number of columns per line */ uint32_t tot_cno; /* number of bytes in the buffer */ size_t bno; /* last known offset */ size_t off; /* offsets */ off32_t loff[MAX_NLINES]; off32_t cur_lno; /* delimiter offsets */ off16_t *soff; }; static inline void set_loff(prch_ctx_t ctx, uint32_t lno, off32_t off) { ctx->loff[lno] = off; ctx->loff[lno] <<= 1; return; } static inline off32_t get_loff(prch_ctx_t ctx, uint32_t lno) { off32_t res = ctx->loff[lno]; return res >> 1; } /* return 0 if not \r terminated, 1 otherwise */ static inline int lftermdp(prch_ctx_t ctx, uint32_t lno) { return ctx->loff[lno] & 1; } static inline void set_lftermd(prch_ctx_t ctx, uint32_t lno) { ctx->loff[lno] |= 1; return; } static inline size_t get_llen(prch_ctx_t ctx, uint32_t lno) { if (UNLIKELY(lno == 0)) { return get_loff(ctx, 0) - lftermdp(ctx, 0); } return get_loff(ctx, lno) - lftermdp(ctx, lno) - get_loff(ctx, lno - 1) - 1; } /* internal operations */ FDEFU int prchunk_fill(prch_ctx_t ctx) { /* this is a coroutine consisting of a line counter yielding the number of * lines read so far and a reader yielding a buffer fill and the number of * bytes read */ #define CHUNK_SIZE (4096) #define YIELD(x) goto yield##x char *off = ctx->buf + 0; char *bno = ctx->buf + ctx->bno; ssize_t nrd; /* initial work, reset the line counters et al */ ctx->tot_lno = 0; /* we just memcpy() the left over stuff to the front and restart * from there, someone left us a note in __ctx with the left * over offset */ /* normally we'd use memmove() but we know there's little chance * for overlapping regions */ if (UNLIKELY(ctx->bno == 0)) { /* do nothing */ ; } else if (LIKELY(ctx->bno > ctx->off)) { size_t rsz = ctx->bno - ctx->off; /* move the top RSZ bytes to the beginning */ memcpy(ctx->buf, ctx->buf + ctx->off, rsz); ctx->bno = rsz; bno = ctx->buf + rsz; } else if (UNLIKELY(ctx->bno == ctx->off)) { /* what are the odds? just reset the counters */ ctx->bno = 0; bno = ctx->buf; } else { /* the user didn't see the end of the file */ return -1; } yield1: /* read CHUNK_SIZE bytes */ bno += (nrd = read(ctx->fd, bno, CHUNK_SIZE)); /* if we came from yield2 then off == __ctx->bno, and if we * read 0 or less bytes then off >= __ctx->bno + nrd, so we * can simply use that compact expression if the buffer has no * more input. * On the contrary if we came from the outside, i.e. fill_buffer() * has been called, then off would be 0 and __ctx->bno would be * the buffer filled so far, if no more bytes could be read then * we'd proceed processing them (off < __ctx->bno + nrd */ if (UNLIKELY(!nrd && off < bno && ctx->cur_lno <= ctx->tot_lno)) { /* last line then, unyielded :| */ set_loff(ctx, ctx->tot_lno, bno - ctx->buf); off = bno; /* count it as line and check if we need more */ if (++ctx->tot_lno >= MAX_NLINES) { YIELD(3); } YIELD(4); } else if (UNLIKELY(nrd <= 0 && off == ctx->buf)) { /* special case, we worked our arses off and nothing's * in the pipe line so just fuck off here */ if (!ctx->bno) { return -1; } /* go to drain mode */ YIELD(2); } else if (LIKELY(off < bno || off == ctx->buf)) { YIELD(2); } /* proceed to exit */ YIELD(3); yield2: while (off < bno) { size_t rsz = bno - off; char *p = memchr(off, '\n', rsz); if (UNLIKELY(p == NULL)) { if (LIKELY(nrd > 0)) { break; } /* not concluded with \n, let's hope we're in drain mode */ return -1; } /* massage our status structures */ set_loff(ctx, ctx->tot_lno, p - ctx->buf); if (UNLIKELY(p[-1] == '\r')) { /* oh god, when is this nightmare gonna end */ p[-1] = '\0'; set_lftermd(ctx, ctx->tot_lno); } *p = '\0'; off = ++p; /* count it as line and check if we need more */ if (++ctx->tot_lno >= MAX_NLINES) { YIELD(3); } } YIELD(1); yield3: /* need clean up, something like unread(), * in particular leave a note in __ctx with the left over offset */ ctx->cur_lno = 0; yield4: ctx->off = off - ctx->buf; ctx->bno = bno - ctx->buf; #undef YIELD #undef CHUNK_SIZE return 0; } /* public operations */ FDEFU prch_ctx_t init_prchunk(int fd) { #define MAP_MEM (MAP_ANON | MAP_PRIVATE) #define PROT_MEM (PROT_READ | PROT_WRITE) #define MAP_LEN (MAX_NLINES * MAX_LLEN) static struct prch_ctx_s __ctx; __ctx.buf = mmap(NULL, MAP_LEN, PROT_MEM, MAP_MEM, -1, 0); if (__ctx.buf == MAP_FAILED) { return NULL; } /* bit of space for the rechunker */ __ctx.soff = mmap(NULL, MAP_LEN, PROT_MEM, MAP_MEM, -1, 0); if (__ctx.soff == MAP_FAILED) { return NULL; } if ((__ctx.fd = fd) > STDIN_FILENO) { #if defined POSIX_FADV_SEQUENTIAL /* give advice about our read pattern */ int rc = posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL); if (UNLIKELY(rc < 0)) { munmap(__ctx.soff, MAP_LEN); return NULL; } #endif /* POSIX_FADV_SEQUENTIAL */ } return &__ctx; } FDEFU void free_prchunk(prch_ctx_t ctx) { if (LIKELY(ctx->buf != NULL)) { munmap(ctx->buf, MAP_LEN); ctx->buf = NULL; } return; } /* accessors/iterators/et al. */ FDEFU size_t prchunk_get_nlines(prch_ctx_t ctx) { return ctx->tot_lno; } FDEFU size_t prchunk_getlineno(prch_ctx_t ctx, char **p, int lno) { if (UNLIKELY(lno <= 0)) { *p = ctx->buf; return get_llen(ctx, 0); } else if (UNLIKELY((size_t)lno >= prchunk_get_nlines(ctx))) { *p = NULL; return 0; } /* likely case last, what bollocks */ *p = ctx->buf + get_loff(ctx, lno - 1) + 1; return get_llen(ctx, lno); } FDEFU size_t prchunk_getline(prch_ctx_t ctx, char **p) { return prchunk_getlineno(ctx, p, ctx->cur_lno++); } FDEFU void prchunk_reset(prch_ctx_t ctx) { ctx->cur_lno = 0; return; } FDEFU int prchunk_haslinep(prch_ctx_t ctx) { /* the second condition is to allow unterminated last lines */ return ctx->cur_lno < ctx->tot_lno || ctx->cur_lno == 0U; } static inline void set_ncols(prch_ctx_t ctx, size_t ncols) { ctx->tot_cno = ncols; return; } FDEFU size_t prchunk_get_ncols(prch_ctx_t ctx) { return ctx->tot_cno; } static inline void set_col_off(prch_ctx_t ctx, size_t lno, size_t cno, size_t off) { ctx->soff[lno * prchunk_get_ncols(ctx) + cno] = (off16_t)off; return; } static inline off16_t get_col_off(prch_ctx_t ctx, size_t lno, size_t cno) { return ctx->soff[lno * prchunk_get_ncols(ctx) + cno]; } /* rechunker, chop the lines into smaller bits * Strategy is to go over all lines in the current chunk and * memchr() for the delimiter DELIM. * Store the offsets into __ctx->soff and bugger off leaving a \0 * where the delimiter was. */ FDEFU void prchunk_rechunk(prch_ctx_t ctx, char dlm, int ncols) { /* very naive implementation, we prefer prchunk_rechunk_by_dstfld() * where a distance histogram demarks possible places */ size_t lno = 0; size_t cno = 0; char *line; char *off; char *p; char *bno = ctx->buf + ctx->off; size_t rsz; set_ncols(ctx, ncols); off = line = ctx->buf; rsz = bno - off; while ((p = memchr(off, dlm, rsz)) != NULL) { size_t co; size_t llen = get_llen(ctx, lno); while ((co = p - line) > llen) { /* last column offset equals the length of the line */ set_col_off(ctx, lno, cno, llen); /* get the new line */ line = ctx->buf + get_loff(ctx, lno++) + 1; cno = 0; } /* store the offset of the column within the line */ set_col_off(ctx, lno, cno++, co); /* prepare the counters for the next round */ *p = '\0'; off = ++p; rsz = bno - off; } /* last column offset equals the length of the line */ rsz = get_llen(ctx, lno); set_col_off(ctx, lno, cno, rsz); return; } FDEFU size_t prchunk_getcolno(prch_ctx_t ctx, char **p, int lno, int cno) { size_t co1, co2; if (UNLIKELY(cno < 0 || (size_t)cno >= prchunk_get_ncols(ctx))) { *p = NULL; return 0; } (void)prchunk_getlineno(ctx, p, lno); if (UNLIKELY(cno == 0)) { return get_col_off(ctx, lno, 0); } /* likely case last */ co1 = get_col_off(ctx, lno, cno); co2 = get_col_off(ctx, lno, cno - 1); *p += co2 + 1; return co1 - co2 - 1; } #if defined STANDALONE #include <stdio.h> int main(int argc, char *argv[]) { int fd; prch_ctx_t ctx; if (argc <= 1) { fd = STDIN_FILENO; } else if ((fd = open(argv[1], O_RDONLY)) < 0) { return 1; } /* get our prchunk up n running */ if ((ctx = init_prchunk(fd)) == NULL) { error(errno, "Error: ctx NULL"); return 1; } /* fill the buffer */ while (!(prchunk_fill(ctx) < 0)) { char *l[1]; size_t llen; int i = 0; while ((llen = prchunk_getline(ctx, l))) { fprintf(stderr, "%d (%zu) %s\n", i++, llen, l[0]); } } /* and out */ free_prchunk(ctx); close(fd); return 0; } #endif /* STANDALONE */ /* prchunk.c ends here */
745c6d52047e7e553f463a83dc855ace26cd2892
35c04ea32351dc95bc18d46e5c70dda9c1e08668
/Examples/MCUXpresso/LPC55S16-EVK/LPC55S16_LoRaFUOTA/LoRa/src/boards/LPC55S16-EVK/board.c
1b42ec2f79e0f171760bdcf6986c12ba30734bfc
[ "LicenseRef-scancode-warranty-disclaimer" ]
no_license
ErichStyger/mcuoneclipse
0f8e7a2056a26ed79d9d4a0afd64777ff0b2b2fe
04ad311b11860ae5f8285316010961a87fa06d0c
refs/heads/master
2023-08-28T22:54:08.501719
2023-08-25T15:11:44
2023-08-25T15:11:44
7,446,094
620
1,191
NOASSERTION
2020-10-16T03:13:28
2013-01-04T19:38:12
Batchfile
UTF-8
C
false
false
10,794
c
board.c
/*! * \file board.c * * \brief Target board general functions implementation * * \copyright Revised BSD License, see section \ref LICENSE. * * \author Diego Bienz */ #include "platform.h" #include <stdio.h> #include "LPC55S16.h" #include "utilities.h" #include "uart.h" #include "board-config.h" #include "board.h" #include "sx126x-board.h" #include "clock_config.h" #include "pin_mux.h" #include "gpio.h" #include "rtc-board.h" #include "spi.h" #include "delay.h" #include "gps.h" #include "i2c.h" #include "i2c-board.h" #include "lpm-board.h" #include "eeprom-board.h" #include "fsl_power.h" #include "McuArmTools.h" #include "McuUtility.h" #include "sx1276-board.h" #if PL_CONFIG_RADIO_TRANSEIVER_SX126x #include "sx126x-board.h" #elif PL_CONFIG_USE_LORA_SHIELD #include "sx1276-board.h" #endif /*! * Uart objects */ #if(LPC_NUMBER_OF_USARTS > 0) Uart_t Uart0; // Board Uart #endif #if BOARD_CONFIG_HAS_GNSS Uart_t Uart1; // GPS #endif #if PL_CONFIG_USE_LED1 Gpio_t Led1; #endif #if PL_CONFIG_USE_LED2 Gpio_t Led2; #endif #if BOARD_CONFIG_HAS_SECURE_ELEMENT /*! * I2c objects */ I2c_t I2c0; // Secure Element /*! * Puts the secure element into sleep mode */ static void BoardPutSecureElementInSleepMode( void ); #endif /*! * Puts the radio in sleep mode * If coldstart enabled, the radio will loose it's configuration * and needs to be reinitialised after wake up */ static void BoardPutRadioInSleepMode(bool coldstart); /*! * Initializes the unused GPIO to a know status */ static void BoardUnusedIoInit( void ); /*! * System Clock Configuration */ static void SystemClockConfig( void ); /*! * System Clock Re-Configuration when waking up from STOP mode */ static void SystemClockReConfig( void ); /*! * \brief Initializes the EEPROM emulation driver to access the flash. * * \remark This function is defined in eeprom-board.c file */ void EepromMcuInit( void ); /*! * \brief Indicates if an erasing operation is on going. * * \remark This function is defined in eeprom-board.c file * * \retval isEradingOnGoing Returns true is an erasing operation is on going. */ bool EepromMcuIsErasingOnGoing( void ); void BoardCriticalSectionBegin( uint32_t *mask ) { *mask = __get_PRIMASK( ); __disable_irq( ); } void BoardCriticalSectionEnd( uint32_t *mask ) { __set_PRIMASK( *mask ); __enable_irq(); } void BoardInitPeriph( void ) { #if BOARD_CONFIG_HAS_GNSS GpsInit(); #endif } void BoardInitMcu( void ) { BOARD_InitBootPins(); SystemClockConfig(); #if(LPC_NUMBER_OF_USARTS > 0) // Configure your terminal for 8 Bits data (7 data bit + 1 parity bit), no parity and no flow ctrl UartInit( &Uart0, UART_1, NC, NC ); UartConfig( &Uart0, RX_TX, BOARD_UART_BAUDRATE, UART_8_BIT, UART_1_STOP_BIT, NO_PARITY, NO_FLOW_CTRL ); #endif // LEDs #if PL_CONFIG_USE_LED1 GpioInit(&Led1, LED_1, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 ); #endif #if PL_CONFIG_USE_LED2 GpioInit(&Led2, LED_2, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 1 ); #endif RtcInit( ); BoardUnusedIoInit( ); //SPI for LoRa transceiver #if PL_CONFIG_RADIO_TRANSEIVER_SX126x //#define PL_CONFIG_RADIO_TRANSEIVER_RFM96 (1) /* if shell support is enabled */ //#define PL_CONFIG_RADIO_TRANSEIVER_SX126x (0) /* if shell support is enabled */ //SPI for LoRa transceiver SpiInit( &SX126x.Spi, SPI_1, NC, NC, NC, NC ); SX126xIoInit( ); SX126xIoDbgInit(); SX126xReset(); SX126xIoTcxoInit(); #elif PL_CONFIG_USE_LORA_SHIELD SpiInit( &SX1276.Spi, SPI_1, NC, NC, NC, NC ); SX1276IoInit( ); SX1276IoDbgInit(); SX1276Reset(); SX1276IoTcxoInit(); #endif #if BOARD_CONFIG_HAS_SECURE_ELEMENT //I2C for Secure Element I2cInit(&I2c0, I2C_1, NC, NC); #endif //Actually flash on this platform EepromMcuInit(); } void BoardResetMcu( void ) { CRITICAL_SECTION_BEGIN( ); //Restart system NVIC_SystemReset( ); } void BoardDeInitMcu( void ) { GpsStop(); #if(LPC_NUMBER_OF_USARTS > 0) if(Uart0.IsInitialized) { UartDeInit(&Uart0); } #endif #if BOARD_CONFIG_HAS_GNSS if(Uart1.IsInitialized) { UartDeInit(&Uart1); } #endif BoardPutRadioInSleepMode(true); #if PL_CONFIG_RADIO_TRANSEIVER_SX126x SpiDeInit(&SX126x.Spi); #elif PL_CONFIG_USE_LORA_SHIELD SpiDeInit(&SX1276.Spi); #endif #if BOARD_CONFIG_HAS_SECURE_ELEMENT BoardPutSecureElementInSleepMode(); I2cDeInit(&I2c0); #endif } void BoardGetUniqueId(McuArmTools_UID *id) { McuArmTools_UIDGet(id); } uint32_t BoardGetRandomSeed( void ) { uint32_t seed[4]; McuArmTools_UID uuid; BoardGetUniqueId(&uuid); seed[0] = 0; for(int i = 0; i < 4; i++){ seed[0] += uuid.id[i] << 8*i; } seed[1] = 0; for(int i = 0; i < 4; i++){ seed[1] += uuid.id[i+4] << 8*i; } seed[2] = 0; for(int i = 0; i < 4; i++){ seed[2] += uuid.id[i+8] << 8*i; } seed[3] = 0; for(int i = 0; i < 4; i++){ seed[3] += uuid.id[i+12] << 8*i; } return seed[0] ^ seed[1] ^ seed[2] ^ seed[3]; } /** * NOT IMPLEMENTED ON THIS PLATFORM */ uint8_t BoardGetBatteryLevel( void ) { return 0; } static void BoardUnusedIoInit( void ) { /* Nothing to do */ } void SystemClockConfig( void ) { BOARD_InitBootClocks(); } void SystemClockReConfig( void ) { BOARD_InitBootClocks(); } #if !McuLib_CONFIG_SDK_USE_FREERTOS void SysTick_Handler( void ) { /* SysTick interrupt. Could be used to react on that */ } #endif /*! * \brief Enters off Power Mode (Deep Power Down on LPC55) * A reset is executed automatically on wake up * * Deep power-down: Deep-power down mode shuts down virtually all on-chip power * consumption but requires a significantly longer wake-up time (compared to * power-down mode). For maximal power savings, the entire system (CPU and all * peripherals) is shut down except for the PMU, the PMC, the RTC and the OS event * timer. On wake-up, the part reboots. * * IMPORTANT: SRAM retention defines which RAM sections should be retained while deep power down. It is important to place * variables in the retained sections if they are used after wake up from deep power down. One can place a variable * in a specified section as follows: * * bool __attribute__((section (".retainedSection"))) myBool = false; * * While the defined section .retainedSection is defined in the linker script. */ void LpmEnterOffMode( void ){ /* First proper deinit of the MCU */ BoardDeInitMcu(); POWER_EnterDeepPowerDown(BOARD_EXCLUDE_FROM_DEEP_POWERDOWN, BOARD_SRAM_RETENTION_DEEP_POWERDOWN, BOARD_WAKEUP_INTERRUPTS_DEEP_POWERDOWN, 0); } /*! * \brief Exits off Power Mode */ void LpmExitOffMode( void ){ /* Nothing to do, board will execute a RESET */ } /** * \brief Enters Low Power Stop Mode * * \note ARM exits the function when waking up */ void LpmEnterStopMode( void) { POWER_EnterDeepSleep(BOARD_EXCLUDE_FROM_DEEPSLEEP, BOARD_SRAM_RETENTION_DEEPSLEEP, BOARD_WAKEUP_INTERRUPTS_DEEPSLEEP, 0); } /*! * \brief Exits Low Power Stop Mode */ void LpmExitStopMode( void ) { CRITICAL_SECTION_BEGIN( ); SystemClockReConfig(); CRITICAL_SECTION_END( ); } /*! * \brief Enters Low Power Sleep Mode * * \note ARM exits the function when waking up */ void LpmEnterSleepMode( void) { POWER_EnterSleep(); } void BoardLowPowerHandler( void ) { // Wait for any cleanup to complete before entering standby/shutdown mode while( EepromMcuIsErasingOnGoing( ) == true ){ } __disable_irq( ); /*! * If an interrupt has occurred after __disable_irq( ), it is kept pending * and cortex will not enter low power anyway */ LpmEnterLowPower( ); __enable_irq( ); } static void BoardPutRadioInSleepMode(bool coldstart){ SleepParams_t params = { 0 }; params.Fields.WarmStart = coldstart; #if PL_CONFIG_RADIO_TRANSEIVER_SX126x SX126xSetSleep(params); #elif PL_CONFIG_USE_LORA_SHIELD SX1276SetSleep(); #endif } void BoardPrintUUID(void) { McuArmTools_UID uid; unsigned char buf[96]; BoardGetUniqueId(&uid); McuArmTools_UIDtoString(&uid, buf, sizeof(buf)); printf( "###### Board UUID: %s ######\r\n\r\n", buf); } #if BOARD_CONFIG_HAS_SECURE_ELEMENT static void BoardPutSecureElementInSleepMode( void ){ /* Wake up */ uint8_t buffer[1] = {0}; I2cMcuWriteBuffer(&I2c0, 0x00, 0, buffer, (size_t)0); DelayMs(100); /* Send to sleep */ buffer[0] = 0x1; // sleep word address value I2cMcuWriteBuffer(&I2c0, 0xC0, 0x1, buffer, (size_t)1); } #endif #if !defined ( __CC_ARM ) /* * Function to be used by stdout for printf etc */ int _write( int fd, const void *buf, size_t count ) { #if(LPC_NUMBER_OF_USARTS > 0) while( UartPutBuffer( &Uart0, ( uint8_t* )buf, ( uint16_t )count ) != 0 ){ }; #else McuShell_ConstStdIOType *io = McuShell_GetStdio(); if (io!=NULL) { McuShell_SendData(buf, count, McuShell_GetStdio()->stdOut); } #endif return count; } /* * Function to be used by stdin for scanf etc */ int _read( int fd, const void *buf, size_t count ) { #if(LPC_NUMBER_OF_USARTS > 0) size_t bytesRead = 0; while( UartGetBuffer( &Uart0, ( uint8_t* )buf, count, ( uint16_t* )&bytesRead ) != 0 ){ }; // Echo back the character while( UartPutBuffer( &Uart0, ( uint8_t* )buf, ( uint16_t )bytesRead ) != 0 ){ }; return bytesRead; #else size_t bytesRead = 0; McuShell_ConstStdIOType *io = McuShell_GetStdio(); unsigned char ch; *(unsigned char*)buf = '\0'; if (io==NULL) { return 0; } while(count>0) { if (io->keyPressed()) { io->stdIn(&ch); if (ch!='\0') { McuUtility_chcat((unsigned char*)buf, count, ch); count--; } } } return bytesRead; #endif } #else #include <stdio.h> // Keil compiler int fputc( int c, FILE *stream ) { while( UartPutChar( &Uart0, ( uint8_t )c ) != 0 ); return c; } int fgetc( FILE *stream ) { uint8_t c = 0; while( UartGetChar( &Uart0, &c ) != 0 ); // Echo back the character while( UartPutChar( &Uart0, c ) != 0 ); return ( int )c; } #endif #ifdef USE_FULL_ASSERT #include <stdio.h> /* * Function Name : assert_failed * Description : Reports the name of the source file and the source line number * where the assert_param error has occurred. * Input : - file: pointer to the source file name * - line: assert_param error line source number * Output : None * Return : None */ void assert_failed( uint8_t* file, uint32_t line ) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %lu\n", file, line) */ printf( "Wrong parameters value: file %s on line %lu\n", ( const char* )file, line ); /* Infinite loop */ while( 1 ) { } } #endif
4d060da6d2d8235645c18741608e8a0625d486bc
bc010403013ffe60d43950224c1921982d83cbc1
/inc/tpg_memory.h
221d8afb6f0caedb0d3759beafb98d4e11f12ed1
[ "BSD-3-Clause" ]
permissive
Juniper/warp17
69f11fbd1a9b8c7aa9c2eb9291a8e0e108193a6e
f51cc6b8f1da7ca9703c7fbb951a638ae4a0e9dc
refs/heads/dev/common
2023-09-04T12:59:33.140329
2020-09-28T10:49:23
2020-09-28T10:49:23
59,734,760
412
88
BSD-3-Clause
2022-10-02T04:27:14
2016-05-26T08:47:40
C
UTF-8
C
false
false
8,203
h
tpg_memory.h
/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * Copyright (c) 2016, Juniper Networks, Inc. All rights reserved. * * * The contents of this file are subject to the terms of the BSD 3 clause * License (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at * https://github.com/Juniper/warp17/blob/master/LICENSE. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * File name: * tpg_memory.h * * Description: * Common place where memory and buffer pools get allocated. * * Author: * Dumitru Ceara, Eelco Chaudron * * Initial Created: * 06/29/2015 * * Notes: * */ /***************************************************************************** * Multiple include protection ****************************************************************************/ #ifndef _H_TPG_MEMORY_ #define _H_TPG_MEMORY_ /***************************************************************************** * Definitions ****************************************************************************/ /* * The pools aren't shared so making it single consumer/producer improve * performance */ #if defined(TPG_RING_IF) #define MEM_MBUF_POOL_FLAGS 0 #else #define MEM_MBUF_POOL_FLAGS (MEMPOOL_F_SP_PUT | MEMPOOL_F_SC_GET) #endif #define MEM_TCB_POOL_FLAGS (MEMPOOL_F_SP_PUT | MEMPOOL_F_SC_GET) #define MEM_UCB_POOL_FLAGS (MEMPOOL_F_SP_PUT | MEMPOOL_F_SC_GET) #define MEM_CMDLINE_OPTIONS() \ CMDLINE_OPT_ARG("tcb-pool-sz", true), \ CMDLINE_OPT_ARG("ucb-pool-sz", true), \ CMDLINE_OPT_ARG("mbuf-pool-sz", true), \ CMDLINE_OPT_ARG("mbuf-sz", true), \ CMDLINE_OPT_ARG("mbuf-hdr-pool-sz", true), \ CMDLINE_OPT_ARG("mpool-any-sock", false) #define MEM_CMDLINE_PARSER() \ CMDLINE_ARG_PARSER(mem_handle_cmdline_opt, NULL, \ " --tcb-pool-sz: Configure the size of the TCP control block pool\n" \ " (one TCB is used per TCP connection endpoint). The\n" \ " size of the pool will be given by the argument of\n" \ " this option multiplied by 1024. By default 10M\n" \ " TCBs are allocated.\n" \ " --ucb-pool-sz: Configure the size of the UDP control block pool\n" \ " (one UCB is used per UDP connection endpoint). The\n" \ " size of the pool will be given by the argument of\n" \ " this option multiplied by 1024. By default 10M\n" \ " UCBs are allocated.\n" \ " --mbuf-pool-sz: Configure the size of the packet pool. The size of\n" \ " the pool will be given by the argument of this\n" \ " option multiplied by 1024. By default 768K packets\n" \ " are allocated.\n" \ " --mbuf-sz: Configure the size of a packet fragment (mbuf) in\n" \ " bytes. By default fragments are 2048 bytes.\n" \ " --mbuf-hdr-pool-sz: Configure the size of the packet headers pool. The\n" \ " size of the pool will be given by the argument of\n" \ " this option multiplied by 1024. By default 512K\n" \ " packet headers are allocated.\n" \ " --mpool-any-sock: Configure if memory pools should be created from\n" \ " any available memory if the local socket memory is\n" \ " exhausted. By default this feature is disabled as\n" \ " it might affect performance.\n") /***************************************************************************** * External's for tpg_memory.c ****************************************************************************/ RTE_DECLARE_PER_LCORE(struct rte_mempool *, mbuf_pool); RTE_DECLARE_PER_LCORE(struct rte_mempool *, mbuf_pool_tx_hdr); RTE_DECLARE_PER_LCORE(struct rte_mempool *, mbuf_pool_clone); RTE_DECLARE_PER_LCORE(struct rte_mempool *, tcb_pool); RTE_DECLARE_PER_LCORE(struct rte_mempool *, ucb_pool); extern bool mem_init(void); extern void mem_lcore_init(uint32_t lcore_id); extern struct rte_mempool *mem_get_mbuf_cfg_pool(void); extern struct rte_mempool *mem_get_mbuf_pool(uint32_t port, uint32_t queue_id); extern struct rte_mempool **mem_get_tcb_pools(void); extern struct rte_mempool **mem_get_ucb_pools(void); extern cmdline_arg_parser_res_t mem_handle_cmdline_opt(const char *opt_name, char *opt_arg); /***************************************************************************** * mem_get_mbuf_local_pool() ****************************************************************************/ static inline __attribute__((always_inline)) struct rte_mempool *mem_get_mbuf_local_pool(void) { return RTE_PER_LCORE(mbuf_pool); } /***************************************************************************** * mem_get_mbuf_local_pool_tx_hdr() ****************************************************************************/ static inline __attribute__((always_inline)) struct rte_mempool *mem_get_mbuf_local_pool_tx_hdr(void) { return RTE_PER_LCORE(mbuf_pool_tx_hdr); } /***************************************************************************** * mem_get_mbuf_local_pool_clone() ****************************************************************************/ static inline __attribute__((always_inline)) struct rte_mempool *mem_get_mbuf_local_pool_clone(void) { return RTE_PER_LCORE(mbuf_pool_clone); } /***************************************************************************** * mem_get_tcb_local_pool() ****************************************************************************/ static inline __attribute__((always_inline)) struct rte_mempool *mem_get_tcb_local_pool(void) { return RTE_PER_LCORE(tcb_pool); } /***************************************************************************** * mem_get_ucb_local_pool() ****************************************************************************/ static inline __attribute__((always_inline)) struct rte_mempool *mem_get_ucb_local_pool(void) { return RTE_PER_LCORE(ucb_pool); } #endif /* _H_TPG_MEMORY_ */
111a491e27cdd95c9067cfeefd4ae1344bbf6ce6
e65a4dbfbfb0e54e59787ba7741efee12f7687f3
/audio/festalon/files/patch-src_filter.h
4087949be93c6138041c2d5326e1f35d0b9ee15b
[ "BSD-2-Clause" ]
permissive
freebsd/freebsd-ports
86f2e89d43913412c4f6b2be3e255bc0945eac12
605a2983f245ac63f5420e023e7dce56898ad801
refs/heads/main
2023-08-30T21:46:28.720924
2023-08-30T19:33:44
2023-08-30T19:33:44
1,803,961
916
918
NOASSERTION
2023-09-08T04:06:26
2011-05-26T11:15:35
null
UTF-8
C
false
false
345
h
patch-src_filter.h
--- src/filter.h.orig 2005-02-27 23:39:24 UTC +++ src/filter.h @@ -20,6 +20,8 @@ typedef struct { #ifdef ARCH_X86 int16 coeffs_i16[NCOEFFS] __attribute__ ((aligned (8))); + #elif __x86_64__ + int16 coeffs_i16[NCOEFFS] __attribute__ ((aligned (8))); #elif ARCH_POWERPC int16 coeffs_i16[NCOEFFS] __attribute__ ((aligned (16))); #endif
b6532be3cae8baa1fee468be0153335fc3a2d220
581731c0a1c166a00d2e18ecf5e73da155fad8d1
/tools/rescomp/src/image.c
b919ac43c3d4a3938ffa91b0b4721919c778e798
[ "DOC" ]
permissive
andwn/cave-story-md
03e9004ab643574601726c41a851190c1adb25f6
2b225269c56dd7877e140f9012f8c233270cf966
refs/heads/master
2023-06-22T21:33:09.710999
2023-06-21T11:52:35
2023-06-21T11:52:35
32,826,698
531
47
null
2023-04-04T00:36:56
2015-03-24T21:39:08
C
UTF-8
C
false
false
4,658
c
image.c
#include <stdio.h> #include <string.h> #include "../inc/rescomp.h" #include "../inc/plugin.h" #include "../inc/tools.h" #include "../inc/img_tools.h" #include "../inc/tile_tools.h" #include "../inc/image.h" #include "../inc/palette.h" #include "../inc/map.h" #include "../inc/tileset.h" // forward static int isSupported(char *type); static int execute(char *info, FILE *fs, FILE *fh); // IMAGE resource support Plugin image = { isSupported, execute }; static int isSupported(char *type) { if (!strcasecmp(type, "IMAGE")) return 1; return 0; } static int execute(char *info, FILE *fs, FILE *fh) { char temp[MAX_PATH_LEN]; char id[50]; char fileIn[MAX_PATH_LEN]; char packedStr[256]; int w, h, bpp; int wt, ht; int size, psize; int packed; int maxIndex, mapBase; int nbElem; unsigned char *data; unsigned short *palette; tileimg_ *result; packed = 0; mapBase = 0; strcpy(packedStr, ""); nbElem = sscanf(info, "%s %s \"%[^\"]\" %s %d", temp, id, temp, packedStr, &mapBase); if (nbElem < 3) { printf("Wrong IMAGE definition\n"); printf("IMAGE name \"file\" [packed [mapbase]]\n"); printf(" name Image variable name\n"); printf(" file the image to convert to Image structure (should be a 8bpp .bmp or .png)\n"); printf(" packed compression type, accepted values:\n"); printf(" -1 / BEST / AUTO = use best compression\n"); printf(" 0 / NONE = no compression\n"); printf(" 1 / APLIB = aplib library (good compression ratio but slow)\n"); printf(" 2 / FAST / LZ4W = custom lz4 compression (average compression ratio but fast)\n"); printf(" mapbase define the base tilemap value, useful to set the priority, default palette and base tile index.\n"); return FALSE; } // adjust input file path adjustPath(resDir, temp, fileIn); // get packed value packed = getCompression(packedStr); // retrieve basic infos about the image if (!Img_getInfos(fileIn, &w, &h, &bpp)) return FALSE; // get size in tile wt = (w + 7) / 8; ht = (h + 7) / 8; // inform about incorrect size if ((w & 7) != 0) { printf("Warning: Image %s width is not a multiple of 8 (%d)\n", fileIn, w); printf("Width changed to %d\n", wt * 8); } if ((h & 7) != 0) { printf("Warning: Image %s height is not a multiple of 8 (%d)\n", fileIn, h); printf("Height changed to %d\n", ht * 8); } // get image data (always 8bpp) data = Img_getData(fileIn, &size, 8, 8); if (!data) return FALSE; // find max color index maxIndex = getMaxIndex(data, size); // not allowed here if (maxIndex >= 64) { printf("Error: Image %s use color index >= 64\n", fileIn); printf("IMAGE resource require image with a maximum of 64 colors.\n"); return FALSE; } // convert to tiled image result = getTiledImage(data, wt, ht, TRUE, mapBase); if (!result) return FALSE; // pack data if (packed != PACK_NONE) { int tmpPacked; tmpPacked = packed; if (!packTileSet(result->tileset, &tmpPacked)) return FALSE; tmpPacked = packed; if (!packMap(result->map, &tmpPacked)) return FALSE; } // get palette palette = Img_getPalette(fileIn, &psize); if (!palette) return FALSE; // optimize palette size if (maxIndex < 16) psize = 16; else if (maxIndex < 32) psize = 32; else if (maxIndex < 48) psize = 48; else psize = 64; // EXPORT PALETTE strcpy(temp, id); strcat(temp, "_palette"); outPalette(palette, 0, psize, fs, fh, temp, FALSE); // EXPORT TILEMAP strcpy(temp, id); strcat(temp, "_tilemap"); outMap(result->map, fs, fh, temp, FALSE); // EXPORT TILESET strcpy(temp, id); strcat(temp, "_tileset"); outTileset(result->tileset, fs, fh, temp, FALSE); // EXPORT IMAGE outImage(fs, fh, id, TRUE); return TRUE; } void outImage(FILE* fs, FILE* fh, char* id, int global) { // output Image structure decl(fs, fh, "Image", id, 2, global); // Palette pointer fprintf(fs, " dc.l %s_palette\n", id); // TileSet pointer fprintf(fs, " dc.l %s_tileset\n", id); // Map pointer fprintf(fs, " dc.l %s_tilemap\n", id); fprintf(fs, "\n"); }
38044d1eac39b348040811f2a5b7fc94352dbac6
aa3befea459382dc5c01c925653d54f435b3fb0f
/drivers/sensors/lis2dh.c
f1fcf2597d7d23a1ece068ab17643f1ec0c10fea
[ "MIT-open-group", "BSD-3-Clause", "HPND-sell-variant", "BSD-4-Clause-UC", "LicenseRef-scancode-warranty-disclaimer", "MIT-0", "LicenseRef-scancode-bsd-atmel", "LicenseRef-scancode-gary-s-brown", "LicenseRef-scancode-proprietary-license", "SunPro", "MIT", "LicenseRef-scancode-public-domain-disclaimer", "LicenseRef-scancode-other-permissive", "HPND", "ISC", "Apache-2.0", "LicenseRef-scancode-public-domain", "BSD-2-Clause", "GPL-1.0-or-later", "CC-BY-2.0", "CC-BY-4.0" ]
permissive
apache/nuttx
14519a7bff4a87935d94fb8fb2b19edb501c7cec
606b6d9310fb25c7d92c6f95bf61737e3c79fa0f
refs/heads/master
2023-08-25T06:55:45.822534
2023-08-23T16:03:31
2023-08-24T21:25:47
228,103,273
407
241
Apache-2.0
2023-09-14T18:26:05
2019-12-14T23:27:55
C
UTF-8
C
false
false
53,763
c
lis2dh.c
/**************************************************************************** * drivers/sensors/lis2dh.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The * ASF licenses this file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. * ****************************************************************************/ /**************************************************************************** * Included Files ****************************************************************************/ #include <nuttx/config.h> #include <nuttx/arch.h> #include <assert.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <poll.h> #include <debug.h> #include <nuttx/kmalloc.h> #include <nuttx/mutex.h> #include <nuttx/signal.h> #include <nuttx/random.h> #include <nuttx/i2c/i2c_master.h> #include <nuttx/sensors/lis2dh.h> /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ #ifdef CONFIG_LIS2DH_DEBUG # define lis2dh_dbg(x, ...) _info(x, ##__VA_ARGS__) #else # define lis2dh_dbg(x, ...) sninfo(x, ##__VA_ARGS__) #endif #ifndef CONFIG_LIS2DH_I2C_FREQUENCY # define CONFIG_LIS2DH_I2C_FREQUENCY 400000 #endif #ifdef CONFIG_LIS2DH_DRIVER_SELFTEST # define LSB_AT_10BIT_RESOLUTION 4 # define LSB_AT_12BIT_RESOLUTION 1 # define SELFTEST_BUF_SIZE 5 # define SELFTEST_MAX_READ_ATTEMPTS 200 # define SELFTEST_ABS_DIFF_MIN_10BIT 17 # define SELFTEST_ABS_DIFF_MAX_10_BIT 360 # define SELFTEST_ABS_DIFF_MIN_12BIT (LSB_AT_10BIT_RESOLUTION * SELFTEST_ABS_DIFF_MIN_10BIT) # define SELFTEST_ABS_DIFF_MAX_12BIT (LSB_AT_10BIT_RESOLUTION * SELFTEST_ABS_DIFF_MAX_10_BIT) # define SELFTEST_0 0 # define SELFTEST_1 1 #endif /* Miscellaneous macros */ #define LIS2DH_I2C_RETRIES 10 #define LIS2DH_COUNT_INTS /**************************************************************************** * Private Data Types ****************************************************************************/ enum interrupts { LIS2DH_INT1 = 1, LIS2DH_INT2 = 2 }; struct lis2dh_dev_s { FAR struct i2c_master_s *i2c; /* I2C interface */ uint8_t addr; /* I2C address */ FAR struct lis2dh_config_s *config; /* Platform specific configuration */ struct lis2dh_setup *setup; /* User defined device operation mode setup */ struct lis2dh_vector_s vector_data; /* Latest read data read from lis2dh */ int scale; /* Full scale in milliG */ mutex_t devlock; /* Manages exclusive access to this structure */ bool fifo_used; /* LIS2DH configured to use FIFO */ bool fifo_stopped; /* FIFO got full and has stopped. */ #ifdef LIS2DH_COUNT_INTS volatile int16_t int_pending; /* Interrupt received but data not read, yet */ #else volatile bool int_pending; /* Interrupt received but data not read, yet */ #endif struct pollfd *fds[CONFIG_LIS2DH_NPOLLWAITERS]; }; /**************************************************************************** * Private Function prototypes ****************************************************************************/ static int lis2dh_open(FAR struct file *filep); static int lis2dh_close(FAR struct file *filep); static ssize_t lis2dh_read(FAR struct file *, FAR char *, size_t); static ssize_t lis2dh_write(FAR struct file *filep, FAR const char *buffer, size_t buflen); static int lis2dh_ioctl(FAR struct file *filep, int cmd, unsigned long arg); static int lis2dh_access(FAR struct lis2dh_dev_s *dev, uint8_t subaddr, FAR uint8_t *buf, int length); static int lis2dh_get_reading(FAR struct lis2dh_dev_s *dev, FAR struct lis2dh_vector_s *res, bool force_read); static int lis2dh_powerdown(FAR struct lis2dh_dev_s *dev); static int lis2dh_reboot(FAR struct lis2dh_dev_s *dev); static int lis2dh_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup); static int lis2dh_int_handler(int irq, FAR void *context, FAR void *arg); static int lis2dh_setup(FAR struct lis2dh_dev_s *dev, FAR struct lis2dh_setup *new_setup); static inline int16_t lis2dh_raw_to_mg(uint8_t raw_hibyte, uint8_t raw_lobyte, int scale); static int lis2dh_read_temp(FAR struct lis2dh_dev_s *dev, FAR int16_t *temper); static int lis2dh_clear_interrupts(FAR struct lis2dh_dev_s *priv, uint8_t interrupts); static unsigned int lis2dh_get_fifo_readings(FAR struct lis2dh_dev_s *priv, FAR struct lis2dh_result *res, unsigned int readcount, FAR int *perr); #ifdef CONFIG_LIS2DH_DRIVER_SELFTEST static int lis2dh_handle_selftest(FAR struct lis2dh_dev_s *priv); static int16_t lis2dh_raw_convert_to_12bit(uint8_t raw_hibyte, uint8_t raw_lobyte); static FAR const struct lis2dh_vector_s * lis2dh_get_raw_readings(FAR struct lis2dh_dev_s *dev, FAR int *err); #endif /**************************************************************************** * Private Data ****************************************************************************/ static const struct file_operations g_lis2dhops = { lis2dh_open, /* open */ lis2dh_close, /* close */ lis2dh_read, /* read */ lis2dh_write, /* write */ NULL, /* seek */ lis2dh_ioctl, /* ioctl */ NULL, /* mmap */ NULL, /* truncate */ lis2dh_poll /* poll */ }; /**************************************************************************** * Private Functions ****************************************************************************/ static int lis2dh_who_am_i(FAR struct lis2dh_dev_s *dev, uint8_t *id) { int ret; ret = lis2dh_access(dev, ST_LIS2DH_WHOAMI_REG, id, 1); if (ret < 0) { lis2dh_dbg("Cannot read who am i value\n"); return -EIO; } return ret; } /**************************************************************************** * Name: lis2dh_open * * Description: * This function is called whenever the LIS2DH device is opened. * ****************************************************************************/ static int lis2dh_open(FAR struct file *filep) { FAR struct inode *inode = filep->f_inode; FAR struct lis2dh_dev_s *priv = inode->i_private; uint8_t regval; int ret = OK; /* Probe device */ if (lis2dh_access(priv, ST_LIS2DH_WHOAMI_REG, &regval, 1) > 0) { /* Check chip identification, in the future several more compatible * parts may be added here. */ if (regval == ST_LIS2DH_WHOAMI_VALUE) { priv->config->irq_enable(priv->config, true); /* Normal exit point */ ret = lis2dh_clear_interrupts(priv, LIS2DH_INT1 | LIS2DH_INT2); return ret; } /* Otherwise, we mark an invalid device found at given address */ ret = -ENODEV; } else { /* No response at given address is marked as */ ret = -EFAULT; } /* Error exit */ return ret; } /**************************************************************************** * Name: lis2dh_close * * Description: * This routine is called when the LIS2DH device is closed. * ****************************************************************************/ static int lis2dh_close(FAR struct file *filep) { FAR struct inode *inode = filep->f_inode; FAR struct lis2dh_dev_s *priv = inode->i_private; priv->config->irq_enable(priv->config, false); return lis2dh_powerdown(priv); } /**************************************************************************** * Name: lis2dh_fifo_start * * Description: * This function restarts FIFO reading. * ****************************************************************************/ static int lis2dh_fifo_start(FAR struct lis2dh_dev_s *priv) { uint8_t buf; int ret = OK; buf = 0x00 | priv->setup->trigger_selection | priv->setup->fifo_trigger_threshold; if (lis2dh_access(priv, ST_LIS2DH_FIFO_CTRL_REG, &buf, -1) != 1) { lis2dh_dbg("lis2dh: Failed to write FIFO control register\n"); ret = -EIO; } else { buf = priv->setup->fifo_mode | priv->setup->trigger_selection | priv->setup->fifo_trigger_threshold; if (lis2dh_access(priv, ST_LIS2DH_FIFO_CTRL_REG, &buf, -1) != 1) { lis2dh_dbg("lis2dh: Failed to write FIFO control register\n"); ret = -EIO; } else { priv->fifo_stopped = false; lis2dh_dbg("lis2dh: FIFO restarted\n"); } } return ret; } /**************************************************************************** * Name: lis2dh_read * * Description: * This routine is called when the LIS2DH device is read. * ****************************************************************************/ static ssize_t lis2dh_read(FAR struct file *filep, FAR char *buffer, size_t buflen) { FAR struct inode *inode = filep->f_inode; FAR struct lis2dh_dev_s *priv = inode->i_private; FAR struct lis2dh_result *ptr; int readcount = (buflen - sizeof(struct lis2dh_res_header)) / sizeof(struct lis2dh_vector_s); uint8_t buf; uint8_t int1_src = 0; uint8_t int2_src = 0; irqstate_t flags; int ret; if (buflen < sizeof(struct lis2dh_result) || (buflen - sizeof(struct lis2dh_res_header)) % sizeof(struct lis2dh_vector_s) != 0) { lis2dh_dbg("lis2dh: Illegal amount of bytes to read: %d\n", buflen); return -EINVAL; } ret = nxmutex_lock(&dev->devlock); if (ret < 0) { return ret; } /* Do not allow read() if no SNIOC_WRITESETUP first. */ if (!priv->setup) { lis2dh_dbg("lis2dh: Read from unconfigured device\n"); return -EINVAL; } flags = enter_critical_section(); #ifdef LIS2DH_COUNT_INTS if (priv->int_pending > 0) { priv->int_pending--; } DEBUGASSERT(priv->int_pending >= 0 && priv->int_pending < 10); #else priv->int_pending = false; #endif leave_critical_section(flags); /* Set pointer to first measurement data */ ptr = (FAR struct lis2dh_result *)buffer; ptr->header.meas_count = 0; if (!priv->fifo_used) { /* FIFO not used, read only one sample. */ if (readcount > 0) { ret = lis2dh_get_reading(priv, &ptr->measurements[0], true); if (ret < 0) { lis2dh_dbg("lis2dh: Failed to read xyz\n"); } else { ptr->header.meas_count = 1; } } } else /* FIFO modes */ { uint8_t fifo_mode = priv->setup->fifo_mode & ST_LIS2DH_FIFOCR_MODE_MASK; bool fifo_empty = false; uint8_t fifo_num_samples; ptr->header.meas_count = 0; do { /* Check if FIFO needs to be restarted after being read empty. * We need to read SRC_REG before reading measurement, as reading * sample from FIFO clears OVRN_FIFO flag. */ if (lis2dh_access(priv, ST_LIS2DH_FIFO_SRC_REG, &buf, 1) != 1) { lis2dh_dbg("lis2dh: Failed to read FIFO source register\n"); return -EIO; } if (fifo_mode != LIS2DH_STREAM_MODE) { /* FIFO is full and has stopped. */ priv->fifo_stopped |= !!(buf & ST_LIS2DH_FIFOSR_OVRN_FIFO); } if (buf & ST_LIS2DH_FIFOSR_OVRN_FIFO) { lis2dh_dbg("lis2dh: FIFO overrun\n"); } if (buf & ST_LIS2DH_FIFOSR_EMPTY) { lis2dh_dbg("lis2dh: FIFO empty\n"); fifo_empty = true; if (fifo_mode != LIS2DH_STREAM_MODE) { priv->fifo_stopped = true; } /* FIFO is empty, skip reading. */ break; } /* How many samples available in FIFO? */ fifo_num_samples = (buf & ST_LIS2DH_FIFOSR_NUM_SAMP_MASK) + 1; if (fifo_num_samples > (readcount - ptr->header.meas_count)) { fifo_num_samples = (readcount - ptr->header.meas_count); } ptr->header.meas_count += lis2dh_get_fifo_readings(priv, ptr, fifo_num_samples, &ret); } while (!fifo_empty && ptr->header.meas_count < readcount); if (!fifo_empty && fifo_mode != LIS2DH_TRIGGER_MODE) { /* FIFO was not read empty, more data available. */ flags = enter_critical_section(); #ifdef LIS2DH_COUNT_INTS priv->int_pending++; #else priv->int_pending = true; #endif poll_notify(priv->fds, CONFIG_LIS2DH_NPOLLWAITERS, POLLIN); leave_critical_section(flags); } else if (fifo_mode != LIS2DH_STREAM_MODE && priv->fifo_stopped) { /* FIFO is empty and has stopped by overrun event. Reset FIFO for * further reading. */ ret = lis2dh_fifo_start(priv); } } /* Make sure interrupt will get cleared (by reading this register) in case * of latched configuration. */ buf = 0; if (lis2dh_access(priv, ST_LIS2DH_INT1_SRC_REG, &buf, 1) != 1) { lis2dh_dbg("lis2dh: Failed to read INT1_SRC_REG\n"); ret = -EIO; } if (buf & ST_LIS2DH_INT_SR_ACTIVE) { /* Interrupt has happened */ int1_src = buf; ptr->header.int1_occurred = true; } else { ptr->header.int1_occurred = false; } /* Make sure interrupt will get cleared (by reading this register) in case * of latched configuration. */ buf = 0; if (lis2dh_access(priv, ST_LIS2DH_INT2_SRC_REG, &buf, 1) != 1) { lis2dh_dbg("lis2dh: Failed to read INT2_SRC_REG\n"); ret = -EIO; } if (buf & ST_LIS2DH_INT_SR_ACTIVE) { /* Interrupt has happened */ int2_src = buf; ptr->header.int2_occurred = true; } else { ptr->header.int2_occurred = false; } ptr->header.int1_source = int1_src; ptr->header.int2_source = int2_src; nxmutex_unlock(&dev->devlock); /* 'ret' was just for debugging, we do return partial reads here. */ return sizeof(ptr->header) + ptr->header.meas_count * sizeof(struct lis2dh_vector_s); } /**************************************************************************** * Name: lis2dh_write * Description: * This routine is called when the LIS2DH device is written to. ****************************************************************************/ static ssize_t lis2dh_write(FAR struct file *filep, FAR const char *buffer, size_t buflen) { DEBUGASSERT(filep != NULL && buffer != NULL && buflen > 0); return -ENOSYS; } /**************************************************************************** * Name: lis2dh_ioctl * * Description: * This routine is called when ioctl function call * for the LIS2DH device is done. * ****************************************************************************/ static int lis2dh_ioctl(FAR struct file *filep, int cmd, unsigned long arg) { FAR struct inode *inode; FAR struct lis2dh_dev_s *priv; int ret; uint8_t buf; DEBUGASSERT(filep); inode = filep->f_inode; DEBUGASSERT(inode && inode->i_private); priv = (FAR struct lis2dh_dev_s *)inode->i_private; ret = nxmutex_lock(&dev->devlock); if (ret < 0) { return ret; } switch (cmd) { case SNIOC_WRITESETUP: { /* Write to the configuration registers. */ ret = lis2dh_setup(priv, (struct lis2dh_setup *)arg); lis2dh_dbg("lis2dh: conf: %p ret: %d\n", (struct lis2dh_setup *)arg, ret); /* Make sure interrupt will get cleared in * case of latched configuration. */ lis2dh_clear_interrupts(priv, LIS2DH_INT1 | LIS2DH_INT2); } break; case SNIOC_WRITE_INT1THRESHOLD: { buf = (uint8_t)arg; if (lis2dh_access(priv, ST_LIS2DH_INT1_THS_REG, &buf, -1) != 1) { lis2dh_dbg("lis2dh: Failed to write INT1_THS_REG\n"); ret = -EIO; } lis2dh_clear_interrupts(priv, LIS2DH_INT1); } break; case SNIOC_WRITE_INT2THRESHOLD: { buf = (uint8_t)arg; if (lis2dh_access(priv, ST_LIS2DH_INT2_THS_REG, &buf, -1) != 1) { lis2dh_dbg("lis2dh: Failed to write INT2_THS_REG\n"); ret = -EIO; } lis2dh_clear_interrupts(priv, LIS2DH_INT2); } break; case SNIOC_RESET_HPFILTER: { /* Read reference register to reset/recalib DC offset for HP filter */ if (lis2dh_access(priv, ST_LIS2DH_REFERENCE_REG, &buf, 1) != 1) { lis2dh_dbg("lis2dh: Failed to write reference register\n"); ret = -EIO; } lis2dh_clear_interrupts(priv, LIS2DH_INT2); } break; case SNIOC_START_SELFTEST: #ifdef CONFIG_LIS2DH_DRIVER_SELFTEST { priv->config->irq_enable(priv->config, false); lis2dh_clear_interrupts(priv, LIS2DH_INT1 | LIS2DH_INT2); ret = lis2dh_handle_selftest(priv); priv->config->irq_enable(priv->config, true); } #else { ret = -EINVAL; } #endif break; case SNIOC_READ_TEMP: { ret = lis2dh_read_temp(priv, (int16_t *)arg); } break; case SNIOC_WHO_AM_I: { ret = lis2dh_who_am_i(priv, (uint8_t *)arg); } break; default: { lis2dh_dbg("lis2dh: Unrecognized cmd: %d\n", cmd); ret = -ENOTTY; } break; } nxmutex_unlock(&dev->devlock); return ret; } /**************************************************************************** * Name: lis2dh_poll * * Description: * This routine is called during LIS2DH device poll * ****************************************************************************/ static int lis2dh_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup) { FAR struct inode *inode; FAR struct lis2dh_dev_s *priv; int ret; int i; DEBUGASSERT(filep && fds); inode = filep->f_inode; DEBUGASSERT(inode && inode->i_private); priv = (FAR struct lis2dh_dev_s *)inode->i_private; ret = nxmutex_lock(&dev->devlock); if (ret < 0) { return ret; } if (setup) { /* Ignore waits that do not include POLLIN */ if ((fds->events & POLLIN) == 0) { ret = -EDEADLK; goto out; } /* This is a request to set up the poll. Find an available * slot for the poll structure reference */ for (i = 0; i < CONFIG_LIS2DH_NPOLLWAITERS; i++) { /* Find an available slot */ if (!priv->fds[i]) { /* Bind the poll structure and this slot */ priv->fds[i] = fds; fds->priv = &priv->fds[i]; break; } } if (i >= CONFIG_LIS2DH_NPOLLWAITERS) { fds->priv = NULL; ret = -EBUSY; goto out; } if (priv->int_pending) { poll_notify(priv->fds, CONFIG_LIS2DH_NPOLLWAITERS, POLLIN); } } else if (fds->priv) { /* This is a request to tear down the poll. */ struct pollfd **slot = (struct pollfd **)fds->priv; DEBUGASSERT(slot != NULL); /* Remove all memory of the poll setup */ *slot = NULL; fds->priv = NULL; } out: nxmutex_unlock(&dev->devlock); return ret; } /**************************************************************************** * Name: lis2dh_callback * * Description: * lis2dh interrupt handler * ****************************************************************************/ static int lis2dh_int_handler(int irq, FAR void *context, FAR void *arg) { FAR struct lis2dh_dev_s *priv = (FAR struct lis2dh_dev_s *)arg; irqstate_t flags; DEBUGASSERT(priv != NULL); flags = enter_critical_section(); #ifdef LIS2DH_COUNT_INTS priv->int_pending++; #else priv->int_pending = true; #endif poll_notify(priv->fds, CONFIG_LIS2DH_NPOLLWAITERS, POLLIN); leave_critical_section(flags); return OK; } #ifdef CONFIG_LIS2DH_DRIVER_SELFTEST /**************************************************************************** * Name: lis2dh_clear_registers * * Description: * Clear lis2dh registers * * Input Parameters: * priv - pointer to LIS2DH Private Structure * * Returned Value: * Returns OK in case of success, otherwise ERROR * ****************************************************************************/ static int lis2dh_clear_registers(FAR struct lis2dh_dev_s *priv) { uint8_t buf = 0; uint8_t i; DEBUGASSERT(priv); for (i = ST_LIS2DH_TEMP_CFG_REG; i <= ST_LIS2DH_ACT_DUR_REG; i++) { /* Skip read only registers */ if ((i <= 0x1e) || (i >= 0x27 && i <= 0x2d) || (i == 0x2f) || (i == 0x31)) { continue; } if (lis2dh_access(priv, i, &buf, -1) != 1) { lis2dh_dbg("lis2dh: Failed to clear register 0x%02x\n", i); return ERROR; } } return OK; } /**************************************************************************** * Name: lis2dh_write_register * * Description: * Clear lis2dh registers * * Input Parameters: * priv - pointer to LIS2DH Private Structure * reg - target register * value - value to write * * Returned Value: * Returns OK in case of success, otherwise ERROR * ****************************************************************************/ static int lis2dh_write_register(FAR struct lis2dh_dev_s *priv, uint8_t reg, uint8_t value) { DEBUGASSERT(priv); if (lis2dh_access(priv, reg, &value, -1) != 1) { lis2dh_dbg("lis2dh: Failed to write %d to register 0x%02x\n", value, reg); return ERROR; } return OK; } /**************************************************************************** * Name: lis2dh_read_register * * Description: * read lis2dh register * * Input Parameters: * priv - pointer to LIS2DH Private Structure * reg - register to read * * Returned Value: * Returns positive register value in case of success, * otherwise ERROR ( < 0) ****************************************************************************/ static int lis2dh_read_register(FAR struct lis2dh_dev_s *priv, uint8_t reg) { uint8_t buf; DEBUGASSERT(priv); if (lis2dh_access(priv, reg, &buf, sizeof(buf)) == sizeof(buf)) { return buf; } return ERROR; } /**************************************************************************** * Name: lis2dh_handle_selftest * * Description: * Handle selftest. Note, that after running selftest lis2dh is left in * shutdown mode without valid setup. Therefore SNIOC_WRITESETUP must be * sent again to proceed with normal operations. * ****************************************************************************/ static int lis2dh_handle_selftest(FAR struct lis2dh_dev_s *priv) { const struct lis2dh_vector_s *results; uint8_t i; uint8_t j; uint8_t buf; int16_t avg_x_no_st = 0; int16_t avg_y_no_st = 0; int16_t avg_z_no_st = 0; int16_t avg_x_with_st = 0; int16_t avg_y_with_st = 0; int16_t avg_z_with_st = 0; int16_t abs_st_x_value; int16_t abs_st_y_value; int16_t abs_st_z_value; int ret = OK; int err = OK; DEBUGASSERT(priv); lis2dh_powerdown(priv); if (lis2dh_clear_registers(priv) != OK) { ret = -EIO; goto out; } /* Set the control register (23h) to ±2g FS, normal mode with BDU (Block * Data Update) and HR (High Resolution) bits enabled. */ if (lis2dh_write_register(priv, ST_LIS2DH_CTRL_REG4, 0x88) != OK) { lis2dh_dbg("lis2dh: Failed to write CTRL4 REG for selftest\n"); ret = -EIO; goto out; } /* Set the control register (20h) to 50Hz ODR (Output Data Rate) with * X/Y/Z axis enabled. */ if (lis2dh_write_register(priv, ST_LIS2DH_CTRL_REG1, 0x47) != OK) { lis2dh_dbg("lis2dh: Failed to write CTRL1 REG for selftest\n"); ret = -EIO; goto out; } /* Dummy reads so that values have stabilized */ for (i = 0; i < 20; i++) { if (lis2dh_get_raw_readings(priv, &err) == NULL) { ret = -EIO; goto out; } } for (i = 0; i < SELFTEST_BUF_SIZE; i++) { results = lis2dh_get_raw_readings(priv, &err); if (results == NULL) { ret = -EIO; goto out; } avg_x_no_st += results->x; avg_y_no_st += results->y; avg_z_no_st += results->z; } avg_x_no_st = avg_x_no_st / SELFTEST_BUF_SIZE; avg_y_no_st = avg_y_no_st / SELFTEST_BUF_SIZE; avg_z_no_st = avg_z_no_st / SELFTEST_BUF_SIZE; for (i = SELFTEST_0; i <= SELFTEST_1; i++) { avg_x_with_st = 0; avg_y_with_st = 0; avg_z_with_st = 0; /* Enable self-test 0 or 1 at +/-2g FS with BDU and HR bits enabled. */ buf = (i == SELFTEST_0) ? 0x8a : 0x8c; if (lis2dh_write_register(priv, ST_LIS2DH_CTRL_REG4, buf) != OK) { lis2dh_dbg("lis2dh: Failed to write CTRL4 REG for selftest\n"); ret = -EIO; goto out; } /* Dummy reads so that values have stabilized */ for (i = 0; i < 10; i++) { if (lis2dh_get_raw_readings(priv, &err) == NULL) { ret = -EIO; goto out; } } for (j = 0; j < SELFTEST_BUF_SIZE; j++) { results = lis2dh_get_raw_readings(priv, &err); if (results == NULL) { ret = -EIO; goto out; } avg_x_with_st += results->x; avg_y_with_st += results->y; avg_z_with_st += results->z; } avg_x_with_st = avg_x_with_st / SELFTEST_BUF_SIZE; avg_y_with_st = avg_y_with_st / SELFTEST_BUF_SIZE; avg_z_with_st = avg_z_with_st / SELFTEST_BUF_SIZE; abs_st_x_value = abs(avg_x_with_st - avg_x_no_st); abs_st_y_value = abs(avg_y_with_st - avg_y_no_st); abs_st_z_value = abs(avg_z_with_st - avg_z_no_st); syslog(LOG_NOTICE, "ST %d, ABSX: %d, ABSY: %d, ABSZ: %d\n", i, abs_st_x_value, abs_st_y_value, abs_st_z_value); if (abs_st_x_value < SELFTEST_ABS_DIFF_MIN_12BIT || abs_st_x_value > SELFTEST_ABS_DIFF_MAX_12BIT || abs_st_y_value < SELFTEST_ABS_DIFF_MIN_12BIT || abs_st_y_value > SELFTEST_ABS_DIFF_MAX_12BIT || abs_st_z_value < SELFTEST_ABS_DIFF_MIN_12BIT || abs_st_z_value > SELFTEST_ABS_DIFF_MAX_12BIT) { syslog(LOG_NOTICE, "Selftest %d fail! Limits (%d <= value <= %d). " "Results: x: %d, y: %d, z: %d ", i, SELFTEST_ABS_DIFF_MIN_12BIT, SELFTEST_ABS_DIFF_MAX_12BIT, abs_st_x_value, abs_st_y_value, abs_st_z_value); ret = -ERANGE; goto out; } } /* Verify INT1 and INT2 lines */ if (lis2dh_clear_registers(priv) != OK) { ret = -EIO; goto out; } /* Both INT lines should be low */ if (priv->config->read_int1_pin != NULL) { if (priv->config->read_int1_pin() != 0) { syslog(LOG_NOTICE, "INT1 line is HIGH - expected LOW\n"); ret = -ENXIO; goto out; } } if (priv->config->read_int2_pin) { if (priv->config->read_int2_pin() != 0) { syslog(LOG_NOTICE, "INT2 line is HIGH - expected LOW\n"); ret = -ENODEV; goto out; } } /* 400Hz ODR all axes enabled * FIFO overrun & DATA READY on INT1 * FIFO enabled and INT1 & INT2 latched * FIFO mode, INT1 , THS 0 * OR combination, all events enabled */ if ((lis2dh_write_register(priv, ST_LIS2DH_CTRL_REG1, 0x77) != OK) || (lis2dh_write_register(priv, ST_LIS2DH_CTRL_REG3, 0x12) != OK) || (lis2dh_write_register(priv, ST_LIS2DH_CTRL_REG5, 0x4a) != OK) || (lis2dh_write_register(priv, ST_LIS2DH_FIFO_CTRL_REG, 0x40) != OK) || (lis2dh_write_register(priv, ST_LIS2DH_INT1_CFG_REG, 0x3f) != OK)) { syslog(LOG_NOTICE, "Writing registers for INT line check failed\n"); ret = -EIO; goto out; } /* Clear INT1 & INT2 */ if ((lis2dh_read_register(priv, ST_LIS2DH_INT1_SRC_REG) == ERROR) || (lis2dh_read_register(priv, ST_LIS2DH_INT2_SRC_REG) == ERROR)) { syslog(LOG_NOTICE, "Failed to clear INT1 / INT2 registers\n"); ret = -EIO; goto out; } nxsig_usleep(20000); /* Now INT1 should have been latched high and INT2 should be still low */ if (priv->config->read_int1_pin) { if (priv->config->read_int1_pin() != 1) { syslog(LOG_NOTICE, "INT1 line is LOW - expected HIGH\n"); ret = -ENXIO; goto out; } } if (priv->config->read_int2_pin != NULL) { if (priv->config->read_int2_pin() != 0) { syslog(LOG_NOTICE, "INT2 line is HIGH - expected LOW\n"); ret = -ENODEV; goto out; } /* Enable interrupt 1 on INT2 pin */ if (lis2dh_write_register(priv, ST_LIS2DH_CTRL_REG6, 0x40) != OK) { syslog(LOG_NOTICE, "Failed to enable interrupt 1 on INT2 pin"); ret = -EIO; goto out; } nxsig_usleep(20000); if (priv->config->read_int2_pin() != 1) { syslog(LOG_NOTICE, "INT2 line is LOW - expected HIGH\n"); ret = -ENODEV; goto out; } } out: lis2dh_clear_registers(priv); lis2dh_powerdown(priv); return ret; } /**************************************************************************** * Name: lis2dh_raw_to_mg * * Description: * Convert raw acceleration value to mg * * Input Parameters: * raw_hibyte - Hi byte of raw data * raw_lobyte - Lo byte of raw data * * Returned Value: * Returns acceleration value in mg ****************************************************************************/ static int16_t lis2dh_raw_convert_to_12bit(uint8_t raw_hibyte, uint8_t raw_lobyte) { int16_t value; value = (raw_hibyte << 8) | raw_lobyte; value = value >> 4; value &= 0xfff; if (value & 0x800) { value = ~value; value &= 0xfff; value += 1; value = -value; } return value; } /**************************************************************************** * Name: lis2dh_data_available * * Description: * Check if new data is available to read * * Input Parameters: * dev - pointer to LIS2DH Private Structure * * Returned Value: * Return true if new data is available. Otherwise returns false * ****************************************************************************/ static bool lis2dh_data_available(FAR struct lis2dh_dev_s *dev) { uint8_t retval; DEBUGASSERT(dev); if (lis2dh_access(dev, ST_LIS2DH_STATUS_REG, &retval, sizeof(retval)) == sizeof(retval)) { return ((retval & ST_LIS2DH_SR_ZYXDA) != 0); } return false; } /**************************************************************************** * Name: lis2dh_get_raw_readings * * Description: * Read X, Y, Z - acceleration values from chip * * Input Parameters: * dev - pointer to LIS2DH Private Structure * * Returned Value: * Returns acceleration vectors (High resolution = 12bit values) on * success, NULL otherwise. * ****************************************************************************/ static FAR const struct lis2dh_vector_s * lis2dh_get_raw_readings(FAR struct lis2dh_dev_s *dev, int *err) { uint8_t retval[6]; uint8_t retries_left = SELFTEST_MAX_READ_ATTEMPTS; DEBUGASSERT(dev); *err = 0; while (--retries_left > 0) { nxsig_usleep(20000); if (lis2dh_data_available(dev)) { if (lis2dh_access(dev, ST_LIS2DH_OUT_X_L_REG, retval, sizeof(retval)) == sizeof(retval)) { dev->vector_data.x = lis2dh_raw_convert_to_12bit(retval[1], retval[0]); dev->vector_data.y = lis2dh_raw_convert_to_12bit(retval[3], retval[2]); dev->vector_data.z = lis2dh_raw_convert_to_12bit(retval[5], retval[4]); return &dev->vector_data; } return NULL; } } return NULL; } #endif /* CONFIG_LIS2DH_DRIVER_SELFTEST */ /**************************************************************************** * Name: lis2dh_clear_interrupts * * Description: * Clear interrupts from LIS2DH chip * ****************************************************************************/ static int lis2dh_clear_interrupts(FAR struct lis2dh_dev_s *priv, uint8_t interrupts) { uint8_t buf; int ret = OK; if (interrupts & LIS2DH_INT1) { /* Make sure interrupt will get cleared (by reading this register) in * case of latched configuration. */ if (lis2dh_access(priv, ST_LIS2DH_INT1_SRC_REG, &buf, 1) != 1) { lis2dh_dbg("lis2dh: Failed to read INT1_SRC_REG\n"); ret = -EIO; } } if (interrupts & LIS2DH_INT2) { /* Make sure interrupt will get cleared (by reading this register) in * case of latched configuration. */ if (lis2dh_access(priv, ST_LIS2DH_INT2_SRC_REG, &buf, 1) != 1) { lis2dh_dbg("lis2dh: Failed to read INT2_SRC_REG\n"); ret = -EIO; } } return ret; } /**************************************************************************** * Name: lis2dh_get_reading * * Description: * Read X, Y, Z - acceleration value from chip * * Input Parameters: * dev - pointer to LIS2DH Private Structure * force_read - Read even if new data is not available (old data) * * Returned Value: * Returns OK if success, negative error code otherwise * ****************************************************************************/ static int lis2dh_get_reading(FAR struct lis2dh_dev_s *dev, FAR struct lis2dh_vector_s *res, bool force_read) { int scale = dev->scale; uint8_t retval[7]; int16_t x; int16_t y; int16_t z; if (lis2dh_access(dev, ST_LIS2DH_STATUS_REG, retval, 7) == 7) { /* If result is not yet ready, return NULL */ if (!force_read && !(retval[0] & ST_LIS2DH_SR_ZYXDA)) { lis2dh_dbg("lis2dh: Results were not ready\n"); return -EAGAIN; } /* Add something to entropy pool. */ add_sensor_randomness((((uint32_t)retval[6] << 25) | ((uint32_t)retval[6] >> 7)) ^ ((uint32_t)retval[5] << 20) ^ ((uint32_t)retval[4] << 15) ^ ((uint32_t)retval[3] << 10) ^ ((uint32_t)retval[2] << 5) ^ ((uint32_t)retval[1] << 0)); x = lis2dh_raw_to_mg(retval[2], retval[1], scale); y = lis2dh_raw_to_mg(retval[4], retval[3], scale); z = lis2dh_raw_to_mg(retval[6], retval[5], scale); if (dev->setup->xy_axis_fixup) { res->x = y; res->y = -x; } else { res->x = x; res->y = y; } res->z = z; return OK; } return -EIO; } /**************************************************************************** * Name: lis2dh_get_fifo_readings * * Description: * Bulk read from FIFO * ****************************************************************************/ static unsigned int lis2dh_get_fifo_readings(FAR struct lis2dh_dev_s *priv, FAR struct lis2dh_result *res, unsigned int readcount, FAR int *perr) { int scale = priv->scale; union { uint8_t raw[6]; struct lis2dh_vector_s sample; } *buf = (void *)&res->measurements[res->header.meas_count]; bool xy_axis_fixup = priv->setup->xy_axis_fixup; size_t buflen = readcount * 6; int16_t x; int16_t y; int16_t z; unsigned int i; if (readcount == 0) { return 0; } if (lis2dh_access(priv, ST_LIS2DH_OUT_X_L_REG, (void *)buf, buflen) != buflen) { lis2dh_dbg("lis2dh: Failed to read FIFO (%d bytes, %d samples)\n", buflen, readcount); *perr = -EIO; return 0; } /* Add something to entropy pool. */ up_rngaddentropy(RND_SRC_SENSOR, (void *)buf, buflen / 4); /* Convert raw values to mG */ for (i = 0; i < readcount; i++) { x = lis2dh_raw_to_mg(buf[i].raw[1], buf[i].raw[0], scale); y = lis2dh_raw_to_mg(buf[i].raw[3], buf[i].raw[2], scale); z = lis2dh_raw_to_mg(buf[i].raw[5], buf[i].raw[4], scale); if (xy_axis_fixup) { buf[i].sample.x = y; buf[i].sample.y = -x; } else { buf[i].sample.x = x; buf[i].sample.y = y; } buf[i].sample.z = z; } return readcount; } /**************************************************************************** * Name: lis2dh_raw_to_mg * * Description: * Convert raw acceleration value to mg * * Input Parameters: * raw_hibyte - Hi byte of raw data * raw_lobyte - Lo byte of raw data * scale - full scale in milliG * * Returned Value: * Returns acceleration value in mg * ****************************************************************************/ static inline int16_t lis2dh_raw_to_mg(uint8_t raw_hibyte, uint8_t raw_lobyte, int scale) { int16_t value; /* Value is signed integer, range INT16_MIN..INT16_MAX. */ value = (raw_hibyte << 8) | raw_lobyte; /* Scale to mg, INT16_MIN..INT16_MAX => -scale..scale */ return (int32_t)value * scale / INT16_MAX; } /**************************************************************************** * Name: lis2dh_read_temp * * Description: * * Input Parameters: * * Returned Value: * ****************************************************************************/ static int lis2dh_read_temp(FAR struct lis2dh_dev_s *dev, FAR int16_t *temper) { int ret; uint8_t buf[2] = { 0 }; ret = lis2dh_access(dev, ST_LIS2DH_OUT_TEMP_L_REG, buf, 2); if (ret < 0) { lis2dh_dbg("Cannot read temperature\n"); return -EIO; } *temper = buf[0] | ((int16_t)buf[1] << 8); return OK; } /**************************************************************************** * LIS2DH Access with range check * * Description: * Read or write data via I2C * * Input Parameters: * dev LIS2DH Private Structure * subaddr LIS2DH Sub Address * buf Pointer to buffer, either for read or write access * length When >0 it denotes read access, when <0 it denotes write access * of -length * * Returned Value: * Returns actual length of data on success or negated errno. * ****************************************************************************/ static int lis2dh_access(FAR struct lis2dh_dev_s *dev, uint8_t subaddr, FAR uint8_t *buf, int length) { uint16_t flags = 0; int retval; int retries; DEBUGASSERT(dev != NULL && buf != NULL && length != 0); if (length > 0) { flags = I2C_M_READ; } else { flags = I2C_M_NOSTART; length = -length; } /* Check valid address ranges and set auto address increment flag */ if (subaddr == ST_LIS2DH_STATUS_AUX_REG) { if (length > 1) { length = 1; } } else if (subaddr >= ST_LIS2DH_OUT_TEMP_L_REG && subaddr < 0x10) { if (length > (0x10 - subaddr)) { length = 0x10 - subaddr; } } else if (subaddr >= ST_LIS2DH_TEMP_CFG_REG && subaddr <= ST_LIS2DH_ACT_DUR_REG) { if (subaddr == ST_LIS2DH_OUT_X_L_REG) { /* FIFO bulk read, length maximum 6*32 = 192 bytes. */ if (length > 6 * 32) { length = 6 * 32; } } else { if (length > (ST_LIS2DH_ACT_DUR_REG + 1 - subaddr)) { length = ST_LIS2DH_ACT_DUR_REG + 1 - subaddr; } } } else { return -EFAULT; } if (length > 1) { subaddr |= 0x80; } for (retries = 0; retries < LIS2DH_I2C_RETRIES; retries++) { /* Create message and send */ struct i2c_msg_s msgv[2] = { { .frequency = CONFIG_LIS2DH_I2C_FREQUENCY, .addr = dev->addr, .flags = 0, .buffer = &subaddr, .length = 1 }, { .frequency = CONFIG_LIS2DH_I2C_FREQUENCY, .addr = dev->addr, .flags = flags, .buffer = buf, .length = length } }; retval = I2C_TRANSFER(dev->i2c, msgv, 2); if (retval >= 0) { return length; } else { /* Some error. Try to reset I2C bus and keep trying. */ #ifdef CONFIG_I2C_RESET int ret = I2C_RESET(dev->i2c); if (ret < 0) { lis2dh_dbg("I2C_RESET failed: %d\n", ret); return ret; } #endif continue; } } lis2dh_dbg("failed, error: %d\n", retval); return retval; } /**************************************************************************** * Name: lis2dh_reboot * * Description: * * Input Parameters: * * Returned Value: * ****************************************************************************/ static int lis2dh_reboot(FAR struct lis2dh_dev_s *dev) { struct timespec start; struct timespec curr; int32_t diff_msec; uint8_t value; /* Prefer monotonic for timeout calculation when enabled. */ clock_systime_timespec(&start); /* Reboot to reset chip. */ value = ST_LIS2DH_CR5_BOOT; if (lis2dh_access(dev, ST_LIS2DH_CTRL_REG5, &value, -1) != 1) { return -EIO; } /* Reboot is completed when reboot bit is cleared. */ do { value = 0; if (lis2dh_access(dev, ST_LIS2DH_CTRL_REG5, &value, 1) != 1) { return -EIO; } if (!(value & ST_LIS2DH_CR5_BOOT)) { break; } clock_systime_timespec(&curr); diff_msec = (curr.tv_sec - start.tv_sec) * 1000; diff_msec += (curr.tv_nsec - start.tv_nsec) / (1000 * 1000); if (diff_msec > 100) { return -ETIMEDOUT; } nxsig_usleep(1); } while (true); /* Reboot completed, chip is now in power-down state. */ return OK; } /**************************************************************************** * Name: lis2dh_powerdown * * Description: * * Input Parameters: * * Returned Value: * ****************************************************************************/ static int lis2dh_powerdown(FAR struct lis2dh_dev_s * dev) { uint8_t buf = 0; int ret = OK; if (lis2dh_access(dev, ST_LIS2DH_CTRL_REG1, &buf, -1) != 1) { lis2dh_dbg("Failed to clear CTRL_REG1\n"); ret = -EIO; } return ret; } /**************************************************************************** * LIS2DH Setup * * Description: * Apply new register setup * * Input Parameters: * dev - pointer to LIS2DH Private Structure * new_setup - pointer to new setup data to be configured * * Returned Value: * Returns OK on success, ERROR otherwise. * ****************************************************************************/ static int lis2dh_setup(FAR struct lis2dh_dev_s * dev, FAR struct lis2dh_setup *new_setup) { uint8_t value; dev->setup = new_setup; /* Clear old configuration. On first boot after power-loss, reboot bit does * not get cleared, and lis2dh_reboot() times out. Anyway, chip accepts * new configuration and functions correctly. */ lis2dh_reboot(dev); /* TEMP_CFG_REG */ value = dev->setup->temp_enable ? (0x3 << 6): 0; if (lis2dh_access(dev, ST_LIS2DH_TEMP_CFG_REG, &value, -1) != 1) { goto error; } /* CTRL_REG2 */ value = dev->setup->hpmode | dev->setup->hpcf | dev->setup->fds | dev->setup->hpclick | dev->setup->hpis2 | dev->setup->hpis1; if (lis2dh_access(dev, ST_LIS2DH_CTRL_REG2, &value, -1) != 1) { goto error; } /* CTRL_REG3 */ value = dev->setup->int1_click_enable | dev->setup->int1_aoi_enable | dev->setup->int2_aoi_enable | dev->setup->int1_drdy_enable | dev->setup->int2_drdy_enable | dev->setup->int_wtm_enable | dev->setup->int_overrun_enable; if (lis2dh_access(dev, ST_LIS2DH_CTRL_REG3, &value, -1) != 1) { goto error; } /* CTRL_REG4 */ value = dev->setup->bdu | dev->setup->endian | dev->setup->fullscale | dev->setup->high_resolution_enable | dev->setup->selftest | dev->setup->spi_mode; if (lis2dh_access(dev, ST_LIS2DH_CTRL_REG4, &value, -1) != 1) { goto error; } /* CTRL_REG5 */ value = dev->setup->reboot | dev->setup->fifo_enable | dev->setup->int1_latch | dev->setup->int1_4d_enable | dev->setup->int2_latch | dev->setup->int2_4d_enable; if (lis2dh_access(dev, ST_LIS2DH_CTRL_REG5, &value, -1) != 1) { goto error; } /* CTRL_REG6 */ value = dev->setup->int2_click_enable | dev->setup->int_enable | dev->setup->boot_int1_enable | dev->setup->high_low_active; if (lis2dh_access(dev, ST_LIS2DH_CTRL_REG6, &value, -1) != 1) { goto error; } /* REFERENCE */ value = dev->setup->reference; if (lis2dh_access(dev, ST_LIS2DH_REFERENCE_REG, &value, -1) != 1) { goto error; } /* FIFO_CTRL_REG */ value = dev->setup->fifo_mode | dev->setup->trigger_selection | dev->setup->fifo_trigger_threshold; if (lis2dh_access(dev, ST_LIS2DH_FIFO_CTRL_REG, &value, -1) != 1) { goto error; } /* INT1_CFG */ value = dev->setup->int1_interrupt_mode | dev->setup->int1_enable_6d | dev->setup->int1_int_z_high_enable | dev->setup->int1_int_z_low_enable | dev->setup->int1_int_y_high_enable | dev->setup->int1_int_y_low_enable | dev->setup->int1_int_x_high_enable | dev->setup->int1_int_x_low_enable; if (lis2dh_access(dev, ST_LIS2DH_INT1_CFG_REG, &value, -1) != 1) { goto error; } /* INT1_THS */ value = dev->setup->int1_int_threshold; if (lis2dh_access(dev, ST_LIS2DH_INT1_THS_REG, &value, -1) != 1) { goto error; } /* INT1_DURATION */ value = dev->setup->int1_int_duration; if (lis2dh_access(dev, ST_LIS2DH_INT1_DUR_REG, &value, -1) != 1) { goto error; } /* INT2_CFG */ value = dev->setup->int2_interrupt_mode | dev->setup->int2_enable_6d | dev->setup->int2_int_z_high_enable | dev->setup->int2_int_z_low_enable | dev->setup->int2_int_y_high_enable | dev->setup->int2_int_y_low_enable | dev->setup->int2_int_x_high_enable | dev->setup->int2_int_x_low_enable; if (lis2dh_access(dev, ST_LIS2DH_INT2_CFG_REG, &value, -1) != 1) { goto error; } /* INT2_THS */ value = dev->setup->int2_int_threshold; if (lis2dh_access(dev, ST_LIS2DH_INT2_THS_REG, &value, -1) != 1) { goto error; } /* INT2_DURATION */ value = dev->setup->int2_int_duration; if (lis2dh_access(dev, ST_LIS2DH_INT2_DUR_REG, &value, -1) != 1) { goto error; } /* CLICK_CFG */ value = dev->setup->z_double_click_enable | dev->setup->z_single_click_enable | dev->setup->y_double_click_enable | dev->setup->y_single_click_enable | dev->setup->x_double_click_enable | dev->setup->x_single_click_enable; if (lis2dh_access(dev, ST_LIS2DH_CLICK_CFG_REG, &value, -1) != 1) { goto error; } /* CLICK_THS */ value = dev->setup->click_threshold; if (lis2dh_access(dev, ST_LIS2DH_CLICK_THS_REG, &value, -1) != 1) { goto error; } /* TIME_LIMIT */ value = dev->setup->click_time_limit; if (lis2dh_access(dev, ST_LIS2DH_TIME_LIMIT_REG, &value, -1) != 1) { goto error; } /* TIME_LATENCY */ value = dev->setup->click_time_latency; if (lis2dh_access(dev, ST_LIS2DH_TIME_LATENCY_REG, &value, -1) != 1) { goto error; } /* TIME_WINDOW */ value = dev->setup->click_time_window; if (lis2dh_access(dev, ST_LIS2DH_TIME_WINDOW_REG, &value, -1) != 1) { goto error; } /* CTRL_REG1 */ value = dev->setup->data_rate | dev->setup->low_power_mode_enable | dev->setup->zen | dev->setup->yen | dev->setup->xen; if (lis2dh_access(dev, ST_LIS2DH_CTRL_REG1, &value, -1) != 1) { goto error; } switch (dev->setup->fullscale & 0x30) { default: case ST_LIS2DH_CR4_FULL_SCALE_2G: dev->scale = 2000; break; case ST_LIS2DH_CR4_FULL_SCALE_4G: dev->scale = 4000; break; case ST_LIS2DH_CR4_FULL_SCALE_8G: dev->scale = 8000; break; case ST_LIS2DH_CR4_FULL_SCALE_16G: dev->scale = 16000; break; } if (dev->setup->fifo_enable) { dev->fifo_used = true; if (lis2dh_fifo_start(dev) < 0) { goto error; } } else { dev->fifo_used = false; } return OK; error: /* Setup failed - power down */ lis2dh_powerdown(dev); return -EIO; } /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** * Name: lis2dh_register * * Description: * Register the LIS2DH character device as 'devpath' * * Input Parameters: * devpath - The full path to the driver to register. E.g., "/dev/acc0" * i2c - An instance of the I2C interface to use to communicate with * LIS2DH * addr - The I2C address of the LIS2DH. The base I2C address of the * LIS2DH is 0x18. Bit 0 can be controlled via SA0 pad - when * connected to voltage supply the address is 0x19. * config - Pointer to LIS2DH configuration * * Returned Value: * Zero (OK) on success; a negated errno value on failure. * ****************************************************************************/ int lis2dh_register(FAR const char *devpath, FAR struct i2c_master_s *i2c, uint8_t addr, FAR struct lis2dh_config_s *config) { FAR struct lis2dh_dev_s *priv; int ret; DEBUGASSERT(devpath != NULL && i2c != NULL && config != NULL); priv = (FAR struct lis2dh_dev_s *)kmm_zalloc(sizeof(struct lis2dh_dev_s)); if (!priv) { lis2dh_dbg("lis2dh: Failed to allocate instance\n"); return -ENOMEM; } nxmutex_init(&priv->devlock); priv->fifo_used = false; #ifdef LIS2DH_COUNT_INTS priv->int_pending = 0; #else priv->int_pending = false; #endif priv->i2c = i2c; priv->addr = addr; priv->config = config; ret = register_driver(devpath, &g_lis2dhops, 0666, priv); if (ret < 0) { lis2dh_dbg("lis2dh: Failed to register driver: %d\n", ret); goto errout_with_priv; } if (priv->config->irq_clear) { priv->config->irq_clear(config); } priv->config->irq_attach(config, lis2dh_int_handler, priv); priv->config->irq_enable(config, false); return OK; errout_with_priv: nxmutex_destroy(&priv->devlock); kmm_free(priv); return ret; }
d8a63df8c1d7300c7f797b2e07b4fdc1db2a8d08
b4c2b8dc89417e966a67a433267ebb9c156dbff4
/src/vehicles/sounds/DetroitDieselKenworth.h
8851cb14a87ded9a02c799c9af0195251d28e837
[]
no_license
TheDIYGuy999/Rc_Engine_Sound_ESP32
92134030dbc047627310d54ccf1fd34fb3cad791
eeeb47964861b66f8e1db34bffe35657846d8b20
refs/heads/master
2023-08-31T00:17:03.698027
2023-05-04T19:46:51
2023-05-04T19:46:51
225,658,413
230
105
null
2023-08-26T14:38:39
2019-12-03T15:51:13
C
UTF-8
C
false
false
80,630
h
DetroitDieselKenworth.h
const unsigned int sampleRate = 22050; const unsigned int sampleCount = 18200; const signed char samples[] = { 0, 1, 3, 7, 11, 17, 32, 42, 53, 63, 66, 62, 49, 38, 28, 19, 11, 5, 5, 6, 7, 10, 13, 16, 25, 41, 59, 80, 98, 113, 120, 124, 125, 123, 118, 111, 100, 88, 77, 63, 31, 9, -8, -24, -37, -45, -55, -61, -66, -71, -71, -65, -62, -59, -55, -51, -43, -30, -22, -11, -3, -2, -7, -10, -18, -22, -22, -26, -34, -36, -34, -36, -41, -43, -41, -37, -34, -32, -32, -31, -24, -20, -15, -8, -5, -13, -16, -15, -9, -2, 6, 17, 23, 28, 31, 38, 45, 50, 56, 64, 62, 53, 46, 40, 38, 41, 44, 48, 53, 56, 53, 49, 47, 43, 36, 32, 30, 27, 25, 20, 13, 4, -4, -12, -20, -29, -32, -32, -32, -28, -24, -20, -17, -17, -20, -21, -21, -24, -23, -24, -26, -25, -29, -29, -31, -38, -42, -44, -49, -51, -49, -50, -52, -53, -53, -54, -52, -51, -48, -36, -29, -17, -6, 3, 13, 17, 16, 12, 11, 3, -4, -5, -11, -12, -13, -18, -20, -21, -19, -15, -8, 3, 9, 9, 3, -2, -6, -4, -1, 5, 15, 19, 23, 34, 33, 32, 35, 35, 36, 40, 37, 34, 32, 25, 23, 22, 16, 14, 16, 16, 25, 31, 34, 35, 35, 35, 32, 29, 25, 20, 17, 20, 20, 20, 23, 26, 31, 40, 45, 46, 45, 43, 38, 39, 39, 32, 21, 9, -12, -24, -30, -34, -39, -44, -55, -59, -60, -65, -69, -65, -65, -63, -58, -53, -50, -45, -43, -38, -34, -33, -29, -24, -18, -12, -7, -5, -2, -4, -2, -2, -10, -12, -16, -17, -14, -13, -13, -13, -8, -5, -2, 2, 1, -1, -5, -14, -20, -21, -13, 7, 19, 33, 40, 46, 56, 60, 63, 58, 52, 51, 53, 51, 48, 43, 35, 27, 18, 14, 10, 8, 7, 8, 8, 8, 7, 6, -1, -9, -15, -23, -26, -34, -42, -41, -43, -42, -41, -39, -35, -30, -21, -15, -15, -18, -18, -22, -23, -26, -34, -42, -51, -49, -45, -39, -32, -25, -22, -22, -23, -27, -32, -35, -29, -23, -17, -9, -2, 2, 0, -1, 0, 1, 1, 3, 4, 9, 14, 20, 33, 36, 37, 39, 41, 38, 31, 25, 15, 7, 1, 0, 0, 4, 10, 13, 16, 13, 14, 19, 20, 25, 32, 34, 35, 33, 28, 24, 14, 9, 4, -3, -10, -17, -24, -22, -17, -12, -5, 3, 13, 22, 32, 40, 48, 57, 57, 56, 54, 48, 40, 27, 17, 8, -2, -11, -20, -30, -33, -30, -25, -18, -7, -2, 1, 2, 3, 5, -2, -8, -7, -6, -5, 4, 4, 1, -2, -9, -14, -21, -23, -22, -17, -9, -1, 11, 17, 22, 28, 31, 35, 39, 43, 44, 42, 37, 27, 17, 9, 0, -11, -21, -30, -30, -27, -18, -5, 11, 19, 23, 28, 31, 32, 39, 40, 44, 46, 42, 40, 36, 29, 21, 14, 6, -10, -19, -26, -30, -30, -30, -29, -25, -23, -18, -12, -12, -12, -17, -23, -31, -38, -42, -45, -46, -48, -55, -58, -58, -53, -46, -35, -22, -14, -4, 2, 5, 7, 5, -5, -11, -16, -20, -26, -32, -45, -55, -62, -70, -76, -79, -83, -82, -79, -77, -74, -66, -64, -62, -58, -52, -46, -34, -27, -17, -8, -4, 1, 10, 13, 14, 14, 11, 3, 2, 5, 9, 17, 20, 30, 35, 38, 44, 45, 47, 47, 47, 47, 47, 47, 44, 45, 47, 46, 48, 48, 44, 48, 53, 59, 65, 77, 81, 83, 89, 94, 97, 98, 98, 93, 84, 75, 67, 52, 38, 27, 14, 0, -18, -29, -37, -45, -53, -56, -57, -52, -48, -50, -51, -52, -47, -45, -43, -35, -32, -32, -29, -26, -21, -22, -23, -26, -29, -30, -34, -38, -45, -55, -61, -67, -70, -75, -73, -67, -62, -56, -50, -41, -31, -20, -5, 5, 14, 22, 26, 24, 18, 15, 13, 5, 3, 5, 8, 12, 20, 30, 33, 35, 37, 39, 40, 49, 55, 60, 66, 66, 62, 58, 57, 58, 59, 60, 49, 40, 34, 28, 24, 20, 6, -1, -10, -15, -19, -25, -26, -29, -28, -27, -27, -22, -21, -18, -15, -18, -20, -28, -34, -33, -29, -23, -10, -2, -1, 0, 4, 6, 5, 6, 11, 12, 13, 17, 14, 7, 1, -5, -16, -15, -10, -9, -7, -5, -4, -2, 4, 11, 17, 23, 24, 27, 31, 25, 18, 13, 13, 16, 20, 24, 24, 20, 20, 23, 25, 23, 19, 9, 4, 3, 5, 8, 8, 6, 5, 4, 0, -9, -19, -37, -48, -54, -60, -62, -66, -64, -60, -56, -51, -48, -46, -46, -42, -36, -31, -24, -13, -6, 1, 9, 15, 21, 24, 24, 22, 21, 17, 9, 6, 4, 2, 0, 2, -3, -7, -8, -12, -16, -23, -25, -26, -29, -28, -27, -23, -21, -17, -13, -11, -6, 2, 9, 20, 28, 30, 40, 45, 48, 49, 49, 50, 44, 38, 31, 25, 20, 17, 17, 20, 20, 16, 14, 11, 7, 3, -2, -7, -13, -6, 0, 3, 9, 13, 14, 18, 17, 20, 23, 24, 29, 25, 18, 12, 6, -1, -12, -13, -15, -16, -12, -7, -3, -1, 1, 4, 4, -2, -7, -14, -20, -20, -20, -22, -23, -28, -34, -37, -45, -51, -57, -62, -67, -70, -73, -69, -67, -66, -64, -62, -63, -62, -59, -53, -45, -33, -29, -28, -27, -26, -28, -25, -22, -21, -15, -10, -7, -4, -1, 4, 6, 8, 16, 21, 28, 34, 38, 42, 47, 50, 56, 62, 66, 68, 69, 65, 60, 58, 56, 49, 49, 48, 43, 40, 36, 27, 24, 24, 27, 30, 31, 30, 29, 27, 26, 28, 27, 26, 22, 18, 16, 13, 8, 4, -1, -11, -19, -24, -33, -36, -37, -37, -35, -28, -20, -9, 4, 17, 29, 39, 42, 43, 40, 37, 36, 32, 29, 25, 21, 14, -1, -13, -28, -37, -39, -40, -36, -31, -25, -20, -16, -12, -14, -15, -19, -27, -32, -31, -26, -18, -11, -6, -6, -15, -16, -17, -17, -15, -16, -20, -25, -28, -27, -24, -17, -16, -15, -15, -16, -16, -19, -20, -23, -30, -34, -40, -44, -43, -35, -24, -12, 7, 23, 38, 52, 67, 80, 88, 89, 88, 87, 85, 81, 75, 70, 67, 60, 48, 34, 25, 14, 5, -2, -7, -9, -8, -6, -2, 2, 5, 9, 11, 9, 5, 3, 9, 9, 10, 13, 14, 12, 2, -6, -17, -26, -35, -49, -52, -56, -65, -69, -70, -70, -71, -71, -74, -79, -84, -89, -92, -94, -94, -93, -83, -77, -74, -66, -61, -60, -57, -56, -53, -51, -48, -40, -22, -11, 2, 13, 18, 18, 18, 23, 26, 27, 32, 39, 40, 43, 49, 52, 54, 60, 66, 76, 86, 92, 96, 93, 88, 83, 77, 70, 58, 52, 46, 42, 37, 31, 25, 27, 33, 35, 38, 45, 47, 47, 48, 51, 50, 46, 39, 30, 24, 19, 13, 5, -1, -8, -12, -13, -14, -16, -23, -32, -40, -48, -66, -74, -80, -88, -94, -94, -94, -93, -85, -78, -74, -63, -56, -46, -37, -31, -26, -19, -16, -11, -6, -1, 2, -1, 1, 0, -4, -4, -1, 0, -1, -2, -2, -5, -4, 1, 5, 7, 4, 2, 6, 9, 12, 16, 20, 24, 24, 27, 32, 36, 38, 39, 41, 41, 41, 44, 48, 52, 56, 57, 60, 61, 54, 51, 49, 43, 37, 33, 26, 21, 16, 13, 6, -8, -14, -22, -30, -35, -38, -40, -37, -34, -29, -23, -17, -13, -15, -19, -23, -27, -30, -27, -22, -14, -8, -1, 13, 19, 19, 15, 7, -5, -16, -20, -22, -22, -24, -24, -24, -25, -24, -25, -29, -33, -31, -29, -26, -24, -26, -27, -28, -25, -24, -23, -19, -14, -7, -2, 4, 11, 13, 16, 19, 20, 25, 25, 24, 24, 22, 22, 23, 21, 22, 28, 34, 40, 44, 46, 48, 49, 48, 48, 49, 47, 46, 46, 44, 39, 31, 25, 16, 7, -3, -14, -29, -36, -40, -41, -39, -42, -41, -41, -40, -36, -33, -30, -31, -33, -35, -37, -39, -42, -43, -39, -31, -26, -25, -26, -29, -32, -33, -32, -32, -35, -40, -45, -49, -50, -51, -47, -39, -33, -26, -21, -19, -17, -14, -7, -1, 10, 19, 26, 34, 41, 44, 48, 49, 50, 55, 59, 64, 65, 65, 64, 60, 61, 62, 61, 59, 51, 43, 35, 29, 29, 30, 33, 38, 49, 50, 50, 49, 44, 36, 28, 24, 20, 17, 15, 16, 15, 11, 6, -2, -13, -24, -26, -32, -38, -39, -39, -35, -30, -30, -32, -37, -42, -54, -63, -72, -81, -85, -89, -87, -83, -77, -72, -70, -71, -71, -72, -71, -66, -59, -43, -31, -17, -6, -1, 4, 7, 8, 10, 15, 21, 26, 27, 29, 27, 23, 25, 29, 31, 34, 33, 32, 32, 34, 39, 41, 38, 36, 31, 26, 23, 24, 24, 22, 26, 29, 35, 41, 45, 50, 48, 45, 42, 38, 34, 34, 32, 27, 24, 23, 24, 24, 22, 19, 14, 7, -2, -8, -11, -15, -19, -22, -28, -35, -38, -45, -54, -65, -69, -73, -76, -73, -68, -60, -52, -43, -37, -32, -27, -26, -27, -25, -22, -20, -13, -10, -8, -3, 3, 6, 7, 3, -4, -10, -15, -18, -18, -17, -16, -13, -11, -9, -6, 0, 9, 20, 31, 44, 49, 55, 60, 61, 61, 56, 45, 35, 28, 21, 17, 18, 22, 27, 32, 37, 44, 48, 52, 56, 57, 57, 56, 54, 52, 50, 46, 40, 35, 31, 30, 30, 29, 27, 25, 21, 14, 6, -2, -14, -20, -24, -26, -24, -18, -15, -12, -9, -8, -10, -19, -29, -38, -41, -40, -31, -21, -12, -5, -1, 1, 0, -3, -5, -6, -3, 2, 7, 6, 1, -7, -17, -31, -38, -42, -45, -50, -54, -58, -59, -55, -47, -39, -28, -21, -14, -10, -8, -1, 6, 11, 11, 12, 12, 10, 7, 4, 3, -2, -6, -10, -18, -23, -29, -31, -32, -38, -40, -41, -44, -49, -51, -57, -60, -58, -56, -52, -46, -36, -26, -14, -1, 13, 29, 34, 34, 34, 31, 23, 15, 8, 0, -4, -7, -10, -15, -17, -19, -23, -25, -28, -28, -26, -24, -20, -14, -1, 7, 14, 24, 33, 36, 37, 34, 28, 20, 14, 10, 7, 5, 3, 4, 6, 7, 9, 8, 5, 2, 2, 4, 4, 6, 4, 1, 0, -2, -6, -14, -19, -21, -24, -24, -22, -16, -9, 1, 19, 28, 37, 42, 47, 48, 49, 52, 52, 50, 47, 41, 36, 31, 25, 17, 8, 5, 5, 9, 13, 15, 15, 10, 8, 8, 3, 0, 4, 8, 15, 23, 30, 42, 47, 49, 50, 49, 48, 44, 44, 46, 45, 42, 40, 33, 26, 21, 15, 8, -7, -12, -12, -17, -20, -22, -35, -39, -41, -43, -43, -44, -39, -39, -37, -37, -36, -35, -33, -31, -29, -25, -20, -13, -10, -11, -13, -15, -22, -31, -36, -40, -39, -35, -31, -29, -22, -16, -16, -10, 1, 3, 10, 16, 16, 10, 2, -4, -11, -17, -17, -13, -8, 3, 13, 19, 23, 21, 17, 17, 17, 17, 18, 14, 13, 10, 8, 11, 17, 19, 17, 17, 18, 15, 11, 8, 4, 0, -1, 2, 6, 6, 5, 2, -3, -8, -14, -17, -14, -10, -7, 0, -3, -11, -14, -15, -18, -16, -18, -24, -28, -31, -34, -32, -28, -24, -19, -10, 2, 6, 8, 12, 15, 17, 19, 20, 18, 14, 11, 7, 3, 0, 1, 2, 2, 3, 5, 7, 9, 12, 13, 12, 9, 6, 6, 6, 8, 9, 7, 8, 14, 18, 25, 33, 37, 40, 46, 50, 49, 46, 43, 38, 33, 27, 22, 12, 0, -6, -12, -21, -23, -26, -29, -28, -21, -15, -11, -11, -12, -12, -9, -5, 2, 6, 9, 12, 16, 20, 24, 25, 20, 9, 1, -8, -14, -18, -23, -33, -39, -44, -47, -47, -50, -57, -64, -72, -77, -79, -79, -75, -71, -68, -61, -55, -51, -49, -48, -47, -42, -37, -29, -19, -8, 0, 8, 20, 22, 22, 21, 16, 10, 4, 4, 2, 3, 6, 8, 13, 13, 12, 9, 7, 1, 1, 4, 6, 9, 14, 20, 24, 32, 39, 42, 49, 55, 57, 60, 60, 58, 56, 52, 49, 44, 35, 27, 19, 12, 4, 0, -6, -17, -19, -20, -24, -31, -37, -50, -56, -60, -62, -62, -63, -60, -55, -51, -45, -38, -34, -34, -31, -28, -26, -20, -15, -9, -6, -4, 1, 6, 15, 18, 19, 21, 20, 18, 16, 17, 17, 15, 16, 21, 23, 25, 28, 30, 30, 29, 24, 23, 22, 21, 25, 25, 26, 27, 32, 37, 42, 46, 44, 41, 39, 36, 32, 28, 22, 16, 12, 7, 1, -1, -1, 0, 3, 9, 14, 16, 17, 21, 24, 21, 18, 13, 5, -2, -2, -3, -6, -10, -15, -21, -25, -28, -26, -21, -14, -5, 11, 21, 31, 36, 36, 38, 36, 33, 33, 33, 34, 33, 36, 37, 33, 29, 25, 17, 12, 4, -3, -8, -17, -19, -18, -18, -12, -2, 5, 3, 0, -7, -20, -30, -40, -47, -53, -59, -61, -61, -57, -49, -40, -34, -31, -22, -14, -9, -1, 6, 6, 7, 6, 7, 9, 12, 14, 11, 6, -3, -16, -30, -47, -55, -63, -70, -77, -83, -84, -86, -84, -76, -62, -34, -13, 9, 30, 47, 62, 75, 76, 74, 68, 62, 55, 47, 34, 21, 11, -1, -16, -25, -35, -43, -49, -53, -58, -61, -65, -68, -69, -70, -70, -69, -68, -65, -55, -42, -32, -23, -17, -12, -12, -9, -7, -4, 2, 6, 14, 16, 17, 21, 24, 27, 28, 23, 19, 19, 18, 18, 25, 29, 28, 21, 9, -11, -21, -26, -27, -22, -16, -5, 6, 19, 33, 43, 50, 67, 79, 92, 104, 112, 120, 119, 118, 116, 110, 102, 83, 70, 54, 35, 20, 5, -15, -24, -34, -42, -47, -55, -57, -58, -57, -56, -53, -48, -47, -44, -37, -25, -14, -5, 1, 3, -1, -8, -22, -31, -40, -46, -48, -49, -43, -38, -37, -42, -47, -51, -54, -53, -49, -42, -36, -25, -23, -23, -24, -25, -25, -23, -17, -9, 1, 13, 30, 40, 52, 62, 64, 65, 65, 64, 66, 67, 66, 65, 64, 64, 67, 66, 61, 50, 44, 41, 35, 32, 30, 23, 20, 15, 10, 6, -1, -7, -8, -9, -8, -12, -18, -22, -27, -24, -17, -12, -12, -14, -22, -31, -37, -43, -38, -32, -27, -20, -19, -24, -28, -30, -31, -33, -37, -42, -46, -48, -48, -46, -44, -49, -47, -46, -44, -36, -23, -17, -11, -4, 3, 7, 14, 18, 16, 11, 9, 9, 3, 0, -1, -4, -6, -2, 1, 2, 3, 4, 5, 6, 9, 13, 18, 27, 38, 47, 50, 47, 43, 40, 42, 45, 43, 39, 35, 31, 27, 24, 27, 29, 28, 32, 32, 27, 25, 25, 25, 35, 40, 43, 45, 41, 37, 32, 30, 33, 35, 33, 27, 24, 21, 16, 17, 18, 18, 20, 18, 15, 14, 13, 8, 0, -10, -21, -30, -41, -46, -51, -53, -57, -61, -63, -63, -65, -68, -67, -65, -51, -44, -36, -31, -34, -35, -40, -42, -39, -38, -41, -42, -40, -39, -33, -28, -25, -22, -24, -26, -28, -24, -18, -11, -5, -2, 0, 1, -3, -5, -4, -5, -5, -8, -6, -4, -2, 6, 11, 16, 24, 30, 35, 38, 38, 32, 29, 30, 34, 36, 34, 27, 19, 15, 10, 4, 2, -1, -3, -6, -6, -3, -3, 0, -4, -7, -4, -6, -4, 0, 1, 2, -2, -13, -21, -31, -34, -33, -33, -30, -30, -25, -20, -18, -15, -19, -23, -30, -33, -34, -36, -30, -28, -23, -14, -10, -7, -4, -5, -5, -9, -12, -8, -2, 7, 15, 21, 25, 26, 26, 26, 28, 30, 31, 32, 35, 38, 38, 38, 42, 43, 40, 35, 27, 11, 2, -3, -4, -4, 0, 3, 4, 3, 4, 4, 4, 6, 7, 10, 13, 14, 9, 5, -1, -6, -12, -22, -30, -38, -47, -51, -50, -43, -33, -20, -6, 7, 18, 35, 47, 54, 57, 58, 53, 41, 36, 30, 26, 19, 9, 0, -11, -20, -25, -26, -20, -12, -7, -2, 1, 1, -2, -8, -18, -28, -32, -33, -25, -15, -6, 3, 6, 9, 10, 10, 13, 16, 22, 35, 46, 53, 54, 50, 40, 34, 24, 18, 16, 9, 6, 3, 3, 2, -2, -5, -20, -31, -40, -49, -53, -44, -32, -17, -1, 13, 28, 40, 46, 52, 54, 53, 48, 41, 40, 38, 36, 31, 15, 4, -8, -18, -23, -24, -17, -12, -3, 8, 14, 15, 12, 9, 1, -6, -9, -14, -19, -26, -33, -38, -40, -43, -43, -42, -43, -43, -35, -29, -24, -18, -11, -4, 0, 1, 0, -5, -9, -12, -19, -26, -32, -36, -41, -49, -54, -58, -62, -64, -64, -56, -52, -51, -50, -52, -57, -58, -54, -55, -52, -47, -44, -37, -29, -18, -9, -5, 0, 0, -2, 0, 5, 10, 17, 20, 27, 31, 31, 38, 38, 35, 32, 28, 26, 25, 27, 32, 38, 44, 44, 46, 47, 42, 39, 39, 39, 41, 47, 52, 58, 64, 74, 83, 93, 102, 106, 107, 101, 96, 89, 82, 74, 52, 34, 17, 3, -12, -26, -44, -55, -60, -62, -59, -53, -45, -41, -39, -37, -35, -31, -25, -20, -16, -15, -11, -6, -4, -4, -4, -7, -13, -24, -32, -40, -47, -51, -52, -56, -61, -70, -82, -89, -84, -79, -70, -56, -44, -31, -13, -3, 3, 6, 7, 7, 11, 12, 18, 24, 22, 22, 22, 22, 27, 34, 37, 39, 41, 47, 56, 65, 76, 76, 67, 55, 42, 33, 21, 11, 9, 9, 6, 7, 4, 1, -3, -6, -5, -4, -6, -9, -11, -11, -7, -5, -4, -5, -7, -6, -11, -9, -9, -13, -16, -17, -15, -12, -10, -5, 0, 1, 1, 2, 2, 1, 0, -2, -4, -5, -6, -9, -8, -11, -12, -15, -20, -23, -27, -24, -22, -21, -18, -12, -4, 0, 4, 8, 11, 10, 5, 2, -2, -4, 0, 3, 8, 7, 5, 4, 4, 7, 8, 10, 11, 9, 12, 17, 20, 19, 16, 10, 0, -16, -25, -34, -40, -41, -41, -37, -32, -26, -23, -21, -15, -12, -9, -6, -6, -6, 0, 4, 11, 14, 15, 11, 5, 4, 3, 4, 7, 7, 10, 8, 4, 0, -6, -14, -16, -19, -17, -13, -14, -15, -14, -16, -18, -16, -14, -18, -17, -16, -16, -7, 1, 12, 23, 28, 31, 34, 32, 33, 34, 32, 33, 32, 32, 33, 30, 27, 24, 21, 20, 19, 20, 20, 20, 22, 20, 19, 18, 16, 19, 21, 26, 28, 25, 22, 18, 17, 21, 20, 15, 1, -9, -17, -23, -22, -17, -13, -17, -21, -25, -30, -34, -32, -32, -32, -28, -19, -10, -6, -4, -4, -7, -7, -3, -7, -11, -10, -11, -15, -20, -28, -35, -40, -42, -41, -41, -42, -46, -50, -55, -66, -74, -78, -75, -67, -52, -44, -40, -41, -43, -39, -32, -28, -25, -25, -27, -27, -21, -12, -1, 9, 16, 17, 18, 16, 11, 13, 20, 34, 44, 50, 52, 51, 50, 48, 47, 43, 40, 40, 42, 46, 45, 43, 41, 34, 22, 15, 13, 14, 15, 20, 27, 31, 40, 47, 49, 50, 50, 47, 41, 37, 33, 26, 25, 30, 36, 39, 34, 26, 17, 7, -6, -23, -48, -62, -68, -64, -52, -36, -4, 15, 33, 43, 51, 54, 54, 58, 56, 51, 48, 40, 31, 21, 12, 4, -3, -2, -2, -5, -9, -12, -16, -13, -10, -10, -10, -14, -27, -36, -45, -52, -55, -57, -53, -48, -44, -41, -36, -23, -15, -8, -2, 5, 11, 10, 7, 1, -4, -11, -18, -24, -26, -23, -20, -21, -26, -34, -45, -53, -56, -52, -46, -37, -28, -19, -6, 8, 34, 50, 62, 73, 82, 90, 93, 96, 97, 96, 94, 83, 69, 54, 41, 25, 14, 4, -5, -11, -18, -21, -15, -16, -20, -21, -20, -19, -15, -9, -2, 5, 8, 7, 2, 0, 0, 1, 3, 2, -5, -15, -24, -31, -43, -61, -73, -85, -95, -101, -106, -113, -113, -110, -107, -100, -91, -83, -77, -73, -70, -64, -50, -44, -41, -40, -42, -48, -51, -50, -46, -41, -37, -24, -18, -15, -13, -13, -12, -12, -6, 3, 13, 26, 42, 48, 54, 62, 69, 74, 82, 89, 96, 98, 98, 100, 100, 96, 90, 81, 69, 55, 53, 50, 44, 42, 39, 27, 26, 27, 25, 26, 31, 34, 32, 32, 35, 34, 35, 33, 31, 29, 28, 32, 34, 33, 29, 22, 15, 5, -10, -19, -29, -41, -54, -79, -88, -90, -88, -78, -67, -57, -51, -48, -44, -36, -26, -14, -3, 7, 13, 15, 12, 9, 8, 6, 1, -1, 3, 2, 4, 2, -6, -14, -22, -24, -25, -25, -22, -17, -14, -12, -8, -8, -10, -5, -5, -6, -4, -1, 4, 9, 15, 22, 26, 30, 38, 38, 38, 37, 36, 38, 39, 39, 40, 39, 37, 37, 37, 35, 32, 24, 16, 8, 4, 1, -4, -10, -15, -19, -20, -21, -19, -14, -8, -5, -3, 0, 3, 5, 5, 1, -6, -12, -19, -22, -18, -13, -7, -3, 3, 9, 7, 4, -3, -12, -22, -25, -27, -24, -17, -16, -16, -20, -23, -28, -34, -40, -45, -44, -37, -32, -33, -33, -33, -34, -34, -32, -27, -23, -18, -14, -9, -5, 3, 15, 19, 26, 27, 27, 31, 38, 39, 40, 41, 41, 39, 42, 43, 43, 48, 53, 57, 58, 54, 47, 44, 42, 33, 31, 26, 23, 23, 16, 9, 3, -4, -10, -12, -17, -22, -25, -30, -36, -38, -39, -34, -27, -25, -26, -28, -30, -31, -34, -35, -35, -36, -32, -27, -25, -27, -30, -37, -45, -49, -46, -41, -38, -26, -19, -17, -16, -15, -14, -17, -18, -19, -22, -22, -13, -8, -3, 2, 10, 20, 35, 41, 43, 43, 45, 48, 46, 46, 45, 43, 38, 34, 32, 30, 31, 33, 38, 40, 37, 33, 27, 19, 20, 26, 34, 39, 42, 43, 37, 33, 28, 20, 14, 13, 11, 14, 17, 13, 10, 3, -2, -5, -8, -14, -23, -32, -32, -30, -30, -34, -49, -56, -60, -59, -56, -52, -53, -52, -54, -59, -62, -62, -66, -69, -73, -78, -85, -83, -78, -73, -64, -55, -45, -28, -15, -3, 1, 5, 8, 13, 15, 16, 19, 20, 16, 15, 15, 13, 13, 15, 19, 22, 27, 31, 35, 39, 39, 39, 38, 38, 39, 37, 32, 28, 26, 26, 25, 23, 25, 25, 25, 29, 29, 28, 24, 18, 18, 17, 20, 26, 33, 36, 37, 35, 23, 20, 19, 16, 13, 8, 1, -7, -17, -24, -33, -48, -54, -61, -68, -73, -76, -77, -71, -61, -49, -40, -34, -24, -20, -15, -10, -11, -25, -31, -33, -35, -32, -24, -12, -5, 2, 9, 12, 10, 10, 10, 12, 16, 18, 21, 22, 21, 20, 20, 24, 35, 39, 44, 49, 51, 54, 57, 58, 54, 45, 37, 26, 19, 17, 17, 17, 18, 28, 36, 42, 48, 52, 59, 57, 52, 47, 43, 41, 37, 34, 35, 35, 35, 37, 37, 34, 32, 28, 23, 19, 14, 6, -2, -9, -17, -30, -30, -28, -26, -22, -19, -14, -10, -8, -7, -10, -17, -21, -21, -17, -11, -9, -14, -17, -20, -22, -21, -21, -18, -19, -19, -15, -9, -1, -2, -4, -9, -16, -22, -32, -36, -41, -47, -51, -52, -47, -42, -37, -34, -32, -28, -24, -20, -20, -17, -13, -10, -6, -2, 2, 3, 2, 1, -1, -6, -12, -15, -20, -24, -26, -28, -28, -30, -36, -39, -42, -44, -43, -41, -36, -30, -23, -12, 1, 15, 20, 22, 24, 22, 17, 14, 11, 5, -2, -5, -13, -15, -14, -13, -9, -7, -4, -7, -12, -13, -14, -16, -12, -11, -9, -4, 2, 12, 17, 21, 26, 28, 30, 28, 23, 16, 7, 1, -2, 0, 1, 2, 5, 7, 8, 8, 7, 6, 4, 2, -1, -5, -8, -12, -17, -20, -22, -21, -17, -11, -9, -3, -1, 1, 8, 16, 24, 36, 40, 39, 39, 39, 39, 39, 37, 37, 36, 36, 39, 43, 42, 41, 39, 29, 18, 15, 12, 7, 5, 2, -10, -18, -22, -24, -23, -19, -12, -5, 6, 22, 37, 51, 60, 68, 70, 72, 75, 67, 59, 51, 38, 25, 8, -4, -15, -26, -34, -42, -51, -55, -59, -62, -69, -75, -81, -83, -81, -78, -72, -64, -53, -39, -29, -22, -20, -24, -27, -26, -21, -15, -10, -8, -12, -18, -21, -23, -23, -19, -19, -17, -13, -7, 6, 10, 12, 12, 10, 4, -1, -5, -7, -4, -1, 6, 7, 9, 12, 15, 21, 29, 32, 33, 34, 35, 33, 31, 26, 21, 18, 17, 15, 14, 17, 21, 22, 22, 23, 18, 10, 8, 7, 1, 2, 1, -1, -4, -7, -13, -15, -12, -11, -15, -16, -17, -20, -22, -20, -20, -23, -23, -22, -21, -19, -19, -17, -14, -12, -10, -7, -6, -8, -6, -3, 0, 5, 12, 15, 16, 15, 14, 11, 11, 13, 17, 23, 28, 36, 48, 53, 55, 57, 58, 47, 39, 33, 28, 26, 27, 28, 22, 14, 9, 6, 6, 12, 18, 21, 25, 27, 29, 29, 30, 31, 27, 24, 22, 22, 22, 19, 15, 9, -2, -7, -12, -16, -22, -28, -27, -24, -20, -15, -10, -3, 0, 1, -2, -9, -13, -20, -25, -27, -27, -29, -35, -37, -36, -37, -43, -47, -52, -57, -59, -58, -59, -59, -56, -50, -40, -39, -41, -41, -43, -45, -41, -36, -37, -38, -40, -43, -43, -43, -40, -36, -32, -23, -14, -8, 5, 10, 12, 13, 11, 5, -5, -5, -3, 0, 3, 4, 7, 10, 11, 17, 21, 15, 11, 6, 2, 3, 8, 14, 20, 22, 21, 22, 26, 31, 36, 43, 52, 57, 68, 71, 70, 68, 62, 55, 39, 27, 19, 7, 0, -7, -14, -16, -19, -19, -15, -10, -8, -11, -18, -27, -39, -46, -45, -43, -40, -36, -31, -27, -21, -22, -25, -25, -23, -22, -17, -13, -11, -10, -10, -8, -5, -4, -1, 12, 19, 25, 35, 42, 42, 40, 35, 28, 25, 20, 16, 12, 6, 3, -1, -9, -11, -13, -12, -5, 6, 18, 37, 49, 53, 53, 54, 50, 41, 36, 26, 13, -1, -18, -23, -26, -26, -27, -28, -23, -21, -12, -2, 4, 17, 19, 20, 19, 17, 16, 9, 2, -5, -9, -12, -11, -8, -10, -10, -10, -12, -10, -3, 5, 12, 21, 23, 20, 19, 19, 23, 26, 26, 28, 27, 26, 27, 31, 40, 43, 42, 39, 32, 21, 15, 16, 12, 6, 5, 3, 2, 4, 7, 7, 2, -10, -17, -23, -27, -31, -34, -37, -39, -42, -42, -36, -34, -32, -25, -19, -13, -5, 2, 7, 11, 10, 10, 9, 0, -6, -7, -9, -12, -13, -19, -29, -37, -42, -49, -64, -72, -79, -84, -83, -77, -59, -44, -28, -11, 6, 26, 49, 61, 70, 72, 67, 59, 51, 40, 29, 21, 12, -4, -14, -29, -43, -54, -64, -67, -69, -71, -68, -62, -57, -53, -49, -46, -44, -38, -32, -30, -25, -20, -15, -12, -20, -27, -30, -32, -28, -19, -13, -8, -6, 0, 7, 16, 17, 17, 21, 23, 30, 41, 46, 45, 43, 37, 26, 19, 12, 6, -4, -16, -27, -28, -25, -18, -5, 20, 36, 54, 69, 87, 101, 116, 123, 126, 127, 124, 117, 101, 86, 70, 54, 36, 14, -1, -17, -30, -38, -41, -45, -47, -47, -48, -45, -41, -32, -24, -19, -15, -16, -14, -13, -11, -7, -6, -6, -6, -10, -16, -19, -21, -23, -26, -27, -30, -33, -37, -47, -51, -49, -46, -44, -41, -38, -37, -35, -32, -33, -36, -37, -37, -33, -25, -16, -3, 3, 9, 18, 27, 39, 52, 56, 61, 68, 74, 79, 88, 90, 85, 77, 67, 54, 50, 49, 46, 38, 29, 21, 18, 13, 8, 3, -2, -14, -15, -15, -19, -21, -20, -19, -17, -14, -11, -9, -5, 0, 0, -2, -2, -3, -13, -16, -16, -17, -19, -19, -21, -24, -28, -35, -45, -59, -68, -71, -71, -70, -65, -66, -67, -61, -52, -43, -30, -22, -14, -3, 7, 14, 21, 18, 15, 10, 4, -2, -4, -6, -8, -8, -9, -12, -12, -12, -12, -9, -5, -1, 6, 12, 11, 14, 21, 22, 26, 29, 32, 37, 37, 37, 32, 24, 19, 12, 10, 10, 7, 12, 20, 28, 32, 30, 24, 21, 17, 16, 14, 14, 15, 17, 24, 34, 39, 43, 45, 45, 43, 39, 38, 35, 30, 31, 41, 49, 54, 54, 49, 41, 31, 26, 19, 9, -2, -21, -33, -41, -45, -48, -54, -63, -66, -68, -68, -65, -58, -54, -50, -45, -39, -33, -30, -30, -31, -35, -37, -34, -22, -17, -7, 0, 0, 0, -4, -8, -12, -19, -28, -35, -36, -35, -34, -30, -30, -35, -33, -28, -25, -20, -10, -2, 4, 14, 20, 25, 30, 32, 38, 47, 52, 54, 55, 52, 46, 42, 41, 41, 43, 46, 46, 39, 32, 21, 8, 0, -4, -11, -15, -16, -12, -6, -3, -1, -1, -6, -13, -18, -17, -17, -22, -26, -31, -34, -38, -34, -25, -24, -22, -22, -23, -22, -25, -26, -27, -32, -33, -29, -27, -28, -29, -31, -35, -31, -26, -20, -12, -10, -11, -10, -12, -10, -4, -1, 5, 10, 14, 15, 17, 19, 17, 18, 18, 23, 28, 37, 44, 44, 39, 34, 28, 22, 19, 17, 17, 13, 9, 6, 2, -4, -9, -14, -17, -14, -9, -2, 9, 15, 16, 13, 7, 0, -6, -11, -19, -22, -21, -19, -16, -14, -15, -14, -13, -11, -8, -4, 1, 9, 19, 31, 42, 52, 51, 46, 39, 30, 13, 5, 0, -5, -12, -14, -17, -21, -25, -29, -30, -28, -24, -15, -8, -1, 6, 15, 19, 23, 24, 25, 23, 19, 15, 11, 10, 4, -4, -6, -9, -4, 4, 11, 24, 28, 31, 34, 37, 41, 39, 39, 36, 30, 25, 11, -1, -14, -27, -35, -39, -39, -34, -24, -12, 0, 12, 27, 32, 37, 41, 47, 53, 55, 51, 45, 45, 43, 33, 23, 9, -5, -18, -28, -39, -43, -44, -41, -35, -23, -16, -7, 1, 7, 13, 17, 16, 14, 12, 11, 10, 4, -5, -19, -31, -37, -41, -39, -36, -32, -29, -25, -16, -15, -14, -12, -10, -11, -16, -18, -26, -35, -41, -49, -52, -55, -57, -56, -55, -54, -54, -52, -49, -46, -44, -49, -51, -50, -47, -38, -25, -20, -15, -10, -3, 0, 4, 4, 1, -3, -10, -13, -16, -16, -13, -11, -6, -1, 1, 9, 20, 29, 36, 42, 43, 41, 44, 51, 52, 51, 44, 36, 28, 23, 24, 24, 26, 27, 26, 27, 35, 44, 55, 62, 66, 68, 66, 64, 64, 64, 58, 44, 33, 20, 9, 1, -6, -24, -31, -38, -43, -43, -44, -43, -40, -37, -35, -31, -18, -14, -8, 0, 2, 4, 10, 12, 13, 16, 16, 9, 5, -3, -13, -23, -32, -48, -55, -62, -64, -59, -61, -67, -66, -65, -60, -53, -34, -17, -2, 12, 24, 32, 34, 30, 25, 21, 19, 19, 22, 23, 24, 26, 25, 23, 20, 17, 15, 20, 24, 27, 34, 37, 36, 34, 30, 28, 26, 27, 28, 27, 26, 21, 17, 15, 12, 11, 14, 14, 13, 13, 13, 11, 9, 5, -2, -8, -11, -15, -14, -12, -11, -16, -23, -26, -30, -32, -30, -29, -25, -15, -5, 6, 13, 16, 17, 16, 14, 9, 5, 1, -7, -8, -2, 3, 8, 11, 15, 17, 16, 15, 15, 11, 8, 9, 12, 15, 17, 18, 17, 11, 6, 2, -5, -10, -14, -18, -18, -10, -2, -4, -5, -12, -21, -26, -31, -30, -27, -23, -19, -6, 1, 4, 5, 5, 2, -9, -17, -25, -32, -36, -40, -42, -41, -40, -39, -37, -30, -27, -27, -25, -25, -28, -31, -31, -29, -23, -16, -9, -1, 1, 3, 5, 4, -3, -7, -12, -15, -11, -5, 0, 1, -1, -2, -6, -8, -8, -8, -6, -4, -3, 5, 11, 19, 23, 26, 30, 23, 21, 23, 24, 25, 30, 37, 38, 39, 40, 43, 44, 41, 37, 32, 27, 23, 20, 18, 18, 21, 24, 27, 26, 20, 13, 8, 4, 5, 6, 10, 14, 14, 15, 20, 23, 27, 30, 32, 31, 23, 18, 12, 4, -6, -16, -21, -25, -24, -21, -20, -16, -13, -9, -5, -1, 1, -1, -2, -1, -3, -6, -10, -13, -15, -17, -22, -28, -38, -44, -48, -50, -50, -53, -53, -52, -52, -50, -49, -54, -53, -54, -56, -54, -50, -46, -43, -37, -33, -30, -24, -19, -18, -16, -10, -4, 0, -1, -2, -3, -1, 2, 7, 9, 10, 10, 12, 15, 16, 17, 17, 20, 24, 29, 33, 33, 29, 26, 24, 18, 18, 20, 23, 26, 37, 40, 41, 43, 44, 42, 38, 34, 28, 24, 21, 20, 15, 15, 14, 12, 12, 10, 6, 1, -4, -9, -10, -16, -22, -28, -36, -45, -49, -41, -33, -21, -10, 1, 15, 26, 39, 47, 49, 49, 46, 44, 40, 32, 23, 13, -4, -15, -23, -30, -36, -38, -33, -26, -20, -13, -9, -7, -9, -11, -16, -21, -24, -23, -17, -9, -2, 3, 10, 16, 18, 18, 19, 17, 15, 12, 7, 3, -2, -6, -5, -7, -9, -13, -18, -25, -29, -30, -30, -29, -26, -21, -20, -19, -19, -18, -15, -6, 5, 18, 33, 46, 61, 65, 68, 71, 74, 78, 84, 86, 84, 79, 71, 57, 50, 39, 25, 16, 7, -7, -14, -18, -18, -18, -14, -4, 2, 7, 7, 8, 14, 18, 24, 30, 34, 32, 19, 8, -5, -19, -33, -45, -59, -67, -72, -74, -73, -76, -80, -84, -88, -92, -94, -91, -89, -89, -88, -84, -79, -74, -71, -66, -59, -57, -50, -45, -43, -40, -36, -31, -24, -25, -28, -29, -27, -22, -13, -1, 12, 23, 33, 44, 44, 41, 38, 40, 45, 46, 50, 54, 55, 59, 63, 71, 73, 73, 71, 67, 56, 48, 41, 35, 29, 24, 25, 25, 24, 24, 27, 25, 25, 26, 28, 34, 39, 48, 53, 53, 53, 52, 48, 32, 18, 6, -2, -11, -19, -20, -23, -25, -25, -25, -30, -35, -38, -41, -47, -54, -56, -54, -51, -47, -43, -37, -30, -26, -22, -13, -5, 1, 4, 7, 8, 4, 2, -1, -2, -2, 0, 1, -4, -4, -3, -5, -4, 0, -4, -4, -3, -2, 2, 9, 16, 15, 12, 9, 10, 16, 20, 22, 26, 29, 31, 33, 33, 33, 31, 28, 25, 20, 17, 14, 15, 17, 17, 22, 25, 22, 14, 5, -4, -4, -3, -1, -1, -5, -13, -22, -30, -37, -40, -43, -43, -38, -31, -24, -19, -14, -15, -18, -19, -18, -15, -8, 1, 9, 12, 9, 2, -4, -11, -17, -21, -23, -24, -22, -15, -9, -9, -12, -22, -28, -27, -25, -23, -19, -20, -20, -20, -22, -24, -29, -32, -31, -27, -21, -14, -6, -1, 4, 7, 9, 13, 16, 21, 30, 37, 43, 44, 40, 37, 33, 29, 26, 20, 17, 17, 17, 20, 28, 28, 26, 26, 23, 16, 10, 8, 8, 11, 14, 19, 20, 19, 16, 8, 0, -11, -15, -16, -15, -14, -18, -28, -32, -35, -35, -38, -41, -41, -39, -35, -32, -32, -29, -29, -27, -21, -15, -13, -8, -7, -10, -11, -11, -13, -13, -13, -12, -11, -10, -5, -2, -2, -1, 1, -2, -5, -8, -11, -11, -11, -9, -2, 6, 15, 26, 35, 45, 46, 46, 46, 46, 47, 50, 48, 48, 51, 53, 61, 63, 61, 54, 46, 34, 19, 16, 15, 20, 30, 38, 41, 39, 34, 24, 16, 10, 7, 6, 5, 1, -2, -5, -4, -5, -8, -11, -14, -17, -19, -19, -20, -21, -21, -24, -26, -30, -35, -40, -49, -53, -57, -61, -64, -67, -73, -80, -86, -89, -94, -99, -98, -96, -93, -88, -81, -64, -52, -39, -24, -8, 3, 13, 19, 20, 18, 15, 17, 16, 16, 22, 28, 32, 36, 38, 34, 26, 20, 20, 24, 29, 33, 36, 36, 33, 34, 37, 39, 39, 41, 48, 51, 55, 57, 54, 43, 35, 29, 28, 31, 32, 33, 35, 36, 40, 44, 43, 39, 33, 26, 20, 13, 1, -10, -19, -24, -29, -34, -41, -45, -50, -54, -56, -57, -55, -52, -48, -43, -38, -33, -30, -26, -22, -20, -16, -15, -14, -12, -13, -19, -25, -31, -30, -26, -23, -20, -14, -10, -7, -7, -10, -14, -15, -12, -10, -9, -10, -12, -6, 2, 13, 24, 33, 43, 45, 49, 52, 50, 45, 34, 27, 20, 14, 9, 6, 4, 7, 14, 22, 28, 35, 40, 48, 51, 50, 49, 47, 44, 41, 36, 32, 30, 29, 31, 31, 28, 24, 20, 16, 12, 7, -2, -13, -23, -25, -26, -25, -26, -28, -27, -26, -25, -24, -25, -36, -39, -39, -37, -34, -32, -29, -28, -26, -22, -18, -7, -1, 4, 13, 20, 24, 23, 20, 13, 4, -2, -7, -13, -14, -12, -10, -13, -16, -20, -31, -37, -35, -34, -26, -19, -12, -4, 4, 13, 24, 25, 20, 16, 13, 10, 9, 8, 5, 3, 4, 4, 5, 4, 0, -6, -13, -22, -27, -32, -36, -38, -38, -35, -31, -27, -24, -20, -9, 1, 13, 25, 33, 35, 34, 30, 23, 15, 6, -4, -10, -10, -6, -2, 0, -4, -7, -12, -17, -23, -30, -39, -48, -53, -55, -52, -40, -34, -23, -9, 2, 10, 19, 20, 13, 6, 4, 2, 5, 9, 14, 12, 9, 8, 6, 6, 5, 3, 0, -5, -7, -11, -16, -19, -20, -20, -19, -16, -15, -15, -11, -11, -12, -12, -9, -7, -3, 6, 18, 27, 34, 39, 46, 46, 45, 45, 45, 42, 44, 50, 53, 51, 47, 35, 23, 12, 2, -7, -15, -20, -20, -18, -16, -14, -9, -2, 6, 15, 25, 34, 46, 53, 58, 65, 68, 65, 59, 52, 48, 45, 44, 41, 36, 31, 26, 21, 13, -5, -21, -38, -51, -59, -69, -72, -74, -79, -79, -76, -71, -63, -52, -41, -32, -25, -15, -15, -14, -8, -2, 1, 3, 5, 7, 9, 10, 5, -1, -9, -14, -14, -17, -26, -32, -33, -31, -28, -25, -26, -27, -27, -25, -19, -16, -14, -11, -8, -5, 0, 8, 15, 18, 21, 28, 42, 47, 50, 52, 52, 51, 49, 47, 43, 37, 30, 25, 25, 28, 29, 29, 25, 14, 9, 2, -6, -13, -18, -23, -26, -29, -29, -29, -29, -25, -22, -18, -15, -13, -10, -7, -5, -2, 1, 3, 4, 4, 6, 5, 2, -3, -12, -13, -12, -12, -12, -12, -14, -14, -11, -9, -9, -11, -12, -11, -12, -12, -9, -9, -7, -4, 2, 8, 19, 24, 26, 27, 27, 28, 31, 30, 29, 25, 18, 14, 11, 9, 10, 12, 14, 22, 30, 39, 46, 46, 46, 43, 42, 42, 42, 46, 43, 38, 33, 21, 9, -6, -24, -29, -34, -35, -34, -37, -40, -41, -41, -43, -45, -35, -28, -18, -7, -2, 0, -5, -13, -16, -13, -14, -18, -24, -34, -42, -47, -46, -57, -65, -65, -67, -68, -63, -57, -56, -56, -57, -56, -55, -52, -51, -51, -50, -47, -41, -37, -33, -28, -27, -18, -4, 5, 13, 14, 17, 23, 25, 28, 32, 31, 26, 14, 9, 7, 4, 2, 1, -3, -4, -1, 4, 8, 12, 14, 17, 21, 27, 35, 39, 43, 48, 54, 62, 69, 75, 69, 67, 66, 59, 55, 51, 48, 39, 31, 25, 13, 6, -4, -14, -21, -24, -23, -16, -9, -9, -11, -14, -17, -23, -29, -34, -42, -42, -36, -30, -19, -7, -2, -1, 2, 4, 2, -3, -9, -16, -21, -22, -25, -29, -24, -18, -13, -6, -1, -1, 5, 15, 22, 26, 30, 30, 30, 28, 24, 23, 18, 8, 7, 7, 8, 14, 21, 24, 22, 19, 13, 6, 5, 8, 13, 19, 21, 18, 12, 8, 4, -2, -5, -9, -16, -17, -19, -12, -5, 3, 10, 9, 10, 11, 9, 5, 1, 2, 1, 1, 2, -1, -4, -5, -4, -5, -10, -12, -10, -5, 1, 7, 12, 13, 16, 19, 19, 21, 24, 29, 36, 44, 51, 52, 49, 47, 43, 36, 28, 15, 7, 3, 1, 3, 6, 11, 12, 11, 10, 9, 7, 2, -2, -5, -10, -13, -19, -22, -25, -28, -30, -29, -28, -26, -22, -17, -8, 6, 13, 18, 21, 23, 25, 25, 21, 13, 4, -1, 1, 1, 1, 0, -9, -19, -33, -47, -61, -73, -83, -92, -96, -92, -83, -70, -57, -33, -13, 3, 17, 31, 42, 49, 52, 55, 53, 52, 48, 34, 20, 6, -6, -19, -33, -37, -43, -50, -54, -54, -54, -54, -55, -56, -60, -66, -75, -84, -90, -94, -94, -83, -74, -64, -55, -53, -53, -45, -36, -26, -17, -9, -2, 8, 19, 25, 30, 35, 33, 30, 31, 33, 33, 35, 37, 36, 33, 26, 14, 1, -8, -12, -13, -10, -13, -13, -2, 13, 29, 44, 61, 86, 97, 109, 118, 122, 124, 121, 116, 110, 102, 90, 68, 56, 43, 30, 18, 5, -11, -18, -24, -31, -33, -37, -49, -56, -62, -63, -60, -54, -47, -43, -33, -23, -17, -4, 0, 0, -1, -2, -6, -18, -25, -33, -42, -48, -51, -52, -55, -61, -64, -62, -59, -50, -38, -29, -22, -15, -11, -14, -18, -18, -21, -18, -10, 1, 9, 16, 23, 35, 44, 53, 55, 58, 74, 80, 82, 79, 78, 76, 74, 75, 69, 59, 50, 46, 48, 48, 47, 42, 32, 16, 8, 8, 5, 1, -1, -3, -5, -10, -9, -9, -10, -6, -3, 0, -1, -3, 0, 0, -2, -4, -10, -21, -33, -35, -33, -31, -29, -28, -30, -35, -41, -45, -46, -43, -38, -32, -29, -29, -30, -27, -24, -26, -25, -17, -10, -2, 3, 1, -4, -10, -11, -7, -4, -2, -4, -7, -12, -13, -10, -4, 3, 6, 11, 9, 3, -3, -6, -8, 1, 7, 13, 21, 26, 39, 41, 39, 34, 25, 17, 15, 17, 19, 19, 17, 16, 14, 16, 15, 15, 17, 17, 21, 19, 16, 16, 14, 18, 23, 22, 21, 24, 22, 24, 26, 29, 33, 34, 37, 35, 35, 37, 38, 41, 36, 30, 23, 16, 6, -7, -14, -21, -27, -35, -42, -43, -44, -45, -42, -43, -50, -54, -59, -62, -64, -64, -62, -58, -54, -52, -54, -55, -55, -53, -46, -38, -29, -23, -20, -17, -18, -17, -16, -19, -23, -27, -26, -28, -28, -17, -7, 1, 5, 6, -2, -8, -11, -11, -9, -7, -7, 1, 8, 17, 26, 33, 42, 43, 44, 46, 50, 55, 58, 61, 57, 52, 51, 49, 46, 40, 34, 30, 22, 10, -1, -11, -16, -21, -23, -27, -27, -26, -28, -26, -18, -16, -13, -8, -4, -6, -10, -11, -15, -14, -15, -19, -21, -21, -19, -15, -11, -7, -9, -13, -18, -22, -22, -23, -21, -20, -25, -30, -27, -28, -25, -20, -19, -20, -17, -13, -10, -7, -6, -3, -2, 1, 5, 7, 13, 24, 33, 39, 42, 43, 43, 44, 42, 39, 33, 24, 7, -3, -11, -18, -20, -20, -20, -19, -19, -20, -15, -9, 3, 14, 19, 24, 26, 18, 10, -2, -14, -23, -29, -34, -36, -35, -32, -27, -17, -2, 9, 19, 27, 39, 54, 56, 56, 53, 48, 41, 29, 16, 2, -9, -19, -25, -30, -32, -36, -33, -24, -8, -2, 0, -1, -6, -11, -18, -17, -14, -10, -1, 7, 11, 13, 10, 2, -2, -10, -13, -13, -11, -6, 0, 20, 28, 32, 36, 36, 39, 45, 48, 52, 53, 52, 47, 41, 32, 17, 1, -15, -37, -45, -49, -41, -27, -14, 11, 25, 37, 47, 51, 51, 44, 36, 32, 31, 31, 29, 27, 23, 17, 13, 11, 6, 4, 3, 2, 4, 8, 11, 12, 15, 18, 15, 10, 9, 4, -5, -8, -11, -17, -20, -27, -33, -42, -50, -54, -55, -52, -52, -48, -36, -27, -16, -3, 7, 22, 29, 27, 24, 18, 6, -13, -23, -32, -42, -49, -55, -73, -81, -87, -90, -88, -81, -74, -72, -71, -69, -69, -68, -67, -67, -64, -57, -50, -30, -13, 2, 15, 23, 25, 25, 23, 20, 17, 16, 18, 19, 26, 33, 40, 43, 42, 41, 38, 35, 33, 31, 35, 38, 40, 45, 47, 43, 33, 24, 18, 13, 14, 21, 31, 46, 62, 78, 94, 97, 96, 92, 88, 84, 75, 66, 52, 38, 27, 15, -2, -11, -19, -28, -39, -50, -50, -53, -58, -59, -62, -66, -65, -61, -55, -51, -44, -35, -29, -17, -7, 4, 20, 25, 27, 22, 12, -2, -31, -50, -65, -75, -83, -88, -86, -86, -88, -85, -80, -67, -53, -38, -26, -15, 1, 20, 24, 26, 26, 23, 23, 17, 6, -2, -8, -8, 3, 8, 16, 26, 37, 45, 54, 59, 61, 63, 63, 57, 53, 51, 48, 46, 45, 44, 44, 43, 37, 30, 25, 19, 14, 10, 5, -2, -2, -1, 1, 4, 2, 0, -3, -4, -3, -5, -5, -6, -15, -16, -19, -19, -15, -10, -9, -9, -9, -8, -4, 3, 8, 13, 14, 13, 12, 4, 0, -5, -12, -17, -20, -22, -25, -25, -25, -25, -23, -22, -20, -15, -10, -4, 9, 17, 23, 28, 31, 35, 31, 28, 23, 16, 14, 12, 13, 13, 9, 6, 3, -2, -2, 1, 5, 5, 4, 5, 6, 10, 11, 10, 5, -6, -17, -25, -32, -35, -30, -26, -23, -19, -19, -26, -27, -25, -19, -16, -13, -11, -11, -12, -14, -11, -10, -8, -6, -6, -8, -12, -20, -20, -20, -22, -23, -21, -21, -24, -25, -28, -34, -34, -30, -25, -18, -15, -14, -13, -11, -6, 2, 11, 18, 18, 15, 12, 14, 19, 29, 36, 35, 34, 32, 30, 31, 28, 26, 25, 22, 23, 28, 32, 36, 38, 33, 22, 17, 15, 15, 16, 20, 26, 31, 36, 36, 34, 30, 29, 31, 31, 31, 29, 20, 19, 17, 15, 16, 12, 10, 4, -6, -15, -23, -27, -26, -21, -14, -9, -5, 6, 9, 7, 3, 1, -1, -7, -5, -6, -10, -13, -14, -18, -25, -30, -37, -48, -63, -69, -70, -72, -73, -72, -75, -74, -72, -71, -70, -69, -64, -63, -61, -57, -54, -54, -54, -51, -49, -45, -37, -25, -20, -14, -5, 6, 14, 23, 30, 32, 30, 27, 24, 20, 14, 14, 15, 17, 21, 22, 23, 26, 27, 28, 30, 31, 32, 29, 26, 20, 15, 13, 15, 19, 24, 32, 35, 36, 40, 42, 42, 42, 42, 44, 46, 49, 51, 48, 43, 38, 29, 17, 2, -8, -16, -19, -19, -25, -30, -32, -33, -27, -13, 15, 33, 47, 59, 62, 59, 51, 44, 36, 29, 24, 20, 22, 20, 13, 5, -4, -17, -23, -26, -26, -23, -16, -10, -10, -15, -24, -32, -40, -43, -47, -50, -48, -44, -34, -28, -23, -18, -14, -10, -3, 4, 11, 16, 18, 11, 1, -11, -23, -30, -34, -36, -32, -30, -28, -26, -26, -24, -25, -30, -39, -48, -47, -40, -26, -8, 14, 35, 52, 62, 72, 74, 73, 73, 75, 80, 86, 93, 96, 96, 89, 75, 62, 49, 37, 26, 19, 11, 4, 0, -3, -7, -5, -9, -20, -25, -27, -27, -21, -11, -3, 5, 19, 27, 29, 24, 18, 6, -17, -24, -30, -40, -49, -58, -67, -77, -84, -86, -89, -93, -91, -90, -87, -82, -78, -82, -82, -79, -79, -79, -74, -70, -69, -68, -64, -59, -54, -51, -48, -44, -44, -40, -30, -17, -4, 8, 19, 33, 39, 48, 58, 64, 65, 66, 69, 72, 76, 83, 92, 93, 91, 87, 80, 68, 55, 53, 51, 50, 50, 53, 65, 67, 64, 60, 49, 36, 33, 33, 37, 41, 46, 43, 37, 34, 32, 30, 27, 17, 13, 6, 3, 6, 7, 6, -1, -11, -20, -32, -51, -58, -62, -68, -76, -82, -92, -95, -92, -87, -79, -66, -56, -47, -42, -35, -20, -2, 2, 5, 3, -4, -11, -16, -17, -20, -21, -20, -20, -23, -25, -27, -32, -32, -21, -16, -12, -7, -1, 4, 5, 3, 3, 1, -2, 1, 5, 13, 26, 36, 38, 37, 39, 41, 46, 52, 55, 55, 52, 55, 64, 64, 62, 61, 53, 44, 38, 33, 26, 23, 24, 25, 20, 12, 0, -9, -17, -20, -20, -21, -19, -17, -17, -15, -13, -15, -17, -22, -23, -24, -24, -21, -19, -18, -15, -6, 2, 1, 3, 2, -5, -8, -6, -10, -15, -16, -21, -30, -31, -31, -30, -33, -37, -36, -31, -23, -15, -10, -9, -10, -11, -11, -12, -16, -22, -21, -19, -14, -5, 5, 11, 10, 7, 5, 8, 8, 13, 15, 17, 20, 21, 23, 21, 18, 17, 21, 29, 43, 55, 66, 71, 74, 73, 62, 50, 37, 26, 18, 12, 11, 12, 13, 11, 8, 3, -2, -8, -14, -22, -30, -32, -33, -34, -33, -33, -34, -37, -38, -39, -45, -51, -54, -55, -54, -48, -39, -29, -16, -10, -7, -7, -9, -17, -23, -27, -30, -33, -34, -32, -34, -36, -36, -36, -35, -33, -31, -29, -27, -21, -7, 1, 12, 22, 29, 34, 33, 29, 24, 24, 25, 31, 44, 52, 59, 66, 69, 68, 64, 61, 61, 58, 50, 43, 37, 31, 29, 31, 35, 38, 40, 42, 45, 47, 45, 42, 37, 31, 25, 19, 11, 1, -5, -7, -11, -20, -24, -25, -28, -27, -23, -26, -30, -36, -40, -45, -49, -51, -53, -54, -55, -55, -58, -61, -63, -66, -73, -77, -79, -81, -83, -85, -86, -88, -89, -85, -80, -73, -62, -41, -29, -21, -15, -8, -1, 10, 19, 27, 34, 38, 38, 39, 34, 30, 30, 29, 29, 29, 26, 26, 29, 31, 36, 39, 38, 38, 39, 41, 45, 45, 47, 49, 51, 55, 55, 52, 48, 44, 41, 33, 29, 27, 24, 26, 32, 37, 35, 35, 34, 31, 30, 29, 25, 20, 13, 5, -8, -18, -26, -32, -40, -47, -58, -64, -65, -61, -53, -40, -29, -23, -22, -21, -20, -19, -20, -19, -17, -18, -18, -14, -13, -10, -7, -5, -8, -10, -13, -16, -18, -20, -20, -20, -19, -18, -15, -8, -3, 1, 4, 7, 10, 15, 22, 31, 39, 44, 45, 40, 35, 33, 30, 29, 31, 32, 34, 34, 33, 32, 28, 24, 23, 22, 26, 29, 27, 29, 30, 30, 30, 30, 27, 19, 16, 16, 16, 18, 20, 20, 20, 20, 19, 13, 9, 3, -1, -5, -12, -15, -13, -8, -4, -1, -3, -9, -17, -24, -29, -33, -35, -34, -31, -25, -20, -20, -17, -17, -20, -18, -14, -8, -6, -4, -2, -2, -4, -13, -15, -20, -25, -28, -35, -39, -39, -38, -37, -34, -36, -37, -36, -33, -28, -22, -13, -10, -5, 2, 10, 16, 17, 13, 7, 6, 6, 1, 4, 6, 2, 0, -1, -6, -9, -15, -22, -29, -33, -34, -31, -27, -25, -23, -24, -23, -22, -16, -7, 4, 24, 33, 40, 42, 38, 31, 22, 14, 9, 4, 0, -3, -8, -14, -19, -19, -19, -19, -19, -21, -23, -23, -17, -11, -4, 5, 11, 12, 13, 13, 11, 9, 9, 6, -1, -6, -7, -7, -5, -1, 1, 1, -1, -1, -1, -6, -13, -20, -24, -27, -29, -25, -24, -25, -26, -24, -20, -18, -16, -13, -4, 6, 24, 36, 42, 47, 51, 52, 54, 56, 56, 54, 50, 49, 50, 50, 49, 43, 35, 22, 16, 12, 8, 3, -2, -5, -5, -3, -2, -5, -10, -10, -8, -3, 7, 16, 24, 30, 37, 44, 51, 58, 58, 58, 60, 60, 59, 52, 40, 23, 7, -8, -24, -39, -46, -51, -58, -64, -68, -73, -77, -78, -78, -77, -71, -65, -56, -46, -32, -19, -5, 2, 0, -5, -7, -11, -14, -15, -15, -16, -19, -18, -19, -24, -29, -32, -35, -37, -35, -32, -27, -18, -1, 5, 11, 19, 21, 18, 12, 8, 8, 8, 13, 23, 26, 33, 37, 39, 39, 35, 32, 31, 31, 33, 34, 31, 24, 19, 18, 15, 13, 12, 9, 8, 10, 15, 15, 13, 11, 4, -2, -7, -16, -20, -22, -26, -27, -21, -20, -20, -20, -22, -24, -25, -26, -25, -22, -23, -25, -19, -16, -14, -10, -6, -3, -4, -6, -7, -7, -7, -2, 3, 5, 8, 14, 17, 21, 24, 20, 17, 18, 25, 27, 28, 29, 27, 22, 26, 30, 27, 19, 9, 3, 0, 3, 12, 19, 21, 23, 25, 27, 28, 30, 30, 29, 30, 32, 33, 36, 39, 41, 41, 39, 38, 37, 29, 24, 19, 10, 1, -6, -23, -30, -36, -41, -41, -40, -38, -34, -28, -23, -18, -12, -7, -6, -6, -5, -2, 2, 3, 4, 2, -1, -6, -14, -20, -29, -36, -42, -48, -53, -57, -59, -61, -61, -63, -65, -66, -66, -65, -64, -64, -63, -62, -62, -63, -56, -53, -53, -48, -40, -31, -19, -10, 1, 4, 7, 16, 17, 14, 10, 8, 5, 3, 6, 6, 7, 10, 12, 12, 12, 10, 7, 5, 2, 4, 3, 4, 8, 11, 17, 21, 25, 31, 38, 47, 55, 59, 62, 58, 56, 63, 64, 62, 56, 49, 42, 34, 35, 31, 25, 19, 13, 7, 6, 8, 9, 3, -7, -12, -23, -34, -39, -41, -41, -37, -31, -25, -21, -17, -12, -11, -10, -12, -14, -21, -25, -23, -24, -22, -16, -13, -10, -8, -4, 5, 14, 28, 32, 35, 36, 28, 25, 16, 3, -6, -16, -23, -27, -24, -20, -16, -9, -1, 11, 22, 32, 40, 44, 45, 47, 45, 44, 41, 35, 26, 21, 17, 13, 5, -7, -20, -27, -35, -37, -38, -39, -33, -28, -20, -9, -1, 10, 15, 21, 22, 17, 15, 12, 4, 0, -2, -3, 1, 6, 6, 1, -5, -9, -5, 0, 7, 14, 17, 22, 27, 30, 34, 37, 38, 39, 37, 39, 39, 36, 33, 28, 22, 16, 14, 7, -5, -10, -15, -17, -15, -7, 7, 18, 24, 25, 24, 17, 4, -8, -27, -45, -55, -61, -58, -53, -49, -46, -41, -31, -24, -13, -4, 3, 14, 29, 37, 38, 37, 35, 25, 18, 10, 2, -8, -21, -35, -46, -58, -70, -81, -89, -96, -98, -99, -94, -87, -70, -53, -36, -14, 7, 24, 43, 50, 55, 59, 60, 59, 51, 41, 31, 24, 18, 5, 0, -4, -12, -17, -19, -27, -34, -40, -46, -56, -65, -74, -80, -81, -79, -76, -69, -66, -61, -57, -54, -45, -28, -16, -9, -1, 5, 7, 15, 20, 21, 19, 14, 9, 9, 15, 24, 33, 42, 50, 51, 51, 45, 36, 22, 14, 7, 0, -4, -5, -6, 1, 10, 18, 25, 35, 52, 68, 84, 94, 101, 107, 110, 113, 113, 108, 100, 83, 63, 42, 22, 0, -23, -42, -51, -55, -54, -53, -52, -53, -54, -54, -53, -51, -38, -26, -16, -4, 9, 17, 24, 21, 13, 7, 4, -4, -9, -12, -13, -13, -15, -15, -17, -24, -29, -34, -38, -46, -45, -42, -41, -39, -33, -28, -29, -34, -36, -35, -30, -21, -12, -8, -8, -5, 4, 16, 28, 34, 39, 48, 56, 69, 78, 82, 80, 74, 77, 80, 76, 72, 66, 52, 42, 37, 32, 25, 19, 15, 12, 12, 10, 6, 3, 0, 0, -2, -6, -12, -19, -21, -22, -22, -20, -12, -9, -3, 1, 3, 2, -3, -4, -8, -13, -16, -20, -25, -29, -32, -37, -44, -53, -61, -64, -65, -67, -66, -68, -64, -58, -53, -41, -24, -14, -6, 0, 3, 5, 8, 10, 9, 8, 9, 11, 12, 14, 12, 2, -7, -12, -13, -14, -13, -10, -8, -12, -12, -11, -7, 1, 11, 24, 30, 32, 31, 29, 24, 22, 18, 14, 10, 8, 14, 18, 26, 35, 39, 36, 30, 29, 29, 32, 36, 38, 38, 34, 33, 35, 34, 31, 27, 23, 18, 15, 11, 10, 11, 8, 9, 15, 17, 16, 17, 13, 10, 7, 2, 0, -9, -18, -23, -31, -40, -40, -45, -51, -51, -50, -47, -50, -55, -63, -71, -70, -62, -51, -40, -31, -28, -23, -23, -21, -18, -16, -9, -7, -5, -4, -1, 3, 8, 7, 2, -2, -8, -15, -16, -14, -12, -10, -13, -17, -19, -21, -19, -15, -15, -10, -5, 0, 6, 10, 14, 23, 30, 39, 47, 56, 64, 67, 64, 61, 61, 56, 48, 45, 39, 35, 27, 10, -3, -12, -25, -31, -30, -27, -24, -19, -16, -15, -13, -18, -21, -25, -28, -29, -32, -33, -31, -26, -22, -18, -11, -13, -14, -13, -14, -13, -13, -19, -23, -28, -35, -30, -30, -32, -31, -28, -25, -19, -9, -4, -2, -2, -6, -8, -8, -6, 3, 4, 0, 1, 3, 5, 7, 13, 18, 21, 28, 34, 37, 36, 29, 24, 17, 13, 8, 2, -1, 1, 4, 7, 12, 14, 13, 11, 10, 8, 8, 16, 18, 23, 26, 27, 22, 16, 10, 1, -6, -11, -17, -20, -21, -20, -22, -19, -13, -9, 2, 10, 16, 28, 34, 40, 44, 46, 45, 43, 40, 32, 24, 15, 3, -9, -15, -19, -18, -16, -16, -9, -4, -2, 0, 3, 9, 11, 17, 20, 18, 19, 17, 15, 15, 13, 9, -1, -4, -10, -17, -18, -18, -11, -5, 0, 7, 7, 11, 18, 23, 26, 29, 30, 25, 20, 9, -5, -19, -30, -40, -43, -44, -43, -39, -25, -10, 4, 14, 22, 31, 47, 55, 61, 70, 73, 71, 68, 64, 56, 42, 31, 17, 7, -2, -10, -18, -23, -25, -24, -20, -17, -15, -7, 4, 8, 12, 12, 9, 1, -5, -14, -18, -21, -34, -48, -52, -59, -62, -59, -51, -45, -40, -32, -28, -24, -21, -18, -14, -10, -6, 0, -1, -4, -9, -18, -27, -41, -63, -75, -82, -83, -84, -81, -80, -80, -83, -83, -79, -75, -70, -63, -59, -56, -48, -30, -20, -13, -5, 0, 3, 6, 7, 3, 0, 3, 7, 11, 18, 25, 28, 29, 30, 28, 26, 25, 25, 29, 33, 36, 41, 46, 48, 44, 35, 23, 18, 15, 13, 31, 38, 47, 58, 70, 81, 89, 98, 102, 105, 105, 103, 97, 86, 74, 61, 43, 29, 13, 1, -11, -25, -40, -47, -52, -55, -55, -50, -38, -33, -29, -26, -24, -17, -10, 0, 7, 11, 15, 15, 17, 17, 14, 9, -1, -23, -39, -51, -59, -68, -72, -71, -72, -75, -75, -72, -76, -77, -74, -68, -57, -45, -25, -12, -5, -1, 5, 13, 16, 20, 27, 29, 30, 31, 30, 34, 38, 38, 38, 36, 33, 29, 28, 32, 34, 34, 35, 33, 34, 38, 39, 39, 37, 35, 33, 31, 35, 34, 33, 33, 29, 25, 26, 27, 25, 20, 18, 15, 14, 14, 15, 15, 13, 7, 0, -9, -17, -23, -27, -27, -27, -25, -24, -21, -17, -11, -5, -7, -8, -5, 0, 3, 3, 3, -1, -8, -9, -8, -8, -10, -10, -11, -11, -10, -9, -10, -11, -11, -11, -8, -4, -2, 1, 3, -1, -7, -10, -13, -24, -27, -24, -22, -21, -12, -8, -7, -6, -3, 3, 3, 3, 1, -6, -7, -6, -9, -7, -7, -9, -16, -26, -32, -39, -40, -37, -36, -35, -36, -38, -37, -32, -25, -12, -5, -1, 1, 5, 13, 20, 27, 30, 33, 34, 28, 23, 18, 13, 6, 0, -4, -7, -6, -5, -2, 3, 3, 0, -3, -4, -5, -7, -8, -5, -1, 5, 14, 19, 22, 23, 22, 25, 23, 19, 19, 23, 28, 31, 39, 44, 46, 46, 46, 44, 34, 28, 26, 25, 22, 23, 20, 13, 7, 3, -1, -4, -1, 1, 2, 3, 4, 9, 13, 16, 20, 22, 24, 24, 21, 15, 6, -5, -16, -20, -23, -26, -31, -33, -35, -36, -37, -37, -34, -33, -31, -28, -29, -31, -31, -31, -27, -29, -31, -32, -37, -41, -40, -37, -38, -39, -41, -44, -47, -51, -53, -54, -58, -60, -60, -60, -57, -46, -40, -34, -27, -25, -24, -26, -33, -37, -37, -36, -32, -23, -17, -13, -9, -1, 8, 14, 20, 24, 26, 29, 32, 34, 36, 36, 36, 39, 42, 41, 40, 37, 33, 27, 23, 26, 32, 37, 44, 50, 45, 41, 39, 38, 40, 41, 39, 39, 36, 32, 33, 34, 33, 30, 29, 30, 24, 23, 22, 17, 15, 12, -4, -14, -24, -33, -40, -41, -38, -33, -23, -11, 1, 22, 37, 52, 61, 64, 66, 62, 58, 56, 51, 47, 37, 26, 13, 1, -8, -14, -19, -19, -21, -24, -27, -29, -29, -28, -30, -34, -36, -34, -35, -35, -31, -27, -25, -19, -15, -14, -15, -15, -11, -4, 1, 5, 5, 1, -5, -9, -13, -14, -19, -27, -35, -38, -42, -41, -40, -39, -38, -36, -32, -31, -29, -25, -19, -8, 4, 20, 37, 55, 68, 76, 78, 76, 70, 63, 56, 52, 48, 43, 42, 41, 38, 33, 30, 27, 14, 11, 7, 1, 1, 6, 10, 15, 18, 20, 23, 26, 25, 21, 21, 21, 17, 19, 18, 14, 7, -4, -24, -42, -59, -72, -82, -87, -88, -88, -86, -85, -86, -87, -85, -86, -88, -88, -88, -85, -82, -79, -74, -69, -64, -52, -46, -44, -43, -41, -37, -30, -22, -14, -8, -2, 3, 4, 5, 3, 0, 1, 5, 6, 10, 19, 29, 37, 47, 52, 53, 52, 51, 53, 54, 54, 58, 62, 61, 60, 59, 61, 62, 59, 57, 53, 50, 48, 48, 46, 46, 46, 48, 50, 55, 62, 66, 64, 57, 51, 50, 46, 41, 36, 26, 18, 11, -2, -7, -15, -24, -33, -38, -47, -56, -58, -59, -63, -63, -62, -58, -52, -48, -40, -30, -27, -22, -22, -22, -18, -9, -7, -9, -11, -13, -23, -21, -18, -16, -13, -12, -12, -14, -17, -22, -25, -24, -23, -22, -20, -18, -19, -19, -16, -13, -12, -8, -1, 7, 5, 6, 13, 20, 22, 30, 30, 29, 34, 39, 42, 40, 37, 36, 39, 41, 38, 33, 30, 29, 28, 29, 26, 21, 19, 15, 9, -2, -7, -13, -20, -24, -24, -28, -30, -27, -25, -27, -25, -23, -23, -22, -20, -20, -22, -19, -15, -12, -10, -7, -6, -6, -6, -5, -6, -10, -13, -13, -16, -18, -18, -18, -19, -21, -21, -17, -13, -11, -8, -8, -13, -20, -23, -24, -24, -19, -16, -16, -11, -7, -4, 1, 5, 4, 3, 4, 9, 20, 31, 38, 49, 52, 53, 51, 47, 41, 36, 34, 33, 33, 37, 49, 53, 55, 54, 52, 47, 37, 33, 29, 26, 23, 18, 16, 14, 11, 8, 3, -6, -13, -18, -20, -21, -24, -26, -28, -28, -29, -34, -36, -38, -40, -41, -40, -39, -35, -32, -29, -25, -22, -16, -16, -18, -22, -26, -31, -38, -42, -44, -42, -38, -34, -26, -26, -23, -18, -15, -9, -5, -5, -8, -10, -10, -11, -9, -4, 4, 13, 24, 40, 46, 46, 40, 34, 29, 25, 23, 23, 22, 20, 24, 30, 37, 42, 43, 39, 31, 28, 25, 23, 25, 32, 36, 43, 49, 51, 53, 52, 49, 46, 44, 40, 35, 31, 29, 28, 24, 16, 0, -12, -24, -33, -38, -42, -39, -36, -35, -37, -44, -52, -61, -64, -68, -71, -73, -74, -72, -70, -71, -76, -80, -85, -86, -84, -83, -83, -82, -72, -65, -58, -47, -36, -19, -8, 0, 8, 13, 16, 20, 18, 16, 10, 4, 0, -2, -1, 3, 11, 16, 25, 34, 40, 45, 51, 52, 49, 46, 43, 42, 42, 44, 46, 47, 48, 47, 45, 42, 41, 39, 35, 31, 27, 17, 10, 5, 5, 7, 15, 20, 26, 28, 26, 23, 18, 13, 9, 3, -4, -10, -20, -25, -32, -39, -45, -58, -63, -63, -56, -50, -44, -33, -29, -26, -22, -20, -22, -22, -27, -36, -43, -48, -50, -45, -36, -25, -16, -9, 1, 5, 10, 16, 22, 24, 23, 20, 17, 13, 11, 10, 3, -2, -6, -7, -4, 4, 13, 21, 30, 37, 41, 44, 41, 38, 36, 35, 30, 27, 28, 30, 31, 36, 44, 48, 54, 57, 60, 66, 69, 65, 61, 55, 48, 41, 36, 32, 29, 26, 26, 27, 26, 21, 13, 3, -8, -19, -21, -23, -26, -27, -30, -28, -25, -24, -20, -15, -11, -8, -8, -8, -8, -7, -4, 0, 5, 4, 2, -3, -7, -11, -10, -7, -7, -5, -3, 0, 5, 5, 0, -7, -15, -18, -21, -26, -32, -35, -37, -40, -40, -39, -45, -45, -44, -45, -45, -36, -29, -20, -10, -1, 4, 9, 12, 10, 6, 2, 0, -9, -16, -18, -23, -27, -26, -26, -26, -29, -33, -36, -37, -36, -32, -24, -19, -16, -10, -7, -2, 3, 6, 11, 15, 20, 24, 26, 26, 20, 15, 10, 2, -4, -8, -13, -13, -12, -13, -16, -18, -19, -18, -19, -23, -25, -21, -21, -17, -9, -1, 7, 15, 20, 18, 12, 4, 1, 1, 2, 6, 9, 8, 15, 20, 23, 27, 24, 17, 8, 2, 0, 2, 2, 4, 6, 2, -4, -9, -13, -19, -20, -20, -20, -19, -15, -7, -3, 3, 9, 11, 17, 20, 20, 19, 18, 19, 27, 34, 37, 39, 42, 40, 31, 27, 22, 17, 13, 17, 22, 22, 23, 22, 18, 11, 8, 9, 11, 15, 28, 34, 44, 57, 71, 81, 85, 81, 71, 56, 43, 31, 20, 14, 6, -3, -13, -23, -25, -29, -35, -42, -49, -56, -60, -64, -67, -69, -67, -60, -52, -47, -47, -45, -41, -38, -35, -33, -28, -25, -30, -35, -42, -45, -48, -48, -42, -41, -39, -34, -31, -32, -28, -26, -27, -25, -17, -6, -4, -1, 2, 1, -1, 4, 7, 14, 21, 26, 29, 27, 26, 25, 27, 29, 34, 31, 25, 22, 20, 13, 14, 16, 14, 15, 15, 12, 13, 18, 23, 25, 25, 26, 20, 12, 8, 3, -4, -9, -8, -9, -12, -14, -17, -19, -20, -21, -21, -21, -18, -16, -12, -10, -10, -9, -13, -16, -15, -15, -14, -6, 0, 7, 13, 18, 19, 17, 17, 18, 19, 20, 25, 34, 40, 41, 40, 39, 32, 28, 26, 26, 27, 27, 25, 19, 10, 2, 0, 0, 4, 10, 11, 11, 14, 16, 19, 24, 23, 22, 22, 18, 19, 22, 25, 29, 37, 41, 42, 41, 36, 28, 15, 10, 1, -7, -9, -11, -17, -22, -27, -30, -31, -33, -30, -28, -29, -29, -29, -24, -20, -19, -21, -26, -27, -25, -17, -11, -7, -5, -5, -7, -11, -15, -22, -27, -33, -38, -36, -37, -39, -36, -38, -43, -48, -51, -58, -64, -63, -61, -55, -48, -41, -36, -32, -27, -26, -26, -29, -34, -35, -32, -26, -16, -5, -3, -3, -5, -4, 1, 11, 16, 19, 23, 24, 23, 23, 19, 15, 12, 12, 17, 17, 19, 20, 16, 13, 18, 20, 25, 37, 43, 43, 48, 51, 54, 57, 56, 48, 46, 40, 36, 36, 33, 25, 21, 18, 14, 10, 7, -2, -8, -11, -9, -9, -9, -9, -12, -13, -17, -22, -27, -33, -33, -30, -25, -23, -24, -26, -29, -32, -32, -31, -29, -25, -23, -19, -15, -12, -5, 3, 7, 12, 13, 8, 8, 10, 13, 15, 22, 21, 15, 14, 14, 12, 9, 11, 13, 12, 17, 23, 24, 24, 20, 18, 19, 18, 19, 22, 21, 22, 24, 21, 19, 14, 8, 5, -4, -8, -11, -11, -8, -2, 10, 12, 14, 15, 13, 16, 15, 15, 11, 2, -4, -8, -10, -9, -11, -16, -19, -25, -30, -30, -28, -27, -24, -12, -4, 5, 17, 24, 30, 29, 26, 26, 28, 31, 34, 33, 31, 32, 34, 32, 24, 18, 11, 8, 8, 11, 8, 3, -2, -8, -11, -9, -7, -7, -9, -10, -15, -20, -21, -22, -25, -25, -27, -30, -30, -27, -19, -14, -5, -3, -4, -2, -3, -2, 0, -1, -3, -7, -7, -4, -5, -6, -6, -10, -17, -34, -46, -56, -62, -64, -70, -68, -65, -64, -58, -46, -26, -13, 6, 25, 39, 50, 61, 63, 60, 52, 45, 35, 25, 15, 5, -3, -12, -27, -35, -41, -45, -49, -52, -50, -52, -54, -54, -53, -53, -56, -54, -48, -43, -37, -31, -28, -25, -23, -19, -17, -13, -9, -4, 0, 2, 3, 5, 5, 9, 15, 17, 20, 26, 34, 41, 45, 44, 37, 34, 32, 26, 17, 3, -5, -12, -14, -16, -18, -19, -13, -2, 12, 26, 37, 55, 71, 90, 107, 118, 126, 125, 120, 114, 110, 105, 92, 81, 65, 46, 27, 9, -19, -36, -50, -57, -62, -67, -66, -63, -61, -60, -59, -56, -54, -52, -48, -45, -40, -30, -22, -18, -20, -22, -26, -31, -29, -21, -14, -11, -12, -14, -16, -18, -19, -22, -37, -47, -54, -56, -55, -51, -44, -36, -30, -26, -22, -12, -9, -7, 1, 8, 21, 36, 49, 57, 60, 61, 61, 63, 69, 77, 82, 82, 76, 72, 68, 71, 78, 75, 68, 54, 40, 31, 27, 23, 14, 4, -4, -7, -13, -13, -14, -14, -8, -3, 6, 13, 18, 23, 27, 27, 27, 29, 27, 20, 10, -1, -17, -23, -30, -35, -38, -49, -56, -60, -59, -57, -53, -51, -53, -58, -58, -55, -52, -43, -38, -36, -35, -29, -19, -14, -14, -16, -18, -20, -16, -14, -12, -16, -24, -28, -25, -22, -20, -15, -14, -16, -17, -15, -15, -15, -13, -12, -8, -2, 4, 11, 22, 33, 35, 36, 33, 30, 28, 29, 31, 28, 23, 15, 1, 0, -1, 1, 3, 2, -4, -8, -9, -8, -6, -4, 1, 7, 13, 22, 32, 43, 45, 46, 47, 45, 43, 53, 56, 52, 50, 48, 45, 42, 40, 39, 35, 28, 14, 3, -6, -15, -24, -28, -32, -40, -48, -58, -64, -69, -69, -70, -71, -69, -73, -70, -62, -52, -40, -31, -20, -15, -12, -6, 2, 6, 7, 6, -1, -5, -5, -1, 9, 5, -3, -10, -19, -24, -17, -7, 0, 5, 11, 15, 17, 17, 17, 12, 5, 2, 7, 14, 21, 29, 33, 33, 34, 37, 41, 43, 40, 40, 44, 48, 52, 54, 49, 43, 38, 36, 29, 19, 15, 10, 4, -1, -5, -12, -15, -21, -26, -29, -32, -33, -28, -23, -23, -25, -29, -30, -26, -24, -27, -27, -33, -36, -34, -29, -22, -17, -18, -23, -31, -40, -44, -42, -37, -31, -25, -23, -24, -17, -18, -19, -22, -28, -32, -36, -33, -26, -18, -10, 6, 6, 7, 9, 8, 8, 9, 14, 19, 26, 36, 41, 41, 38, 35, 31, 25, 16, 7, 1, -2, -4, 4, 12, 15, 14, 10, 8, 5, 7, 8, 9, 12, 16, 25, 30, 29, 24, 18, 9, -2, -9, -15, -22, -27, -29, -27, -20, -6, 5, 16, 32, 39, 47, 51, 54, 54, 49, 41, 33, 26, 16, 0, -9, -17, -24, -29, -31, -26, -22, -17, -9, -7, -9, -10, -7, -2, 4, 9, 10, 10, 9, 6, 4, 6, -1, -6, -7, -7, -10, -9, 0, 2, 2, 3, 5, 11, 18, 24, 29, 33, 37, 32, 26, 22, 13, 1, -12, -32, -41, -48, -48, -43, -30, -16, -3, 12, 23, 32, 42, 45, 48, 53, 58, 61, 66, 66, 61, 48, 32, 8, -6, -14, -15, -14, -13, -9, -7, -7, -7, -6, -10, -12, -10, -8, -3, -1, -8, -11, -19, -31, -37, -43, -62, -70, -74, -74, -67, -56, -39, -27, -14, 0, 10, 20, 20, 15, 7, 0, -6, -22, -30, -37, -45, -52, -64, -74, -79, -86, -91, -89, -88, -87, -84, -78, -72, -67, -60, -53, -47, -43, -34, -20, -12, -7, 0, 7, 11, 14, 16, 18, 18, 20, 23, 24, 23, 25, 31, 35, 44, 49, 53, 53, 50, 46, 37, 34, 34, 36, 43, 50, 55, 57, 54, 50, 50, 55, 62, 71, 86, 98, 104, 110, 110, 107, 101, 98, 95, 80, 65, 46, 28, 14, -2, -9, -21, -35, -45, -52, -58, -59, -56, -54, -55, -59, -63, -63, -58, -47, -37, -20, -9, 2, 12, 23, 34, 40, 36, 26, 14, 2, -12, -28, -33, -38, -45, -52, -61, -72, -81, -84, -84, -82, -78, -69, -61, -56, -46, -37, -26, -18, -9, 0, 9, 27, 30, 31, 27, 22, 20, 20, 20, 21, 24, 26, 29, 35, 36, 35, 37, 40, 44, 43, 39, 38, 34, 29, 29, 27, 26, 22, 17, 8, 1, -4, -8, -8, -9, -13, -15, -18, -14, -8, -3, -1, -6, -13, -20, -21, -22, -22, -20, -28, -34, -32, -30, -24, -20, -22, -23, -22, -15, -11, -3, 8, 14, 20, 24, 23, 21, 19, 15, 12, 14, 15, 17, 16, 14, 11, 4, 4, 7, 8, 13, 14, 15, 20, 24, 25, 17, 15, 12, 13, 17, 19, 19, 17, 18, 15, 10, 2, -1, -2, 1, 7, 9, 3, -5, -11, -14, -13, -11, -12, -18, -26, -33, -40, -46, -47, -48, -46, -44, -42, -32, -31, -31, -30, -31, -30, -13, -2, 7, 15, 17, 18, 14, 10, 8, 6, 5, -2, -6, -10, -14, -16, -12, -8, -7, -7, -10, -11, -14, -15, -15, -13, -10, -6, -1, -1, 0, 1, 1, 2, 12, 21, 28, 35, 39, 43, 39, 36, 34, 28, 27, 29, 30, 33, 33, 28, 18, 14, 12, 10, 9, 8, 6, 4, 3, 4, 2, -2, -1, 2, 7, 11, 11, 12, 12, 12, 17, 20, 21, 21, 20, 18, 17, 13, 7, -9, -18, -22, -25, -24, -24, -28, -34, -37, -37, -36, -29, -26, -23, -22, -21, -20, -12, -8, -8, -7, -8, -16, -20, -22, -25, -33, -42, -48, -51, -53, -54, -56, -61, -70, -72, -70, -67, -65, -64, -60, -57, -53, -47, -40, -39, -36, -31, -26, -19, -9, 6, 14, 21, 28, 33, 41, 44, 47, 52, 53, 51, 51, 50, 47, 46, 46, 43, 35, 36, 34, 30, 30, 31, 31, 34, 39, 41, 38, 36, 31, 25, 23, 24, 26, 29, 27, 24, 26, 31, 39, 42, 41, 37, 31, 33, 40, 48, 51, 44, 36, 22, -2, -13, -24, -32, -36, -42, -38, -30, -21, -11, 1, 14, 16, 18, 18, 18, 14, 13, 11, 8, 4, 3, 3, 1, -3, -13, -21, -24, -20, -14, -7, -3, -4, -10, -16, -26, -39, -47, -51, -51, -45, -38, -29, -20, -15, -6, -6, -4, -2, -1, 5, 5, 3, 1, -3, -9, -20, -25, -25, -23, -16, -12, -14, -17, -21, -24, -27, -26, -31, -35, -35, -37, -35, -22, -8, 9, 24, 37, 46, 53, 55, 55, 60, 65, 68, 70, 73, 69, 64, 62, 57, 52, 44, 39, 34, 28, 20, 15, 9, 4, 4, 15, 20, 21, 18, 14, 9, 4, 1, -1, -3, -4, -6, -12, -13, -16, -25, -34, -41, -48, -54, -56, -57, -55, -51, -49, -50, -54, -59, -62, -69, -71, -70, -72, -74, -68, -63, -58, -54, -51, -50, -46, -42, -37, -34, -33, -31, -34, -30, -24, -22, -23, -27, -24, -18, -11, -3, 7, 20, 24, 27, 32, 39, 42, 43, 47, 51, 54, 55, 57, 56, 53, 51, 48, 46, 43, 43, 45, 44, 40, 42, 43, 43, 48, 52, 52, 51, 51, 49, 46, 48, 51, 47, 44, 40, 34, 26, 12, 5, -1, -7, -12, -12, -13, -13, -15, -25, -36, -43, -57, -62, -63, -69, -77, -84, -86, -85, -82, -77, -73, -65, -58, -49, -38, -28, -18, -4, 2, 7, 15, 18, 16, 16, 18, 17, 18, 22, 20, 17, 15, 11, 4, -1, -5, -6, -2, 5, 10, 14, 11, 8, 5, 3, 7, 20, 28, 33, 38, 43, 48, 56, 54, 53, 51, 44, 38, 37, 34, 30, 31, 35, 37, 41, 43, 44, 44, 41, 38, 32, 25, 16, 4, -11, -16, -21, -29, -34, -35, -38, -38, -34, -30, -28, -25, -22, -23, -22, -20, -22, -27, -25, -22, -20, -15, -9, -7, -8, -7, -7, -12, -21, -22, -21, -21, -23, -23, -29, -35, -35, -32, -33, -33, -29, -29, -30, -28, -24, -21, -19, -16, -15, -14, -13, -10, -7, -3, 5, 13, 19, 33, 40, 40, 37, 34, 27, 23, 20, 15, 13, 13, 10, 11, 11, 5, 0, 0, 1, 7, 18, 27, 36, 45, 44, 41, 33, 25, 19, 14, 13, 14, 18, 21, 21, 16, 12, 7, 0, -6, -14, -19, -23, -24, -25, -25, -23, -19, -17, -19, -24, -32, -40, -43, -43, -38, -32, -29, -27, -27, -30, -34, -36, -35, -33, -30, -23, -17, -13, -17, -19, -19, -23, -26, -28, -29, -29, -26, -20, -14, -4, 5, 14, 27, 39, 45, 52, 55, 51, 48, 48, 49, 52, 57, 61, 63, 62, 54, 47, 39, 32, 27, 22, 17, 14, 11, 14, 20, 26, 30, 36, 43, 46, 49, 49, 43, 35, 28, 23, 17, 14, 12, 12, 10, 7, 3, -4, -15, -26, -37, -45, -51, -49, -48, -53, -61, -65, -65, -62, -55, -53, -55, -57, -60, -62, -65, -68, -73, -83, -88, -91, -90, -86, -82, -75, -65, -55, -43, -31, -12, -6, -1, 3, 3, 3, 5, 7, 8, 11, 16, 24, 30, 34, 39, 41, 36, 25, 22, 20, 18, 16, 15, 12, 14, 16, 17, 23, 30, 35, 45, 54, 58, 59, 58, 54, 47, 42, 37, 31, 22, 16, 12, 12, 15, 22, 25, 30, 36, 35, 30, 26, 23, 18, 13, 6, -3, -14, -20, -25, -28, -34, -46, -52, -55, -52, -48, -41, -29, -27, -22, -18, -16, -13, -12, -17, -23, -25, -28, -31, -28, -28, -31, -31, -32, -32, -28, -20, -17, -17, -17, -17, -15, -12, -5, 4, 7, 7, 9, 9, 14, 22, 35, 46, 56, 64, 67, 69, 64, 56, 47, 38, 31, 20, 16, 17, 19, 23, 29, 38, 44, 49, 52, 58, 66, 68, 69, 68, 63, 54, 41, 31, 21, 13, 8, 4, 2, 6, 10, 11, 10, 4, -2, -10, -17, -24, -35, -40, -40, -37, -28, -23, -23, -26, -26, -25, -24, -21, -13, -7, -1, 4, 9, 10, 1, -5, -10, -13, -13, -11, -10, -6, -8, -13, -15, -23, -32, -40, -45, -50, -54, -54, -52, -50, -46, -39, -34, -29, -27, -21, -17, -14, -4, 2, 4, 5, 7, 6, 2, 2, 1, 0, -4, -8, -18, -24, -23, -20, -16, -12, -14, -22, -30, -34, -39, -43, -42, -43, -41, -38, -36, -31, -24, -15, -5, 4, 17, 22, 24, 22, 18, 17, 16, 14, 13, 13, 13, 13, 13, 12, 8, 0, -4, -12, -16, -17, -16, -14, -6, 14, 26, 35, 39, 41, 38, 35, 33, 29, 21, 15, 4, -3, -8, -10, -10, -8, 0, 4, 8, 13, 17, 15, 14, 14, 13, 12, 11, 4, 0, -5, -11, -16, -18, -21, -20, -17, -13, -7, 2, 8, 8, 7, 6, 6, 11, 20, 28, 32, 33, 30, 24, 20, 18, 19, 19, 20, 23, 24, 25, 24, 21, 15, 10, 4, -1, -5, -10, -10, -7, 1, 12, 22, 39, 44, 44, 43, 41, 38, 33, 34, 33, 31, 26, 21, 16, 11, 5, 1, -3, -10, -14, -19, -24, -29, -34, -41, -50, -59, -70, -78, -81, -86, -84, -73, -59, -43, -20, -10, -6, -5, -5, -6, -10, -14, -22, -32, -39, -42, -41, -38, -35, -37, -37, -29, -24, -16, -11, -7, -4, 0, -1, 0, 0, -2, -1, 3, 6, 9, 13, 16, 19, 26, 34, 42, 50, 55, 56, 54, 52, 48, 45, 42, 39, 38, 38, 37, 33, 23, 15, 8, 3, 2, 5, 4, 2, 2, 2, 5, 4, 7, 5, 0, -1, -2, 2, -1, -6, -13, -22, -25, -23, -21, -14, -7, -5, -1, 4, 6, 6, 2, -2, 0, 0, 1, 4, 5, 5, 7, 9, 10, 9, 5, 2, 2, 2, 4, 7, 9, 13, 17, 22, 25, 25, 22, 22, 16, 7, 1, -5, -9, -5, 0, 3, -1, -13, -27, -28, -26, -21, -12, 3, 15, 22, 30, 36, 38, 34, 34, 37, 42, 47, 48, 44, 35, 25, 15, 5, -8, -25, -35, -48, -57, -59, -61, -59, -55, -50, -45, -37, -30, -26, -25, -27, -24, -17, -8, 1, 7, 9, 12, 17, 12, 5, 0, -5, -11, -16, -21, -27, -32, -35, -34, -27, -23, -26, -33, -35, -38, -40, -43, -50, -57, -61, -62, -55, -45, -38, -32, -21, -12, -4, 2, 10, 19, 24, 26, 29, 25, 16, 9, -4, -9, -12, -11, -10, -15, -15, -11, -3, 3, 8, 10, 7, 5, 7, 15, 20, 27, 27, 25, 33, 44, 56, 61, 66, 67, 63, 61, 53, 43, 35, 25, 14, 4, -1, -3, -6, -3, -1, -3, -2, -2, -5, -10, -16, -21, -24, -27, -28, -30, -34, -38, -38, -37, -32, -29, -20, -19, -20, -14, -5, -2, -4, -7, -13, -17, -20, -19, -18, -17, -12, -10, -6, 1, 0, -1, 0, 4, 8, 14, 13, 13, 14, 15, 15, 15, 10, 4, 6, 8, 14, 20, 23, 25, 25, 27, 32, 33, 34, 33, 29, 28, 27, 23, 16, 4, -3, -16, -23, -25, -27, -23, -18, -10, -6, -3, 3, 9, 15, 22, 22, 21, 21, 20, 16, 20, 25, 23, 25, 26, 14, 6, -2, -8, -12, -13, -8, -1, 6, 11, 19, 26, 24, 23, 22, 20, 22, 27, 34, 37, 37, 36, 24, 15, 7, 2, 2, 4, 8, 10, 16, 22, 25, 28, 25, 20, 12, 2, -5, -15, -21, -28, -33, -39, -49, -57, -61, -64, -61, -56, -46, -29, -15, 0, 13, 25, 37, 36, 31, 27, 20, 14, 7, 4, 0, 1, 0, -6, -22, -36, -49, -63, -73, -82, -87, -91, -90, -85, -73, -47, -27, -5, 16, 34, 48, 67, 72, 70, 68, 64, 53, 47, 39, 25, 8, -9, -33, -44, -49, -51, -50, -47, -41, -40, -41, -40, -39, -44, -46, -47, -50, -49, -45, -36, -35, -34, -31, -31, -30, -27, -25, -22, -19, -16, -10, -4, 1, 3, 1, -3, -13, -14, -10, 0, 11, 19, 29, 28, 24, 20, 13, -3, -9, -11, -13, -10, -3, 3, 10, 19, 30, 41, 57, 66, 76, 88, 101, 109, 116, 118, 116, 111, 105, 98, 85, 72, 56, 42, 28, 10, -6, -20, -34, -49, -59, -67, -67, -64, -57, -48, -34, -18, -11, -4, 4, 11, 20, 25, 23, 17, 10, 3, -12, -25, -38, -46, -55, -66, -70, -72, -76, -72, -68, -66, -60, -53, -44, -38, -34, -32, -36, -42, -45, -46, -45, -35, -23, -12, -2, 9, 20, 25, 32, 37, 46, 53, 57, 59, 55, 54, 57, 57, 52, 51, 49, 47, 48, 50, 50, 47, 45, 39, 31, 32, 33, 32, 30, 20, 4, -8, -8, -9, -7, -6, -9, -9, -6, -1, -3, -6, -7, -8, -6, -6, -10, -15, -19, -18, -16, -12, -8, -7, -15, -22, -27, -30, -30, -29, -34, -40, -43, -46, -51, -52, -49, -47, -45, -38, -25, -20, -13, -5, -1, -2, 0, 1, 2, 6, 8, 12, 10, 4, -3, -12, -18, -22, -21, -16, -7, 0, 7, 17, 19, 21, 23, 27, 33, 35, 39, 40, 37, 32, 29, 25, 20, 14, 13, 12, 12, 17, 23, 30, 37, 45, 48, 50, 46, 39, 33, 31, 35, 39, 45, 49, 48, 40, 33, 27, 22, 16, 11, 11, 14, 14, 15, 21, 27, 27, 26, 24, 17, 13, 4, -2, -10, -22, -31, -40, -44, -47, -52, -54, -55, -54, -49, -45, -42, -38, -34, -30, -26, -23, -25, -29, -36, -40, -43, -41, -36, -32, -32, -33, -35, -40, -45, -41, -34, -29, -22, -19, -17, -20, -22, -22, -26, -30, -31, -33, -37, -36, -28, -25, -22, -15, -15, -11, -2, 9, 24, 36, 42, 45, 50, 54, 57, 55, 54, 57, 56, 53, 50, 41, 32, 28, 23, 19, 15, 10, 3, -3, -8, -16, -18, -19, -21, -19, -15, -8, -4, -5, -4, -7, -15, -18, -20, -24, -28, -28, -30, -30, -27, -24, -22, -21, -23, -25, -27, -27, -23, -24, -20, -16, -15, -11, -7, -2, -3, -3, -1, -1, -2, 0, -6, -9, -6, -5, 2, 7, 12, 18, 24, 27, 28, 26, 21, 19, 16, 18, 23, 24, 25, 22, 14, 10, 6, 5, 5, 3, 4, 10, 15, 18, 16, 16, 16, 16, 20, 21, 20, 19, 8, 1, -6, -11, -16, -22, -28, -33, -37, -40, -40, -31, -20, -9, 4, 19, 31, 42, 48, 52, 52, 51, 49, 47, 47, 46, 43, 37, 23, 9, -1, -9, -18, -24, -25, -24, -22, -19, -18, -16, -19, -19, -20, -23, -25, -29, -26, -24, -18, -11, -8, -1, -6, -13, -17, -21, -22, -12, -2, 7, 15, 20, 28, 32, 37, 40, 40, 42, 37, 30, 22, 13, 3, -16, -30, -44, -53, -56, -53, -38, -28, -16, -2, 11, 25, 38, 43, 45, 47, 47, 43, 41, 35, 32, 31, 28, 27, 25, 21, 19, 16, 13, 21, 27, 29, 25, 20, 13, 7, 4, 5, 4, -6, -11, -15, -20, -20, -23, -28, -37, -43, -49, -55, -55, -47, -39, -29, -18, -7, 3, 12, 13, 9, 1, -9, -19, -32, -35, -36, -38, -40, -47, -53, -58, -59, -59, -60, -58, -62, -65, -68, -72, -73, -75, -72, -68, -66, -62, -51, -47, -38, -27, -15, -2, 15, 27, 32, 34, 31, 24, 10, 5, 8, 16, 22, 35, 40, 44, 47, 46, 43, 37, 36, 37, 40, 43, 51, 58, 55, 53, 47, 37, 30, 31, 34, 45, 52, 54, 66, 75, 85, 94, 100, 102, 98, 92, 84, 74, 61, 49, 38, 23, 10, -2, -22, -50, -59, -63, -63, -61, -56, -56, -53, -49, -43, -38, -33, -25, -19, -18, -14, -9, 2, 6, 6, 6, 0, -19, -31, -44, -58, -68, -78, -89, -92, -94, -95, -92, -88, -81, -67, -50, -32, -17, -3, 5, 7, 10, 14, 16, 24, 25, 26, 25, 24, 23, 22, 19, 16, 18, 22, 27, 28, 33, 37, 42, 48, 50, 45, 38, 33, 29, 30, 29, 25, 22, 22, 24, 29, 34, 33, 28, 25, 23, 16, 14, 10, 9, 8, 3, -2, -11, -20, -24, -27, -29, -31, -31, -32, -35, -32, -27, -22, -15, -10, -8, -6, -1, 1, 5, 9, 8, 7, 4, -1, -5, -11, -14, -16, -15, -10, -2, 8, 14, 17, 16, 16, 16, 17, 16, 15, 11, 7, 7, 8, 6, 1, -2, -6, -9, -8, -9, -11, -11, -10, -9, -2, 3, 7, 7, 7, 7, 5, 5, 2, -3, -6, -8, -4, -5, -8, -8, -10, -18, -23, -26, -26, -26, -26, -19, -17, -18, -20, -19, -20, -21, -17, -13, -11, -9, -8, -8, -10, -10, -7, -4, -2, -4, -6, -7, -7, -11, -10, -9, -8, -6, -3, 2, 5, 6, 7, 8, 8, 3, -2, -5, -1, 1, 3, 6, 5, 8, 12, 17, 27, 29, 31, 31, 30, 28, 25, 22, 16, 11, 8, 9, 13, 19, 26, 35, 37, 34, 34, 30, 27, 26, 26, 25, 22, 20, 17, 17, 19, 19, 17, 12, 7, 6, 12, 16, 21, 25, 27, 24, 15, 9, 0, -7, -12, -14, -14, -12, -10, -10, -12, -18, -20, -25, -31, -34, -35, -33, -32, -31, -27, -22, -24, -26, -29, -34, -39, -44, -51, -56, -62, -67, -70, -72, -65, -60, -56, -52, -50, -44, -41, -37, -33, -32, -32, -34, -36, -37, -37, -38, -36, -30, -23, -16, -11, -5, 2, 5, 7, 7, 8, 9, 14, 19, 24, 31, 34, 41, 45, 49, 51, 53, 54, 52, 52, 51, 48, 45, 44, 39, 38, 38, 38, 41, 41, 39, 38, 39, 46, 49, 52, 50, 44, 35, 27, 23, 19, 18, 18, 13, 5, -6, -16, -28, -40, -51, -63, -70, -66, -58, -43, -24, -2, 33, 54, 68, 74, 75, 67, 57, 45, 34, 22, 11, 4, 0, -4, -10, -19, -27, -38, -42, -44, -42, -38, -29, -23, -22, -23, -27, -31, -34, -37, -39, -38, -36, -31, -25, -22, -19, -13, -4, 14, 22, 26, 27, 25, 19, 2, -12, -25, -38, -45, -46, -37, -29, -24, -22, -24, -25, -26, -25, -22, -19, -14, -5, 5, 17, 30, 44, 57, 76, 84, 88, 92, 92, 89, 89, 87, 86, 80, 70, 57, 45, 33, 23, 12, -1, -8, -12, -12, -15, -20, -26, -30, -31, -27, -20, -16, -8, -1, 4, 9, 15, 23, 26, 27, 26, 25, 21, 7, -5, -18, -30, -41, -53, -67, -75, -81, -88, -93, -96, -97, -99, -98, -100, -102, -98, -89, -79, -74, -74, -76, -79, -82, -78, -68, -62, -64, -59, -51, -44, -39, -35, -28, -25, -18, -5, 13, 29, 49, 59, 60, 57, 57, 64, 67, 69, 73, 80, 83, 82, 88, 93, 93, 89, 88, 82, 70, 65, 65, 68, 75, 77, 77, 76, 72, 67, 53, 43, 34, 25, 20, 18, 25, 34, 39, 40, 40, 38, 33, 28, 25, 19, 10, 4, 2, -3, -10, -16, -23, -41, -51, -56, -65, -77, -85, -86, -84, -79, -72, -69, -70, -73, -70, -61, -47, -33, -17, -14, -11, -4, 1, 4, 0, -8, -18, -26, -25, -22, -16, -9, -5, -2, -2, -2, -4, -8, -6, -2, 3, 9, 14, 16, 11, 3, -4, -9, -15, -12, -4, 6, 12, 20, 25, 27, 26, 27, 30, 29, 24, 23, 26, 32, 37, 44, 47, 46, 35, 27, 25, 19, 15, 15, 13, 10, 4, -4, -14, -25, -39, -38, -36, -30, -22, -20, -20, -20, -18, -17, -20, -28, -36, -40, -40, -36, -29, -18, -8, -4, 0, 9, 13, 13, 15, 15, 12, 5, -5, -12, -17, -19, -20, -21, -30, -33, -32, -33, -31, -29, -25, -17, -13, -10, -7, -2, -1, 0, 0, -1, -4, -7, -6, -5, -1, 6, 21, 28, 34, 42, 46, 47, 42, 37, 34, 29, 23, 20, 20, 24, 32, 39, 40, 37, 34, 33, 32, 29, 30, 25, 19, 16, 16, 16, 16, 18, 15, 10, 7, 5, 0, 0, 0, -3, -6, -12, -20, -21, -21, -20, -19, -22, -27, -29, -30, -30, -27, -22, -20, -21, -22, -25, -28, -31, -32, -33, -33, -32, -28, -26, -28, -32, -35, -36, -37, -40, -38, -34, -35, -34, -24, -21, -18, -10, -1, 14, 23, 30, 34, 33, 32, 32, 33, 37, 42, 48, 56, 67, 69, 70, 67, 64, 61, 55, 50, 46, 43, 40, 37, 34, 30, 26, 24, 24, 26, 28, 30, 33, 33, 27, 22, 14, 9, 5, 2, -5, -13, -20, -28, -35, -42, -44, -44, -44, -41, -38, -34, -35, -36, -37, -40, -42, -47, -50, -55, -61, -66, -73, -84, -89, -91, -90, -87, -76, -69, -64, -58, -55, -54, -49, -43, -33, -22, -15, -10, -8, -8, -2, 6, 11, 17, 16, 15, 14, 12, 12, 15, 18, 21, 25, 31, 32, 32, 34, 38, 41, 47, 54, 55, 56, 57, 56, 55, 54, 49, 42, 37, 32, 26, 24, 22, 17, 13, 11, 17, 22, 24, 26, 26, 27, 25, 24, 24, 18, 9, -4, -12, -20, -28, -36, -45, -60, -67, -70, -72, -71, -67, -60, -52, -45, -41, -36, -29, -25, -21, -20, -22, -29, -38, -40, -44, -44, -38, -30, -17, -6, 4, 11, 16, 16, 13, 12, 10, 10, 16, 23, 28, 30, 29, 28, 29, 31, 32, 32, 37, 44, 53, 57, 57, 53, 46, 42, 41, 44, 47, 50, 54, 58, 63, 65, 65, 63, 58, 47, 43, 38, 33, 30, 26, 24, 25, 30, 37, 40, 40, 35, 29, 22, 15, 9, 2, -3, -12, -17, -22, -31, -39, -41, -42, -38, -36, -31, -22, -21, -20, -22, -26, -26, -20, -13, -8, -4, -1, -7, -10, -9, -8, -9, -9, -12, -14, -13, -10, -10, -14, -20, -28, -36, -43, -46, -48, -47, -44, -41, -41, -35, -32, -29, -26, -30, -34, -40, -41, -39, -34, -29, -20, -1, 11, 23, 30, 35, 37, 34, 30, 20, 9, 0, -15, -20, -23, -25, -29, -34, -43, -50, -54, -56, -53, -46, -43, -38, -33, -25, -14, 4, 16, 22, 25, 24, 24, 20, 15, 11, 10, 9, 11, 12, 12, 10, 4, -3, -8, -12, -17, -22, -27, -28, -25, -22, -16, -11, -6, 7, 18, 27, 31, 32, 30, 19, 13, 6, 1, -3, -7, -8, -9, -7, -4, 0, 5, 6, 6, 7, 12, 16, 15, 14, 11, 5, 1, -2, -6, -6, -7, -5, -1, 4, 11, 20, 28, 31, 32, 31, 30, 28, 29, 31, 30, 22, 18, 17, 18, 22, 35, 37, 36, 35, 31, 29, 34, 39, 42, 44, 43, 39, 29, 23, 17, 10, 3, 0, 2, 6, 16, 27, 34, 44, 49, 49, 48, 45, 36, 25, 15, 6, -2, -10, -22, -25, -30, -37, -41, -45, -53, -60, -70, -74, -73, -68, -61, -56, -49, -45, -41, -29, -21, -16, -13, -12, -16, -27, -30, -35, -41, -44, -48, -49, -50, -49, -43, -40, -38, -32, -26, -21, -16, -11, -10, -9, -10, -11, -11, -10, -6, -5, -2, 3, 5, 6, 5, 5, 8, 14, 21, 35, 45, 48, 46, 40, 26, 19, 15, 13, 14, 14, 16, 21, 25, 29, 33, 35, 35, 30, 23, 16, 11, 4, 0, -6, -13, -19, -22, -19, -16, -17, -19, -19, -20, -19, -11, -6, -7, -7, -13, -19, -20, -19, -14, -6, 7, 11, 12, 14, 13, 10, 6, 4, 0, -2, -2, -3, 4, 9, 13, 17, 17, 11, 12, 17, 25, 39, 52, 57, 56, 53, 44, 35, 22, 15, 13, 13, 15, 16, 13, 13, 14, 14, 13, 13, 10, 11, 12, 14, 22, 30, 31, 30, 28, 27, 24, 21, 23, 22, 18, 16, 10, 2, -3, -8, -18, -29, -34, -30, -30, -27, -21, -17, -16, -15, -15, -17, -21, -25, -26, -31, -33, -31, -32, -31, -28, -25, -24, -20, -15, -13, -16, -19, -23, -31, -42, -44, -49, -53, -54, -57, -66, -68, -70, -72, -72, -70, -65, -62, -58, -54, -54, -49, -42, -37, -34, -31, -22, -8, 3, 16, 26, 30, 32, 35, 39, 42, 42, 41, 35, 31, 28, 22, 19, 20, 11, 6, 2, -3, -3, 3, 13, 15, 14, 12, 15, 21, 29, 38, 43, 46, 47, 50, 52, 55, 54, 52, 53, 47, 38, 32, 24, 14, 4, 1, -2, -3, -3, -8, -19, -26, -31, -32, -33, -32, -33, -35, -35, -30, -26, -15, -6, -1, -2, -3, -8, -15, -13, -12, -7, -3, 4, 8, 10, 11, 12, 14, 11, 8, 8, 5, 2, 6, 9, 12, 14, 13, 11, 6, 2, 0, -3, -4, -2, -2, 5, 14, 19, 23, 28, 32, 34, 40, 42, 40, 39, 38, 32, 24, 17, 10, -7, -15, -19, -23, -29, -29, -21, -15, -9, -6, -6, 0, 8, 15, 17, 15, 8, -7, -14, -18, -18, -15, -13, -11, -9, -10, -12, -13, -12, -9, -8, -8, -8, -6, -4, -3, -3, 0, 3, 6, 15, 20, 22, 28, 33, 34, 31, 27, 25, 21, 17, 10, 3, -1, -2, 3, 12, 20, 20, 19, 21, 21, 16, 11, 0, -15, -28, -38, -48, -54, -55, -53, -50, -45, -30, -16, -3, 13, 30, 40, 39, 36, 30, 18, 9, 5, 2, 0, 2, 3, 0, -3, -9, -17, -24, -32, -42, -52, -59, -65, -72, -76, -79, -77, -73, -65, -50, -18, 8, 30, 48, 58, 59, 54, 49, 40, 31, 24, 13, 0, -6, -11, -12, -12, -18, -22, -28, -34, -41, -46, -47, -47, -47, -52, -57, -60, -64, -61, -56, -52, -49, -43, -36, -33, -27, -21, -16, -9, -8, -10, -9, -4, 1, 11, 16, 21, 25, 26, 31, 36, 38, 39, 43, 45, 45, 41, 35, 31, 23, 10, -4, -14, -25, -32, -31, -18, -3, 17, 34, 51, 69, 92, 106, 117, 123, 125, 123, 115, 108, 98, 84, 68, 41, 26, 14, 0, -13, -23, -38, -45, -49, -52, -52, -51, -50, -50, -47, -42, -39, -32, -27, -19, -10, -3, 3, 11, 10, 8, 5, 1, -6, -17, -20, -22, -21, -23, -26, -32, -38, -39, -38, -39, -43, -45, -44, -41, -36, -30, -29, -27, -28, -26, -19, -16, -11, -4, 1, 10, 27, 58, 74, 83, 87, 87, 77, 71, 66, 61, 52, 45, 37, 30, 28, 25, 23, 23, 22, 25, 26, 23, 20, 13, 7, 0, -3, -4, -9, -13, -15, -21, -21, -14, -8, -2, 1, 4, 4, 3, 3, -1, -7, -10, -13, -21, -32, -36, -40, -44, -49, -54, -64, -65, -62, -58, -57, -55, -56, -61, -63, -64, -62, -58, -50, -36, -23, -11, 0, 10, 15, 20, 22, 23, 19, 11, 5, 2, -4, -12, -17, -20, -22, -21, -19, -15, -12, -9, -3, 6, 13, 17, 21, 21, 19, 20, 25, 19, 13, 11, 12, 12, 17, 31, 33, 34, 32, 27, 29, 29, 28, 33, 36, 35, 36, 34, 34, 36, 36, 38, 42, 44, 46, 50, 50, 37, 30, 21, 13, 15, 19, 24, 26, 24, 21, 18, 14, 11, 8, 4, 2, -1, -11, -15, -15, -17, -20, -20, -25, -28, -28, -31, -35, -38, -41, -45, -49, -51, -49, -49, -45, -42, -40, -39, -41, -41, -41, -42, -41, -36, -25, -18, -9, 0, 6, 15, 19, 19, 20, 12, 4, 2, -4, -10, -15, -19, -23, -31, -29, -23, -17, -13, -6, 6, 10, 15, 19, 23, 24, 25, 30, 32, 27, 25, 28, 31, 37, 43, 49, 46, 40, 36, 27, 15, 6, 1, 0, 1, 1, 1, 0, -7, -11, -14, -21, -26, -26, -26, -27, -27, -29, -31, -33, -34, -32, -28, -22, -17, -10, -5, 0, 2, 4, 4, -6, -15, -23, -29, -33, -34, -28, -25, -23, -21, -20, -27, -31, -33, -33, -30, -28, -17, -12, -9, -3, 1, 5, 9, 7, 10, 16, 22, 37, 45, 50, 53, 53, 53, 47, 43, 34, 22, 12, 3, -2, -5, -5, -3, 1, 2, 4, 8, 12, 15, 14, 17, 14, 10, 9, 2, -9, -17, -28, -33, -37, -38, -35, -35, -31, -28, -27, -21, -12, -1, 14, 25, 36, 45, 47, 50, 45, 42, 39, 30, 24, 20, 18, 16, 15, 14, 11, 7, 4, -2, -3, -7, -11, -12, -15, -16, -12, -5, 0, 4, 6, 3, -6, -12, -16, -19, -20, -18, -15, -7, -1, 5, 15, 24, 31, 39, 45, 53, 55, 56, 55, 53, 51, 45, 30, 22, 9, -6, -18, -29, -40, -42, -37, -29, -18, -6, 10, 25, 36, 42, 49, 54, 56, 55, 52, 50, 45, 32, 23, 13, 5, -5, -14, -23, -27, -30, -31, -29, -22, -19, -15, -10, -10, -15, -18, -23, -26, -27, -29, -32, -33, -36, -41, -44, -48, -51, -51, -47, -36, -29, -25, -16, -9, -4, -2, 0, 1, 1, -1, -6, -10, -15, -28, -38, -50, -64, -74, -82, -92, -92, -90, -86, -81, -72, -67, -64, -63, -62, -59, -57, -54, -51, -49, -39, -30, -17, -2, 7, 9, 9, 11, 13, 19, 29, 38, 46, 56, 57, 62, 63, 59, 55, 41, 33, 28, 23, 24, 35, 40, 44, 43, 40, 37, 31, 29, 28, 34, 39, 40, 49, 57, 68, 80, 93, 106, 109, 111, 107, 103, 99, 86, 75, 64, 48, 27, 6, -22, -41, -55, -63, -68, -66, -62, -54, -43, -36, -29, -19, -14, -11, -9, -6, -4, -5, -2, 2, 3, 1, -3, -7, -13, -16, -17, -17, -23, -31, -41, -48, -51, -55, -60, -62, -66, -70, -72, -61, -54, -46, -37, -28, -21, -9, -1, 5, 8, 12, 15, 12, 11, 13, 18, 25, 32, 31, 29, 28, 28, 28, 29, 32, 33, 33, 33, 32, 26, 30, 36, 38, 38, 37, 31, 23, 22, 20, 15, 6, 3, -1, -8, -10, -11, -13, -15, -19, -22, -25, -25, -15, -4, 4, 9, 9, 1, -3, -6, -7, -10, -7, -3, -1, 3, 5, 5, 7, 5, 5, 5, 4, 2, 4, 6, 8, 11, 10, 5, 1, -3, -8, -9, -8, -8, -9, -6, 0, 5, 8, 13, 16, 13, 10, 9, 5, 4, 2, -1, 0, -1, 4, 7, 8, 10, 9, 7, 2, -2, -3, -3, -3, -1, -3, -7, -13, -19, -23, -33, -36, -39, -42, -43, -42, -41, -40, -38, -34, -34, -31, -26, -23, -22, -18, -10, -2, 3, 11, 15, 15, 19, 19, 14, 12, 7, 0, -10, -13, -15, -19, -20, -19, -18, -18, -19, -18, -14, -11, -5, -1, -4, -8, -7, -3, 3, 10, 14, 17, 20, 25, 29, 32, 31, 32, 33, 33, 37, 41, 43, 44, 41, 36, 34, 28, 22, 20, 22, 23, 21, 18, 15, 12, 11, 11, 11, 11, 10, 11, 15, 18, 18, 20, 22, 16, 11, 8, 2, -4, -8, -13, -16, -18, -16, -15, -17, -21, -25, -27, -29, -26, -22, -20, -16, -8, 0, 7, 9, 5, -3, -10, -17, -22, -22, -25, -27, -27, -31, -40, -40, -45, -52, -55, -58, -59, -58, -55, -53, -51, -48, -46, -42, -36, -34, -34, -35, -36, -39, -42, -45, -48, -48, -46, -44, -40, -36, -31, -24, -19, -15, -12, -7, 4, 8, 13, 15, 17, 25, 31, 41, 47, 46, 47, 50, 49, 51, 54, 54, 54, 56, 58, 58, 58, 58, 51, 48, 47, 47, 46, 43, 38, 37, 35, 34, 34, 33, 28, 26, 24, 21, 19, 16, 14, 14, 14, 13, 12, 9, 4, -4, -16, -27, -35, -49, -53, -50, -43, -31, -6, 10, 24, 34, 42, 48, 51, 52, 56, 53, 43, 30, 19, 8, 1, -8, -20, -34, -38, -39, -38, -35, -28, -16, -11, -7, -5, -7, -14, -17, -20, -24, -24, -25, -25, -20, -15, -14, -10, -8, -5, 1, 8, 12, 14, 15, 13, 11, 11, 14, 8, -6, -16, -27, -35, -42, -47, -52, -52, -52, -52, -47, -36, -24, -9, 7, 24, 40, 58, 69, 78, 83, 87, 88, 90, 91, 90, 88, 86, 76, 62, 45, 29, 13, -5, -21, -21, -21, -18, -15, -12, -11, -13, -12, -8, -9, -13, -17, -20, -20, -16, -11, -7, -2, 1, 3, 5, 3, -4, -13, -20, -28, -36, -48, -60, -71, -80, -89, -97, -100, -103, -105, -104, -100, -94, -87, -82, -79, -76, -70, -58, -54, -54, -54, -54, -56, -55, -49, -39, -29, -22, -11, 6, 13, 19, 26, 32, 40, 43, 43, 41, 41, 47, 53, 55, 59, 64, 68, 69, 72, 73, 72, 75, 76, 70, 64, 57, 52, 49, 47, 40, 37, 38, 40, 43, 46, 47, 49, 47, 46, 47, 46, 44, 42, 41, 37, 33, 30, 24, 19, 16, 9, -3, -6, -12, -22, -27, -33, -46, -54, -65, -73, -79, -85, -81, -77, -76, -74, -71, -62, -55, -47, -37, -27, -17, -4, 3, 10, 15, 17, 18, 20, 18, 13, 8, 2, 2, 4, 6, 5, -3, -13, -22, -25, -22, -16, -13, -12, -7, -6, -8, -7, -5, -2, 2, 9, 13, 16, 20, 31, 36, 41, 44, 42, 40, 34, 29, 25, 24, 24, 27, 30, 32, 31, 30, 28, 19, 16, 12, 7, 9, 16, 20, 18, 15, 7, -4, -16, -20, -27, -30, -29, -31, -30, -27, -26, -26, -24, -22, -19, -15, -11, -10, -7, -4, -3, -2, -2, -5, -9, -9, -9, -11, -13, -16, -23, -27, -29, -29, -27, -25, -20, -16, -14, -12, -9, -6, -6, -9, -11, -17, -19, -14, -13, -10, -6, -6, -8, -7, -3, 3, 10, 17, 22, 25, 26, 27, 31, 35, 38, 42, 43, 41, 40, 37, 35, 36, 37, 40, 44, 45, 39, 36, 33, 30, 31, 27, 21, 15, 6, -1, -7, -15, -18, -25, -30, -31, -31, -29, -25, -23, -25, -27, -30, -28, -25, -24, -22, -23, -27, -29, -32, -37, -43, -48, -54, -55, -54, -52, -45, -37, -33, -30, -31, -32, -30, -29, -28, -28, -30, -31, -27, -21, -18, -13, -10, -8, -4, -4, -1, 3, 5, 12, 24, 29, 35, 42, 49, 56, 62, 67, 70, 72, 74, 77, 79, 77, 74, 72, 65, 54, 45, 35, 28, 22, 21, 21, 23, 27, 30, 32, 40, 40, 38, 36, 31, 22, 8, 4, -2, -9, -12, -13, -15, -16, -16, -20, -26, -37, -41, -41, -39, -32, -25, -23, -28, -38, -49, -60, -73, -76, -80, -83, -83, -83, -84, -83, -78, -71, -66, -63, -61, -61, -63, -56, -44, -29, -17, -6, 2, 8, 13, 17, 14, 13, 16, 17, 15, 16, 17, 23, 30, 35, 38, 35, 35, 38, 43, 50, 55, 53, 48, 43, 40, 39, 32, 29, 22, 14, 13, 14, 14, 15, 14, 14, 18, 23, 21, 18, 17, 17, 20, 28, 34, 39, 42, 42, 38, 31, 22, 11, -1, -13, -32, -41, -47, -53, -56, -57, -60, -63, -63, -63, -65, -61, -55, -50, -46, -42, -38, -38, -34, -28, -24, -21, -21, -23, -24, -23, -19, -12, -3, 5, 14, 19, 21, 23, 20, 16, 14, 12, 9, 4, 3, 5, 8, 12, 20, 39, 48, 57, 64, 68, 69, 66, 63, 58, 48, 39, 30, 20, 12, 9, 6, 4, 8, 8, 9, 12, 15, 20, 26, 30, 32, 31, 28, 24, 19, 15, 16, 17, 18, 23, 26, 27, 26, 22, 14, 2, -5, -11, -15, -17, -18, -16, -14, -12, -9, -8, -7, -4, -6, -14, -20, -25, -28, -22, -15, -9, -4, 0, 2, 3, 4, 5, 6, 6, 4, 5, 7, 7, 9, 9, 5, -4, -15, -23, -28, -31, -35, -38, -38, -37, -36, -33, -29, -29, -28, -25, -26, -23, -22, -24, -20, -13, -7, -2, 3, 8, 10, 8, 5, 1, -4, -7, -6, -2, -4, -5, -7, -13, -19, -21, -22, -23, -24, -24, -33, -40, -45, -49, -46, -40, -26, -14, -4, 0, 3, 3, -1, -1, 1, 2, 0, -1, -3, -2, -1, -1, -3, -10, -13, -14, -17, -23, -31, -35, -35, -28, -17, -6, 6, 13, 20, 26, 28, 19, 11, 3, -5, -6, -1, 3, 4, 1, -2, -1, 1, 3, 4, 4, 6, 10, 22, 29, 30, 28, 27, 24, 16, 15, 14, 10, 7, 2, -7, -10, -12, -13, -10, -6, -2, 3, 8, 14, 20, 28, 32, 35, 39, 37, 35, 32, 25, 19, 16, 13, 9, 11, 15, 18, 23, 30, 36, 36, 36, 35, 35, 35, 31, 30, 30, 30, 32, 34, 36, 38, 39, 44, 49, 45, 42, 39, 33, 29, 25, 10, -5, -19, -28, -33, -34, -31, -31, -37, -45, -48, -50, -48, -44, -43, -45, -45, -39, -31, -23, -16, -14, -17, -18, -24, -32, -37, -42, -40, -36, -34, -33, -33, -35, -39, -41, -41, -44, -45, -39, -33, -27, -21, -14, -7, -2, 1, 3, 7, 11, 15, 20, 18, 16, 14, 10, 6, 3, 1, 0, 0, 3, 10, 16, 21, 23, 25, 28, 28, 28, 33, 39, 45, 54, 54, 50, 42, 31, 21, 8, 6, 4, 0, -6, -15, -20, -25, -29, -35, -42, -43, -40, -38, -33, -27, -26, -22, -17, -13, -8, -6, -10, -11, -10, -9, -6, -3, 1, 3, 5, 7, 6, 4, 1, -2, -3, 0, 8, 15, 19, 18, 13, 8, 6, 10, 13, 18, 21, 23, 26, 30, 31, 34, 36, 36, 36, 37, 36, 33, 33, 34, 32, 31, 32, 30, 26, 25, 23, 25, 31, 32, 30, 30, 30, 29, 28, 28, 26, 16, 10, 3, -5, -12, -19, -31, -37, -40, -42, -41, -38, -41, -44, -49, -54, -53, -49, -42, -35, -30, -26, -21, -13, -14, -23, -30, -33, -42, -40, -37, -31, -26, -26, -29, -36, -42, -43, -40, -36, -32, -34, -36, -43, -47, -43, -43, -43, -41, -40, -42, -42, -38, -41, -41, -36, -25, -15, -2, 10, 18, 21, 26, 30, 32, 31, 34, 39, 40, 38, 34, 29, 23, 13, 11, 12, 10, 11, 15, 16, 20, 25, 28, 27, 28, 36, 37, 40, 47, 47, 42, 40, 37, 32, 29, 29, 26, 21, 17, 12, 6, 4, 4, 7, 6, 0, -7, -12, -15, -17, -18, -19, -23, -32, -36, -36, -33, -35, -35, -27, -24, -19, -14, -12, -15, -13, -13, -13, -8, -1, 4, 7, 5, 4, 4, 0, 9, 11, 11, 9, 8, 12, 10, 10, 14, 14, 15, 17, 16, 14, 13, 13, 13, 14, 13, 12, 9, 7, 9, 15, 22, 25, 25, 23, 14, 9, 4, 5, 4, -1, -2, -2, -1, 0, 0, 4, 2, 3, 3, 1, 1, 2, 7, 9, 9, 8, 3, 1, 2, 7, 8, 3, 1, 0, -4, -5, -5, -9, -13, -13, -13, -15, -16, -17, -17, -14, -10, -4, 5, 20, 31, 37, 39, 40, 39, 40, 38, 38, 41, 40, 39, 35, 29, 20, 13, 8, -2, -6, -8, -15, -15, -10, -6, -5, -11, -16, -21, -32, -39, -48, -53, -54, -51, -35, -24, -9, 8, 20, 33, 41, 38, 37, 31, 25, 27, 28, 30, 30, 30, 28, 13, 3, -11, -23, -36, -51, -64, -70, -74, -72, -72, -71, -70, -67, -61, -53, -43, -27, -11, 7, 23, 40, 52, 56, 52, 45, 40, 33, 23, 15, 6, -3, -11, -18, -27, -37, -48, -60, -71, -77, -83, -81, -78, -73, -66, -57, -50, -47, -43, -34, -29, -30, -27, -28, -28, -24, -19, -13, -9, -5, -2, -1, };
694bb087e7cdd16d232c8a27ad2aafb507a56090
99bdb3251fecee538e0630f15f6574054dfc1468
/bsp/allwinner/libraries/sunxi-hal/hal/source/sdmmc/osal/os/FreeRTOS/os_queue.c
eb9dbca96d996f2035edf20bf9f89bb6a995adad
[ "Zlib", "LicenseRef-scancode-proprietary-license", "MIT", "BSD-3-Clause", "X11", "BSD-4-Clause-UC", "LicenseRef-scancode-unknown-license-reference", "Apache-2.0" ]
permissive
RT-Thread/rt-thread
03a7c52c2aeb1b06a544143b0e803d72f47d1ece
3602f891211904a27dcbd51e5ba72fefce7326b2
refs/heads/master
2023-09-01T04:10:20.295801
2023-08-31T16:20:55
2023-08-31T16:20:55
7,408,108
9,599
5,805
Apache-2.0
2023-09-14T13:37:26
2013-01-02T14:49:21
C
UTF-8
C
false
false
5,901
c
os_queue.c
/** * @file os_queue.c * @author ALLWINNERTECH IOT WLAN Team */ /* * Copyright (C) 2017 ALLWINNERTECH TECHNOLOGY CO., LTD. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. * 3. Neither the name of ALLWINNERTECH TECHNOLOGY CO., LTD. nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "os_queue.h" #include "os_util.h" /** * @brief Create and initialize a queue object * @param[in] queue Pointer to the queue object * @param[in] queueLen The maximum number of items that the queue can hold at * any one time. * @param[in] itemSize The size, in bytes, of each data item that can be stored * in the queue. * @retval OS_Status, OS_OK on success */ OS_Status OS_QueueCreate(OS_Queue_t *queue, uint32_t queueLen, uint32_t itemSize) { // OS_HANDLE_ASSERT(!OS_QueueIsValid(queue), queue->handle); queue->handle = xQueueCreate(queueLen, itemSize); if (queue->handle == NULL) { OS_ERR("err %"OS_HANDLE_F"\n", queue->handle); return OS_FAIL; } return OS_OK; } /** * @brief Delete the queue object * @param[in] queue Pointer to the queue object * @retval OS_Status, OS_OK on success */ OS_Status OS_QueueDelete(OS_Queue_t *queue) { UBaseType_t ret; OS_HANDLE_ASSERT(OS_QueueIsValid(queue), queue->handle); ret = uxQueueMessagesWaiting(queue->handle); if (ret > 0) { OS_ERR("queue %"OS_HANDLE_F" is not empty\n", queue->handle); return OS_FAIL; } vQueueDelete(queue->handle); OS_QueueSetInvalid(queue); return OS_OK; } /** * @brief Send (write) an item to the back of the queue * @param[in] queue Pointer to the queue object * @param[in] item Pointer to the data to be copied into the queue. * The size of each item the queue can hold is set when the * queue is created, and that many bytes will be copied from * item into the queue storage area. * @param[in] waitMS The maximum amount of time the thread should remain in the * blocked state to wait for space to become available on the * queue, should the queue already be full. * OS_WAIT_FOREVER for waiting forever, zero for no waiting. * @retval OS_Status, OS_OK on success */ OS_Status OS_QueueSend(OS_Queue_t *queue, const void *item, OS_Time_t waitMS) { BaseType_t ret; BaseType_t taskWoken; OS_HANDLE_ASSERT(OS_QueueIsValid(queue), queue->handle); if (OS_IsISRContext()) { taskWoken = pdFALSE; ret = xQueueSendFromISR(queue->handle, item, &taskWoken); if (ret != pdPASS) { OS_DBG("%s() fail @ %d\n", __func__, __LINE__); return OS_FAIL; } portEND_SWITCHING_ISR(taskWoken); } else { ret = xQueueSend(queue->handle, item, OS_CalcWaitTicks(waitMS)); if (ret != pdPASS) { OS_DBG("%s() fail @ %d, %"OS_TIME_F" ms\n", __func__, __LINE__, waitMS); return OS_FAIL; } } return OS_OK; } /** * @brief Receive (read) an item from the queue * @param[in] queue Pointer to the queue object * @param[in] item Pointer to the memory into which the received data will be * copied. The length of the buffer must be at least equal to * the queue item size which is set when the queue is created. * @param[in] waitMS The maximum amount of time the thread should remain in the * blocked state to wait for data to become available on the * queue, should the queue already be empty. * OS_WAIT_FOREVER for waiting forever, zero for no waiting. * @retval OS_Status, OS_OK on success */ OS_Status OS_QueueReceive(OS_Queue_t *queue, void *item, OS_Time_t waitMS) { BaseType_t ret; BaseType_t taskWoken; OS_HANDLE_ASSERT(OS_QueueIsValid(queue), queue->handle); if (OS_IsISRContext()) { taskWoken = pdFALSE; ret = xQueueReceiveFromISR(queue->handle, item, &taskWoken); if (ret != pdPASS) { OS_DBG("%s() fail @ %d\n", __func__, __LINE__); return OS_FAIL; } portEND_SWITCHING_ISR(taskWoken); } else { ret = xQueueReceive(queue->handle, item, OS_CalcWaitTicks(waitMS)); if (ret != pdPASS) { OS_DBG("%s() fail @ %d, %"OS_TIME_F" ms\n", __func__, __LINE__, waitMS); return OS_FAIL; } } return OS_OK; }
a5750d48f4305e5e71b498bb23489d28c8e7c3e6
eecd5e4c50d8b78a769bcc2675250576bed34066
/src/mat/tests/ex3.c
d81fbc3c79703e7fad0a8032e6e45f367e91b5ae
[ "BSD-2-Clause" ]
permissive
petsc/petsc
3b1a04fea71858e0292f9fd4d04ea11618c50969
9c5460f9064ca60dd71a234a1f6faf93e7a6b0c9
refs/heads/main
2023-08-17T20:51:16.507070
2023-08-17T16:08:06
2023-08-17T16:08:06
8,691,401
341
169
NOASSERTION
2023-03-29T11:02:58
2013-03-10T20:55:21
C
UTF-8
C
false
false
2,011
c
ex3.c
static char help[] = "Tests relaxation for dense matrices.\n\n"; #include <petscmat.h> int main(int argc, char **args) { Mat C; Vec u, x, b, e; PetscInt i, n = 10, midx[3]; PetscScalar v[3]; PetscReal omega = 1.0, norm; PetscFunctionBeginUser; PetscCall(PetscInitialize(&argc, &args, (char *)0, help)); PetscCall(PetscOptionsGetReal(NULL, NULL, "-omega", &omega, NULL)); PetscCall(PetscOptionsGetInt(NULL, NULL, "-n", &n, NULL)); PetscCall(MatCreate(PETSC_COMM_SELF, &C)); PetscCall(MatSetSizes(C, n, n, n, n)); PetscCall(MatSetType(C, MATSEQDENSE)); PetscCall(MatSetUp(C)); PetscCall(VecCreateSeq(PETSC_COMM_SELF, n, &b)); PetscCall(VecCreateSeq(PETSC_COMM_SELF, n, &x)); PetscCall(VecCreateSeq(PETSC_COMM_SELF, n, &u)); PetscCall(VecCreateSeq(PETSC_COMM_SELF, n, &e)); PetscCall(VecSet(u, 1.0)); PetscCall(VecSet(x, 0.0)); v[0] = -1.; v[1] = 2.; v[2] = -1.; for (i = 1; i < n - 1; i++) { midx[0] = i - 1; midx[1] = i; midx[2] = i + 1; PetscCall(MatSetValues(C, 1, &i, 3, midx, v, INSERT_VALUES)); } i = 0; midx[0] = 0; midx[1] = 1; v[0] = 2.0; v[1] = -1.; PetscCall(MatSetValues(C, 1, &i, 2, midx, v, INSERT_VALUES)); i = n - 1; midx[0] = n - 2; midx[1] = n - 1; v[0] = -1.0; v[1] = 2.; PetscCall(MatSetValues(C, 1, &i, 2, midx, v, INSERT_VALUES)); PetscCall(MatAssemblyBegin(C, MAT_FINAL_ASSEMBLY)); PetscCall(MatAssemblyEnd(C, MAT_FINAL_ASSEMBLY)); PetscCall(MatMult(C, u, b)); for (i = 0; i < n; i++) { PetscCall(MatSOR(C, b, omega, SOR_FORWARD_SWEEP, 0.0, 1, 1, x)); PetscCall(VecWAXPY(e, -1.0, x, u)); PetscCall(VecNorm(e, NORM_2, &norm)); PetscCall(PetscPrintf(PETSC_COMM_SELF, "2-norm of error %g\n", (double)norm)); } PetscCall(MatDestroy(&C)); PetscCall(VecDestroy(&x)); PetscCall(VecDestroy(&b)); PetscCall(VecDestroy(&u)); PetscCall(VecDestroy(&e)); PetscCall(PetscFinalize()); return 0; } /*TEST test: TEST*/
d9a1bef54907b0151c8a815f4a75016734438cc8
e47e2263ca0b60d0c8327f74b4d4078deadea430
/tess-two/jni/com_googlecode_leptonica_android/src/src/maze.c
cc7679563cafdc0194ad52377f33b4c4d1fcbff5
[ "BSD-2-Clause", "CC-BY-2.5", "Apache-2.0" ]
permissive
rmtheis/tess-two
43ed1bdcceee88df696efdee7c3965572ff2121f
ab4cab1bd9794aacb74162aff339daa921a68c3f
refs/heads/master
2023-03-10T08:27:42.539055
2022-03-17T11:21:24
2022-03-17T11:21:24
2,581,357
3,632
1,331
Apache-2.0
2019-10-20T00:51:50
2011-10-15T11:14:00
C
UTF-8
C
false
false
36,822
c
maze.c
/*====================================================================* - Copyright (C) 2001 Leptonica. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials - provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *====================================================================*/ /*! * \file maze.c * <pre> * * This is a game with a pedagogical slant. A maze is represented * by a binary image. The ON pixels (fg) are walls. The goal is * to navigate on OFF pixels (bg), using Manhattan steps * (N, S, E, W), between arbitrary start and end positions. * The problem is thus to find the shortest route between two points * in a binary image that are 4-connected in the bg. This is done * with a breadth-first search, implemented with a queue. * We also use a queue of pointers to generate the maze (image). * * PIX *generateBinaryMaze() * static MAZEEL *mazeelCreate() * * PIX *pixSearchBinaryMaze() * static l_int32 localSearchForBackground() * * Generalizing a maze to a grayscale image, the search is * now for the "shortest" or least cost path, for some given * cost function. * * PIX *pixSearchGrayMaze() * </pre> */ #include <string.h> #ifdef _WIN32 #include <stdlib.h> #include <time.h> #endif /* _WIN32 */ #include "allheaders.h" static const l_int32 MIN_MAZE_WIDTH = 50; static const l_int32 MIN_MAZE_HEIGHT = 50; static const l_float32 DEFAULT_WALL_PROBABILITY = 0.65; static const l_float32 DEFAULT_ANISOTROPY_RATIO = 0.25; enum { /* direction from parent to newly created element */ START_LOC = 0, DIR_NORTH = 1, DIR_SOUTH = 2, DIR_WEST = 3, DIR_EAST = 4 }; struct MazeElement { l_float32 distance; l_int32 x; l_int32 y; l_uint32 val; /* value of maze pixel at this location */ l_int32 dir; /* direction from parent to child */ }; typedef struct MazeElement MAZEEL; static MAZEEL *mazeelCreate(l_int32 x, l_int32 y, l_int32 dir); static l_int32 localSearchForBackground(PIX *pix, l_int32 *px, l_int32 *py, l_int32 maxrad); #ifndef NO_CONSOLE_IO #define DEBUG_PATH 0 #define DEBUG_MAZE 0 #endif /* ~NO_CONSOLE_IO */ /*---------------------------------------------------------------------* * Binary maze generation as cellular automaton * *---------------------------------------------------------------------*/ /*! * \brief generateBinaryMaze() * * \param[in] w, h size of maze * \param[in] xi, yi initial location * \param[in] wallps probability that a pixel to the side is ON * \param[in] ranis ratio of prob that pixel in forward direction * is a wall to the probability that pixel in * side directions is a wall * \return pix, or NULL on error * * <pre> * Notes: * (1) We have two input probability factors that determine the * density of walls and average length of straight passages. * When ranis < 1.0, you are more likely to generate a wall * to the side than going forward. Enter 0.0 for either if * you want to use the default values. * (2) This is a type of percolation problem, and exhibits * different phases for different parameters wallps and ranis. * For larger values of these parameters, regions in the maze * are not explored because the maze generator walls them * off and cannot get through. The boundary between the * two phases in this two-dimensional parameter space goes * near these values: * wallps ranis * 0.35 1.00 * 0.40 0.85 * 0.45 0.70 * 0.50 0.50 * 0.55 0.40 * 0.60 0.30 * 0.65 0.25 * 0.70 0.19 * 0.75 0.15 * 0.80 0.11 * (3) Because there is a considerable amount of overhead in calling * pixGetPixel() and pixSetPixel(), this function can be sped * up with little effort using raster line pointers and the * GET_DATA* and SET_DATA* macros. * </pre> */ PIX * generateBinaryMaze(l_int32 w, l_int32 h, l_int32 xi, l_int32 yi, l_float32 wallps, l_float32 ranis) { l_int32 x, y, dir; l_uint32 val; l_float32 frand, wallpf, testp; MAZEEL *el, *elp; PIX *pixd; /* the destination maze */ PIX *pixm; /* for bookkeeping, to indicate pixels already visited */ L_QUEUE *lq; /* On Windows, seeding is apparently necessary to get decent mazes. * Windows rand() returns a value up to 2^15 - 1, whereas unix * rand() returns a value up to 2^31 - 1. Therefore the generated * mazes will differ on the two platforms. */ #ifdef _WIN32 srand(28*333); #endif /* _WIN32 */ if (w < MIN_MAZE_WIDTH) w = MIN_MAZE_WIDTH; if (h < MIN_MAZE_HEIGHT) h = MIN_MAZE_HEIGHT; if (xi <= 0 || xi >= w) xi = w / 6; if (yi <= 0 || yi >= h) yi = h / 5; if (wallps < 0.05 || wallps > 0.95) wallps = DEFAULT_WALL_PROBABILITY; if (ranis < 0.05 || ranis > 1.0) ranis = DEFAULT_ANISOTROPY_RATIO; wallpf = wallps * ranis; #if DEBUG_MAZE fprintf(stderr, "(w, h) = (%d, %d), (xi, yi) = (%d, %d)\n", w, h, xi, yi); fprintf(stderr, "Using: prob(wall) = %7.4f, anisotropy factor = %7.4f\n", wallps, ranis); #endif /* DEBUG_MAZE */ /* These are initialized to OFF */ pixd = pixCreate(w, h, 1); pixm = pixCreate(w, h, 1); lq = lqueueCreate(0); /* Prime the queue with the first pixel; it is OFF */ el = mazeelCreate(xi, yi, START_LOC); pixSetPixel(pixm, xi, yi, 1); /* mark visited */ lqueueAdd(lq, el); /* While we're at it ... */ while (lqueueGetCount(lq) > 0) { elp = (MAZEEL *)lqueueRemove(lq); x = elp->x; y = elp->y; dir = elp->dir; if (x > 0) { /* check west */ pixGetPixel(pixm, x - 1, y, &val); if (val == 0) { /* not yet visited */ pixSetPixel(pixm, x - 1, y, 1); /* mark visited */ frand = (l_float32)rand() / (l_float32)RAND_MAX; testp = wallps; if (dir == DIR_WEST) testp = wallpf; if (frand <= testp) { /* make it a wall */ pixSetPixel(pixd, x - 1, y, 1); } else { /* not a wall */ el = mazeelCreate(x - 1, y, DIR_WEST); lqueueAdd(lq, el); } } } if (y > 0) { /* check north */ pixGetPixel(pixm, x, y - 1, &val); if (val == 0) { /* not yet visited */ pixSetPixel(pixm, x, y - 1, 1); /* mark visited */ frand = (l_float32)rand() / (l_float32)RAND_MAX; testp = wallps; if (dir == DIR_NORTH) testp = wallpf; if (frand <= testp) { /* make it a wall */ pixSetPixel(pixd, x, y - 1, 1); } else { /* not a wall */ el = mazeelCreate(x, y - 1, DIR_NORTH); lqueueAdd(lq, el); } } } if (x < w - 1) { /* check east */ pixGetPixel(pixm, x + 1, y, &val); if (val == 0) { /* not yet visited */ pixSetPixel(pixm, x + 1, y, 1); /* mark visited */ frand = (l_float32)rand() / (l_float32)RAND_MAX; testp = wallps; if (dir == DIR_EAST) testp = wallpf; if (frand <= testp) { /* make it a wall */ pixSetPixel(pixd, x + 1, y, 1); } else { /* not a wall */ el = mazeelCreate(x + 1, y, DIR_EAST); lqueueAdd(lq, el); } } } if (y < h - 1) { /* check south */ pixGetPixel(pixm, x, y + 1, &val); if (val == 0) { /* not yet visited */ pixSetPixel(pixm, x, y + 1, 1); /* mark visited */ frand = (l_float32)rand() / (l_float32)RAND_MAX; testp = wallps; if (dir == DIR_SOUTH) testp = wallpf; if (frand <= testp) { /* make it a wall */ pixSetPixel(pixd, x, y + 1, 1); } else { /* not a wall */ el = mazeelCreate(x, y + 1, DIR_SOUTH); lqueueAdd(lq, el); } } } LEPT_FREE(elp); } lqueueDestroy(&lq, TRUE); pixDestroy(&pixm); return pixd; } static MAZEEL * mazeelCreate(l_int32 x, l_int32 y, l_int32 dir) { MAZEEL *el; el = (MAZEEL *)LEPT_CALLOC(1, sizeof(MAZEEL)); el->x = x; el->y = y; el->dir = dir; return el; } /*---------------------------------------------------------------------* * Binary maze search * *---------------------------------------------------------------------*/ /*! * \brief pixSearchBinaryMaze() * * \param[in] pixs 1 bpp, maze * \param[in] xi, yi beginning point; use same initial point * that was used to generate the maze * \param[in] xf, yf end point, or close to it * \param[out] ppixd [optional] maze with path illustrated, or * if no path possible, the part of the maze * that was searched * \return pta shortest path, or NULL if either no path * exists or on error * * <pre> * Notes: * (1) Because of the overhead in calling pixGetPixel() and * pixSetPixel(), we have used raster line pointers and the * GET_DATA* and SET_DATA* macros for many of the pix accesses. * (2) Commentary: * The goal is to find the shortest path between beginning and * end points, without going through walls, and there are many * ways to solve this problem. * We use a queue to implement a breadth-first search. Two auxiliary * "image" data structures can be used: one to mark the visited * pixels and one to give the direction to the parent for each * visited pixel. The first structure is used to avoid putting * pixels on the queue more than once, and the second is used * for retracing back to the origin, like the breadcrumbs in * Hansel and Gretel. Each pixel taken off the queue is destroyed * after it is used to locate the allowed neighbors. In fact, * only one distance image is required, if you initialize it * to some value that signifies "not yet visited." (We use * a binary image for marking visited pixels because it is clearer.) * This method for a simple search of a binary maze is implemented in * pixSearchBinaryMaze(). * An alternative method would store the (manhattan) distance * from the start point with each pixel on the queue. The children * of each pixel get a distance one larger than the parent. These * values can be stored in an auxiliary distance map image * that is constructed simultaneously with the search. Once the * end point is reached, the distance map is used to backtrack * along a minimum path. There may be several equal length * minimum paths, any one of which can be chosen this way. * </pre> */ PTA * pixSearchBinaryMaze(PIX *pixs, l_int32 xi, l_int32 yi, l_int32 xf, l_int32 yf, PIX **ppixd) { l_int32 i, j, x, y, w, h, d, found; l_uint32 val, rpixel, gpixel, bpixel; void **lines1, **linem1, **linep8, **lined32; MAZEEL *el, *elp; PIX *pixd; /* the shortest path written on the maze image */ PIX *pixm; /* for bookkeeping, to indicate pixels already visited */ PIX *pixp; /* for bookkeeping, to indicate direction to parent */ L_QUEUE *lq; PTA *pta; PROCNAME("pixSearchBinaryMaze"); if (ppixd) *ppixd = NULL; if (!pixs) return (PTA *)ERROR_PTR("pixs not defined", procName, NULL); pixGetDimensions(pixs, &w, &h, &d); if (d != 1) return (PTA *)ERROR_PTR("pixs not 1 bpp", procName, NULL); if (xi <= 0 || xi >= w) return (PTA *)ERROR_PTR("xi not valid", procName, NULL); if (yi <= 0 || yi >= h) return (PTA *)ERROR_PTR("yi not valid", procName, NULL); pixGetPixel(pixs, xi, yi, &val); if (val != 0) return (PTA *)ERROR_PTR("(xi,yi) not bg pixel", procName, NULL); pixd = NULL; pta = NULL; /* Find a bg pixel near input point (xf, yf) */ localSearchForBackground(pixs, &xf, &yf, 5); #if DEBUG_MAZE fprintf(stderr, "(xi, yi) = (%d, %d), (xf, yf) = (%d, %d)\n", xi, yi, xf, yf); #endif /* DEBUG_MAZE */ pixm = pixCreate(w, h, 1); /* initialized to OFF */ pixp = pixCreate(w, h, 8); /* direction to parent stored as enum val */ lines1 = pixGetLinePtrs(pixs, NULL); linem1 = pixGetLinePtrs(pixm, NULL); linep8 = pixGetLinePtrs(pixp, NULL); lq = lqueueCreate(0); /* Prime the queue with the first pixel; it is OFF */ el = mazeelCreate(xi, yi, 0); /* don't need direction here */ pixSetPixel(pixm, xi, yi, 1); /* mark visited */ lqueueAdd(lq, el); /* Fill up the pix storing directions to parents, * stopping when we hit the point (xf, yf) */ found = FALSE; while (lqueueGetCount(lq) > 0) { elp = (MAZEEL *)lqueueRemove(lq); x = elp->x; y = elp->y; if (x == xf && y == yf) { found = TRUE; LEPT_FREE(elp); break; } if (x > 0) { /* check to west */ val = GET_DATA_BIT(linem1[y], x - 1); if (val == 0) { /* not yet visited */ SET_DATA_BIT(linem1[y], x - 1); /* mark visited */ val = GET_DATA_BIT(lines1[y], x - 1); if (val == 0) { /* bg, not a wall */ SET_DATA_BYTE(linep8[y], x - 1, DIR_EAST); /* parent E */ el = mazeelCreate(x - 1, y, 0); lqueueAdd(lq, el); } } } if (y > 0) { /* check north */ val = GET_DATA_BIT(linem1[y - 1], x); if (val == 0) { /* not yet visited */ SET_DATA_BIT(linem1[y - 1], x); /* mark visited */ val = GET_DATA_BIT(lines1[y - 1], x); if (val == 0) { /* bg, not a wall */ SET_DATA_BYTE(linep8[y - 1], x, DIR_SOUTH); /* parent S */ el = mazeelCreate(x, y - 1, 0); lqueueAdd(lq, el); } } } if (x < w - 1) { /* check east */ val = GET_DATA_BIT(linem1[y], x + 1); if (val == 0) { /* not yet visited */ SET_DATA_BIT(linem1[y], x + 1); /* mark visited */ val = GET_DATA_BIT(lines1[y], x + 1); if (val == 0) { /* bg, not a wall */ SET_DATA_BYTE(linep8[y], x + 1, DIR_WEST); /* parent W */ el = mazeelCreate(x + 1, y, 0); lqueueAdd(lq, el); } } } if (y < h - 1) { /* check south */ val = GET_DATA_BIT(linem1[y + 1], x); if (val == 0) { /* not yet visited */ SET_DATA_BIT(linem1[y + 1], x); /* mark visited */ val = GET_DATA_BIT(lines1[y + 1], x); if (val == 0) { /* bg, not a wall */ SET_DATA_BYTE(linep8[y + 1], x, DIR_NORTH); /* parent N */ el = mazeelCreate(x, y + 1, 0); lqueueAdd(lq, el); } } } LEPT_FREE(elp); } lqueueDestroy(&lq, TRUE); pixDestroy(&pixm); LEPT_FREE(linem1); if (ppixd) { pixd = pixUnpackBinary(pixs, 32, 1); *ppixd = pixd; } composeRGBPixel(255, 0, 0, &rpixel); /* start point */ composeRGBPixel(0, 255, 0, &gpixel); composeRGBPixel(0, 0, 255, &bpixel); /* end point */ if (found) { L_INFO(" Path found\n", procName); pta = ptaCreate(0); x = xf; y = yf; while (1) { ptaAddPt(pta, x, y); if (x == xi && y == yi) break; if (pixd) /* write 'gpixel' onto the path */ pixSetPixel(pixd, x, y, gpixel); pixGetPixel(pixp, x, y, &val); if (val == DIR_NORTH) y--; else if (val == DIR_SOUTH) y++; else if (val == DIR_EAST) x++; else if (val == DIR_WEST) x--; } } else { L_INFO(" No path found\n", procName); if (pixd) { /* paint all visited locations */ lined32 = pixGetLinePtrs(pixd, NULL); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { val = GET_DATA_BYTE(linep8[i], j); if (val != 0 && pixd) SET_DATA_FOUR_BYTES(lined32[i], j, gpixel); } } LEPT_FREE(lined32); } } if (pixd) { pixSetPixel(pixd, xi, yi, rpixel); pixSetPixel(pixd, xf, yf, bpixel); } pixDestroy(&pixp); LEPT_FREE(lines1); LEPT_FREE(linep8); return pta; } /*! * \brief localSearchForBackground() * * \param[in] pix * \param[out] px, py starting position for search; return found position * \param[in] maxrad max distance to search from starting location * \return 0 if bg pixel found; 1 if not found */ static l_int32 localSearchForBackground(PIX *pix, l_int32 *px, l_int32 *py, l_int32 maxrad) { l_int32 x, y, w, h, r, i, j; l_uint32 val; x = *px; y = *py; pixGetPixel(pix, x, y, &val); if (val == 0) return 0; /* For each value of r, restrict the search to the boundary * pixels in a square centered on (x,y), clipping to the * image boundaries if necessary. */ pixGetDimensions(pix, &w, &h, NULL); for (r = 1; r < maxrad; r++) { for (i = -r; i <= r; i++) { if (y + i < 0 || y + i >= h) continue; for (j = -r; j <= r; j++) { if (x + j < 0 || x + j >= w) continue; if (L_ABS(i) != r && L_ABS(j) != r) /* not on "r ring" */ continue; pixGetPixel(pix, x + j, y + i, &val); if (val == 0) { *px = x + j; *py = y + i; return 0; } } } } return 1; } /*---------------------------------------------------------------------* * Gray maze search * *---------------------------------------------------------------------*/ /*! * \brief pixSearchGrayMaze() * * \param[in] pixs 1 bpp, maze * \param[in] xi, yi beginning point; use same initial point * that was used to generate the maze * \param[in] xf, yf end point, or close to it * \param[out] ppixd [optional] maze with path illustrated, or * if no path possible, the part of the maze * that was searched * \return pta shortest path, or NULL if either no path * exists or on error * * Commentary: * Consider first a slight generalization of the binary maze * search problem. Suppose that you can go through walls, * but the cost is higher say, an increment of 3 to go into * a wall pixel rather than 1? You're still trying to find * the shortest path. One way to do this is with an ordered * queue, and a simple way to visualize an ordered queue is as * a set of stacks, each stack being marked with the distance * of each pixel in the stack from the start. We place the * start pixel in stack 0, pop it, and process its 4 children. * Each pixel is given a distance that is incremented from that * of its parent 0 in this case, depending on if it is a wall * pixel or not. That value may be recorded on a distance map, * according to the algorithm below. For children of the first * pixel, those not on a wall go in stack 1, and wall * children go in stack 3. Stack 0 being emptied, the process * then continues with pixels being popped from stack 1. * Here is the algorithm for each child pixel. The pixel's * distance value, were it to be placed on a stack, is compared * with the value for it that is on the distance map. There * are three possible cases: * 1 If the pixel has not yet been registered, it is pushed * on its stack and the distance is written to the map. * 2 If it has previously been registered with a higher distance, * the distance on the map is relaxed to that of the * current pixel, which is then placed on its stack. * 3 If it has previously been registered with an equal * or lower value, the pixel is discarded. * The pixels are popped and processed successively from * stack 1, and when stack 1 is empty, popping starts on stack 2. * This continues until the destination pixel is popped off * a stack. The minimum path is then derived from the distance map, * going back from the end point as before. This is just Dijkstra's * algorithm for a directed graph; here, the underlying graph * consisting of the pixels and four edges connecting each pixel * to its 4-neighbor is a special case of a directed graph, where * each edge is bi-directional. The implementation of this generalized * maze search is left as an exercise to the reader. * * Let's generalize a bit further. Suppose the "maze" is just * a grayscale image -- think of it as an elevation map. The cost * of moving on this surface depends on the height, or the gradient, * or whatever you want. All that is required is that the cost * is specified and non-negative on each link between adjacent * pixels. Now the problem becomes: find the least cost path * moving on this surface between two specified end points. * For example, if the cost across an edge between two pixels * depends on the "gradient", you can use: * cost = 1 + L_ABSdeltaV * where deltaV is the difference in value between two adjacent * pixels. If the costs are all integers, we can still use an array * of stacks to avoid ordering the queue e.g., by using a heap sort. * This is a neat problem, because you don't even have to build a * maze -- you can can use it on any grayscale image! * * Rather than using an array of stacks, a more practical * approach is to implement with a priority queue, which is * a queue that is sorted so that the elements with the largest * or smallest key values always come off first. The * priority queue is efficiently implemented as a heap, and * this is how we do it. Suppose you run the algorithm * using a priority queue, doing the bookkeeping with an * auxiliary image data structure that saves the distance of * each pixel put on the queue as before, according to the method * described above. We implement it as a 2-way choice by * initializing the distance array to a large value and putting * a pixel on the queue if its distance is less than the value * found on the array. When you finally pop the end pixel from * the queue, you're done, and you can trace the path backward, * either always going downhill or using an auxiliary image to * give you the direction to go at each step. This is implemented * here in searchGrayMaze. * * Do we really have to use a sorted queue? Can we solve this * generalized maze with an unsorted queue of pixels? Or even * an unsorted stack, doing a depth-first search (DFS)? * Consider a different algorithm for this generalized maze, where * we travel again breadth first, but this time use a single, * unsorted queue. An auxiliary image is used as before to * store the distances and to determine if pixels get pushed * on the stack or dropped. As before, we must allow pixels * to be revisited, with relaxation of the distance if a shorter * path arrives later. As a result, we will in general have * multiple instances of the same pixel on the stack with different * distances. However, because the queue is not ordered, some of * these pixels will be popped when another instance with a lower * distance is still on the stack. Here, we're just popping them * in the order they go on, rather than setting up a priority * based on minimum distance. Thus, unlike the priority queue, * when a pixel is popped we have to check the distance map to * see if a pixel with a lower distance has been put on the queue, * and, if so, we discard the pixel we just popped. So the * "while" loop looks like this: * ~ pop a pixel from the queue * ~ check its distance against the distance stored in the * distance map; if larger, discard * ~ otherwise, for each of its neighbors: * ~ compute its distance from the start pixel * ~ compare this distance with that on the distance map: * ~ if the distance map value higher, relax the distance * and push the pixel on the queue * ~ if the distance map value is lower, discard the pixel * * How does this loop terminate? Before, with an ordered queue, * it terminates when you pop the end pixel. But with an unordered * queue or stack, the first time you hit the end pixel, the * distance is not guaranteed to be correct, because the pixels * along the shortest path may not have yet been visited and relaxed. * Because the shortest path can theoretically go anywhere, * we must keep going. How do we know when to stop? Dijkstra * uses an ordered queue to systematically remove nodes from * further consideration. Each time a pixel is popped, we're * done with it; it's "finalized" in the Dijkstra sense because * we know the shortest path to it. However, with an unordered * queue, the brute force answer is: stop when the queue * or stack is empty, because then every pixel in the image * has been assigned its minimum "distance" from the start pixel. * * This is similar to the situation when you use a stack for the * simpler uniform-step problem: with breadth-first search BFS * the pixels on the queue are automatically ordered, so you are * done when you locate the end pixel as a neighbor of a popped pixel; * whereas depth-first search DFS, using a stack, requires, * in general, a search of every accessible pixel. Further, if * a pixel is revisited with a smaller distance, that distance is * recorded and the pixel is put on the stack again. * * But surely, you ask, can't we stop sooner? What if the * start and end pixels are very close to each other? * OK, suppose they are, and you have very high walls and a * long snaking level path that is actually the minimum cost. * That long path can wind back and forth across the entire * maze many times before ending up at the end point, which * could be just over a wall from the start. With the unordered * queue, you very quickly get a high distance for the end * pixel, which will be relaxed to the minimum distance only * after all the pixels of the path have been visited and placed * on the queue, multiple times for many of them. So that's the * price for not ordering the queue! */ PTA * pixSearchGrayMaze(PIX *pixs, l_int32 xi, l_int32 yi, l_int32 xf, l_int32 yf, PIX **ppixd) { l_int32 x, y, w, h, d; l_uint32 val, valr, vals, rpixel, gpixel, bpixel; void **lines8, **liner32, **linep8; l_int32 cost, dist, distparent, sival, sivals; MAZEEL *el, *elp; PIX *pixd; /* optionally plot the path on this RGB version of pixs */ PIX *pixr; /* for bookkeeping, to indicate the minimum distance */ /* to pixels already visited */ PIX *pixp; /* for bookkeeping, to indicate direction to parent */ L_HEAP *lh; PTA *pta; PROCNAME("pixSearchGrayMaze"); if (ppixd) *ppixd = NULL; if (!pixs) return (PTA *)ERROR_PTR("pixs not defined", procName, NULL); pixGetDimensions(pixs, &w, &h, &d); if (d != 8) return (PTA *)ERROR_PTR("pixs not 8 bpp", procName, NULL); if (xi <= 0 || xi >= w) return (PTA *)ERROR_PTR("xi not valid", procName, NULL); if (yi <= 0 || yi >= h) return (PTA *)ERROR_PTR("yi not valid", procName, NULL); pixd = NULL; pta = NULL; /* Allocate stuff */ pixr = pixCreate(w, h, 32); pixSetAll(pixr); /* initialize to max value */ pixp = pixCreate(w, h, 8); /* direction to parent stored as enum val */ lines8 = pixGetLinePtrs(pixs, NULL); linep8 = pixGetLinePtrs(pixp, NULL); liner32 = pixGetLinePtrs(pixr, NULL); lh = lheapCreate(0, L_SORT_INCREASING); /* always remove closest pixels */ /* Prime the heap with the first pixel */ pixGetPixel(pixs, xi, yi, &val); el = mazeelCreate(xi, yi, 0); /* don't need direction here */ el->distance = 0; pixGetPixel(pixs, xi, yi, &val); el->val = val; pixSetPixel(pixr, xi, yi, 0); /* distance is 0 */ lheapAdd(lh, el); /* Breadth-first search with priority queue (implemented by a heap), labeling direction to parents in pixp and minimum distance to visited pixels in pixr. Stop when we pull the destination point (xf, yf) off the queue. */ while (lheapGetCount(lh) > 0) { elp = (MAZEEL *)lheapRemove(lh); if (!elp) { L_ERROR("heap broken!!\n", procName); goto cleanup_stuff; } x = elp->x; y = elp->y; if (x == xf && y == yf) { /* exit condition */ LEPT_FREE(elp); break; } distparent = (l_int32)elp->distance; val = elp->val; sival = val; if (x > 0) { /* check to west */ vals = GET_DATA_BYTE(lines8[y], x - 1); valr = GET_DATA_FOUR_BYTES(liner32[y], x - 1); sivals = (l_int32)vals; cost = 1 + L_ABS(sivals - sival); /* cost to move to this pixel */ dist = distparent + cost; if (dist < valr) { /* shortest path so far to this pixel */ SET_DATA_FOUR_BYTES(liner32[y], x - 1, dist); /* new dist */ SET_DATA_BYTE(linep8[y], x - 1, DIR_EAST); /* parent to E */ el = mazeelCreate(x - 1, y, 0); el->val = vals; el->distance = dist; lheapAdd(lh, el); } } if (y > 0) { /* check north */ vals = GET_DATA_BYTE(lines8[y - 1], x); valr = GET_DATA_FOUR_BYTES(liner32[y - 1], x); sivals = (l_int32)vals; cost = 1 + L_ABS(sivals - sival); /* cost to move to this pixel */ dist = distparent + cost; if (dist < valr) { /* shortest path so far to this pixel */ SET_DATA_FOUR_BYTES(liner32[y - 1], x, dist); /* new dist */ SET_DATA_BYTE(linep8[y - 1], x, DIR_SOUTH); /* parent to S */ el = mazeelCreate(x, y - 1, 0); el->val = vals; el->distance = dist; lheapAdd(lh, el); } } if (x < w - 1) { /* check east */ vals = GET_DATA_BYTE(lines8[y], x + 1); valr = GET_DATA_FOUR_BYTES(liner32[y], x + 1); sivals = (l_int32)vals; cost = 1 + L_ABS(sivals - sival); /* cost to move to this pixel */ dist = distparent + cost; if (dist < valr) { /* shortest path so far to this pixel */ SET_DATA_FOUR_BYTES(liner32[y], x + 1, dist); /* new dist */ SET_DATA_BYTE(linep8[y], x + 1, DIR_WEST); /* parent to W */ el = mazeelCreate(x + 1, y, 0); el->val = vals; el->distance = dist; lheapAdd(lh, el); } } if (y < h - 1) { /* check south */ vals = GET_DATA_BYTE(lines8[y + 1], x); valr = GET_DATA_FOUR_BYTES(liner32[y + 1], x); sivals = (l_int32)vals; cost = 1 + L_ABS(sivals - sival); /* cost to move to this pixel */ dist = distparent + cost; if (dist < valr) { /* shortest path so far to this pixel */ SET_DATA_FOUR_BYTES(liner32[y + 1], x, dist); /* new dist */ SET_DATA_BYTE(linep8[y + 1], x, DIR_NORTH); /* parent to N */ el = mazeelCreate(x, y + 1, 0); el->val = vals; el->distance = dist; lheapAdd(lh, el); } } LEPT_FREE(elp); } lheapDestroy(&lh, TRUE); if (ppixd) { pixd = pixConvert8To32(pixs); *ppixd = pixd; } composeRGBPixel(255, 0, 0, &rpixel); /* start point */ composeRGBPixel(0, 255, 0, &gpixel); composeRGBPixel(0, 0, 255, &bpixel); /* end point */ x = xf; y = yf; pta = ptaCreate(0); while (1) { /* write path onto pixd */ ptaAddPt(pta, x, y); if (x == xi && y == yi) break; if (pixd) pixSetPixel(pixd, x, y, gpixel); pixGetPixel(pixp, x, y, &val); if (val == DIR_NORTH) y--; else if (val == DIR_SOUTH) y++; else if (val == DIR_EAST) x++; else if (val == DIR_WEST) x--; pixGetPixel(pixr, x, y, &val); #if DEBUG_PATH fprintf(stderr, "(x,y) = (%d, %d); dist = %d\n", x, y, val); #endif /* DEBUG_PATH */ } if (pixd) { pixSetPixel(pixd, xi, yi, rpixel); pixSetPixel(pixd, xf, yf, bpixel); } cleanup_stuff: lheapDestroy(&lh, TRUE); pixDestroy(&pixp); pixDestroy(&pixr); LEPT_FREE(lines8); LEPT_FREE(linep8); LEPT_FREE(liner32); return pta; }
6e29320fcce5519b748d751e39ac756a383b2073
336d3942e52ba91604d479e590a1e35d6d7c14a4
/deps/jemalloc/test/integration/rallocx.c
68b8f3816540fe77f89a4d071841e39b19e2a5c6
[ "BSD-3-Clause", "BSD-2-Clause" ]
permissive
redis/redis
8fb932a09677ed8854c94d81c941655eceda2138
e792653753dc62b5a00822121e585511542a024b
refs/heads/unstable
2023-08-29T14:53:21.757052
2023-08-27T08:42:55
2023-08-27T08:42:55
156,018
19,822
6,754
BSD-3-Clause
2023-09-14T18:06:48
2009-03-21T22:32:25
C
UTF-8
C
false
false
7,912
c
rallocx.c
#include "test/jemalloc_test.h" static unsigned get_nsizes_impl(const char *cmd) { unsigned ret; size_t z; z = sizeof(unsigned); expect_d_eq(mallctl(cmd, (void *)&ret, &z, NULL, 0), 0, "Unexpected mallctl(\"%s\", ...) failure", cmd); return ret; } static unsigned get_nlarge(void) { return get_nsizes_impl("arenas.nlextents"); } static size_t get_size_impl(const char *cmd, size_t ind) { size_t ret; size_t z; size_t mib[4]; size_t miblen = 4; z = sizeof(size_t); expect_d_eq(mallctlnametomib(cmd, mib, &miblen), 0, "Unexpected mallctlnametomib(\"%s\", ...) failure", cmd); mib[2] = ind; z = sizeof(size_t); expect_d_eq(mallctlbymib(mib, miblen, (void *)&ret, &z, NULL, 0), 0, "Unexpected mallctlbymib([\"%s\", %zu], ...) failure", cmd, ind); return ret; } static size_t get_large_size(size_t ind) { return get_size_impl("arenas.lextent.0.size", ind); } TEST_BEGIN(test_grow_and_shrink) { /* * Use volatile to workaround buffer overflow false positives * (-D_FORTIFY_SOURCE=3). */ void *volatile p, *volatile q; size_t tsz; #define NCYCLES 3 unsigned i, j; #define NSZS 1024 size_t szs[NSZS]; #define MAXSZ ZU(12 * 1024 * 1024) p = mallocx(1, 0); expect_ptr_not_null(p, "Unexpected mallocx() error"); szs[0] = sallocx(p, 0); for (i = 0; i < NCYCLES; i++) { for (j = 1; j < NSZS && szs[j-1] < MAXSZ; j++) { q = rallocx(p, szs[j-1]+1, 0); expect_ptr_not_null(q, "Unexpected rallocx() error for size=%zu-->%zu", szs[j-1], szs[j-1]+1); szs[j] = sallocx(q, 0); expect_zu_ne(szs[j], szs[j-1]+1, "Expected size to be at least: %zu", szs[j-1]+1); p = q; } for (j--; j > 0; j--) { q = rallocx(p, szs[j-1], 0); expect_ptr_not_null(q, "Unexpected rallocx() error for size=%zu-->%zu", szs[j], szs[j-1]); tsz = sallocx(q, 0); expect_zu_eq(tsz, szs[j-1], "Expected size=%zu, got size=%zu", szs[j-1], tsz); p = q; } } dallocx(p, 0); #undef MAXSZ #undef NSZS #undef NCYCLES } TEST_END static bool validate_fill(void *p, uint8_t c, size_t offset, size_t len) { bool ret = false; /* * Use volatile to workaround buffer overflow false positives * (-D_FORTIFY_SOURCE=3). */ uint8_t *volatile buf = (uint8_t *)p; size_t i; for (i = 0; i < len; i++) { uint8_t b = buf[offset+i]; if (b != c) { test_fail("Allocation at %p (len=%zu) contains %#x " "rather than %#x at offset %zu", p, len, b, c, offset+i); ret = true; } } return ret; } TEST_BEGIN(test_zero) { /* * Use volatile to workaround buffer overflow false positives * (-D_FORTIFY_SOURCE=3). */ void *volatile p, *volatile q; size_t psz, qsz, i, j; size_t start_sizes[] = {1, 3*1024, 63*1024, 4095*1024}; #define FILL_BYTE 0xaaU #define RANGE 2048 for (i = 0; i < sizeof(start_sizes)/sizeof(size_t); i++) { size_t start_size = start_sizes[i]; p = mallocx(start_size, MALLOCX_ZERO); expect_ptr_not_null(p, "Unexpected mallocx() error"); psz = sallocx(p, 0); expect_false(validate_fill(p, 0, 0, psz), "Expected zeroed memory"); memset(p, FILL_BYTE, psz); expect_false(validate_fill(p, FILL_BYTE, 0, psz), "Expected filled memory"); for (j = 1; j < RANGE; j++) { q = rallocx(p, start_size+j, MALLOCX_ZERO); expect_ptr_not_null(q, "Unexpected rallocx() error"); qsz = sallocx(q, 0); if (q != p || qsz != psz) { expect_false(validate_fill(q, FILL_BYTE, 0, psz), "Expected filled memory"); expect_false(validate_fill(q, 0, psz, qsz-psz), "Expected zeroed memory"); } if (psz != qsz) { memset((void *)((uintptr_t)q+psz), FILL_BYTE, qsz-psz); psz = qsz; } p = q; } expect_false(validate_fill(p, FILL_BYTE, 0, psz), "Expected filled memory"); dallocx(p, 0); } #undef FILL_BYTE } TEST_END TEST_BEGIN(test_align) { void *p, *q; size_t align; #define MAX_ALIGN (ZU(1) << 25) align = ZU(1); p = mallocx(1, MALLOCX_ALIGN(align)); expect_ptr_not_null(p, "Unexpected mallocx() error"); for (align <<= 1; align <= MAX_ALIGN; align <<= 1) { q = rallocx(p, 1, MALLOCX_ALIGN(align)); expect_ptr_not_null(q, "Unexpected rallocx() error for align=%zu", align); expect_ptr_null( (void *)((uintptr_t)q & (align-1)), "%p inadequately aligned for align=%zu", q, align); p = q; } dallocx(p, 0); #undef MAX_ALIGN } TEST_END TEST_BEGIN(test_align_enum) { /* Span both small sizes and large sizes. */ #define LG_MIN 12 #define LG_MAX 15 for (size_t lg_align = LG_MIN; lg_align <= LG_MAX; ++lg_align) { for (size_t lg_size = LG_MIN; lg_size <= LG_MAX; ++lg_size) { size_t size = 1 << lg_size; for (size_t lg_align_next = LG_MIN; lg_align_next <= LG_MAX; ++lg_align_next) { int flags = MALLOCX_LG_ALIGN(lg_align); void *p = mallocx(1, flags); assert_ptr_not_null(p, "Unexpected mallocx() error"); assert_zu_eq(nallocx(1, flags), TEST_MALLOC_SIZE(p), "Wrong mallocx() usable size"); int flags_next = MALLOCX_LG_ALIGN(lg_align_next); p = rallocx(p, size, flags_next); assert_ptr_not_null(p, "Unexpected rallocx() error"); expect_zu_eq(nallocx(size, flags_next), TEST_MALLOC_SIZE(p), "Wrong rallocx() usable size"); free(p); } } } #undef LG_MAX #undef LG_MIN } TEST_END TEST_BEGIN(test_lg_align_and_zero) { /* * Use volatile to workaround buffer overflow false positives * (-D_FORTIFY_SOURCE=3). */ void *volatile p, *volatile q; unsigned lg_align; size_t sz; #define MAX_LG_ALIGN 25 #define MAX_VALIDATE (ZU(1) << 22) lg_align = 0; p = mallocx(1, MALLOCX_LG_ALIGN(lg_align)|MALLOCX_ZERO); expect_ptr_not_null(p, "Unexpected mallocx() error"); for (lg_align++; lg_align <= MAX_LG_ALIGN; lg_align++) { q = rallocx(p, 1, MALLOCX_LG_ALIGN(lg_align)|MALLOCX_ZERO); expect_ptr_not_null(q, "Unexpected rallocx() error for lg_align=%u", lg_align); expect_ptr_null( (void *)((uintptr_t)q & ((ZU(1) << lg_align)-1)), "%p inadequately aligned for lg_align=%u", q, lg_align); sz = sallocx(q, 0); if ((sz << 1) <= MAX_VALIDATE) { expect_false(validate_fill(q, 0, 0, sz), "Expected zeroed memory"); } else { expect_false(validate_fill(q, 0, 0, MAX_VALIDATE), "Expected zeroed memory"); expect_false(validate_fill( (void *)((uintptr_t)q+sz-MAX_VALIDATE), 0, 0, MAX_VALIDATE), "Expected zeroed memory"); } p = q; } dallocx(p, 0); #undef MAX_VALIDATE #undef MAX_LG_ALIGN } TEST_END /* * GCC "-Walloc-size-larger-than" warning detects when one of the memory * allocation functions is called with a size larger than the maximum size that * they support. Here we want to explicitly test that the allocation functions * do indeed fail properly when this is the case, which triggers the warning. * Therefore we disable the warning for these tests. */ JEMALLOC_DIAGNOSTIC_PUSH JEMALLOC_DIAGNOSTIC_IGNORE_ALLOC_SIZE_LARGER_THAN TEST_BEGIN(test_overflow) { size_t largemax; void *p; largemax = get_large_size(get_nlarge()-1); p = mallocx(1, 0); expect_ptr_not_null(p, "Unexpected mallocx() failure"); expect_ptr_null(rallocx(p, largemax+1, 0), "Expected OOM for rallocx(p, size=%#zx, 0)", largemax+1); expect_ptr_null(rallocx(p, ZU(PTRDIFF_MAX)+1, 0), "Expected OOM for rallocx(p, size=%#zx, 0)", ZU(PTRDIFF_MAX)+1); expect_ptr_null(rallocx(p, SIZE_T_MAX, 0), "Expected OOM for rallocx(p, size=%#zx, 0)", SIZE_T_MAX); expect_ptr_null(rallocx(p, 1, MALLOCX_ALIGN(ZU(PTRDIFF_MAX)+1)), "Expected OOM for rallocx(p, size=1, MALLOCX_ALIGN(%#zx))", ZU(PTRDIFF_MAX)+1); dallocx(p, 0); } TEST_END /* Re-enable the "-Walloc-size-larger-than=" warning */ JEMALLOC_DIAGNOSTIC_POP int main(void) { return test( test_grow_and_shrink, test_zero, test_align, test_align_enum, test_lg_align_and_zero, test_overflow); }
01f579b11cf24238351748afd8a1ed5835f4a521
bdb4bbd6d96f34cd14a7a42a578a2b8c777bf68c
/yolov7/include/macros.h
b187c943bde76b97be7822950325e10327ae087a
[ "MIT" ]
permissive
wang-xinyu/tensorrtx
199aa1a27ae16e1523cd6636fdc38a32380d0753
3cbb7cd25796509cb49cc2251020d589d98228c9
refs/heads/master
2023-09-05T07:34:56.640496
2023-07-21T06:30:11
2023-07-21T06:30:11
223,904,726
6,067
1,715
MIT
2023-07-21T06:30:13
2019-11-25T09:01:36
C++
UTF-8
C
false
false
484
h
macros.h
#ifndef __MACROS_H #define __MACROS_H #include "NvInfer.h" #ifdef API_EXPORTS #if defined(_MSC_VER) #define API __declspec(dllexport) #else #define API __attribute__((visibility("default"))) #endif #else #if defined(_MSC_VER) #define API __declspec(dllimport) #else #define API #endif #endif // API_EXPORTS #if NV_TENSORRT_MAJOR >= 8 #define TRT_NOEXCEPT noexcept #define TRT_CONST_ENQUEUE const #else #define TRT_NOEXCEPT #define TRT_CONST_ENQUEUE #endif #endif // __MACROS_H
9572259a9e1aecc1e0b7ae50d9a7e98bddf22c91
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
/sys/arch/dreamcast/dreamcast/sysasic.c
fcdb36061f18b8c0583e763e9106050aac9c0493
[]
no_license
NetBSD/src
1a9cbc22ed778be638b37869ed4fb5c8dd616166
23ee83f7c0aea0777bd89d8ebd7f0cde9880d13c
refs/heads/trunk
2023-08-31T13:24:58.105962
2023-08-27T15:50:47
2023-08-27T15:50:47
88,439,547
656
348
null
2023-07-20T20:07:24
2017-04-16T20:03:43
null
UTF-8
C
false
false
8,116
c
sysasic.c
/* $NetBSD: sysasic.c,v 1.14 2008/04/28 20:23:16 martin Exp $ */ /*- * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include <sys/cdefs.h> __KERNEL_RCSID(0, "$NetBSD: sysasic.c,v 1.14 2008/04/28 20:23:16 martin Exp $"); #include <sys/param.h> #include <sys/systm.h> #include <sys/device.h> #include <sys/syslog.h> #include <sh3/exception.h> #include <machine/intr.h> #include <machine/sysasicvar.h> #define SYSASIC_INTR_ST 0xa05f6900 #define SYSASIC_INTR_EN(level) (0xa05f6910 + ((level) << 4)) #define SYSASIC_IRQ_LEVEL_13 0 #define SYSASIC_IRQ_LEVEL_11 1 #define SYSASIC_IRQ_LEVEL_9 2 #define SYSASIC_IRQ_LEVEL_MAX 2 #define SYSASIC_IRQ_INDEX_TO_IRQ(i) (13 - 2 * (i)) /* per-irq */ struct sysasic_intrhand { /* for quick check on interrupt */ #define SYSASIC_EVENT_NMAP ((SYSASIC_EVENT_MAX + 1 + (32 - 1)) / 32) #define SYSASIC_EVENT_INTR_MAP(ev) ((ev) >> 5) #define SYSASIC_EVENT_INTR_BIT(ev) ((unsigned) 1 << ((ev) & 31)) unsigned syh_events[SYSASIC_EVENT_NMAP]; /* enabled */ unsigned syh_hndmap[SYSASIC_EVENT_NMAP]; /* handler installed */ void *syh_intc; int syh_idx; } sysasic_intrhand[SYSASIC_IRQ_LEVEL_MAX + 1]; /* per-event */ struct syh_eventhand { int (*hnd_fn)(void *); /* sub handler */ void *hnd_arg; struct sysasic_intrhand *hnd_syh; } sysasic_eventhand[SYSASIC_EVENT_MAX + 1]; int sysasic_intr(void *); const char * __pure sysasic_intr_string(int irl) { switch (irl) { default: #ifdef DEBUG panic("sysasic_intr_string: unknown IRL%d", irl); #endif case SYSASIC_IRL9: return "SH4 IRL 9"; case SYSASIC_IRL11: return "SH4 IRL 11"; case SYSASIC_IRL13: return "SH4 IRL 13"; } /* NOTREACHED */ } /* * Set up an interrupt handler to start being called. */ void * sysasic_intr_establish(int event, int ipl, int irl, int (*ih_fun)(void *), void *ih_arg) { struct sysasic_intrhand *syh; struct syh_eventhand *hnd; int idx; static const int idx2evt[3] = { SH_INTEVT_IRL13, SH_INTEVT_IRL11, SH_INTEVT_IRL9 }; #ifdef DEBUG int i; #endif KDASSERT(event >= 0 && event <= SYSASIC_EVENT_MAX); KDASSERT(ih_fun); /* * Dreamcast use SH4 INTC as IRL mode. If IRQ is specified, * its priority level is fixed. * * We use IPL to specify the IRQ for clearness, that is, we use * a splxxx() and IPL_XXX pair in a device driver. */ switch (irl) { default: #ifdef DEBUG panic("sysasic_intr_establish: unknown IRL %d", irl); #endif case SYSASIC_IRL9: idx = SYSASIC_IRQ_LEVEL_9; break; case SYSASIC_IRL11: idx = SYSASIC_IRQ_LEVEL_11; break; case SYSASIC_IRL13: idx = SYSASIC_IRQ_LEVEL_13; break; } syh = &sysasic_intrhand[idx]; if (syh->syh_intc == NULL) { syh->syh_idx = idx; syh->syh_intc = intc_intr_establish(idx2evt[idx], IST_LEVEL, irl, sysasic_intr, syh); } #ifdef DEBUG /* check if the event handler is already installed */ for (i = 0; i <= SYSASIC_IRQ_LEVEL_MAX; i++) if ((sysasic_intrhand[i].syh_hndmap[SYSASIC_EVENT_INTR_MAP(event)] & SYSASIC_EVENT_INTR_BIT(event)) != 0) panic("sysasic_intr_establish: event %d already installed irq %d", event, SYSASIC_IRQ_INDEX_TO_IRQ(i)); #endif /* mark this event is established */ syh->syh_hndmap[SYSASIC_EVENT_INTR_MAP(event)] |= SYSASIC_EVENT_INTR_BIT(event); hnd = &sysasic_eventhand[event]; hnd->hnd_fn = ih_fun; hnd->hnd_arg = ih_arg; hnd->hnd_syh = syh; sysasic_intr_enable(hnd, 1); return (void *)hnd; } /* * Deregister an interrupt handler. */ void sysasic_intr_disestablish(void *arg) { struct syh_eventhand *hnd = arg; struct sysasic_intrhand *syh; int event; int i; event = hnd - sysasic_eventhand; KDASSERT(event >= 0 && event <= SYSASIC_EVENT_MAX); syh = hnd->hnd_syh; #ifdef DIAGNOSTIC if ((syh->syh_hndmap[SYSASIC_EVENT_INTR_MAP(event)] & SYSASIC_EVENT_INTR_BIT(event)) == 0) panic("sysasic_intr_disestablish: event %d not installed for irq %d", event, SYSASIC_IRQ_INDEX_TO_IRQ(syh->syh_idx)); #endif sysasic_intr_enable(hnd, 0); hnd->hnd_fn = 0; hnd->hnd_arg = 0; hnd->hnd_syh = 0; syh->syh_hndmap[SYSASIC_EVENT_INTR_MAP(event)] &= ~SYSASIC_EVENT_INTR_BIT(event); /* deinstall intrc if no event exists */ for (i = 0; i < SYSASIC_EVENT_NMAP; i++) if (syh->syh_hndmap[i]) return; intc_intr_disestablish(syh->syh_intc); syh->syh_intc = 0; } void sysasic_intr_enable(void *arg, int on) { struct syh_eventhand *hnd = arg; struct sysasic_intrhand *syh; int event; volatile uint32_t *masks, *stats; int evmap; unsigned evbit; event = hnd - sysasic_eventhand; KDASSERT(event >= 0 && event <= SYSASIC_EVENT_MAX); syh = hnd->hnd_syh; #ifdef DIAGNOSTIC if ((syh->syh_hndmap[SYSASIC_EVENT_INTR_MAP(event)] & SYSASIC_EVENT_INTR_BIT(event)) == 0) panic("sysasic_intr_enable: event %d not installed for irq %d", event, SYSASIC_IRQ_INDEX_TO_IRQ(syh->syh_idx)); #endif masks = (volatile uint32_t *) SYSASIC_INTR_EN(syh->syh_idx); stats = (volatile uint32_t *) SYSASIC_INTR_ST; evmap = SYSASIC_EVENT_INTR_MAP(event); evbit = SYSASIC_EVENT_INTR_BIT(event); if (on) { /* clear pending event if any */ stats[evmap] = evbit; /* set event map */ syh->syh_events[evmap] |= evbit; /* enable interrupt */ masks[evmap] = syh->syh_events[evmap]; } else { /* disable interrupt */ masks[evmap] = syh->syh_events[evmap] & ~evbit; /* clear pending event if any */ stats[evmap] = evbit; /* clear event map */ syh->syh_events[evmap] &= ~evbit; } } int sysasic_intr(void *arg) { struct sysasic_intrhand *syh = arg; unsigned ev; int n, pos; uint32_t *evwatched; volatile uint32_t *evmap; struct syh_eventhand *evh; #ifdef DEBUG int handled = 0; static int reportcnt = 10; #endif /* bitmap of watched events */ evwatched = syh->syh_events; /* status / clear */ evmap = (volatile uint32_t *) SYSASIC_INTR_ST; for (n = 0; n < (SYSASIC_EVENT_NMAP << 5); n |= 31, n++, evmap++) { if ((ev = *evwatched++) && (ev &= *evmap)) { /* clear interrupts */ *evmap = ev; n--; /* to point at current bit after n += pos */ /* call handlers */ do { pos = ffs(ev); n += pos; #ifdef __OPTIMIZE__ /* optimized, assuming 1 <= pos <= 32 */ __asm("shld %2,%0" : "=r" (ev) : "0" (ev), "r" (-pos)); #else /* ``shift count >= bit width'' is undefined */ if (pos >= 32) ev = 0; else ev >>= pos; #endif evh = &sysasic_eventhand[n]; #ifdef DEBUG KDASSERT(evh->hnd_fn); if ((*evh->hnd_fn)(evh->hnd_arg)) handled = 1; #else (*evh->hnd_fn)(evh->hnd_arg); #endif } while (ev); } } #ifdef DEBUG if (!handled && reportcnt > 0) { reportcnt--; log(LOG_ERR, "sysasic_intr: stray irq%d interrupt%s\n", SYSASIC_IRQ_INDEX_TO_IRQ(syh->syh_idx), reportcnt == 0 ? "; stopped logging" : ""); } #endif return 0; }
7ed70a991d44b2376566ba45db75288f62d2e5b2
f84321cbc44eadc437dddeb4e3529ddcc1c5bcae
/atomics/ping-pong/c11-ping-pong.c
0069e576776e75b7ff36ab5e042801e406f1fdef
[ "MIT" ]
permissive
jeffhammond/HPCInfo
7d08fda4ab3a6301f6c7853bd72c7fbe06639f9f
8aff33b946cbd978b951f22c1b5a9140587be95e
refs/heads/master
2023-08-17T01:45:51.607023
2023-08-11T05:28:50
2023-08-11T05:28:50
12,674,497
261
60
MIT
2023-04-19T14:47:20
2013-09-08T01:45:33
C
UTF-8
C
false
false
3,180
c
c11-ping-pong.c
#if !defined(__llvm__) && !defined(__clang__) && !defined(__INTEL_COMPILER) && \ defined(__GNUC__) && (__GNUC__ <= 6) #error GCC will not compile this code because of "https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65467" #else /* Intel compiler does not support _Atomic hence defines __STDC_NO_ATOMICS__, * but it supports the atomic_<integer> API. */ #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) && \ (!defined(__STDC_NO_ATOMICS__) || (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1600))) #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <stdatomic.h> #ifdef _OPENMP # include <omp.h> #else # error No OpenMP support! #endif #ifdef SEQUENTIAL_CONSISTENCY int load_model = memory_order_seq_cst; int store_model = memory_order_seq_cst; #else int load_model = memory_order_acquire; int store_model = memory_order_release; #endif int main(int argc, char * argv[]) { int nt = omp_get_max_threads(); #if 1 if (nt != 2) omp_set_num_threads(2); #else if (nt < 2) omp_set_num_threads(2); if (nt % 2 != 0) omp_set_num_threads(nt-1); #endif int iterations = (argc>1) ? atoi(argv[1]) : 1000000; printf("thread ping-pong benchmark\n"); printf("num threads = %d\n", omp_get_max_threads()); printf("iterations = %d\n", iterations); #ifdef SEQUENTIAL_CONSISTENCY printf("memory model = %s\n", "seq_cst"); #else printf("memory model = %s\n", "acq-rel"); #endif fflush(stdout); atomic_int left_ready = ATOMIC_VAR_INIT(-1); atomic_int right_ready = ATOMIC_VAR_INIT(-1); int left_payload = 0; int right_payload = 0; #pragma omp parallel { int me = omp_get_thread_num(); /// 0=left 1=right bool parity = (me % 2 == 0); int junk = 0; /// START TIME #pragma omp barrier double t0 = omp_get_wtime(); for (int i=0; i<iterations; ++i) { if (parity) { /// send to left left_payload = i; atomic_store_explicit( &left_ready, i, store_model); /// recv from right while (i != atomic_load_explicit( &right_ready, load_model)); //printf("%d: left received %d\n", i, right_payload); junk += right_payload; } else { /// recv from left while (i != atomic_load_explicit( &left_ready, load_model)); //printf("%d: right received %d\n", i, left_payload); junk += left_payload; ///send to right right_payload = i; atomic_store_explicit( &right_ready, i, store_model); } } /// STOP TIME #pragma omp barrier double t1 = omp_get_wtime(); /// PRINT TIME double dt = t1-t0; #pragma omp critical { printf("total time elapsed = %lf\n", dt); printf("time per iteration = %e\n", dt/iterations); printf("%d\n", junk); } } return 0; } #else // C11 #error You need C11 atomics for this test! #endif // C11 #endif // GCC <= 6
fbf10cf10b6184a062164e413a1bad66b97668f6
99bdb3251fecee538e0630f15f6574054dfc1468
/bsp/gd32vf103v-eval/libraries/n22/drivers/n22_tmr.h
2645f73304177b4d5810752b3b6008e0e636f5b2
[ "Zlib", "LicenseRef-scancode-proprietary-license", "MIT", "BSD-3-Clause", "X11", "BSD-4-Clause-UC", "LicenseRef-scancode-unknown-license-reference", "Apache-2.0" ]
permissive
RT-Thread/rt-thread
03a7c52c2aeb1b06a544143b0e803d72f47d1ece
3602f891211904a27dcbd51e5ba72fefce7326b2
refs/heads/master
2023-09-01T04:10:20.295801
2023-08-31T16:20:55
2023-08-31T16:20:55
7,408,108
9,599
5,805
Apache-2.0
2023-09-14T13:37:26
2013-01-02T14:49:21
C
UTF-8
C
false
false
418
h
n22_tmr.h
// See LICENSE file for licence details #ifndef N22_TMR_H #define N22_TMR_H #define TMR_MSIP 0xFFC #define TMR_MSIP_size 0x4 #define TMR_MTIMECMP 0x8 #define TMR_MTIMECMP_size 0x8 #define TMR_MTIME 0x0 #define TMR_MTIME_size 0x8 #define TMR_CTRL_ADDR 0xd1000000 #define TMR_REG(offset) _REG32(TMR_CTRL_ADDR, offset) #define TMR_FREQ ((uint32_t)SystemCoreClock/4) //units HZ #endif
f7748207f840d12e27bffb01596b137bd145e6c3
9de0cec678bc4a3bec2b4adabef9f39ff5b4afac
/PWGHF/hfe/WZe_POWHEG_ForHFEContamination/OfflineAnalysis/Plot_We.C
687c34b735988de572c0863f89292a881ce614da
[]
permissive
alisw/AliPhysics
91bf1bd01ab2af656a25ff10b25e618a63667d3e
5df28b2b415e78e81273b0d9bf5c1b99feda3348
refs/heads/master
2023-08-31T20:41:44.927176
2023-08-31T14:51:12
2023-08-31T14:51:12
61,661,378
129
1,150
BSD-3-Clause
2023-09-14T18:48:45
2016-06-21T19:31:29
C++
UTF-8
C
false
false
790
c
Plot_We.C
void Plot_We() { TCanvas *c1 = new TCanvas(); gPad->SetLogy(); // Ze //TFile *file0 = TFile::Open("We_pp_all.root"); TFile *file0 = TFile::Open("We_pp.root"); // TH1F *ze=(TH1F*) file0->Get("ze"); Double_t norm = 2.0*acos(-1.0)*1.2*15337.0/1.17e-05; ze->Scale(1.0/19.0); //scale # of files ze->Scale(1.0/norm); /* Double_t xbins[14] = {1.5,2,3,4,5,6,8,10,12,14,16,20,26,35}; ze->Rebin(13,"ze_rebin",xbins); ze_rebin->Scale(1,"width"); ze_rebin->Draw(); */ TH1D *we = ze->Clone("we"); ze->Draw(); /* TFile *fout = new TFile("Wp_e.root","recreate"); //ze_rebin->Write("Wpe"); we->Write("Wpe"); */ TFile *fout = new TFile("Wm_e.root","recreate"); //ze_rebin->Write("Wpe"); we->Write("Wme"); }
7d637ac8e966caf7a6a74e3a098369cadc9fbe10
fdbb74a95924e2677466614f6ab6e2bb13b2a95a
/libc/isystem/tgmath.h
d5f6aa9c01cbaff433c8d1e893c2246e15d6e3a8
[ "ISC" ]
permissive
jart/cosmopolitan
fb11b5658939023977060a7c6c71a74093d9cb44
0d748ad58e1063dd1f8560f18a0c75293b9415b7
refs/heads/master
2023-09-06T09:17:29.303607
2023-09-02T03:49:13
2023-09-02T03:50:18
272,457,606
11,887
435
ISC
2023-09-14T17:47:58
2020-06-15T14:16:13
C
UTF-8
C
false
false
10,919
h
tgmath.h
#ifndef _TGMATH_H #define _TGMATH_H #include "libc/complex.h" #include "libc/imag.internal.h" #include "libc/math.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) #if __STDC_VERSION__ + 0 >= 201112 /* from https://en.cppreference.com/w/c/numeric/tgmath */ #define fabs(x) \ _Generic((x), float \ : fabsf, default \ : fabs, long double \ : fabsl, complex float \ : cabsf, complex double \ : cabs, complex long double \ : cabsl)(x) #define exp(x) \ _Generic((x), float \ : expf, default \ : exp, long double \ : expl, complex float \ : cexpf, complex double \ : cexp, complex long double \ : cexpl)(x) #define log(x) \ _Generic((x), float \ : logf, default \ : log, long double \ : logl, complex float \ : clogf, complex double \ : clog, complex long double \ : clogl)(x) #define pow(x, y) \ _Generic((x), float \ : powf, default \ : pow, long double \ : powl, complex float \ : cpowf, complex double \ : cpow, complex long double \ : cpowl)(x, y) #define sqrt(x) \ _Generic((x), float \ : sqrtf, default \ : sqrt, long double \ : sqrtl, complex float \ : csqrtf, complex double \ : csqrt, complex long double \ : csqrtl)(x) #define sin(x) \ _Generic((x), float \ : sinf, default \ : sin, long double \ : sinl, complex float \ : csinf, complex double \ : csin, complex long double \ : csinl)(x) #define cos(x) \ _Generic((x), float \ : cosf, default \ : cos, long double \ : cosl, complex float \ : ccosf, complex double \ : ccos, complex long double \ : ccosl)(x) #define tan(x) \ _Generic((x), float \ : tanf, default \ : tan, long double \ : tanl, complex float \ : ctanf, complex double \ : ctan, complex long double \ : ctanl)(x) #define asin(x) \ _Generic((x), float \ : asinf, default \ : asin, long double \ : asinl, complex float \ : casinf, complex double \ : casin, complex long double \ : casinl)(x) #define acos(x) \ _Generic((x), float \ : acosf, default \ : acos, long double \ : acosl, complex float \ : cacosf, complex double \ : cacos, complex long double \ : cacosl)(x) #define atan(x) \ _Generic((x), float \ : atanf, default \ : atan, long double \ : atanl, complex float \ : catanf, complex double \ : catan, complex long double \ : catanl)(x) #define sinh(x) \ _Generic((x), float \ : sinhf, default \ : sinh, long double \ : sinhl, complex float \ : csinhf, complex double \ : csinh, complex long double \ : csinhl)(x) #define cosh(x) \ _Generic((x), float \ : coshf, default \ : cosh, long double \ : coshl, complex float \ : ccoshf, complex double \ : ccosh, complex long double \ : ccoshl)(x) #define tanh(x) \ _Generic((x), float \ : tanhf, default \ : tanh, long double \ : tanhl, complex float \ : ctanhf, complex double \ : ctanh, complex long double \ : ctanhl)(x) #define asinh(x) \ _Generic((x), float \ : asinhf, default \ : asinh, long double \ : asinhl, complex float \ : casinhf, complex double \ : casinh, complex long double \ : casinhl)(x) #define acosh(x) \ _Generic((x), float \ : acoshf, default \ : acosh, long double \ : acoshl, complex float \ : cacoshf, complex double \ : cacosh, complex long double \ : cacoshl)(x) #define atanh(x) \ _Generic((x), float \ : atanhf, default \ : atanh, long double \ : atanhl, complex float \ : catanhf, complex double \ : catanh, complex long double \ : catanhl)(x) #define atan2(x, y) \ _Generic((x), float : atan2f, default : atan2, long double : atan2l)(x, y) #define cbrt(x) \ _Generic((x), float : cbrtf, default : cbrt, long double : cbrtl)(x) #define ceil(x) \ _Generic((x), float : ceilf, default : ceil, long double : ceill)(x) #define copysign(x, y) \ _Generic((x), float \ : copysignf, default \ : copysign, long double \ : copysignl)(x, y) #define erf(x) _Generic((x), float : erff, default : erf, long double : erfl)(x) #define erfc(x) \ _Generic((x), float : erfcf, default : erfc, long double : erfcl)(x) #define exp2(x) \ _Generic((x), float : exp2f, default : exp2, long double : exp2l)(x) #define expm1(x) \ _Generic((x), float : expm1f, default : expm1, long double : expm1l)(x) #define fdim(x, y) \ _Generic((x), float : fdimf, default : fdim, long double : fdiml)(x, y) #define floor(x) \ _Generic((x), float : floorf, default : floor, long double : floorl)(x) #define fma(x, y, z) \ _Generic((x), float : fmaf, default : fma, long double : fmal)(x, y, z) #define fmax(x, y) \ _Generic((x), float : fmaxf, default : fmax, long double : fmaxl)(x, y) #define fmin(x, y) \ _Generic((x), float : fminf, default : fmin, long double : fminl)(x, y) #define fmod(x, y) \ _Generic((x), float : fmodf, default : fmod, long double : fmodl)(x, y) #define frexp(x, y) \ _Generic((x), float : frexpf, default : frexp, long double : frexpl)(x, y) #define hypot(x, y) \ _Generic((x), float : hypotf, default : hypot, long double : hypotl)(x, y) #define ilogb(x) \ _Generic((x), float : ilogbf, default : ilogb, long double : ilogbl)(x) #define ldexp(x, y) \ _Generic((x), float : ldexpf, default : ldexp, long double : ldexpl)(x, y) #define lgamma(x) \ _Generic((x), float : lgammaf, default : lgamma, long double : lgammal)(x) #define llrint(x) \ _Generic((x), float : llrintf, default : llrint, long double : llrintl)(x) #define llround(x) \ _Generic((x), float : llroundf, default : llround, long double : llroundl)(x) #define log10(x) \ _Generic((x), float : log10f, default : log10, long double : log10l)(x) #define log1p(x) \ _Generic((x), float : log1pf, default : log1p, long double : log1pl)(x) #define log2(x) \ _Generic((x), float : log2f, default : log2, long double : log2l)(x) #define logb(x) \ _Generic((x), float : logbf, default : logb, long double : logbl)(x) #define lrint(x) \ _Generic((x), float : lrintf, default : lrint, long double : lrintl)(x) #define lround(x) \ _Generic((x), float : lroundf, default : lround, long double : lroundl)(x) #define nearbyint(x) \ _Generic((x), float \ : nearbyintf, default \ : nearbyint, long double \ : nearbyintl)(x) #define nextafter(x, y) \ _Generic((x), float \ : nextafterf, default \ : nextafter, long double \ : nextafterl)(x, y) #define nexttoward(x, y) \ _Generic((x), float \ : nexttowardf, default \ : nexttoward, long double \ : nexttowardl)(x, y) #define remainder(x, y) \ _Generic((x), float \ : remainderf, default \ : remainder, long double \ : remainderl)(x, y) #define remquo(x, y, z) \ _Generic((x), float \ : remquof, default \ : remquo, long double \ : remquol)(x, y, z) #define rint(x) \ _Generic((x), float : rintf, default : rint, long double : rintl)(x) #define round(x) \ _Generic((x), float : roundf, default : round, long double : roundl)(x) #define scalbln(x, y) \ _Generic((x), float \ : scalblnf, default \ : scalbln, long double \ : scalblnl)(x, y) #define scalbn(x, y) \ _Generic((x), float : scalbnf, default : scalbn, long double : scalbnl)(x, y) #define tgamma(x) \ _Generic((x), float : tgammaf, default : tgamma, long double : tgammal)(x) #define trunc(x) \ _Generic((x), float : truncf, default : trunc, long double : truncl)(x) #define carg(x) \ _Generic((x), complex float \ : cargf, default \ : carg, complex long double \ : cargl)(x) #define conj(x) \ _Generic((x), complex float \ : conjf, default \ : conj, complex long double \ : conjl)(x) #undef creal #define creal(x) \ _Generic((x), complex float \ : crealf, default \ : creal, complex long double \ : creall)(x) #undef cimag #define cimag(x) \ _Generic((x), complex float \ : cimagf, default \ : cimag, complex long double \ : cimagl)(x) #define cproj(x) \ _Generic((x), complex float \ : cprojf, default \ : cproj, complex long double \ : cprojl)(x) #endif /* C11 */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* _TGMATH_H */
bc0c0f81ae5b659e6595b3629d9e625c96a9b181
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/linux-a64/drivers/net/hyperv/hyperv_net.h
e6fe0d80d6122fcd8dfcf7bb65fa71dac68c1e73
[ "Linux-syscall-note", "GPL-2.0-only", "GPL-1.0-or-later", "LicenseRef-scancode-warranty-disclaimer", "LicenseRef-scancode-free-unknown", "Apache-2.0" ]
permissive
OLIMEX/DIY-LAPTOP
ae82f4ee79c641d9aee444db9a75f3f6709afa92
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
refs/heads/rel3
2023-08-04T01:54:19.483792
2023-04-03T07:18:12
2023-04-03T07:18:12
80,094,055
507
92
Apache-2.0
2023-04-03T07:05:59
2017-01-26T07:25:50
C
UTF-8
C
false
false
22,460
h
hyperv_net.h
/* * * Copyright (c) 2011, Microsoft Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place - Suite 330, Boston, MA 02111-1307 USA. * * Authors: * Haiyang Zhang <haiyangz@microsoft.com> * Hank Janssen <hjanssen@microsoft.com> * K. Y. Srinivasan <kys@microsoft.com> * */ #ifndef _HYPERV_NET_H #define _HYPERV_NET_H #include <linux/list.h> #include <linux/hyperv.h> #include <linux/rndis.h> /* Fwd declaration */ struct hv_netvsc_packet; /* Represent the xfer page packet which contains 1 or more netvsc packet */ struct xferpage_packet { struct list_head list_ent; u32 status; /* # of netvsc packets this xfer packet contains */ u32 count; }; /* * Represent netvsc packet which contains 1 RNDIS and 1 ethernet frame * within the RNDIS */ struct hv_netvsc_packet { /* Bookkeeping stuff */ struct list_head list_ent; u32 status; struct hv_device *device; bool is_data_pkt; u16 vlan_tci; /* * Valid only for receives when we break a xfer page packet * into multiple netvsc packets */ struct xferpage_packet *xfer_page_pkt; union { struct { u64 recv_completion_tid; void *recv_completion_ctx; void (*recv_completion)(void *context); } recv; struct { u64 send_completion_tid; void *send_completion_ctx; void (*send_completion)(void *context); } send; } completion; /* This points to the memory after page_buf */ void *extension; u32 total_data_buflen; /* Points to the send/receive buffer where the ethernet frame is */ void *data; u32 page_buf_cnt; struct hv_page_buffer page_buf[0]; }; struct netvsc_device_info { unsigned char mac_adr[ETH_ALEN]; bool link_state; /* 0 - link up, 1 - link down */ int ring_size; }; enum rndis_device_state { RNDIS_DEV_UNINITIALIZED = 0, RNDIS_DEV_INITIALIZING, RNDIS_DEV_INITIALIZED, RNDIS_DEV_DATAINITIALIZED, }; struct rndis_device { struct netvsc_device *net_dev; enum rndis_device_state state; bool link_state; atomic_t new_req_id; spinlock_t request_lock; struct list_head req_list; unsigned char hw_mac_adr[ETH_ALEN]; }; /* Interface */ int netvsc_device_add(struct hv_device *device, void *additional_info); int netvsc_device_remove(struct hv_device *device); int netvsc_send(struct hv_device *device, struct hv_netvsc_packet *packet); void netvsc_linkstatus_callback(struct hv_device *device_obj, unsigned int status); int netvsc_recv_callback(struct hv_device *device_obj, struct hv_netvsc_packet *packet); int rndis_filter_open(struct hv_device *dev); int rndis_filter_close(struct hv_device *dev); int rndis_filter_device_add(struct hv_device *dev, void *additional_info); void rndis_filter_device_remove(struct hv_device *dev); int rndis_filter_receive(struct hv_device *dev, struct hv_netvsc_packet *pkt); int rndis_filter_send(struct hv_device *dev, struct hv_netvsc_packet *pkt); int rndis_filter_set_packet_filter(struct rndis_device *dev, u32 new_filter); int rndis_filter_set_device_mac(struct hv_device *hdev, char *mac); #define NVSP_INVALID_PROTOCOL_VERSION ((u32)0xFFFFFFFF) #define NVSP_PROTOCOL_VERSION_1 2 #define NVSP_PROTOCOL_VERSION_2 0x30002 enum { NVSP_MSG_TYPE_NONE = 0, /* Init Messages */ NVSP_MSG_TYPE_INIT = 1, NVSP_MSG_TYPE_INIT_COMPLETE = 2, NVSP_VERSION_MSG_START = 100, /* Version 1 Messages */ NVSP_MSG1_TYPE_SEND_NDIS_VER = NVSP_VERSION_MSG_START, NVSP_MSG1_TYPE_SEND_RECV_BUF, NVSP_MSG1_TYPE_SEND_RECV_BUF_COMPLETE, NVSP_MSG1_TYPE_REVOKE_RECV_BUF, NVSP_MSG1_TYPE_SEND_SEND_BUF, NVSP_MSG1_TYPE_SEND_SEND_BUF_COMPLETE, NVSP_MSG1_TYPE_REVOKE_SEND_BUF, NVSP_MSG1_TYPE_SEND_RNDIS_PKT, NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE, /* Version 2 messages */ NVSP_MSG2_TYPE_SEND_CHIMNEY_DELEGATED_BUF, NVSP_MSG2_TYPE_SEND_CHIMNEY_DELEGATED_BUF_COMP, NVSP_MSG2_TYPE_REVOKE_CHIMNEY_DELEGATED_BUF, NVSP_MSG2_TYPE_RESUME_CHIMNEY_RX_INDICATION, NVSP_MSG2_TYPE_TERMINATE_CHIMNEY, NVSP_MSG2_TYPE_TERMINATE_CHIMNEY_COMP, NVSP_MSG2_TYPE_INDICATE_CHIMNEY_EVENT, NVSP_MSG2_TYPE_SEND_CHIMNEY_PKT, NVSP_MSG2_TYPE_SEND_CHIMNEY_PKT_COMP, NVSP_MSG2_TYPE_POST_CHIMNEY_RECV_REQ, NVSP_MSG2_TYPE_POST_CHIMNEY_RECV_REQ_COMP, NVSP_MSG2_TYPE_ALLOC_RXBUF, NVSP_MSG2_TYPE_ALLOC_RXBUF_COMP, NVSP_MSG2_TYPE_FREE_RXBUF, NVSP_MSG2_TYPE_SEND_VMQ_RNDIS_PKT, NVSP_MSG2_TYPE_SEND_VMQ_RNDIS_PKT_COMP, NVSP_MSG2_TYPE_SEND_NDIS_CONFIG, NVSP_MSG2_TYPE_ALLOC_CHIMNEY_HANDLE, NVSP_MSG2_TYPE_ALLOC_CHIMNEY_HANDLE_COMP, }; enum { NVSP_STAT_NONE = 0, NVSP_STAT_SUCCESS, NVSP_STAT_FAIL, NVSP_STAT_PROTOCOL_TOO_NEW, NVSP_STAT_PROTOCOL_TOO_OLD, NVSP_STAT_INVALID_RNDIS_PKT, NVSP_STAT_BUSY, NVSP_STAT_PROTOCOL_UNSUPPORTED, NVSP_STAT_MAX, }; struct nvsp_message_header { u32 msg_type; }; /* Init Messages */ /* * This message is used by the VSC to initialize the channel after the channels * has been opened. This message should never include anything other then * versioning (i.e. this message will be the same for ever). */ struct nvsp_message_init { u32 min_protocol_ver; u32 max_protocol_ver; } __packed; /* * This message is used by the VSP to complete the initialization of the * channel. This message should never include anything other then versioning * (i.e. this message will be the same for ever). */ struct nvsp_message_init_complete { u32 negotiated_protocol_ver; u32 max_mdl_chain_len; u32 status; } __packed; union nvsp_message_init_uber { struct nvsp_message_init init; struct nvsp_message_init_complete init_complete; } __packed; /* Version 1 Messages */ /* * This message is used by the VSC to send the NDIS version to the VSP. The VSP * can use this information when handling OIDs sent by the VSC. */ struct nvsp_1_message_send_ndis_version { u32 ndis_major_ver; u32 ndis_minor_ver; } __packed; /* * This message is used by the VSC to send a receive buffer to the VSP. The VSP * can then use the receive buffer to send data to the VSC. */ struct nvsp_1_message_send_receive_buffer { u32 gpadl_handle; u16 id; } __packed; struct nvsp_1_receive_buffer_section { u32 offset; u32 sub_alloc_size; u32 num_sub_allocs; u32 end_offset; } __packed; /* * This message is used by the VSP to acknowledge a receive buffer send by the * VSC. This message must be sent by the VSP before the VSP uses the receive * buffer. */ struct nvsp_1_message_send_receive_buffer_complete { u32 status; u32 num_sections; /* * The receive buffer is split into two parts, a large suballocation * section and a small suballocation section. These sections are then * suballocated by a certain size. */ /* * For example, the following break up of the receive buffer has 6 * large suballocations and 10 small suballocations. */ /* * | Large Section | | Small Section | * ------------------------------------------------------------ * | | | | | | | | | | | | | | | | | | * | | * LargeOffset SmallOffset */ struct nvsp_1_receive_buffer_section sections[1]; } __packed; /* * This message is sent by the VSC to revoke the receive buffer. After the VSP * completes this transaction, the vsp should never use the receive buffer * again. */ struct nvsp_1_message_revoke_receive_buffer { u16 id; }; /* * This message is used by the VSC to send a send buffer to the VSP. The VSC * can then use the send buffer to send data to the VSP. */ struct nvsp_1_message_send_send_buffer { u32 gpadl_handle; u16 id; } __packed; /* * This message is used by the VSP to acknowledge a send buffer sent by the * VSC. This message must be sent by the VSP before the VSP uses the sent * buffer. */ struct nvsp_1_message_send_send_buffer_complete { u32 status; /* * The VSC gets to choose the size of the send buffer and the VSP gets * to choose the sections size of the buffer. This was done to enable * dynamic reconfigurations when the cost of GPA-direct buffers * decreases. */ u32 section_size; } __packed; /* * This message is sent by the VSC to revoke the send buffer. After the VSP * completes this transaction, the vsp should never use the send buffer again. */ struct nvsp_1_message_revoke_send_buffer { u16 id; }; /* * This message is used by both the VSP and the VSC to send a RNDIS message to * the opposite channel endpoint. */ struct nvsp_1_message_send_rndis_packet { /* * This field is specified by RNIDS. They assume there's two different * channels of communication. However, the Network VSP only has one. * Therefore, the channel travels with the RNDIS packet. */ u32 channel_type; /* * This field is used to send part or all of the data through a send * buffer. This values specifies an index into the send buffer. If the * index is 0xFFFFFFFF, then the send buffer is not being used and all * of the data was sent through other VMBus mechanisms. */ u32 send_buf_section_index; u32 send_buf_section_size; } __packed; /* * This message is used by both the VSP and the VSC to complete a RNDIS message * to the opposite channel endpoint. At this point, the initiator of this * message cannot use any resources associated with the original RNDIS packet. */ struct nvsp_1_message_send_rndis_packet_complete { u32 status; }; union nvsp_1_message_uber { struct nvsp_1_message_send_ndis_version send_ndis_ver; struct nvsp_1_message_send_receive_buffer send_recv_buf; struct nvsp_1_message_send_receive_buffer_complete send_recv_buf_complete; struct nvsp_1_message_revoke_receive_buffer revoke_recv_buf; struct nvsp_1_message_send_send_buffer send_send_buf; struct nvsp_1_message_send_send_buffer_complete send_send_buf_complete; struct nvsp_1_message_revoke_send_buffer revoke_send_buf; struct nvsp_1_message_send_rndis_packet send_rndis_pkt; struct nvsp_1_message_send_rndis_packet_complete send_rndis_pkt_complete; } __packed; /* * Network VSP protocol version 2 messages: */ struct nvsp_2_vsc_capability { union { u64 data; struct { u64 vmq:1; u64 chimney:1; u64 sriov:1; u64 ieee8021q:1; u64 correlation_id:1; }; }; } __packed; struct nvsp_2_send_ndis_config { u32 mtu; u32 reserved; struct nvsp_2_vsc_capability capability; } __packed; /* Allocate receive buffer */ struct nvsp_2_alloc_rxbuf { /* Allocation ID to match the allocation request and response */ u32 alloc_id; /* Length of the VM shared memory receive buffer that needs to * be allocated */ u32 len; } __packed; /* Allocate receive buffer complete */ struct nvsp_2_alloc_rxbuf_comp { /* The NDIS_STATUS code for buffer allocation */ u32 status; u32 alloc_id; /* GPADL handle for the allocated receive buffer */ u32 gpadl_handle; /* Receive buffer ID */ u64 recv_buf_id; } __packed; struct nvsp_2_free_rxbuf { u64 recv_buf_id; } __packed; union nvsp_2_message_uber { struct nvsp_2_send_ndis_config send_ndis_config; struct nvsp_2_alloc_rxbuf alloc_rxbuf; struct nvsp_2_alloc_rxbuf_comp alloc_rxbuf_comp; struct nvsp_2_free_rxbuf free_rxbuf; } __packed; union nvsp_all_messages { union nvsp_message_init_uber init_msg; union nvsp_1_message_uber v1_msg; union nvsp_2_message_uber v2_msg; } __packed; /* ALL Messages */ struct nvsp_message { struct nvsp_message_header hdr; union nvsp_all_messages msg; } __packed; #define NETVSC_MTU 65536 #define NETVSC_RECEIVE_BUFFER_SIZE (1024*1024*2) /* 2MB */ #define NETVSC_RECEIVE_BUFFER_ID 0xcafe /* Preallocated receive packets */ #define NETVSC_RECEIVE_PACKETLIST_COUNT 256 #define NETVSC_PACKET_SIZE 2048 /* Per netvsc channel-specific */ struct netvsc_device { struct hv_device *dev; u32 nvsp_version; atomic_t num_outstanding_sends; wait_queue_head_t wait_drain; bool start_remove; bool destroy; /* * List of free preallocated hv_netvsc_packet to represent receive * packet */ struct list_head recv_pkt_list; spinlock_t recv_pkt_list_lock; /* Receive buffer allocated by us but manages by NetVSP */ void *recv_buf; u32 recv_buf_size; u32 recv_buf_gpadl_handle; u32 recv_section_cnt; struct nvsp_1_receive_buffer_section *recv_section; /* Used for NetVSP initialization protocol */ struct completion channel_init_wait; struct nvsp_message channel_init_pkt; struct nvsp_message revoke_packet; /* unsigned char HwMacAddr[HW_MACADDR_LEN]; */ struct net_device *ndev; /* Holds rndis device info */ void *extension; }; /* NdisInitialize message */ struct rndis_initialize_request { u32 req_id; u32 major_ver; u32 minor_ver; u32 max_xfer_size; }; /* Response to NdisInitialize */ struct rndis_initialize_complete { u32 req_id; u32 status; u32 major_ver; u32 minor_ver; u32 dev_flags; u32 medium; u32 max_pkt_per_msg; u32 max_xfer_size; u32 pkt_alignment_factor; u32 af_list_offset; u32 af_list_size; }; /* Call manager devices only: Information about an address family */ /* supported by the device is appended to the response to NdisInitialize. */ struct rndis_co_address_family { u32 address_family; u32 major_ver; u32 minor_ver; }; /* NdisHalt message */ struct rndis_halt_request { u32 req_id; }; /* NdisQueryRequest message */ struct rndis_query_request { u32 req_id; u32 oid; u32 info_buflen; u32 info_buf_offset; u32 dev_vc_handle; }; /* Response to NdisQueryRequest */ struct rndis_query_complete { u32 req_id; u32 status; u32 info_buflen; u32 info_buf_offset; }; /* NdisSetRequest message */ struct rndis_set_request { u32 req_id; u32 oid; u32 info_buflen; u32 info_buf_offset; u32 dev_vc_handle; }; /* Response to NdisSetRequest */ struct rndis_set_complete { u32 req_id; u32 status; }; /* NdisReset message */ struct rndis_reset_request { u32 reserved; }; /* Response to NdisReset */ struct rndis_reset_complete { u32 status; u32 addressing_reset; }; /* NdisMIndicateStatus message */ struct rndis_indicate_status { u32 status; u32 status_buflen; u32 status_buf_offset; }; /* Diagnostic information passed as the status buffer in */ /* struct rndis_indicate_status messages signifying error conditions. */ struct rndis_diagnostic_info { u32 diag_status; u32 error_offset; }; /* NdisKeepAlive message */ struct rndis_keepalive_request { u32 req_id; }; /* Response to NdisKeepAlive */ struct rndis_keepalive_complete { u32 req_id; u32 status; }; /* * Data message. All Offset fields contain byte offsets from the beginning of * struct rndis_packet. All Length fields are in bytes. VcHandle is set * to 0 for connectionless data, otherwise it contains the VC handle. */ struct rndis_packet { u32 data_offset; u32 data_len; u32 oob_data_offset; u32 oob_data_len; u32 num_oob_data_elements; u32 per_pkt_info_offset; u32 per_pkt_info_len; u32 vc_handle; u32 reserved; }; /* Optional Out of Band data associated with a Data message. */ struct rndis_oobd { u32 size; u32 type; u32 class_info_offset; }; /* Packet extension field contents associated with a Data message. */ struct rndis_per_packet_info { u32 size; u32 type; u32 ppi_offset; }; enum ndis_per_pkt_info_type { TCPIP_CHKSUM_PKTINFO, IPSEC_PKTINFO, TCP_LARGESEND_PKTINFO, CLASSIFICATION_HANDLE_PKTINFO, NDIS_RESERVED, SG_LIST_PKTINFO, IEEE_8021Q_INFO, ORIGINAL_PKTINFO, PACKET_CANCEL_ID, ORIGINAL_NET_BUFLIST, CACHED_NET_BUFLIST, SHORT_PKT_PADINFO, MAX_PER_PKT_INFO }; struct ndis_pkt_8021q_info { union { struct { u32 pri:3; /* User Priority */ u32 cfi:1; /* Canonical Format ID */ u32 vlanid:12; /* VLAN ID */ u32 reserved:16; }; u32 value; }; }; #define NDIS_VLAN_PPI_SIZE (sizeof(struct rndis_per_packet_info) + \ sizeof(struct ndis_pkt_8021q_info)) /* Format of Information buffer passed in a SetRequest for the OID */ /* OID_GEN_RNDIS_CONFIG_PARAMETER. */ struct rndis_config_parameter_info { u32 parameter_name_offset; u32 parameter_name_length; u32 parameter_type; u32 parameter_value_offset; u32 parameter_value_length; }; /* Values for ParameterType in struct rndis_config_parameter_info */ #define RNDIS_CONFIG_PARAM_TYPE_INTEGER 0 #define RNDIS_CONFIG_PARAM_TYPE_STRING 2 /* CONDIS Miniport messages for connection oriented devices */ /* that do not implement a call manager. */ /* CoNdisMiniportCreateVc message */ struct rcondis_mp_create_vc { u32 req_id; u32 ndis_vc_handle; }; /* Response to CoNdisMiniportCreateVc */ struct rcondis_mp_create_vc_complete { u32 req_id; u32 dev_vc_handle; u32 status; }; /* CoNdisMiniportDeleteVc message */ struct rcondis_mp_delete_vc { u32 req_id; u32 dev_vc_handle; }; /* Response to CoNdisMiniportDeleteVc */ struct rcondis_mp_delete_vc_complete { u32 req_id; u32 status; }; /* CoNdisMiniportQueryRequest message */ struct rcondis_mp_query_request { u32 req_id; u32 request_type; u32 oid; u32 dev_vc_handle; u32 info_buflen; u32 info_buf_offset; }; /* CoNdisMiniportSetRequest message */ struct rcondis_mp_set_request { u32 req_id; u32 request_type; u32 oid; u32 dev_vc_handle; u32 info_buflen; u32 info_buf_offset; }; /* CoNdisIndicateStatus message */ struct rcondis_indicate_status { u32 ndis_vc_handle; u32 status; u32 status_buflen; u32 status_buf_offset; }; /* CONDIS Call/VC parameters */ struct rcondis_specific_parameters { u32 parameter_type; u32 parameter_length; u32 parameter_lffset; }; struct rcondis_media_parameters { u32 flags; u32 reserved1; u32 reserved2; struct rcondis_specific_parameters media_specific; }; struct rndis_flowspec { u32 token_rate; u32 token_bucket_size; u32 peak_bandwidth; u32 latency; u32 delay_variation; u32 service_type; u32 max_sdu_size; u32 minimum_policed_size; }; struct rcondis_call_manager_parameters { struct rndis_flowspec transmit; struct rndis_flowspec receive; struct rcondis_specific_parameters call_mgr_specific; }; /* CoNdisMiniportActivateVc message */ struct rcondis_mp_activate_vc_request { u32 req_id; u32 flags; u32 dev_vc_handle; u32 media_params_offset; u32 media_params_length; u32 call_mgr_params_offset; u32 call_mgr_params_length; }; /* Response to CoNdisMiniportActivateVc */ struct rcondis_mp_activate_vc_complete { u32 req_id; u32 status; }; /* CoNdisMiniportDeactivateVc message */ struct rcondis_mp_deactivate_vc_request { u32 req_id; u32 flags; u32 dev_vc_handle; }; /* Response to CoNdisMiniportDeactivateVc */ struct rcondis_mp_deactivate_vc_complete { u32 req_id; u32 status; }; /* union with all of the RNDIS messages */ union rndis_message_container { struct rndis_packet pkt; struct rndis_initialize_request init_req; struct rndis_halt_request halt_req; struct rndis_query_request query_req; struct rndis_set_request set_req; struct rndis_reset_request reset_req; struct rndis_keepalive_request keep_alive_req; struct rndis_indicate_status indicate_status; struct rndis_initialize_complete init_complete; struct rndis_query_complete query_complete; struct rndis_set_complete set_complete; struct rndis_reset_complete reset_complete; struct rndis_keepalive_complete keep_alive_complete; struct rcondis_mp_create_vc co_miniport_create_vc; struct rcondis_mp_delete_vc co_miniport_delete_vc; struct rcondis_indicate_status co_indicate_status; struct rcondis_mp_activate_vc_request co_miniport_activate_vc; struct rcondis_mp_deactivate_vc_request co_miniport_deactivate_vc; struct rcondis_mp_create_vc_complete co_miniport_create_vc_complete; struct rcondis_mp_delete_vc_complete co_miniport_delete_vc_complete; struct rcondis_mp_activate_vc_complete co_miniport_activate_vc_complete; struct rcondis_mp_deactivate_vc_complete co_miniport_deactivate_vc_complete; }; /* Remote NDIS message format */ struct rndis_message { u32 ndis_msg_type; /* Total length of this message, from the beginning */ /* of the sruct rndis_message, in bytes. */ u32 msg_len; /* Actual message */ union rndis_message_container msg; }; struct rndis_filter_packet { void *completion_ctx; void (*completion)(void *context); struct rndis_message msg; }; /* Handy macros */ /* get the size of an RNDIS message. Pass in the message type, */ /* struct rndis_set_request, struct rndis_packet for example */ #define RNDIS_MESSAGE_SIZE(msg) \ (sizeof(msg) + (sizeof(struct rndis_message) - \ sizeof(union rndis_message_container))) /* get pointer to info buffer with message pointer */ #define MESSAGE_TO_INFO_BUFFER(msg) \ (((unsigned char *)(msg)) + msg->info_buf_offset) /* get pointer to status buffer with message pointer */ #define MESSAGE_TO_STATUS_BUFFER(msg) \ (((unsigned char *)(msg)) + msg->status_buf_offset) /* get pointer to OOBD buffer with message pointer */ #define MESSAGE_TO_OOBD_BUFFER(msg) \ (((unsigned char *)(msg)) + msg->oob_data_offset) /* get pointer to data buffer with message pointer */ #define MESSAGE_TO_DATA_BUFFER(msg) \ (((unsigned char *)(msg)) + msg->per_pkt_info_offset) /* get pointer to contained message from NDIS_MESSAGE pointer */ #define RNDIS_MESSAGE_PTR_TO_MESSAGE_PTR(rndis_msg) \ ((void *) &rndis_msg->msg) /* get pointer to contained message from NDIS_MESSAGE pointer */ #define RNDIS_MESSAGE_RAW_PTR_TO_MESSAGE_PTR(rndis_msg) \ ((void *) rndis_msg) #define __struct_bcount(x) #define RNDIS_HEADER_SIZE (sizeof(struct rndis_message) - \ sizeof(union rndis_message_container)) #define NDIS_PACKET_TYPE_DIRECTED 0x00000001 #define NDIS_PACKET_TYPE_MULTICAST 0x00000002 #define NDIS_PACKET_TYPE_ALL_MULTICAST 0x00000004 #define NDIS_PACKET_TYPE_BROADCAST 0x00000008 #define NDIS_PACKET_TYPE_SOURCE_ROUTING 0x00000010 #define NDIS_PACKET_TYPE_PROMISCUOUS 0x00000020 #define NDIS_PACKET_TYPE_SMT 0x00000040 #define NDIS_PACKET_TYPE_ALL_LOCAL 0x00000080 #define NDIS_PACKET_TYPE_GROUP 0x00000100 #define NDIS_PACKET_TYPE_ALL_FUNCTIONAL 0x00000200 #define NDIS_PACKET_TYPE_FUNCTIONAL 0x00000400 #define NDIS_PACKET_TYPE_MAC_FRAME 0x00000800 #endif /* _HYPERV_NET_H */
edebb2374b8ade3e2cf543ff5349c688c9b81812
6ff85b80c6fe1b3ad5416a304b93551a5e80de10
/C/Loop/Validation.c
dbc2409245c18c2d42c835a4cdb03a6559ddc2ec
[ "MIT" ]
permissive
maniero/SOpt
c600cc2333e0a47ce013be3516bbb8080502ff2a
5d17e1a9cbf115eaea6d30af2079d0c92ffff7a3
refs/heads/master
2023-08-10T16:48:46.058739
2023-08-10T13:42:17
2023-08-10T13:42:17
78,631,930
1,002
136
MIT
2023-01-28T12:10:01
2017-01-11T11:19:24
C#
UTF-8
C
false
false
1,306
c
Validation.c
#include <stdio.h> #include <locale.h> int main(void) { setlocale(LC_ALL,"Portuguese"); struct Aluno { char nome[10]; float notaMath, notaPhysics, media; } aluno[5]; for (int contador = 0; contador < 5; contador++) { printf("Nome do aluno %d: ", contador + 1); scanf("%s", aluno[contador].nome); while (1) { printf("Nota de matemática: "); scanf("%f", &aluno[contador].notaMath); if (aluno[contador].notaMath > 10.0) printf("Apenas notas até 10.\n"); else break; } while (1) { printf("Nota de física: "); scanf("%f", &aluno[contador].notaPhysics); if (aluno[contador].notaPhysics > 10.0) printf("Apenas notas até 10.\n"); else break; } aluno[contador].media = (aluno[contador].notaMath + aluno[contador].notaPhysics) / 2; printf("\n"); } printf("\n\n------------Informações dos Alunos------------\n"); for (int contador = 0; contador < 5; contador++) { printf("Nome do aluno %d: %s\n", contador+1, aluno[contador].nome); printf("Nota de matemática: %.1f\n", aluno[contador].notaMath); printf("Nota de física: %.1f\n", aluno[contador].notaPhysics); printf("Média das notas: %.1f\n", aluno[contador].media); printf("\n\n"); } } //https://pt.stackoverflow.com/q/241369/101