Skip to content

Commit db5b887

Browse files
committed
implements min/max with wasm instructions
1 parent 043317a commit db5b887

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

src/de/inetsoftware/jwebassembly/api/java/lang/ReplacementForMath.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,68 @@ static double abs( double x ) {
298298
static float abs( float x ) {
299299
return 0; // for Java compiler
300300
}
301+
302+
/**
303+
* Replacement for {@link Math#max(double,double)}
304+
*
305+
* @param a an argument.
306+
* @param b another argument.
307+
* @return the larger of a and b.
308+
*/
309+
@Replace( "java/lang/Math.max(DD)D" )
310+
@WasmTextCode( "local.get 0 " //
311+
+ "local.get 1 " //
312+
+ "f64.max " //
313+
+ "return" )
314+
static double max( double a, double b ) {
315+
return 0; // for Java compiler
316+
}
317+
318+
/**
319+
* Replacement for {@link Math#max(float,float)}
320+
*
321+
* @param a an argument.
322+
* @param b another argument.
323+
* @return the larger of a and b.
324+
*/
325+
@Replace( "java/lang/Math.max(FF)F" )
326+
@WasmTextCode( "local.get 0 " //
327+
+ "local.get 1 " //
328+
+ "f32.max " //
329+
+ "return" )
330+
static float max( float a, float b ) {
331+
return 0; // for Java compiler
332+
}
333+
334+
/**
335+
* Replacement for {@link Math#min(double,double)}
336+
*
337+
* @param a an argument.
338+
* @param b another argument.
339+
* @return the smaller of a and b.
340+
*/
341+
@Replace( "java/lang/Math.min(DD)D" )
342+
@WasmTextCode( "local.get 0 " //
343+
+ "local.get 1 " //
344+
+ "f64.min " //
345+
+ "return" )
346+
static double min( double a, double b ) {
347+
return 0; // for Java compiler
348+
}
349+
350+
/**
351+
* Replacement for {@link Math#min(float,float)}
352+
*
353+
* @param a an argument.
354+
* @param b another argument.
355+
* @return the smaller of a and b.
356+
*/
357+
@Replace( "java/lang/Math.min(FF)F" )
358+
@WasmTextCode( "local.get 0 " //
359+
+ "local.get 1 " //
360+
+ "f32.min " //
361+
+ "return" )
362+
static float min( float a, float b ) {
363+
return 0; // for Java compiler
364+
}
301365
}

0 commit comments

Comments
 (0)