time-to-botec

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

addon.c (6318B)


      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/ceil.h"
     20 #include "stdlib/math/base/special/ceilf.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 /**
     28 * Evaluates the identity function for an unsigned 32-bit integer.
     29 *
     30 * @param x   input value
     31 * @return    input value
     32 */
     33 static uint32_t identity_u( const uint32_t x ) {
     34 	return x;
     35 }
     36 
     37 /**
     38 * Evaluates the identity function for an unsigned 16-bit integer.
     39 *
     40 * @param x   input value
     41 * @return    input value
     42 */
     43 static uint16_t identity_t( const uint16_t x ) {
     44 	return x;
     45 }
     46 
     47 /**
     48 * Evaluates the identity function for an unsigned 8-bit integer.
     49 *
     50 * @param x   input value
     51 * @return    input value
     52 */
     53 static uint8_t identity_b( const uint8_t x ) {
     54 	return x;
     55 }
     56 
     57 /**
     58 * Evaluates the identity function for an signed 32-bit integer.
     59 *
     60 * @param x   input value
     61 * @return    input value
     62 */
     63 static int32_t identity_i( const int32_t x ) {
     64 	return x;
     65 }
     66 
     67 /**
     68 * Evaluates the identity function for an signed 16-bit integer.
     69 *
     70 * @param x   input value
     71 * @return    input value
     72 */
     73 static int16_t identity_k( const int16_t x ) {
     74 	return x;
     75 }
     76 
     77 /**
     78 * Evaluates the identity function for an signed 8-bit integer.
     79 *
     80 * @param x   input value
     81 * @return    input value
     82 */
     83 static int8_t identity_s( const int8_t x ) {
     84 	return x;
     85 }
     86 
     87 // Define an interface name:
     88 static const char name[] = "stdlib_strided_ceil";
     89 
     90 // Define a list of strided array functions:
     91 static StridedArrayFcn functions[] = {
     92 	// NOTE: these are ordered according to likelihood of use (e.g., more likely that `float64` arrays are provided than `uint8`)
     93 
     94 	// float64 (1)
     95 	stdlib_strided_d_d,
     96 
     97 	// float32 (2)
     98 	stdlib_strided_f_f,
     99 	stdlib_strided_f_d,
    100 
    101 	// int32 (2)
    102 	stdlib_strided_i_i,
    103 	stdlib_strided_i_d,
    104 
    105 	// int16 (4)
    106 	stdlib_strided_k_k,
    107 	stdlib_strided_k_i,
    108 	stdlib_strided_k_f,
    109 	stdlib_strided_k_d,
    110 
    111 	// int8 (5)
    112 	stdlib_strided_s_s,
    113 	stdlib_strided_s_k,
    114 	stdlib_strided_s_i,
    115 	stdlib_strided_s_f,
    116 	stdlib_strided_s_d,
    117 
    118 	// uint32 (2)
    119 	stdlib_strided_u_u,
    120 	stdlib_strided_u_d,
    121 
    122 	// uint16 (5)
    123 	stdlib_strided_t_i,
    124 	stdlib_strided_t_t,
    125 	stdlib_strided_t_u,
    126 	stdlib_strided_t_f,
    127 	stdlib_strided_t_d,
    128 
    129 	// uint8 (7)
    130 	stdlib_strided_b_k,
    131 	stdlib_strided_b_i,
    132 	stdlib_strided_b_b,
    133 	stdlib_strided_b_t,
    134 	stdlib_strided_b_u,
    135 	stdlib_strided_b_f,
    136 	stdlib_strided_b_d
    137 };
    138 
    139 // Define the **strided array** argument types for each strided array function:
    140 static int32_t types[] = {
    141 	// float64 (1)
    142 	STDLIB_STRIDED_FLOAT64, STDLIB_STRIDED_FLOAT64,
    143 
    144 	// float32 (2)
    145 	STDLIB_STRIDED_FLOAT32, STDLIB_STRIDED_FLOAT32,
    146 	STDLIB_STRIDED_FLOAT32, STDLIB_STRIDED_FLOAT64,
    147 
    148 	// int32 (2)
    149 	STDLIB_STRIDED_INT32, STDLIB_STRIDED_INT32,
    150 	STDLIB_STRIDED_INT32, STDLIB_STRIDED_FLOAT64,
    151 
    152 	// int16 (4)
    153 	STDLIB_STRIDED_INT16, STDLIB_STRIDED_INT16,
    154 	STDLIB_STRIDED_INT16, STDLIB_STRIDED_INT32,
    155 	STDLIB_STRIDED_INT16, STDLIB_STRIDED_FLOAT32,
    156 	STDLIB_STRIDED_INT16, STDLIB_STRIDED_FLOAT64,
    157 
    158 	// int8 (5)
    159 	STDLIB_STRIDED_INT8, STDLIB_STRIDED_INT8,
    160 	STDLIB_STRIDED_INT8, STDLIB_STRIDED_INT16,
    161 	STDLIB_STRIDED_INT8, STDLIB_STRIDED_INT32,
    162 	STDLIB_STRIDED_INT8, STDLIB_STRIDED_FLOAT32,
    163 	STDLIB_STRIDED_INT8, STDLIB_STRIDED_FLOAT64,
    164 
    165 	// uint32 (2)
    166 	STDLIB_STRIDED_UINT32, STDLIB_STRIDED_UINT32,
    167 	STDLIB_STRIDED_UINT32, STDLIB_STRIDED_FLOAT64,
    168 
    169 	// uint16 (5)
    170 	STDLIB_STRIDED_UINT16, STDLIB_STRIDED_INT32,
    171 	STDLIB_STRIDED_UINT16, STDLIB_STRIDED_UINT16,
    172 	STDLIB_STRIDED_UINT16, STDLIB_STRIDED_UINT32,
    173 	STDLIB_STRIDED_UINT16, STDLIB_STRIDED_FLOAT32,
    174 	STDLIB_STRIDED_UINT16, STDLIB_STRIDED_FLOAT64,
    175 
    176 	// uint8 (7)
    177 	STDLIB_STRIDED_UINT8, STDLIB_STRIDED_INT16,
    178 	STDLIB_STRIDED_UINT8, STDLIB_STRIDED_INT32,
    179 	STDLIB_STRIDED_UINT8, STDLIB_STRIDED_UINT8,
    180 	STDLIB_STRIDED_UINT8, STDLIB_STRIDED_UINT16,
    181 	STDLIB_STRIDED_UINT8, STDLIB_STRIDED_UINT32,
    182 	STDLIB_STRIDED_UINT8, STDLIB_STRIDED_FLOAT32,
    183 	STDLIB_STRIDED_UINT8, STDLIB_STRIDED_FLOAT64
    184 };
    185 
    186 // Define a list of strided array function "data" (in this case, callbacks):
    187 static void *data[] = {
    188 	// float64 (1)
    189 	(void *)stdlib_base_ceil,
    190 
    191 	// float32 (2)
    192 	(void *)stdlib_base_ceilf,
    193 	(void *)stdlib_base_ceilf,
    194 
    195 	// int32 (2)
    196 	(void *)identity_i,
    197 	(void *)identity_i,
    198 
    199 	// int16 (4)
    200 	(void *)identity_k,
    201 	(void *)identity_k,
    202 	(void *)identity_k,
    203 	(void *)identity_k,
    204 
    205 	// int8 (5)
    206 	(void *)identity_s,
    207 	(void *)identity_s,
    208 	(void *)identity_s,
    209 	(void *)identity_s,
    210 	(void *)identity_s,
    211 
    212 	// uint32 (2)
    213 	(void *)identity_u,
    214 	(void *)identity_u,
    215 
    216 	// uint16 (5)
    217 	(void *)identity_t,
    218 	(void *)identity_t,
    219 	(void *)identity_t,
    220 	(void *)identity_t,
    221 	(void *)identity_t,
    222 
    223 	// uint8 (7)
    224 	(void *)identity_b,
    225 	(void *)identity_b,
    226 	(void *)identity_b,
    227 	(void *)identity_b,
    228 	(void *)identity_b,
    229 	(void *)identity_b,
    230 	(void *)identity_b
    231 };
    232 
    233 // Create a strided array function object:
    234 static const struct StridedFunctionObject obj = {
    235 	// Strided array function name:
    236 	name,
    237 
    238 	// Number of input strided arrays:
    239 	1,
    240 
    241 	// Number of output strided arrays:
    242 	1,
    243 
    244 	// Total number of strided array arguments (nin + nout):
    245 	2,
    246 
    247 	// Array containing strided array functions:
    248 	functions,
    249 
    250 	// Number of strided array functions:
    251 	28,
    252 
    253 	// 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:
    254 	types,
    255 
    256 	// 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):
    257 	data
    258 };
    259 
    260 STDLIB_STRIDED_NAPI_MODULE_UNARY( obj )