File size: 2,728 Bytes
f724cf3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// -----------------------------------------------------------------------------
// The proprietary software and information contained in this file is
// confidential and may only be used by an authorized person under a valid
// licensing agreement from Arm Limited or its affiliates.
//
// Copyright (C) 2025. Arm Limited or its affiliates. All rights reserved.
//
// This entire notice must be reproduced on all copies of this file and
// copies of this file may only be made by an authorized person under a valid
// licensing agreement from Arm Limited or its affiliates.
// -----------------------------------------------------------------------------
//
#ifndef NSS_TYPEDEFS
#define NSS_TYPEDEFS

// fp16 types
#define half  float16_t
#define half2 f16vec2
#define half3 f16vec3
#define half4 f16vec4

// fp32 types
#define float  float32_t
#define float2 f32vec2
#define float3 f32vec3
#define float4 f32vec4

// int8 types
#define int8_t int8_t
#define int8_t2 i8vec2
#define int8_t3 i8vec3
#define int8_t4 i8vec4

// int16 types
#define int16_t  int16_t
#define int16_t2 i16vec2
#define int16_t3 i16vec3
#define int16_t4 i16vec4

// uint16 types
#define uint16_t  uint16_t
#define uint16_t2 u16vec2
#define uint16_t3 u16vec3
#define uint16_t4 u16vec4

// int32 types
#define int32_t  int32_t
#define int32_t2 i32vec2
#define int32_t3 i32vec3
#define int32_t4 i32vec4

// uint32 types
#define uint32_t  uint32_t
#define uint32_t2 u32vec2
#define uint32_t3 u32vec3
#define uint32_t4 u32vec4

// methods
#define lerp mix

// --- RCP functions for float16 types ---
half rcp(half x)     { return half( 1.HF) / x; }
half2 rcp(half2 x)   { return half2(1.HF) / x; }
half3 rcp(half3 x)   { return half3(1.HF) / x; }
half4 rcp(half4 x)   { return half4(1.HF) / x; }

// --- RCP functions for float32 types ---
float rcp(float x)   { return float( 1.0f) / x; }
float2 rcp(float2 x) { return float2(1.0f) / x; }
float3 rcp(float3 x) { return float3(1.0f) / x; }
float4 rcp(float4 x) { return float4(1.0f) / x; }

// --- Saturate functions for float16 types ---
half   saturate(half x)     { return clamp(x, half( 0.HF), half( 1.HF)); }
half2  saturate(half2 x)    { return clamp(x, half2(0.HF), half2(1.HF)); }
half3  saturate(half3 x)    { return clamp(x, half3(0.HF), half3(1.HF)); }
half4  saturate(half4 x)    { return clamp(x, half4(0.HF), half4(1.HF)); }

// --- Saturate functions for float32 types ---
float   saturate(float x)     { return clamp(x, 0.f, 1.f); }
float2  saturate(float2 x)    { return clamp(x, float2(0.f), float2(1.f)); }
float3  saturate(float3 x)    { return clamp(x, float3(0.f), float3(1.f)); }
float4  saturate(float4 x)    { return clamp(x, float4(0.f), float4(1.f)); }

#endif  // NSS_TYPEDEFS