Skip to content

Instantly share code, notes, and snippets.

memcpy func
memset func
div func
fabs func
gcvt func
tzset func
strerror func
Perl_pregcomp func
Perl_pregfree func
isalnum func
/*
* See if I can trigger the cache trashing issue.
*
* Use tcc to compile and run with:
* ./tcc -B. -DNOPS=0 -run cache-test-simple.c
*
* For performance metrics, try
* perf stat -d -d -d ./tcc -B. -DNOPS=0 -run cache-test-simple.c
*/
#include <stdio.h>
@run4flat
run4flat / rand-cblock.pl
Last active December 21, 2016 19:26
KISS RNG implementations using different Perl tcc wrappers
use strict;
use warnings;
use C::Blocks;
use C::Blocks::Types qw(uint);
my $N = $ARGV[0] || 100;
sub KISS_rand {
my uint $to_return = 0;
cblock {
static unsigned int x = 123456789,y = 362436000,
@run4flat
run4flat / keyword-scope.pl
Created December 13, 2016 14:33
Use C::Blocks to create a keyword hoook and investigate hints hash scoping at the ends of blocks.
use strict;
use warnings;
use C::Blocks;
use C::Blocks::PerlAPI;
# Write a little keyword hook that simply prints the keywords it encounters
clex {
int (*next_keyword_plugin)(pTHX_ char *, STRLEN, OP **);
int prev_count;
@run4flat
run4flat / ToTest.pm
Last active December 31, 2015 13:49
Most recent round of nvcc's interactions with SvNV and friends
package ToTest;
use 5.008_008;
use strict;
use warnings;
our $VERSION = '0.04';
require XSLoader;
XSLoader::load('ToTest', $VERSION);
@run4flat
run4flat / lib-ToTest.pm
Last active December 31, 2015 13:18
Weird XSness fails to fail
package ToTest;
use 5.008_008;
use strict;
use warnings;
our $VERSION = '0.01';
require XSLoader;
XSLoader::load('ToTest', $VERSION);
@run4flat
run4flat / Tests.i
Last active December 31, 2015 13:08
Output of weird SV stuff
This file has been truncated, but you can view the full file.
# 1 "lib/CUDA/Minimal/Tests.c"
# 1 "<command-line>"
# 1 "/usr/local/cuda/bin/..//include/cuda_runtime.h" 1
# 59 "/usr/local/cuda/bin/..//include/cuda_runtime.h"
# 1 "/usr/local/cuda/bin/..//include/host_config.h" 1
# 119 "/usr/local/cuda/bin/..//include/host_config.h"
# 1 "/usr/include/features.h" 1 3 4
# 323 "/usr/include/features.h" 3 4
# 1 "/usr/include/i386-linux-gnu/bits/predefs.h" 1 3 4
# 324 "/usr/include/features.h" 2 3 4
@run4flat
run4flat / Blocks.pm
Last active December 25, 2015 19:08
Basic use of C::Blocks
use strict;
use warnings;
package C::Blocks;
use Devel::Declare;
sub import {
my $class = shift;
my $caller = caller;
@run4flat
run4flat / An-Explanation.pod
Last active December 18, 2015 09:19
Lexically scoping method calls for a specific class in Perl.

GOAL

Lexically Scoped Methods for a specific class (aiming at PDL).

Why?

In PDL, we have a lot of methods that only make sense for certain analyses, yet when we use a PDL module that defines a set of functions, the module almost always imports its functions into the PDL package. For example, it is rarely useful to apply a one-dimensional Fourier transform to an image, but if any of my code says

@run4flat
run4flat / comments.mkd
Last active December 17, 2015 07:59
tentative feedback to reddit

djimbob, c'mon. FUDDING on Perl 4 is hardly helpful for the OP. If you're going to argue Python against Perl, you should argue Python 3 vs Perl 5.16. This is 2013, after all.

Python is a modern well-designed multi-paradigm programming language.

Sorta. Of course, Python has its warts, like join being a string method and not a list method, and reverse working in-place instead of returning a new list. And, Ruby and Perl are also well-designed multi-paradigm programming languages, and they have their warts, too. As far as a scientist is concerned, Perl and Python differentiate from Ruby because they have N-dimensional libraries, PDL and numpy, respectively, that make them as performant as Matlab (for 99.9% of uses, that is). If the OP is looking for a scripting glue language, he/she should give careful thought to Python or Perl. (Some will also throw R or Matlab into the mix, but I don't think they're well designed languages, just popular ones.)

Python code reads beautifully.

Nope. Check out (the most up-