Skip to content

Commit

Permalink
maint: Merge default to bytecode-interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
arungiridhar committed Oct 17, 2024
2 parents 69562d9 + 416b22b commit 5830943
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 21 deletions.
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ BUILT_SOURCES += libgnu/libgnu.la
libgnu/libgnu.la: oct-conf-post-private.h oct-conf-post-public.h
cd libgnu && $(MAKE) $(AM_MAKEFLAGS) all

OCTAVE_LIBOCTMEX_SOVERSION_MAJOR = 1

include liboctave/module.mk
include libinterp/module.mk
include libmex/module.mk
Expand Down
2 changes: 1 addition & 1 deletion etc/NEWS.9.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Summary of bugs fixed for version 9.3.0 (tbd):
patch and surface graphics objects (bug #66314).
- `barh` properties now better match equivalent `bar` plot. Changing
`horizontal` property for a bar or barh plot now consistently updates
properties to match redrawn plot (bug #65671).
properties to match redrawn plot (bug #65671).
- Tick mark labels are now correctly updated after changing x or y data for
`bar` and `barh` plots (bug #65734).

Expand Down
10 changes: 10 additions & 0 deletions libinterp/corefcn/dynamic-ld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,16 @@ dynamic_loader::load_mex (const std::string& fcn_name,

bool interleaved = symbol != nullptr;

int *mex_soversion =
reinterpret_cast<int *> (mex_file.search ("__octave_mex_soversion__"));

if (mex_soversion && *mex_soversion != OCTAVE_MEX_SOVERSION)
error ("SOVERSION %d found in .mex file function '%s'\n"
" does not match the running Octave (SOVERSION %d)\n"
" this can lead to incorrect results or other failures\n"
" you can fix this problem by recompiling this .mex file",
*mex_soversion, fcn_name.c_str (), OCTAVE_MEX_SOVERSION);

return new octave_mex_function (function, interleaved, have_fmex,
mex_file, fcn_name);
}
Expand Down
1 change: 1 addition & 0 deletions libinterp/corefcn/module.mk
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ noinst_LTLIBRARIES += \

%canon_reldir%_libcorefcn_la_CPPFLAGS = \
$(libinterp_liboctinterp_la_CPPFLAGS) \
-DOCTAVE_MEX_SOVERSION="$(OCTAVE_LIBOCTMEX_SOVERSION_MAJOR)" \
$(FFTW_XCPPFLAGS) \
$(FONTCONFIG_CPPFLAGS) \
$(FT2_CPPFLAGS) \
Expand Down
5 changes: 3 additions & 2 deletions libmex/module.mk
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ nodist_%canon_reldir%_liboctmex_la_SOURCES = \
liboctave/liboctave.la

## Increment the following version numbers as needed and according
## to the rules in the etc/HACKING.md file:
## to the rules in the etc/HACKING.md file.
## Note that OCTAVE_LIBOCTMEX_SOVERSION_MAJOR is set in Makefile.am:

%canon_reldir%_liboctmex_current = 1
%canon_reldir%_liboctmex_current = $(OCTAVE_LIBOCTMEX_SOVERSION_MAJOR)
%canon_reldir%_liboctmex_revision = 0
%canon_reldir%_liboctmex_age = 0

Expand Down
21 changes: 5 additions & 16 deletions scripts/specfun/isprime.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,37 +114,26 @@
pr = [2 3 5 7 11 13 17 19 23 29 31 37];
tf = lookup (pr, x, "b"); # quick search for table matches.

THRESHOLD = 195e8;
THRESHOLD = 17e9;
## FIXME: THRESHOLD is the input value at which Miller-Rabin
## becomes more efficient than direct division. For smaller numbers,
## use direct division. For larger numbers, use Miller-Rabin.
##
## From numerical experiments in Jun 2022, this was observed:
## THRESHOLD Division Miller-Rabin
## 29e9 29.8196s 26.2484s (previous value)
## 20e9 26.7445s 26.0161s
## 10e9 20.9330s 25.3247s
## 19e9 26.5397s 26.8987s
## 195e8 26.5735s 26.4749s
## which is close enough, so new threshold = 195e8.
##
## The test code was this:
## Last updated in Oct 2024, using this test code:
## n = THRESHOLD - (1:1e7); tic; isprime(n); toc
## n = THRESHOLD + (1:1e7); tic; isprime(n); toc
##
## Two notes for future programmers:
##
## 1. Test and tune THRESHOLD periodically. Miller-Rabin is only CPU-limited,
## while factorization by division is very memory-intensive. This is
## plainly noticeable from the loudness of the computer fans when running
## the division technique! CPU speed and RAM speed scale differently over
## 1. Test and tune THRESHOLD periodically so that the two times are equal.
## Miller-Rabin is only CPU-limited, while factorization by division is
## very memory-intensive. CPU speed and RAM speed scale differently over
## time, so test and tune THRESHOLD periodically.
##
## 2. If you make improvements elsewhere in the code that favor one over
## the other (not symmetric), you should also retune THRESHOLD afterwards.
## If the Miller-Rabin part is sped up, the optimum THRESHOLD will
## decrease, and if factorization is sped up, it will increase.
##

## Process large entries that are still suitable for direct division
m = x (x > maxp & x <= THRESHOLD);
Expand Down
38 changes: 37 additions & 1 deletion src/mkoctfile.in.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <fstream>
#include <sstream>
#include <vector>
#include <cstdio>
#include <cstdlib>

#if defined (OCTAVE_USE_WINDOWS_API)
Expand Down Expand Up @@ -669,6 +670,33 @@ create_interleaved_complex_file ()
return retval;
}

static std::string
create_mex_soversion_file ()
{
std::string tmpl = get_temp_directory () + "/oct-XXXXXX.c";

char *ctmpl = new char [tmpl.length () + 1];

ctmpl = strcpy (ctmpl, tmpl.c_str ());

// mkostemps will open the file and return a file descriptor. We
// won't worry about closing it because we will need the file until we
// are done and then the file will be closed when mkoctfile exits.
int fd = octave_mkostemps_wrapper (ctmpl, 2);

// Make C++ string from filled-in template.
std::string retval (ctmpl);
delete [] ctmpl;

// Write symbol definition to file.
FILE *fid = fdopen (fd, "w");
fprintf (fid, "const int __octave_mex_soversion__ = %d;\n",
OCTAVE_MEX_SOVERSION);
fclose (fid);

return retval;
}

static std::string
tmp_objfile_name ()
{
Expand Down Expand Up @@ -989,6 +1017,14 @@ main (int argc, char **sys_argv)
if (vars["ALL_CFLAGS"].find ("-g") != std::string::npos)
defs += " -DMEX_DEBUG";

// Create tmp C source file that defines an extern symbol that can
// be checked when loading the mex file to make sure the SOVERSION
// of liboctmex matches between the .mex file and the Octave version
// attempting to load it.
std::string tmp_file = create_mex_soversion_file ();

cfiles.push_back (tmp_file);

if (mx_has_interleaved_complex)
{
defs += " -DMX_HAS_INTERLEAVED_COMPLEX=1";
Expand All @@ -1000,7 +1036,7 @@ main (int argc, char **sys_argv)
// determine that the file was compiled expecting
// interleaved complex values.

std::string tmp_file = create_interleaved_complex_file ();
tmp_file = create_interleaved_complex_file ();

cfiles.push_back (tmp_file);
}
Expand Down
3 changes: 2 additions & 1 deletion src/module.mk
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ nodist_%canon_reldir%_mkoctfile_SOURCES = %reldir%/mkoctfile.cc

%canon_reldir%_mkoctfile_CPPFLAGS = \
$(SRC_DIR_CPPFLAGS) \
$(OCTAVE_CPPFLAGS)
$(OCTAVE_CPPFLAGS) \
-DOCTAVE_MEX_SOVERSION="$(OCTAVE_LIBOCTMEX_SOVERSION_MAJOR)"

%canon_reldir%_octave_config_SOURCES =

Expand Down

0 comments on commit 5830943

Please sign in to comment.