jackmott / fastnoise-simd Goto Github PK
View Code? Open in Web Editor NEWPerlin style noise sped up with SIMD instructions
License: Other
Perlin style noise sped up with SIMD instructions
License: Other
I am seeing artefacts in the noise values.
Am I using the library wrong? I tried clang and gcc, with same results.
This is the code:
#include "FastNoise3d.h"
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <immintrin.h>
#if defined( MSWIN )
# define ALIGNEDPRE __declspec(align(32))
# define ALIGNEDPST
#else
# define ALIGNEDPRE
# define ALIGNEDPST __attribute__ ((aligned (32)))
#endif
int main(int argc, char* argv[])
{
if ( argc != 3 )
{
fprintf( stderr, "Usage: %s size file.pgm\n", argv[0] );
exit(1);
}
const int sz = atoi( argv[1] );
const char* oname = argv[2];
FILE* f = fopen( oname, "wb" );
assert( f );
initSIMDSimplex(); // NOTE: I've added the constant initialization to this func.
uint8_t* im = (uint8_t*)malloc( sz * sz );
uint8_t* writer = im;
for (int y=0; y<sz; ++y)
{
__m256 y8 = _mm256_set1_ps( y );
for (int x=0; x<sz; x+=8)
{
__m256 x8 = _mm256_setr_ps(0,1,2,3,4,5,6,7);
x8 = _mm256_add_ps( x8, _mm256_set1_ps(x) );
__m256 z8 = _mm256_set1_ps(1.0f);
__m256 v8 = simplexSIMD3d
(
_mm256_mul_ps( x8, _mm256_set1_ps(0.01f) ),
_mm256_mul_ps( y8, _mm256_set1_ps(0.01f) ),
z8
);
ALIGNEDPRE float vals[8] ALIGNEDPST;
_mm256_store_ps( vals, v8 );
for ( int i=0; i<8; ++i )
*writer++ = (uint8_t) ( 127 * ( vals[i] + 1.0f ) );
}
}
fprintf( f, "P5\n%d %d\n255\n", sz, sz );
fwrite( im, sz*sz, 1, f );
fclose(f);
return 0;
}
Note: I've slightly modified the library code (made it C-API, and added constant init to initSIMDSimplex() as I only need that call.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.