CUDApp
CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.
Brought by drakestapleton
CUDApp / om / standalone-oracles / oracle.h
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | #ifndef OMEGA_STANDALONE_ORACLE_H |
| 3 | #define OMEGA_STANDALONE_ORACLE_H |
| 4 | #include <stdint.h> |
| 5 | #include <stdlib.h> |
| 6 | #include <string.h> |
| 7 | #include <math.h> |
| 8 | #include "../../src/cudapp_native.h" |
| 9 | #ifndef CUDAPP_MIGRATION_PENDING_C_STANDALONE_ORACLES |
| 10 | #define CUDAPP_MIGRATION_PENDING_C_STANDALONE_ORACLES 0 |
| 11 | #endif |
| 12 | static inline uint32_t so_bits(float f) { uint32_t u; memcpy(&u,&f,4); return u; } |
| 13 | static inline float so_float(uint64_t u) { uint32_t v=(uint32_t)u; float f; memcpy(&f,&v,4); return f; } |
| 14 | static inline double so_double(uint64_t u) { double f; memcpy(&f,&u,8); return f; } |
| 15 | #if CUDAPP_MIGRATION_PENDING_C_STANDALONE_ORACLES |
| 16 | /* Frozen scalar C oracle, deliberately default-OFF. Binary128 references in |
| 17 | * q38-head are separately retained: Omega has no binary128 scalar type. */ |
| 18 | static inline uint64_t so_call(unsigned op,uint64_t a,uint64_t b,uint64_t c,uint64_t d) { |
| 19 | switch(op) { |
| 20 | case 0:return (uint32_t)a*2654435761u; |
| 21 | case 1:return UINT32_MAX-7u*(uint32_t)a; |
| 22 | case 2:return (uint32_t)a+(uint32_t)b; |
| 23 | case 3:return a==b; |
| 24 | case 4:return a&&b&&c; |
| 25 | case 5:return a+b; |
| 26 | case 6:return (a+c)*b; |
| 27 | case 7:return (a+255)/256; |
| 28 | case 8:return a|(b<<32); |
| 29 | case 9:return 2*(b-a); |
| 30 | case 10:return (a==1||(a==2&&b>=1024))?17:0; |
| 31 | case 11:return a==0?4:8; |
| 32 | case 12:return a>1?a-1:0; |
| 33 | case 13:return a<2; |
| 34 | case 14:return a==b&&c==d; |
| 35 | case 15:return a<=64?4:8; |
| 36 | case 16:return a<=64?0:4; |
| 37 | case 17:return UINT64_C(2)<<30; |
| 38 | case 18:return so_bits((float)((int)(a%7)-3)*0.25f); |
| 39 | case 19:return so_bits((float)((int)(a%5)-2)*0.5f); |
| 40 | case 20:{double x=fabs((double)so_float(a)-(double)so_float(b));uint64_t u;memcpy(&u,&x,8);return u;} |
| 41 | case 21:return so_double(a)>1e-4; |
| 42 | case 22:return (uint32_t)a*1664525u+1013904223u; |
| 43 | case 23:return so_bits(((float)((uint32_t)a>>8)/8388608.0f)-1.0f); |
| 44 | case 24:return (a&0x7fffffffu)<0x7f800000u; |
| 45 | case 25:{float x=so_float(a),y=so_float(b&0x7fffffffu);return so_bits(y>x?y:x);} |
| 46 | case 26:return so_bits(b?(float)(a%17):(float)((int)(a%67)-33)); |
| 47 | case 27:return so_bits(b==0?1.0f:b==1?(a==5119?1.0f:0.0f):(a%2?1.0f:-1.0f)); |
| 48 | case 28:return b+!a; |
| 49 | case 29:return so_float(a)>=so_float(b); |
| 50 | case 30:return so_float(a)>so_float(b)?a:b; |
| 51 | case 31:return so_bits((float)((int)(a%173)-90)); |
| 52 | case 32:return so_bits((float)((int)(a%143)-80)); |
| 53 | case 33:return a>b; |
| 54 | case 34:return a<b; |
| 55 | case 35:return a-b; |
| 56 | case 36:return (!a)==(!b); |
| 57 | case 37:return so_float(a)>so_float(b); |
| 58 | case 38:return so_double(a)>so_double(b)?a:b; |
| 59 | case 39:return a%2?(b^0x80000000u):b; |
| 60 | case 40:return (uint64_t)-(int64_t)(a%64); |
| 61 | case 41:return a==0?b:c; |
| 62 | /* op42 narrows only the exactly representable quarter/half fixture inputs. */ |
| 63 | case 42:return a>>16; |
| 64 | case 43:{float x=so_float(b<<16)*so_float(c<<16);return so_bits(so_float(a)+x);} |
| 65 | case 44:return a||b||c; |
| 66 | default:abort(); |
| 67 | } |
| 68 | } |
| 69 | #else |
| 70 | static inline uint64_t so_call(unsigned op,uint64_t a,uint64_t b,uint64_t c,uint64_t d) { |
| 71 | uint64_t value; |
| 72 | if(omega_so_oracles(&value,op,a,b,c,d)) abort(); |
| 73 | return value; |
| 74 | } |
| 75 | #endif |
| 76 | static inline int so_eq(uint64_t a,uint64_t b) { return (int)so_call(3,a,b,0,0); } |
| 77 | static inline int so_all(uint64_t a,uint64_t b,uint64_t c) { return (int)so_call(4,a,b,c,0); } |
| 78 | static inline int so_any(uint64_t a,uint64_t b,uint64_t c) { return (int)so_call(44,a,b,c,0); } |
| 79 | static inline unsigned so_bad(unsigned n,int ok) { return (unsigned)so_call(28,(unsigned)ok,n,0,0); } |
| 80 | static inline size_t so_bytes(uint64_t n,uint64_t size,uint64_t tail) {return (size_t)so_call(6,n,size,tail,0);} |
| 81 | #endif |