time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

addon.c (3942B)


      1 /**
      2 * @license Apache-2.0
      3 *
      4 * Copyright (c) 2020 The Stdlib Authors.
      5 *
      6 * Licensed under the Apache License, Version 2.0 (the "License");
      7 * you may not use this file except in compliance with the License.
      8 * You may obtain a copy of the License at
      9 *
     10 *    http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing, software
     13 * distributed under the License is distributed on an "AS IS" BASIS,
     14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 * See the License for the specific language governing permissions and
     16 * limitations under the License.
     17 */
     18 
     19 #include "stdlib/math/base/special/sqrt.h"
     20 #include "stdlib/math/base/special/sqrtf.h"
     21 #include "stdlib/strided/dtypes.h"
     22 #include "stdlib/strided/base/function_object.h"
     23 #include "stdlib/strided/base/unary.h"
     24 #include "stdlib/strided/napi/unary.h"
     25 #include <stdint.h>
     26 
     27 // Define an interface name:
     28 static const char name[] = "stdlib_strided_sqrt";
     29 
     30 // Define a list of strided array functions:
     31 static StridedArrayFcn functions[] = {
     32 	// NOTE: these are ordered according to likelihood of use (e.g., more likely that `float64` arrays are provided than `uint8`)
     33 
     34 	// float64
     35 	stdlib_strided_d_d,
     36 
     37 	// float32
     38 	stdlib_strided_f_f,
     39 	stdlib_strided_f_d_as_d_d,
     40 
     41 	// int32
     42 	stdlib_strided_i_d_as_d_d,
     43 
     44 	// int16
     45 	stdlib_strided_k_f_as_f_f,
     46 	stdlib_strided_k_d_as_d_d,
     47 
     48 	// int8
     49 	stdlib_strided_s_f_as_f_f,
     50 	stdlib_strided_s_d_as_d_d,
     51 
     52 	// uint32
     53 	stdlib_strided_u_d_as_d_d,
     54 
     55 	// uint16
     56 	stdlib_strided_t_f_as_f_f,
     57 	stdlib_strided_t_d_as_d_d,
     58 
     59 	// uint8
     60 	stdlib_strided_b_f_as_f_f,
     61 	stdlib_strided_b_d_as_d_d
     62 };
     63 
     64 // Define the **strided array** argument types for each strided array function:
     65 static int32_t types[] = {
     66 	// float64
     67 	STDLIB_STRIDED_FLOAT64, STDLIB_STRIDED_FLOAT64,
     68 
     69 	// float32
     70 	STDLIB_STRIDED_FLOAT32, STDLIB_STRIDED_FLOAT32,
     71 	STDLIB_STRIDED_FLOAT32, STDLIB_STRIDED_FLOAT64,
     72 
     73 	// int32
     74 	STDLIB_STRIDED_INT32, STDLIB_STRIDED_FLOAT64,
     75 
     76 	// int16
     77 	STDLIB_STRIDED_INT16, STDLIB_STRIDED_FLOAT32,
     78 	STDLIB_STRIDED_INT16, STDLIB_STRIDED_FLOAT64,
     79 
     80 	// int8
     81 	STDLIB_STRIDED_INT8, STDLIB_STRIDED_FLOAT32,
     82 	STDLIB_STRIDED_INT8, STDLIB_STRIDED_FLOAT64,
     83 
     84 	// uint32
     85 	STDLIB_STRIDED_UINT32, STDLIB_STRIDED_FLOAT64,
     86 
     87 	// uint16
     88 	STDLIB_STRIDED_UINT16, STDLIB_STRIDED_FLOAT32,
     89 	STDLIB_STRIDED_UINT16, STDLIB_STRIDED_FLOAT64,
     90 
     91 	// uint8
     92 	STDLIB_STRIDED_UINT8, STDLIB_STRIDED_FLOAT32,
     93 	STDLIB_STRIDED_UINT8, STDLIB_STRIDED_FLOAT64
     94 };
     95 
     96 // Define a list of strided array function "data" (in this case, callbacks):
     97 static void *data[] = {
     98 	// float64
     99 	(void *)stdlib_base_sqrt,
    100 
    101 	// float32
    102 	(void *)stdlib_base_sqrtf,
    103 	(void *)stdlib_base_sqrt,
    104 
    105 	// int32
    106 	(void *)stdlib_base_sqrt,
    107 
    108 	// int16
    109 	(void *)stdlib_base_sqrtf,
    110 	(void *)stdlib_base_sqrt,
    111 
    112 	// int8
    113 	(void *)stdlib_base_sqrtf,
    114 	(void *)stdlib_base_sqrt,
    115 
    116 	// uint32
    117 	(void *)stdlib_base_sqrt,
    118 
    119 	// uint16
    120 	(void *)stdlib_base_sqrtf,
    121 	(void *)stdlib_base_sqrt,
    122 
    123 	// uint8
    124 	(void *)stdlib_base_sqrtf,
    125 	(void *)stdlib_base_sqrt
    126 };
    127 
    128 // Create a strided array function object:
    129 static const struct StridedFunctionObject obj = {
    130 	// Strided array function name:
    131 	name,
    132 
    133 	// Number of input strided arrays:
    134 	1,
    135 
    136 	// Number of output strided arrays:
    137 	1,
    138 
    139 	// Total number of strided array arguments (nin + nout):
    140 	2,
    141 
    142 	// Array containing strided array functions:
    143 	functions,
    144 
    145 	// Number of strided array functions:
    146 	13,
    147 
    148 	// Array of type "numbers" (as enumerated elsewhere), where the total number of types equals `narrays * nfunctions` and where each set of `narrays` consecutive types (non-overlapping) corresponds to the set of strided array argument types for a corresponding strided array function:
    149 	types,
    150 
    151 	// Array of void pointers corresponding to the "data" (e.g., callbacks) which should be passed to a respective strided array function (note: the number of pointers should match the number of strided array functions):
    152 	data
    153 };
    154 
    155 STDLIB_STRIDED_NAPI_MODULE_UNARY( obj )